#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 WEXITSTATUS(int);
scalar_t__ WIFCONTINUED(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ WIFSTOPPED(int);
int WSTOPSIG(int);
int WTERMSIG(int);
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int pid;
  pid = fork();
  if (pid < 0) {
    perror("fork error");
    exit(1);
  } else if (pid == 0) {
    execl("./newprogram", "", NULL);
    printf("never\n");
  } else {
    int status;
    int w = waitpid(pid, &status, 0);
    if (w == -1) {
      perror("waitpid");
      exit(2);
    }
    if (WIFEXITED(status)) {
      printf("exited, status=%d\n", WEXITSTATUS(status));
    } else if (WIFSIGNALED(status)) {
      printf("killed by signal %d\n", WTERMSIG(status));
    } else if (WIFSTOPPED(status)) {
      printf("stopped by signal %d\n", WSTOPSIG(status));
    } else if (WIFCONTINUED(status)) {
      printf("continued\n");
    }
    printf("Parent process: child exit: %d\n", 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   10f0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1210 <main+0x40>
lea    0xdff(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    1244 <main+0x74>
lea    0xdea(%rip),%rdi
lea    0xe67(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10d0 <execl@plt>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1342 <main+0x172>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1275 <main+0xa5>
lea    0xdb9(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x2,%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%edi
call   10b0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     12a4 <main+0xd4>
mov    -0x18(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1331 <main+0x161>
mov    -0x18(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     12d3 <main+0x103>
mov    -0x18(%rbp),%edi
call   1070 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    132c <main+0x15c>
mov    -0x18(%rbp),%edi
call   1060 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     1302 <main+0x132>
mov    -0x18(%rbp),%edi
call   10e0 <WSTOPSIG@plt>
mov    %eax,%esi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1327 <main+0x157>
mov    -0x18(%rbp),%edi
call   1050 <WIFCONTINUED@plt>
cmp    $0x0,%rax
je     1322 <main+0x152>
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1327 <main+0x157>
jmp    132c <main+0x15c>
jmp    1331 <main+0x161>
mov    -0x18(%rbp),%esi
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1347 <main+0x177>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1100 <fork@plt>
test   %eax,%eax
js     12b9 <main+0xd9>
je     1229 <main+0x49>
lea    0x4(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   10a0 <waitpid@plt>
cmp    $0xffffffff,%eax
je     12cf <main+0xef>
mov    0x4(%rsp),%edi
call   10c0 <WIFEXITED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     124c <main+0x6c>
call   1090 <WEXITSTATUS@plt>
lea    0xdf9(%rip),%rdi
jmp    1282 <main+0xa2>
lea    0xddb(%rip),%rdi
lea    0xe46(%rip),%rsi
xor    %edx,%edx
call   10e0 <execl@plt>
lea    0xe43(%rip),%rdi
call   1030 <puts@plt>
jmp    129d <main+0xbd>
call   1050 <WIFSIGNALED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     1268 <main+0x88>
call   1080 <WTERMSIG@plt>
lea    0xdcd(%rip),%rdi
jmp    1282 <main+0xa2>
call   1070 <WIFSTOPPED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     12a1 <main+0xc1>
call   10f0 <WSTOPSIG@plt>
lea    0xdc6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xdc8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
call   1060 <WIFCONTINUED@plt>
test   %rax,%rax
je     128b <main+0xab>
lea    0xdcc(%rip),%rdi
call   1030 <puts@plt>
jmp    128b <main+0xab>
lea    0xd40(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd42(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"fork error\00"
@.str.1 = [13 x i8] c"./newprogram\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [7 x i8] c"never\0A\00"
@.str.4 = [8 x i8] c"waitpid\00"
@.str.5 = [19 x i8] c"exited, status=%d\0A\00"
@.str.6 = [21 x i8] c"killed by signal %d\0A\00"
@.str.7 = [22 x i8] c"stopped by signal %d\0A\00"
@.str.8 = [11 x i8] c"continued\0A\00"
@.str.9 = [32 x i8] c"Parent process: child exit: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @fork()
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32* null)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %65
21: ; preds = %15
%22 = load i32, i32* %6
%23 = call i32 @waitpid(i32 %22, i32* %7, i32 0)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 @exit(i32 2)
unreachable
29: ; preds = %21
%30 = load i32, i32* %7
%31 = call i64 @WIFEXITED(i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* %7
%35 = call i32 @WEXITSTATUS(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %35)
br label %62
37: ; preds = %29
%38 = load i32, i32* %7
%39 = call i64 @WIFSIGNALED(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* %7
%43 = call i32 @WTERMSIG(i32 %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %43)
br label %61
45: ; preds = %37
%46 = load i32, i32* %7
%47 = call i64 @WIFSTOPPED(i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = load i32, i32* %7
%51 = call i32 @WSTOPSIG(i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %51)
br label %60
53: ; preds = %45
%54 = load i32, i32* %7
%55 = call i64 @WIFCONTINUED(i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
br label %59
59: ; preds = %57, %53
br label %60
60: ; preds = %59, %49
br label %61
61: ; preds = %60, %41
br label %62
62: ; preds = %61, %33
%63 = load i32, i32* %7
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %62, %18
br label %66
66: ; preds = %65
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"fork error\00"
@.str.1 = [13 x i8] c"./newprogram\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.4 = [8 x i8] c"waitpid\00"
@.str.5 = [19 x i8] c"exited, status=%d\0A\00"
@.str.6 = [21 x i8] c"killed by signal %d\0A\00"
@.str.7 = [22 x i8] c"stopped by signal %d\0A\00"
@.str.9 = [32 x i8] c"Parent process: child exit: %d\0A\00"
@str = [10 x i8] c"continued\00"
@str.10 = [6 x i8] c"never\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32 (...) @fork()
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = icmp eq i32 %4, 0
br i1 %10, label %11, label %14
11: ; preds = %9
%12 = tail call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32* null)
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.10, i64 0, i64 0))
br label %51
14: ; preds = %9
%15 = bitcast i32* %3 to i8*
%16 = call i32 @waitpid(i32 %4, i32* %3, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%20 = call i32 @exit(i32 2)
unreachable
21: ; preds = %14
%22 = load i32, i32* %3
%23 = call i64 @WIFEXITED(i32 %22)
%24 = icmp eq i64 %23, 0
%25 = load i32, i32* %3
br i1 %24, label %29, label %26
26: ; preds = %21
%27 = call i32 @WEXITSTATUS(i32 %25)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %27)
br label %48
29: ; preds = %21
%30 = call i64 @WIFSIGNALED(i32 %25)
%31 = icmp eq i64 %30, 0
%32 = load i32, i32* %3
br i1 %31, label %36, label %33
33: ; preds = %29
%34 = call i32 @WTERMSIG(i32 %32)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %34)
br label %48
36: ; preds = %29
%37 = call i64 @WIFSTOPPED(i32 %32)
%38 = icmp eq i64 %37, 0
%39 = load i32, i32* %3
br i1 %38, label %43, label %40
40: ; preds = %36
%41 = call i32 @WSTOPSIG(i32 %39)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %41)
br label %48
43: ; preds = %36
%44 = call i64 @WIFCONTINUED(i32 %39)
%45 = icmp eq i64 %44, 0
br i1 %45, label %48, label %46
46: ; preds = %43
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %48
48: ; preds = %33, %43, %46, %40, %26
%49 = load i32, i32* %3
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %11, %48
ret i32 0
}