#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 */
scalar_t__ WCOREDUMP(int);
int WEXITSTATUS(int);
scalar_t__ WIFCONTINUED(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ WIFSTOPPED(int);
int WTERMSIG(int);
int /*<<< orphan*/ printf(char *, ...);
void decode_waitpid_status(int status) {
  if (WIFEXITED(status))
    printf("Child exited, status=%d\n", WEXITSTATUS(status));
  if (WIFSIGNALED(status)) {
    printf("Child exit on signal=%d\n", WTERMSIG(status));
    if (WCOREDUMP(status))
      printf("Child core dump\n");
  }
  if (WIFSTOPPED(status))
    printf("Child stopped\n");
  if (WIFCONTINUED(status))
    printf("Child cont.\n");
}


x86 assembly (clang, -O0):
<decode_waitpid_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11b5 <decode_waitpid_status+0x35>
mov    -0x4(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1204 <decode_waitpid_status+0x84>
mov    -0x4(%rbp),%edi
call   1080 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1040 <WCOREDUMP@plt>
cmp    $0x0,%rax
je     11ff <decode_waitpid_status+0x7f>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1204 <decode_waitpid_status+0x84>
mov    -0x4(%rbp),%edi
call   1070 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     1224 <decode_waitpid_status+0xa4>
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1060 <WIFCONTINUED@plt>
cmp    $0x0,%rax
je     1244 <decode_waitpid_status+0xc4>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_waitpid_status>:
push   %rbx
mov    %edi,%ebx
call   10b0 <WIFEXITED@plt>
test   %rax,%rax
je     11b4 <decode_waitpid_status+0x24>
mov    %ebx,%edi
call   10a0 <WEXITSTATUS@plt>
lea    0xe55(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1060 <WIFSIGNALED@plt>
test   %rax,%rax
je     11ef <decode_waitpid_status+0x5f>
mov    %ebx,%edi
call   1090 <WTERMSIG@plt>
lea    0xe4b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <WCOREDUMP@plt>
test   %rax,%rax
je     11ef <decode_waitpid_status+0x5f>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1080 <WIFSTOPPED@plt>
test   %rax,%rax
je     1207 <decode_waitpid_status+0x77>
lea    0xe3c(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1070 <WIFCONTINUED@plt>
test   %rax,%rax
je     1220 <decode_waitpid_status+0x90>
lea    0xe18(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [25 x i8] c"Child exited, status=%d\0A\00"
@.str.1 = [25 x i8] c"Child exit on signal=%d\0A\00"
@str = [12 x i8] c"Child cont.\00"
@str.5 = [14 x i8] c"Child stopped\00"
@str.6 = [16 x i8] c"Child core dump\00"
define void @decode_waitpid_status(i32 %0) {
%2 = tail call i64 @WIFEXITED(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i32 @WEXITSTATUS(i32 %0)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %7
7: ; preds = %4, %1
%8 = tail call i64 @WIFSIGNALED(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %7
%11 = tail call i32 @WTERMSIG(i32 %0)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = tail call i64 @WCOREDUMP(i32 %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.6, i64 0, i64 0))
br label %17
17: ; preds = %10, %15, %7
%18 = tail call i64 @WIFSTOPPED(i32 %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
%23 = tail call i64 @WIFCONTINUED(i32 %0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %27
27: ; preds = %25, %22
ret void
}