#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*/ abort();
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int wait(int *);
int main(void) {
  int status;
  pid_t pid;
  if (fork() == 0) {
    abort();
    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   10f0 <fork@plt>
cmp    $0x0,%rax
jne    11f7 <main+0x27>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0x8(%rbp),%rdi
call   10e0 <wait@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1219 <main+0x49>
lea    0xdec(%rip),%rdi
call   10b0 <perror@plt>
mov    -0xc(%rbp),%esi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   10c0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1254 <main+0x84>
mov    -0x8(%rbp),%edi
call   10a0 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     12a3 <main+0xd3>
mov    -0x8(%rbp),%edi
call   1090 <WTERMSIG@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <WCOREDUMP@plt>
mov    -0x10(%rbp),%esi
mov    %rax,%rcx
lea    0xd86(%rip),%rdx
lea    0xdbf(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdx
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1080 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     12cd <main+0xfd>
mov    -0x8(%rbp),%edi
call   10d0 <WSTOPSIG@plt>
mov    %eax,%esi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1070 <WIFCONTINUED@plt>
cmp    $0x0,%rax
je     12ed <main+0x11d>
lea    0xd8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
je     12e2 <main+0x102>
lea    0xc(%rsp),%rdi
call   10f0 <wait@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     12d1 <main+0xf1>
lea    0xdf4(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
call   10d0 <WIFEXITED@plt>
test   %rax,%rax
je     1241 <main+0x61>
mov    0xc(%rsp),%edi
call   10b0 <WEXITSTATUS@plt>
lea    0xdd5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
call   1070 <WIFSIGNALED@plt>
test   %rax,%rax
je     1288 <main+0xa8>
mov    0xc(%rsp),%edi
call   10a0 <WTERMSIG@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
call   1060 <WCOREDUMP@plt>
test   %rax,%rax
lea    0xd9f(%rip),%rax
lea    0xdd8(%rip),%rdx
cmove  %rax,%rdx
lea    0xdb6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
call   1090 <WIFSTOPPED@plt>
test   %rax,%rax
je     12af <main+0xcf>
mov    0xc(%rsp),%edi
call   10e0 <WSTOPSIG@plt>
lea    0xdb5(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
call   1080 <WIFCONTINUED@plt>
test   %rax,%rax
je     12c9 <main+0xe9>
lea    0xdad(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xd28(%rip),%rdi
call   10c0 <perror@plt>
jmp    120a <main+0x2a>
xor    %eax,%eax
call   1030 <abort@plt>

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 i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (...) @abort()
unreachable
8: ; preds = %0
%9 = call i32 @wait(i32* %2)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = load i32, i32* %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %2
%18 = call i64 @WIFEXITED(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load i32, i32* %2
%22 = call i32 @WEXITSTATUS(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %20, %14
%25 = load i32, i32* %2
%26 = call i64 @WIFSIGNALED(i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = load i32, i32* %2
%30 = call i32 @WTERMSIG(i32 %29)
%31 = load i32, i32* %2
%32 = call i64 @WCOREDUMP(i32 %31)
%33 = icmp ne i64 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, 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)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %30, i8* %35)
br label %37
37: ; preds = %28, %24
%38 = load i32, i32* %2
%39 = call i64 @WIFSTOPPED(i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = load i32, i32* %2
%43 = call i32 @WSTOPSIG(i32 %42)
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %41, %37
%46 = load i32, i32* %2
%47 = call i64 @WIFCONTINUED(i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %51
51: ; preds = %49, %45
ret i32 0
}

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 i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 (...) @abort()
unreachable
7: ; preds = %0
%8 = call i32 @wait(i32* %1)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%14 = load i32, i32* %1
%15 = call i64 @WIFEXITED(i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = load i32, i32* %1
%19 = call i32 @WEXITSTATUS(i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %17, %12
%22 = load i32, i32* %1
%23 = call i64 @WIFSIGNALED(i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %21
%26 = load i32, i32* %1
%27 = call i32 @WTERMSIG(i32 %26)
%28 = load i32, i32* %1
%29 = call i64 @WCOREDUMP(i32 %28)
%30 = icmp eq i64 %29, 0
%31 = select i1 %30, 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)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %27, i8* %31)
br label %33
33: ; preds = %25, %21
%34 = load i32, i32* %1
%35 = call i64 @WIFSTOPPED(i32 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = load i32, i32* %1
%39 = call i32 @WSTOPSIG(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %37, %33
%42 = load i32, i32* %1
%43 = call i64 @WIFCONTINUED(i32 %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %41
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %47
47: ; preds = %45, %41
ret i32 0
}