#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*/ SIGTERM;
int /*<<< orphan*/ execlp(char *, char *, char *, ...);
scalar_t__ fork();
int /*<<< orphan*/ kill(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ printf(char *);
int waitpid(int, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  pid_t p;
  if (fork() == 0) {
    printf("hello, parent!\n");
    return 1;
  }
  if ((p = fork()) == 0) {
    pause();
    return 1;
  }
  if (fork() == 0) {
    volatile int *a = 0;
    *a = 1;
    return 1;
  }
  if (fork() == 0) {
    execlp("/bin/echo", "echo", "-n", NULL);
    return 1;
  }
  if (fork() == 0) {
    execlp("./hello", "hello", NULL);
    return 1;
  }
  kill(p, SIGTERM);
  while (waitpid(-1, 0, 0) != -1)
    ;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
jne    1198 <main+0x38>
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1297 <main+0x137>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11c0 <main+0x60>
mov    $0x0,%al
call   1050 <pause@plt>
movl   $0x1,-0x4(%rbp)
jmp    1297 <main+0x137>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
jne    11ef <main+0x8f>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1297 <main+0x137>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
jne    122c <main+0xcc>
lea    0xe09(%rip),%rdi
lea    0xe07(%rip),%rsi
lea    0xe05(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x0,%al
call   1070 <execlp@plt>
movl   $0x1,-0x4(%rbp)
jmp    1297 <main+0x137>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
jne    1262 <main+0x102>
lea    0xdd9(%rip),%rdi
lea    0xdd4(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   1070 <execlp@plt>
movl   $0x1,-0x4(%rbp)
jmp    1297 <main+0x137>
mov    -0x10(%rbp),%rdi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
mov    $0xffffffff,%edi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <waitpid@plt>
cmp    $0xffffffff,%eax
je     1290 <main+0x130>
jmp    1274 <main+0x114>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11d5 <main+0x75>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11e3 <main+0x83>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11ec <main+0x8c>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11f9 <main+0x99>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1219 <main+0xb9>
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <kill@plt>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xffffffff,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x60>
jmp    1235 <main+0xd5>
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
jmp    1230 <main+0xd0>
xor    %eax,%eax
call   1050 <pause@plt>
jmp    1230 <main+0xd0>
movl   $0x1,0x0
jmp    1230 <main+0xd0>
lea    0xe00(%rip),%rdi
lea    0xdfe(%rip),%rsi
lea    0xdfc(%rip),%rdx
xor    %ecx,%ecx
xor    %eax,%eax
call   1070 <execlp@plt>
jmp    1230 <main+0xd0>
lea    0xded(%rip),%rdi
lea    0xde8(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <execlp@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"hello, parent!\0A\00"
@.str.1 = [10 x i8] c"/bin/echo\00"
@.str.2 = [5 x i8] c"echo\00"
@.str.3 = [3 x i8] c"-n\00"
@.str.4 = [8 x i8] c"./hello\00"
@.str.5 = [6 x i8] c"hello\00"
@SIGTERM = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %37
8: ; preds = %0
%9 = call i64 (...) @fork()
store i64 %9, i64* %2
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = call i32 (...) @pause()
store i32 1, i32* %1
br label %37
13: ; preds = %8
%14 = call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
store i32* null, i32** %3
%17 = load i32*, i32** %3
store volatile i32 1, i32* %17
store i32 1, i32* %1
br label %37
18: ; preds = %13
%19 = call i64 (...) @fork()
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* null)
store i32 1, i32* %1
br label %37
23: ; preds = %18
%24 = call i64 (...) @fork()
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* null)
store i32 1, i32* %1
br label %37
28: ; preds = %23
%29 = load i64, i64* %2
%30 = load i32, i32* @SIGTERM
%31 = call i32 @kill(i64 %29, i32 %30)
br label %32
32: ; preds = %35, %28
%33 = call i32 @waitpid(i32 -1, i32 0, i32 0)
%34 = icmp ne i32 %33, -1
br i1 %34, label %35, label %36
35: ; preds = %32
br label %32
36: ; preds = %32
store i32 0, i32* %1
br label %37
37: ; preds = %36, %26, %21, %16, %11, %6
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"/bin/echo\00"
@.str.2 = [5 x i8] c"echo\00"
@.str.3 = [3 x i8] c"-n\00"
@.str.4 = [8 x i8] c"./hello\00"
@.str.5 = [6 x i8] c"hello\00"
@SIGTERM = global i32 0
@str = [15 x i8] c"hello, parent!\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %30
5: ; preds = %0
%6 = tail call i64 (...) @fork()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 (...) @pause()
br label %30
10: ; preds = %5
%11 = tail call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store volatile i32 1, i32* null
br label %30
14: ; preds = %10
%15 = tail call i64 (...) @fork()
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* null)
br label %30
19: ; preds = %14
%20 = tail call i64 (...) @fork()
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* null)
br label %30
24: ; preds = %19
%25 = load i32, i32* @SIGTERM
%26 = tail call i32 @kill(i64 %6, i32 %25)
br label %27
27: ; preds = %27, %24
%28 = tail call i32 @waitpid(i32 -1, i32 0, i32 0)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %27
30: ; preds = %27, %22, %17, %13, %8, %3
%31 = phi i32 [ 1, %3 ], [ 1, %8 ], [ 1, %13 ], [ 1, %17 ], [ 1, %22 ], [ 0, %27 ]
ret i32 %31
}