#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);
scalar_t__ WIFSTOPPED(int);
int WSTOPSIG(int);
int WTERMSIG(int);
int /*<<< orphan*/ printf(char *, ...);
char *strsignal(int);
void printWaitStatus(const char *msg, int status) {
  if (msg != NULL)
    printf("%s", msg);
  if (WIFEXITED(status)) {
    printf("child exited, status=%d\n", WEXITSTATUS(status));
  } else if (WIFSIGNALED(status)) {
    printf("child killed by signal %d (%s)", WTERMSIG(status),
           strsignal(WTERMSIG(status)));
    printf("\n");
  } else if (WIFSTOPPED(status)) {
    printf("child stopped by signal %d (%s)\n", WSTOPSIG(status),
           strsignal(WSTOPSIG(status)));
  } else {
    printf("what happened to this child? (status=%x)\n", (unsigned int)status);
  }
}


x86 assembly (clang, -O0):
<printWaitStatus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ac <printWaitStatus+0x2c>
mov    -0x8(%rbp),%rsi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1090 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11db <printWaitStatus+0x5b>
mov    -0xc(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    128e <printWaitStatus+0x10e>
mov    -0xc(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     122e <printWaitStatus+0xae>
mov    -0xc(%rbp),%edi
call   1060 <WTERMSIG@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <WTERMSIG@plt>
mov    %eax,%edi
call   1070 <strsignal@plt>
mov    -0x10(%rbp),%esi
mov    %rax,%rdx
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1289 <printWaitStatus+0x109>
mov    -0xc(%rbp),%edi
call   1050 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     1273 <printWaitStatus+0xf3>
mov    -0xc(%rbp),%edi
call   10a0 <WSTOPSIG@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   10a0 <WSTOPSIG@plt>
mov    %eax,%edi
call   1070 <strsignal@plt>
mov    -0x14(%rbp),%esi
mov    %rax,%rdx
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1284 <printWaitStatus+0x104>
mov    -0xc(%rbp),%esi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1289 <printWaitStatus+0x109>
jmp    128e <printWaitStatus+0x10e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printWaitStatus>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
test   %rdi,%rdi
je     11ab <printWaitStatus+0x1b>
mov    %rdi,%rsi
lea    0xe5c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   10a0 <WIFEXITED@plt>
test   %rax,%rax
je     11d4 <printWaitStatus+0x44>
mov    %ebx,%edi
call   1090 <WEXITSTATUS@plt>
lea    0xe3e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <printf@plt>
mov    %ebx,%edi
call   1050 <WIFSIGNALED@plt>
mov    %ebx,%edi
test   %rax,%rax
je     121a <printWaitStatus+0x8a>
call   1070 <WTERMSIG@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1070 <WTERMSIG@plt>
mov    %eax,%edi
call   1080 <strsignal@plt>
lea    0xe1e(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <putchar@plt>
call   1060 <WIFSTOPPED@plt>
test   %rax,%rax
je     1254 <printWaitStatus+0xc4>
mov    %ebx,%edi
call   10b0 <WSTOPSIG@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   10b0 <WSTOPSIG@plt>
mov    %eax,%edi
call   1080 <strsignal@plt>
lea    0xdf9(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <printf@plt>
lea    0xe01(%rip),%rdi
mov    %ebx,%esi
jmp    11c7 <printWaitStatus+0x37>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [25 x i8] c"child exited, status=%d\0A\00"
@.str.2 = [31 x i8] c"child killed by signal %d (%s)\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [33 x i8] c"child stopped by signal %d (%s)\0A\00"
@.str.5 = [42 x i8] c"what happened to this child? (status=%x)\0A\00"
define void @printWaitStatus(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %7, %2
%11 = load i32, i32* %4
%12 = call i64 @WIFEXITED(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* %4
%16 = call i32 @WEXITSTATUS(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %46
18: ; preds = %10
%19 = load i32, i32* %4
%20 = call i64 @WIFSIGNALED(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load i32, i32* %4
%24 = call i32 @WTERMSIG(i32 %23)
%25 = load i32, i32* %4
%26 = call i32 @WTERMSIG(i32 %25)
%27 = call i8* @strsignal(i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %24, i8* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %45
30: ; preds = %18
%31 = load i32, i32* %4
%32 = call i64 @WIFSTOPPED(i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %30
%35 = load i32, i32* %4
%36 = call i32 @WSTOPSIG(i32 %35)
%37 = load i32, i32* %4
%38 = call i32 @WSTOPSIG(i32 %37)
%39 = call i8* @strsignal(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %36, i8* %39)
br label %44
41: ; preds = %30
%42 = load i32, i32* %4
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %41, %34
br label %45
45: ; preds = %44, %22
br label %46
46: ; preds = %45, %14
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [25 x i8] c"child exited, status=%d\0A\00"
@.str.2 = [31 x i8] c"child killed by signal %d (%s)\00"
@.str.4 = [33 x i8] c"child stopped by signal %d (%s)\0A\00"
@.str.5 = [42 x i8] c"what happened to this child? (status=%x)\0A\00"
define void @printWaitStatus(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %6
6: ; preds = %4, %2
%7 = tail call i64 @WIFEXITED(i32 %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i32 @WEXITSTATUS(i32 %1)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %31
12: ; preds = %6
%13 = tail call i64 @WIFSIGNALED(i32 %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = tail call i32 @WTERMSIG(i32 %1)
%17 = tail call i32 @WTERMSIG(i32 %1)
%18 = tail call i8* @strsignal(i32 %17)
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %16, i8* %18)
%20 = tail call i32 @putchar(i32 10)
br label %31
21: ; preds = %12
%22 = tail call i64 @WIFSTOPPED(i32 %1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %21
%25 = tail call i32 @WSTOPSIG(i32 %1)
%26 = tail call i32 @WSTOPSIG(i32 %1)
%27 = tail call i8* @strsignal(i32 %26)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %25, i8* %27)
br label %31
29: ; preds = %21
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0), i32 %1)
br label %31
31: ; preds = %15, %29, %24, %9
ret void
}