#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 pid_t;

/* Variables and functions */
int /*<<< orphan*/ child_process();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t child_pid;
  child_pid = fork();
  if (child_pid == 0) {
    child_process();
  } else if (child_pid == -1) {
    fprintf(stderr, "Oops... Labour pain. Cannot give birth to child: %s\n",
            strerror(errno));
    exit(1);
  } else {
    printf("I am suffering Batman's parents fate. Goodbye my child %u\n",
           child_pid);
  }
  sleep(1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11a6 <main+0x36>
mov    $0x0,%al
call   1040 <child_process@plt>
jmp    11fa <main+0x8a>
cmpl   $0xffffffff,-0x14(%rbp)
jne    11e6 <main+0x76>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe29(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%esi
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
jmp    11fa <main+0x8a>
mov    $0x1,%edi
call   1080 <sleep@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     1191 <main+0x21>
cmp    $0xffffffff,%eax
je     11a6 <main+0x36>
lea    0xead(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
jmp    1198 <main+0x28>
xor    %eax,%eax
call   1040 <child_process@plt>
mov    $0x1,%edi
call   1080 <sleep@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e33(%rip),%rax
mov    (%rax),%ebx
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe3c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"Oops... Labour pain. Cannot give birth to child: %s\0A\00"
@errno = global i32 0
@.str.1 = [59 x i8] c"I am suffering Batman's parents fate. Goodbye my child %u\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @fork()
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (...) @child_process()
br label %25
12: ; preds = %2
%13 = load i32, i32* %6
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = load i32, i32* %6
%23 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21
br label %25
25: ; preds = %24, %10
%26 = call i32 @sleep(i32 1)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"Oops... Labour pain. Cannot give birth to child: %s\0A\00"
@errno = global i32 0
@.str.1 = [59 x i8] c"I am suffering Batman's parents fate. Goodbye my child %u\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %12 [
i32 0, label %4
i32 -1, label %6
]
4: ; preds = %2
%5 = tail call i32 (...) @child_process()
br label %14
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = tail call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i32 %3)
br label %14
14: ; preds = %12, %4
%15 = tail call i32 @sleep(i32 1)
ret i32 0
}