#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 */
scalar_t__ WCOREDUMP(int);
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*/ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int wait(int *);
int main(void) {
  int status;
  pid_t pid;
  if (!fork())
    return 1;
  pid = wait(&status);
  if (pid == -1) {
    perror("wait");
  }
  printf("pid=%d\n", pid);
  if (WIFEXITED(status)) {
    printf("Normal termination with exit status=%d\n", WEXITSTATUS(status));
  }
  if (WIFSIGNALED(status)) {
    printf("Killed by signal=%d%s\n", WTERMSIG(status),
           WCOREDUMP(status) ? " (dumped core)" : "");
  }
  if (WIFSTOPPED(status)) {
    printf("Stopped by signal=%d\n", WSTOPSIG(status));
  }
  if (WIFCONTINUED(status)) {
    printf("Continued\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10e0 <fork@plt>
cmp    $0x0,%eax
jne    11eb <main+0x2b>
movl   $0x1,-0x4(%rbp)
jmp    12e8 <main+0x128>
lea    -0x8(%rbp),%rdi
call   10d0 <wait@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    120d <main+0x4d>
lea    0xdf8(%rip),%rdi
call   10a0 <perror@plt>
mov    -0xc(%rbp),%esi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   10b0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1248 <main+0x88>
mov    -0x8(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1297 <main+0xd7>
mov    -0x8(%rbp),%edi
call   1080 <WTERMSIG@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <WCOREDUMP@plt>
mov    -0x10(%rbp),%esi
mov    %rax,%rcx
lea    0xd92(%rip),%rdx
lea    0xdcb(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdx
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1070 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     12c1 <main+0x101>
mov    -0x8(%rbp),%edi
call   10c0 <WSTOPSIG@plt>
mov    %eax,%esi
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <WIFCONTINUED@plt>
cmp    $0x0,%rax
je     12e1 <main+0x121>
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
je     12bc <main+0xec>
lea    0xc(%rsp),%rdi
call   10e0 <wait@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     12c9 <main+0xf9>
lea    0xe05(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edi
call   10c0 <WIFEXITED@plt>
test   %rax,%rax
je     1230 <main+0x60>
mov    0xc(%rsp),%edi
call   10a0 <WEXITSTATUS@plt>
lea    0xde6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edi
call   1060 <WIFSIGNALED@plt>
test   %rax,%rax
je     1277 <main+0xa7>
mov    0xc(%rsp),%edi
call   1090 <WTERMSIG@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
call   1050 <WCOREDUMP@plt>
test   %rax,%rax
lea    0xdb0(%rip),%rax
lea    0xde9(%rip),%rdx
cmove  %rax,%rdx
lea    0xdc7(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edi
call   1080 <WIFSTOPPED@plt>
test   %rax,%rax
je     129e <main+0xce>
mov    0xc(%rsp),%edi
call   10d0 <WSTOPSIG@plt>
lea    0xdc6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edi
call   1070 <WIFCONTINUED@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     12c1 <main+0xf1>
lea    0xdbc(%rip),%rdi
call   1030 <puts@plt>
jmp    12c1 <main+0xf1>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xd30(%rip),%rdi
call   10b0 <perror@plt>
jmp    11f9 <main+0x29>

LLVM IR (-O0):
@.str = [5 x i8] c"wait\00"
@.str.1 = [8 x i8] c"pid=%d\0A\00"
@.str.2 = [40 x i8] c"Normal termination with exit status=%d\0A\00"
@.str.3 = [23 x i8] c"Killed by signal=%d%s\0A\00"
@.str.4 = [15 x i8] c" (dumped core)\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [22 x i8] c"Stopped by signal=%d\0A\00"
@.str.7 = [11 x i8] c"Continued\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @fork()
%5 = icmp ne i32 %4, 0
br i1 %5, label %7, label %6
6: ; preds = %0
store i32 1, i32* %1
br label %51
7: ; preds = %0
%8 = call i32 @wait(i32* %2)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %2
%17 = call i64 @WIFEXITED(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i32, i32* %2
%21 = call i32 @WEXITSTATUS(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %19, %13
%24 = load i32, i32* %2
%25 = call i64 @WIFSIGNALED(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %36
27: ; preds = %23
%28 = load i32, i32* %2
%29 = call i32 @WTERMSIG(i32 %28)
%30 = load i32, i32* %2
%31 = call i64 @WCOREDUMP(i32 %30)
%32 = icmp ne i64 %31, 0
%33 = zext i1 %32 to i64
%34 = select i1 %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %29, i8* %34)
br label %36
36: ; preds = %27, %23
%37 = load i32, i32* %2
%38 = call i64 @WIFSTOPPED(i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i32, i32* %2
%42 = call i32 @WSTOPSIG(i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %40, %36
%45 = load i32, i32* %2
%46 = call i64 @WIFCONTINUED(i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %50
50: ; preds = %48, %44
store i32 0, i32* %1
br label %51
51: ; preds = %50, %6
%52 = load i32, i32* %1
ret i32 %52
}

LLVM IR (-O2):
@.str = [5 x i8] c"wait\00"
@.str.1 = [8 x i8] c"pid=%d\0A\00"
@.str.2 = [40 x i8] c"Normal termination with exit status=%d\0A\00"
@.str.3 = [23 x i8] c"Killed by signal=%d%s\0A\00"
@.str.4 = [15 x i8] c" (dumped core)\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [22 x i8] c"Stopped by signal=%d\0A\00"
@str = [10 x i8] c"Continued\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %45, label %5
5: ; preds = %0
%6 = call i32 @wait(i32* %1)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%12 = load i32, i32* %1
%13 = call i64 @WIFEXITED(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = load i32, i32* %1
%17 = call i32 @WEXITSTATUS(i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %15, %10
%20 = load i32, i32* %1
%21 = call i64 @WIFSIGNALED(i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %31, label %23
23: ; preds = %19
%24 = load i32, i32* %1
%25 = call i32 @WTERMSIG(i32 %24)
%26 = load i32, i32* %1
%27 = call i64 @WCOREDUMP(i32 %26)
%28 = icmp eq i64 %27, 0
%29 = select i1 %28, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %25, i8* %29)
br label %31
31: ; preds = %23, %19
%32 = load i32, i32* %1
%33 = call i64 @WIFSTOPPED(i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %31
%36 = load i32, i32* %1
%37 = call i32 @WSTOPSIG(i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %35, %31
%40 = load i32, i32* %1
%41 = call i64 @WIFCONTINUED(i32 %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %39
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %45
45: ; preds = %39, %43, %0
%46 = phi i32 [ 1, %0 ], [ 0, %43 ], [ 0, %39 ]
ret i32 %46
}