#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__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ pause();
int /*<<< orphan*/ printf(char *, int, ...);
char *strsignal(int);
int /*<<< orphan*/ wait(int *);
main() {
  int status;
  int a, b, c;
  if (fork()) {
    wait(&status);
    if (WIFEXITED(status))
      printf("Child exited normally with exit status %d\n",
             WEXITSTATUS(status));
    if (WIFSIGNALED(status))
      printf("Child exited on signal %d: %s\n", WTERMSIG(status),
             strsignal(WTERMSIG(status)));
  } else {
    printf("Child PID = %d\n", getpid());
    pause();
    exit(5);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10d0 <fork@plt>
cmp    $0x0,%rax
je     1248 <main+0x98>
lea    -0x8(%rbp),%rdi
call   10c0 <wait@plt>
mov    -0x8(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1203 <main+0x53>
mov    -0x8(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1243 <main+0x93>
mov    -0x8(%rbp),%edi
call   1070 <WTERMSIG@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <WTERMSIG@plt>
mov    %eax,%edi
call   1080 <strsignal@plt>
mov    -0x18(%rbp),%esi
mov    %rax,%rdx
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1270 <main+0xc0>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xdf2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <pause@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
je     1236 <main+0x86>
lea    0xc(%rsp),%rdi
call   10c0 <wait@plt>
mov    0xc(%rsp),%edi
call   10a0 <WIFEXITED@plt>
test   %rax,%rax
je     11f2 <main+0x42>
mov    0xc(%rsp),%edi
call   1090 <WEXITSTATUS@plt>
lea    0xe17(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%edi
call   1050 <WIFSIGNALED@plt>
test   %rax,%rax
je     122e <main+0x7e>
mov    0xc(%rsp),%edi
call   1070 <WTERMSIG@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
call   1070 <WTERMSIG@plt>
mov    %eax,%edi
call   1080 <strsignal@plt>
lea    0xe09(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe06(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <pause@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"Child exited normally with exit status %d\0A\00"
@.str.1 = [31 x i8] c"Child exited on signal %d: %s\0A\00"
@.str.2 = [16 x i8] c"Child PID = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i64 (...) @fork()
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %29
8: ; preds = %0
%9 = call i32 @wait(i32* %2)
%10 = load i32, i32* %2
%11 = call i64 @WIFEXITED(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = load i32, i32* %2
%15 = call i32 @WEXITSTATUS(i32 %14)
%16 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %13, %8
%18 = load i32, i32* %2
%19 = call i64 @WIFSIGNALED(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = load i32, i32* %2
%23 = call i32 @WTERMSIG(i32 %22)
%24 = load i32, i32* %2
%25 = call i32 @WTERMSIG(i32 %24)
%26 = call i8* @strsignal(i32 %25)
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %23, i8* %26)
br label %28
28: ; preds = %21, %17
br label %34
29: ; preds = %0
%30 = call i32 (...) @getpid()
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = call i32 (...) @pause()
%33 = call i32 @exit(i32 5)
unreachable
34: ; preds = %28
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [43 x i8] c"Child exited normally with exit status %d\0A\00"
@.str.1 = [31 x i8] c"Child exited on signal %d: %s\0A\00"
@.str.2 = [16 x i8] c"Child PID = %d\0A\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 %25, label %5
5: ; preds = %0
%6 = call i32 @wait(i32* %1)
%7 = load i32, i32* %1
%8 = call i64 @WIFEXITED(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = load i32, i32* %1
%12 = call i32 @WEXITSTATUS(i32 %11)
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %10, %5
%15 = load i32, i32* %1
%16 = call i64 @WIFSIGNALED(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %30, label %18
18: ; preds = %14
%19 = load i32, i32* %1
%20 = call i32 @WTERMSIG(i32 %19)
%21 = load i32, i32* %1
%22 = call i32 @WTERMSIG(i32 %21)
%23 = call i8* @strsignal(i32 %22)
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %20, i8* %23)
br label %30
25: ; preds = %0
%26 = tail call i32 (...) @getpid()
%27 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = tail call i32 (...) @pause()
%29 = tail call i32 @exit(i32 5)
unreachable
30: ; preds = %14, %18
ret i32 0
}