#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*/ abort_exit();
int /*<<< orphan*/ abort_normal();
int /*<<< orphan*/ err_sys(char *, ...);
scalar_t__ fork();
int /*<<< orphan*/ pr_exit(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ wait(int *);
int main(int argc, char **argv) {
  pid_t pid;
  int status;
  if ((pid = fork()) < 0) {
    err_sys("fork() error");
  } else if (pid == 0) {
    printf("I am child NO1, and I am going by calling abort_normal()\n");
    abort_normal();
  }
  if (wait(&status) != pid) {
    err_sys("wait error on processs %d", pid);
  }
  pr_exit(status);
  if ((pid = fork()) < 0) {
    err_sys("fork() error");
  } else if (pid == 0) {
    printf("I am child NO2, and I am going by calling abort_exit()\n");
    abort_exit();
  }
  if (wait(&status) != pid) {
    err_sys("wait error on processs %d", pid);
  }
  pr_exit(status);
  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   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    11ae <main+0x3e>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
jmp    11d1 <main+0x61>
cmpq   $0x0,-0x18(%rbp)
jne    11cc <main+0x5c>
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <abort_normal@plt>
jmp    11d1 <main+0x61>
lea    -0x1c(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x18(%rbp),%rax
je     11f6 <main+0x86>
mov    -0x18(%rbp),%rsi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
mov    -0x1c(%rbp),%edi
call   1050 <pr_exit@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jge    1226 <main+0xb6>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
jmp    1249 <main+0xd9>
cmpq   $0x0,-0x18(%rbp)
jne    1244 <main+0xd4>
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <abort_exit@plt>
jmp    1249 <main+0xd9>
lea    -0x1c(%rbp),%rdi
call   1070 <wait@plt>
cmp    -0x18(%rbp),%rax
je     126e <main+0xfe>
mov    -0x18(%rbp),%rsi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <err_sys@plt>
mov    -0x1c(%rbp),%edi
call   1050 <pr_exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
js     119b <main+0x2b>
jne    11a9 <main+0x39>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <abort_normal@plt>
jmp    11a9 <main+0x39>
lea    0xe5e(%rip),%rdi
xor    %eax,%eax
call   1040 <err_sys@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
je     11c9 <main+0x59>
lea    0xe4e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <err_sys@plt>
mov    0xc(%rsp),%edi
call   1050 <pr_exit@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
js     11f8 <main+0x88>
jne    1206 <main+0x96>
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <abort_exit@plt>
jmp    1206 <main+0x96>
lea    0xe01(%rip),%rdi
xor    %eax,%eax
call   1040 <err_sys@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    %rbx,%rax
je     1226 <main+0xb6>
lea    0xdf1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <err_sys@plt>
mov    0xc(%rsp),%edi
call   1050 <pr_exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"fork() error\00"
@.str.1 = [58 x i8] c"I am child NO1, and I am going by calling abort_normal()\0A\00"
@.str.2 = [26 x i8] c"wait error on processs %d\00"
@.str.3 = [56 x i8] c"I am child NO2, and I am going by calling abort_exit()\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i64 (...) @fork()
store i64 %8, i64* %6
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %19
12: ; preds = %2
%13 = load i64, i64* %6
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 (...) @abort_normal()
br label %18
18: ; preds = %15, %12
br label %19
19: ; preds = %18, %10
%20 = call i64 @wait(i32* %7)
%21 = load i64, i64* %6
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i64, i64* %6
%25 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i64 %24)
br label %26
26: ; preds = %23, %19
%27 = load i32, i32* %7
%28 = call i32 @pr_exit(i32 %27)
%29 = call i64 (...) @fork()
store i64 %29, i64* %6
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %40
33: ; preds = %26
%34 = load i64, i64* %6
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = call i32 @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%38 = call i32 (...) @abort_exit()
br label %39
39: ; preds = %36, %33
br label %40
40: ; preds = %39, %31
%41 = call i64 @wait(i32* %7)
%42 = load i64, i64* %6
%43 = icmp ne i64 %41, %42
br i1 %43, label %44, label %47
44: ; preds = %40
%45 = load i64, i64* %6
%46 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i64 %45)
br label %47
47: ; preds = %44, %40
%48 = load i32, i32* %7
%49 = call i32 @pr_exit(i32 %48)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"fork() error\00"
@.str.2 = [26 x i8] c"wait error on processs %d\00"
@str = [55 x i8] c"I am child NO2, and I am going by calling abort_exit()\00"
@str.4 = [57 x i8] c"I am child NO1, and I am going by calling abort_normal()\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 (...) @fork()
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %14
9: ; preds = %2
%10 = icmp eq i64 %5, 0
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.4, i64 0, i64 0))
%13 = tail call i32 (...) @abort_normal()
br label %14
14: ; preds = %9, %11, %7
%15 = call i64 @wait(i32* %3)
%16 = icmp eq i64 %15, %5
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i64 %5)
br label %19
19: ; preds = %17, %14
%20 = load i32, i32* %3
%21 = call i32 @pr_exit(i32 %20)
%22 = call i64 (...) @fork()
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %31
26: ; preds = %19
%27 = icmp eq i64 %22, 0
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
%30 = call i32 (...) @abort_exit()
br label %31
31: ; preds = %26, %28, %24
%32 = call i64 @wait(i32* %3)
%33 = icmp eq i64 %32, %22
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = call i32 (i8*, ...) @err_sys(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i64 %22)
br label %36
36: ; preds = %34, %31
%37 = load i32, i32* %3
%38 = call i32 @pr_exit(i32 %37)
ret i32 0
}