#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *malloc(int);
int /*<<< orphan*/ min_caml_start(char *, char *);
int /*<<< orphan*/ stderr;
int main() {
  char *hp, *sp;
  sp = malloc(4000000);
  hp = malloc(4000000);
  if (hp == NULL || sp == NULL) {
    fprintf(stderr, "malloc failed\n");
    return 1;
  }
  fprintf(stderr, "sp = %p, hp = %p\n", sp, hp);
  min_caml_start(sp, hp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x3d0900,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x3d0900,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1171 <main+0x41>
cmpq   $0x0,-0x18(%rbp)
jne    1194 <main+0x64>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c7 <main+0x97>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <min_caml_start@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    $0x3d0900,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    $0x3d0900,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
test   %rbx,%rbx
je     1184 <main+0x54>
test   %r14,%r14
je     1184 <main+0x54>
lea    0xea7(%rip),%rsi
xor    %ebp,%ebp
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <min_caml_start@plt>
jmp    1197 <main+0x67>
lea    0xe75(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"malloc failed\0A\00"
@.str.1 = [18 x i8] c"sp = %p, hp = %p\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i8* @malloc(i32 4000000)
store i8* %4, i8** %3
%5 = call i8* @malloc(i32 4000000)
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = load i8*, i8** %3
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8, %0
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %22
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %3
%17 = load i8*, i8** %2
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17)
%19 = load i8*, i8** %3
%20 = load i8*, i8** %2
%21 = call i32 @min_caml_start(i8* %19, i8* %20)
store i32 0, i32* %1
br label %22
22: ; preds = %14, %11
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"malloc failed\0A\00"
@.str.1 = [18 x i8] c"sp = %p, hp = %p\0A\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(4000000) i8* @malloc(i32 4000000)
%2 = tail call dereferenceable_or_null(4000000) i8* @malloc(i32 4000000)
%3 = icmp eq i8* %2, null
%4 = icmp eq i8* %1, null
%5 = or i1 %4, %3
%6 = load i32, i32* @stderr
br i1 %5, label %7, label %9
7: ; preds = %0
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %12
9: ; preds = %0
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2)
%11 = tail call i32 @min_caml_start(i8* %1, i8* %2)
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ 1, %7 ], [ 0, %9 ]
ret i32 %13
}