#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*/ WEXITSTATUS(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ load_lm32_child(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int load_lm32_main(char *fname) {
  int pid = fork();
  int status;
  switch (pid) {
  case -1:
    fprintf(stderr, "fork(): %s\n", strerror(errno));
    return -1;
  case 0:
    load_lm32_child(fname);
    exit(0);
  default:
    waitpid(pid, &status, 0);
    if (!WEXITSTATUS(status))
      return 0;
    return -1;
  }
}


x86 assembly (clang, -O0):
<load_lm32_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     11aa <load_lm32_main+0x3a>
jmp    119a <load_lm32_main+0x2a>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
je     11e2 <load_lm32_main+0x72>
jmp    11f2 <load_lm32_main+0x82>
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe2f(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1224 <load_lm32_main+0xb4>
mov    -0x10(%rbp),%rdi
call   1040 <load_lm32_child@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    -0x18(%rbp),%edi
call   1050 <WEXITSTATUS@plt>
cmp    $0x0,%eax
jne    121d <load_lm32_main+0xad>
movl   $0x0,-0x4(%rbp)
jmp    1224 <load_lm32_main+0xb4>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_lm32_main>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11a5 <load_lm32_main+0x35>
test   %eax,%eax
je     11d8 <load_lm32_main+0x68>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1060 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1050 <WEXITSTATUS@plt>
neg    %eax
sbb    %eax,%eax
jmp    11d2 <load_lm32_main+0x62>
mov    0x2e34(%rip),%rax
mov    (%rax),%ebx
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe3d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    %rbx,%rdi
call   1040 <load_lm32_child@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [12 x i8] c"fork(): %s\0A\00"
@errno = global i32 0
define i32 @load_lm32_main(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = call i32 (...) @fork()
store i32 %6, i32* %4
%7 = load i32, i32* %4
switch i32 %7, label %17 [
i32 -1, label %8
i32 0, label %13
]
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 -1, i32* %2
br label %25
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @load_lm32_child(i8* %14)
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %1
%18 = load i32, i32* %4
%19 = call i32 @waitpid(i32 %18, i32* %5, i32 0)
%20 = load i32, i32* %5
%21 = call i32 @WEXITSTATUS(i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %24, label %23
23: ; preds = %17
store i32 0, i32* %2
br label %25
24: ; preds = %17
store i32 -1, i32* %2
br label %25
25: ; preds = %24, %23, %8
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"fork(): %s\0A\00"
@errno = global i32 0
define i32 @load_lm32_main(i8* %0) {
%2 = alloca i32
%3 = tail call i32 (...) @fork()
%4 = bitcast i32* %2 to i8*
switch i32 %3, label %13 [
i32 -1, label %5
i32 0, label %10
]
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %19
10: ; preds = %1
%11 = tail call i32 @load_lm32_child(i8* %0)
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %1
%14 = call i32 @waitpid(i32 %3, i32* %2, i32 0)
%15 = load i32, i32* %2
%16 = call i32 @WEXITSTATUS(i32 %15)
%17 = icmp ne i32 %16, 0
%18 = sext i1 %17 to i32
br label %19
19: ; preds = %13, %5
%20 = phi i32 [ -1, %5 ], [ %18, %13 ]
ret i32 %20
}