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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int /*<<< orphan*/ printf(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void gen_exit(void) {
  pid_t pid;
  pid = fork();
  if (pid == 0) {
    printf("exit pid: %d exit_code: %d\n", getpid(), 0);
    exit(0);
  } else if (pid < 0) {
    fprintf(stderr, "fork() failed\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<gen_exit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118c <gen_exit+0x3c>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe82(%rip),%rdi
xor    %edx,%edx
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x8(%rbp)
jge    11b6 <gen_exit+0x66>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11bb <gen_exit+0x6b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_exit>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1161 <gen_exit+0x11>
js     117f <gen_exit+0x2f>
pop    %rax
ret
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe91(%rip),%rdi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"exit pid: %d exit_code: %d\0A\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"fork() failed\0A\00"
define void @gen_exit() {
%1 = alloca i64
%2 = call i64 (...) @fork()
store i64 %2, i64* %1
%3 = load i64, i64* %1
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = call i32 (...) @getpid()
%7 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %6, i32 0)
%8 = call i32 @exit(i32 0)
unreachable
9: ; preds = %0
%10 = load i64, i64* %1
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %9
br label %17
17: ; preds = %16
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"exit pid: %d exit_code: %d\0A\00"
@stderr = global i32 0
@.str.1 = [15 x i8] c"fork() failed\0A\00"
define void @gen_exit() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %4, i32 0)
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %0
%8 = icmp slt i64 %1, 0
br i1 %8, label %9, label %13
9: ; preds = %7
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7
ret void
}