void mini_crt_entry(void) {
  long ret;
  long argc;
  char **argv;
  char *ebp_reg = 0;
  asm("movq %%rbp,%0 \n" : "=r"(ebp_reg));
  argc = *(long *)(ebp_reg + 4);
  argv = (char **)(ebp_reg + 8);
  if (!mini_crt_init_heap()) {
    crt_fatal_error("heap initalize failed");
  }
  if (!mini_crt_init_io()) {
    crt_fatal_error("IO initalize failed");
  }
  ret = main(argc, argv);
  exit(ret);
}


x86 assembly (clang, -O0):
<mini_crt_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x20(%rbp)
mov    %rbp,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <mini_crt_init_heap@plt>
cmp    $0x0,%eax
jne    119d <mini_crt_entry+0x4d>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1060 <crt_fatal_error@plt>
mov    $0x0,%al
call   1030 <mini_crt_init_io@plt>
cmp    $0x0,%eax
jne    11bb <mini_crt_entry+0x6b>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1060 <crt_fatal_error@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1050 <main@plt>
cltq
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<mini_crt_entry>:
push   %r14
push   %rbx
push   %rax
mov    %rbp,%rbx
mov    0x4(%rbx),%r14
xor    %eax,%eax
call   1040 <mini_crt_init_heap@plt>
test   %eax,%eax
jne    1174 <mini_crt_entry+0x24>
lea    0xe93(%rip),%rdi
xor    %eax,%eax
call   1060 <crt_fatal_error@plt>
xor    %eax,%eax
call   1030 <mini_crt_init_io@plt>
test   %eax,%eax
jne    118d <mini_crt_entry+0x3d>
lea    0xe90(%rip),%rdi
xor    %eax,%eax
call   1060 <crt_fatal_error@plt>
add    $0x8,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <main@plt>
mov    %eax,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"heap initalize failed\00"
@.str.1 = [20 x i8] c"IO initalize failed\00"
define void @mini_crt_entry() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i8**
%4 = alloca i8*
store i8* null, i8** %4
%5 = call i8* asm "movq %rbp,$0 \0A", "=r,~{dirflag},~{fpsr},~{flags}"()
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = getelementptr inbounds i8, i8* %6, i64 4
%8 = bitcast i8* %7 to i64*
%9 = load i64, i64* %8
store i64 %9, i64* %2
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i64 8
%12 = bitcast i8* %11 to i8**
store i8** %12, i8*** %3
%13 = call i32 (...) @mini_crt_init_heap()
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %0
%16 = call i32 (i8*, ...) bitcast (i32 (...)* @crt_fatal_error to i32 (i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %0
%18 = call i32 (...) @mini_crt_init_io()
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 (i8*, ...) bitcast (i32 (...)* @crt_fatal_error to i32 (i8*, ...)*)(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = load i64, i64* %2
%24 = load i8**, i8*** %3
%25 = call i32 (i64, i8**, ...) bitcast (i32 (...)* @main to i32 (i64, i8**, ...)*)(i64 %23, i8** %24)
%26 = sext i32 %25 to i64
store i64 %26, i64* %1
%27 = load i64, i64* %1
%28 = trunc i64 %27 to i32
unreachable
}

LLVM IR (-O2):
@.str = [22 x i8] c"heap initalize failed\00"
@.str.1 = [20 x i8] c"IO initalize failed\00"
define void @mini_crt_entry() {
%1 = tail call i8* asm "movq %rbp,$0 \0A", "=r,~{dirflag},~{fpsr},~{flags}"()
%2 = getelementptr inbounds i8, i8* %1, i64 4
%3 = bitcast i8* %2 to i64*
%4 = load i64, i64* %3
%5 = tail call i32 (...) @mini_crt_init_heap()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 (i8*, ...) bitcast (i32 (...)* @crt_fatal_error to i32 (i8*, ...)*)(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = tail call i32 (...) @mini_crt_init_io()
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 (i8*, ...) bitcast (i32 (...)* @crt_fatal_error to i32 (i8*, ...)*)(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = getelementptr inbounds i8, i8* %1, i64 8
%16 = bitcast i8* %15 to i8**
%17 = tail call i32 (i64, i8**, ...) bitcast (i32 (...)* @main to i32 (i64, i8**, ...)*)(i64 %4, i8** %16)
tail call void @exit(i32 %17)
unreachable
}