#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ bootstrap(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snapshotRead(int /*<<< orphan*/ *);
int /*<<< orphan*/ snapshotWrite(int /*<<< orphan*/ *);
void bootstrapSmalltalk(char *snapshotFileName, char *bootstrapDir) {
  FILE *snapshot;
  if (bootstrapDir) {
    snapshot = fopen(snapshotFileName, "w+");
    if (snapshot == NULL) {
      printf("Cannot write to snapshot file: '%s'\n", snapshotFileName);
      exit(EXIT_FAILURE);
    }
    if (!bootstrap(bootstrapDir)) {
      printf("Bootstrap failed\n");
      exit(EXIT_FAILURE);
    }
    snapshotWrite(snapshot);
  } else {
    snapshot = fopen(snapshotFileName, "r");
    if (snapshot == NULL) {
      printf("Cannot read snapshot file: '%s'\n", snapshotFileName);
      exit(EXIT_FAILURE);
    }
    snapshotRead(snapshot);
  }
  fclose(snapshot);
}


x86 assembly (clang, -O0):
<bootstrapSmalltalk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1206 <bootstrapSmalltalk+0x96>
mov    -0x8(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ca <bootstrapSmalltalk+0x5a>
mov    -0x8(%rbp),%rsi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1060 <bootstrap@plt>
cmp    $0x0,%eax
jne    11f8 <bootstrapSmalltalk+0x88>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1090 <snapshotWrite@plt>
jmp    124e <bootstrapSmalltalk+0xde>
mov    -0x8(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1245 <bootstrapSmalltalk+0xd5>
mov    -0x8(%rbp),%rsi
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1050 <snapshotRead@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bootstrapSmalltalk>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
test   %rsi,%rsi
je     11bd <bootstrapSmalltalk+0x3d>
mov    %rsi,%r15
lea    0xe69(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e9 <bootstrapSmalltalk+0x69>
mov    %rax,%rbx
mov    %r15,%rdi
call   1070 <bootstrap@plt>
test   %eax,%eax
je     11f2 <bootstrapSmalltalk+0x72>
mov    %rbx,%rdi
call   10a0 <snapshotWrite@plt>
jmp    11dc <bootstrapSmalltalk+0x5c>
lea    0xe64(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1200 <bootstrapSmalltalk+0x80>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <snapshotRead@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>
lea    0xe13(%rip),%rdi
jmp    1207 <bootstrapSmalltalk+0x87>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
jmp    1211 <bootstrapSmalltalk+0x91>
lea    0xe23(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
@.str.1 = [37 x i8] c"Cannot write to snapshot file: '%s'\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [18 x i8] c"Bootstrap failed\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [33 x i8] c"Cannot read snapshot file: '%s'\0A\00"
define void @bootstrapSmalltalk(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %29
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %8
%19 = load i8*, i8** %4
%20 = call i32 @bootstrap(i8* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %18
%27 = load i32*, i32** %5
%28 = call i32 @snapshotWrite(i32* %27)
br label %42
29: ; preds = %2
%30 = load i8*, i8** %3
%31 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %31, i32** %5
%32 = load i32*, i32** %5
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = load i8*, i8** %3
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %29
%40 = load i32*, i32** %5
%41 = call i32 @snapshotRead(i32* %40)
br label %42
42: ; preds = %39, %26
%43 = load i32*, i32** %5
%44 = call i32 @fclose(i32* %43)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@.str.1 = [37 x i8] c"Cannot write to snapshot file: '%s'\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [33 x i8] c"Cannot read snapshot file: '%s'\0A\00"
@str = [17 x i8] c"Bootstrap failed\00"
define void @bootstrapSmalltalk(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %20, label %4
4: ; preds = %2
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %4
%12 = tail call i32 @bootstrap(i8* %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %11
%19 = tail call i32 @snapshotWrite(i32* %5)
br label %29
20: ; preds = %2
%21 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %20
%28 = tail call i32 @snapshotRead(i32* %21)
br label %29
29: ; preds = %27, %18
%30 = phi i32* [ %5, %18 ], [ %21, %27 ]
%31 = tail call i32 @fclose(i32* %30)
ret void
}