mainDef :: Global
mainDef =
    functionDefaults
    { G.returnType = IntegerType 32
    , G.parameters =
        ([ Parameter (IntegerType 32) (Name "argc") []
         , Parameter (PointerType (PointerType (IntegerType 8) (AddrSpace 0)) (AddrSpace 0)) (Name "argv") []
         ], False)
    , G.name = Name "main"
    , G.basicBlocks =
        [ BasicBlock (UnName 0)
          [ Do $ simpleCall "GC_init" [] -- Initialize Boehm GC
          , Do $ simpleCall "__gmp_set_memory_functions"
                     [ ConstantOperand . C.GlobalReference . Name $ "__idris_gmpMalloc"
                     , ConstantOperand . C.GlobalReference . Name $ "__idris_gmpRealloc"
                     , ConstantOperand . C.GlobalReference . Name $ "__idris_gmpFree"
                     ]
          , Do $ Store False (ConstantOperand . C.GlobalReference . Name $ "__idris_argc") 
                       (LocalReference (Name "argc")) Nothing 0 []
          , Do $ Store False (ConstantOperand . C.GlobalReference . Name $ "__idris_argv") 
                       (LocalReference (Name "argv")) Nothing 0 []
          , UnName 1 := idrCall "{runMain0}" [] ]
          (Do $ Ret (Just (ConstantOperand (C.Int 32 0))) [])
        ]}
mainDef :: Global
mainDef =
    functionDefaults
    { G.returnType = IntegerType 32
    , G.parameters =
        ([ Parameter (IntegerType 32) (Name "argc") []
         , Parameter (PointerType (PointerType (IntegerType 8) (AddrSpace 0)) (AddrSpace 0)) (Name "argv") []
         ], False)
    , G.name = Name "main"
    , G.basicBlocks =
        [ BasicBlock (UnName 0)
          [ Do $ simpleCall "GC_init" [] -- Initialize Boehm GC
          , Do $ simpleCall "__gmp_set_memory_functions"
                     [ ConstantOperand . C.GlobalReference . Name $ "__idris_gmpMalloc"
                     , ConstantOperand . C.GlobalReference . Name $ "__idris_gmpRealloc"
                     , ConstantOperand . C.GlobalReference . Name $ "__idris_gmpFree"
                     ]
          , Do $ Store False (ConstantOperand . C.GlobalReference . Name $ "__idris_argc") 
                       (LocalReference (Name "argc")) Nothing 0 []
          , Do $ Store False (ConstantOperand . C.GlobalReference . Name $ "__idris_argv") 
                       (LocalReference (Name "argv")) Nothing 0 []
          , UnName 1 := idrCall "{runMain0}" [] ]
          (Do $ Ret (Just (ConstantOperand (C.Int 32 0))) [])
        ]}
mainDef =
    functionDefaults
    { G.returnType = IntegerType 32
    , G.parameters =
        ([ Parameter (IntegerType 32) (Name "argc") []
         , Parameter (PointerType (PointerType (IntegerType 8) (AddrSpace 0)) (AddrSpace 0)) (Name "argv") []
         ], False)
    , G.name = Name "main"
    , G.basicBlocks =
        [ BasicBlock (UnName 0)
          [ Do $ simpleCall "GC_init" [] -- Initialize Boehm GC
          , Do $ simpleCall "__gmp_set_memory_functions"
                     [ ConstantOperand . C.GlobalReference . Name $ "__idris_gmpMalloc"
                     , ConstantOperand . C.GlobalReference . Name $ "__idris_gmpRealloc"
                     , ConstantOperand . C.GlobalReference . Name $ "__idris_gmpFree"
                     ]
          , Do $ Store False (ConstantOperand . C.GlobalReference . Name $ "__idris_argc") 
                       (LocalReference (Name "argc")) Nothing 0 []
          , Do $ Store False (ConstantOperand . C.GlobalReference . Name $ "__idris_argv") 
                       (LocalReference (Name "argv")) Nothing 0 []
          , UnName 1 := idrCall "{runMain0}" [] ]
          (Do $ Ret (Just (ConstantOperand (C.Int 32 0))) [])
        ]}