#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__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ WIFSTOPPED(int);
int WSTOPSIG(int);
int WTERMSIG(int);
int /*<<< orphan*/ printf(char *, int);
void printstatus(int status) {
  if (WIFEXITED(status)) {
    printf("Exit %d", WEXITSTATUS(status));
  } else if (WIFSIGNALED(status) && WCOREDUMP(status)) {
    printf("Signal %d (core dumped)", WTERMSIG(status));
  } else if (WIFSIGNALED(status)) {
    printf("Signal %d", WTERMSIG(status));
  } else if (WIFSTOPPED(status)) {
    printf("Stopped on signal %d", WSTOPSIG(status));
  } else {
    printf("Invalid status code %d", status);
  }
}


x86 assembly (clang, -O0):
<printstatus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1090 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11b8 <printstatus+0x38>
mov    -0x4(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
jmp    126f <printstatus+0xef>
mov    -0x4(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     11f7 <printstatus+0x77>
mov    -0x4(%rbp),%edi
call   1040 <WCOREDUMP@plt>
cmp    $0x0,%rax
je     11f7 <printstatus+0x77>
mov    -0x4(%rbp),%edi
call   1070 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
jmp    126a <printstatus+0xea>
mov    -0x4(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1224 <printstatus+0xa4>
mov    -0x4(%rbp),%edi
call   1070 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xe06(%rip),%rdi
call   1030 <printf@plt>
jmp    1265 <printstatus+0xe5>
mov    -0x4(%rbp),%edi
call   1060 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     1251 <printstatus+0xd1>
mov    -0x4(%rbp),%edi
call   10a0 <WSTOPSIG@plt>
mov    %eax,%esi
lea    0xde3(%rip),%rdi
call   1030 <printf@plt>
jmp    1260 <printstatus+0xe0>
mov    -0x4(%rbp),%esi
lea    0xde4(%rip),%rdi
call   1030 <printf@plt>
jmp    1265 <printstatus+0xe5>
jmp    126a <printstatus+0xea>
jmp    126f <printstatus+0xef>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printstatus>:
push   %rbx
mov    %edi,%ebx
call   1090 <WIFEXITED@plt>
test   %rax,%rax
je     11a3 <printstatus+0x23>
mov    %ebx,%edi
call   1080 <WEXITSTATUS@plt>
lea    0xe65(%rip),%rdi
mov    %eax,%esi
pop    %rbx
jmp    1030 <printf@plt>
mov    %ebx,%edi
call   1050 <WIFSIGNALED@plt>
test   %rax,%rax
je     11cb <printstatus+0x4b>
mov    %ebx,%edi
call   1040 <WCOREDUMP@plt>
test   %rax,%rax
je     11cb <printstatus+0x4b>
mov    %ebx,%edi
call   1070 <WTERMSIG@plt>
lea    0xe3f(%rip),%rdi
jmp    119b <printstatus+0x1b>
mov    %ebx,%edi
call   1050 <WIFSIGNALED@plt>
test   %rax,%rax
je     11e7 <printstatus+0x67>
mov    %ebx,%edi
call   1070 <WTERMSIG@plt>
lea    0xe3b(%rip),%rdi
jmp    119b <printstatus+0x1b>
mov    %ebx,%edi
call   1060 <WIFSTOPPED@plt>
test   %rax,%rax
je     1203 <printstatus+0x83>
mov    %ebx,%edi
call   10a0 <WSTOPSIG@plt>
lea    0xe29(%rip),%rdi
jmp    119b <printstatus+0x1b>
lea    0xe35(%rip),%rdi
mov    %ebx,%esi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"Exit %d\00"
@.str.1 = [24 x i8] c"Signal %d (core dumped)\00"
@.str.2 = [10 x i8] c"Signal %d\00"
@.str.3 = [21 x i8] c"Stopped on signal %d\00"
@.str.4 = [23 x i8] c"Invalid status code %d\00"
define void @printstatus(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 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %44
10: ; preds = %1
%11 = load i32, i32* %2
%12 = call i64 @WIFSIGNALED(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i32, i32* %2
%16 = call i64 @WCOREDUMP(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i32, i32* %2
%20 = call i32 @WTERMSIG(i32 %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %20)
br label %43
22: ; preds = %14, %10
%23 = load i32, i32* %2
%24 = call i64 @WIFSIGNALED(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = load i32, i32* %2
%28 = call i32 @WTERMSIG(i32 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %42
30: ; preds = %22
%31 = load i32, i32* %2
%32 = call i64 @WIFSTOPPED(i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32, i32* %2
%36 = call i32 @WSTOPSIG(i32 %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %36)
br label %41
38: ; preds = %30
%39 = load i32, i32* %2
%40 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %38, %34
br label %42
42: ; preds = %41, %26
br label %43
43: ; preds = %42, %18
br label %44
44: ; preds = %43, %6
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"Exit %d\00"
@.str.1 = [24 x i8] c"Signal %d (core dumped)\00"
@.str.2 = [10 x i8] c"Signal %d\00"
@.str.3 = [21 x i8] c"Stopped on signal %d\00"
@.str.4 = [23 x i8] c"Invalid status code %d\00"
define void @printstatus(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 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %30
7: ; preds = %1
%8 = tail call i64 @WIFSIGNALED(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %7
%11 = tail call i64 @WCOREDUMP(i32 %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i32 @WTERMSIG(i32 %0)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %30
16: ; preds = %10, %7
%17 = tail call i64 @WIFSIGNALED(i32 %0)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = tail call i32 @WTERMSIG(i32 %0)
%21 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %30
22: ; preds = %16
%23 = tail call i64 @WIFSTOPPED(i32 %0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = tail call i32 @WSTOPSIG(i32 %0)
%27 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %30
28: ; preds = %22
%29 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %0)
br label %30
30: ; preds = %13, %25, %28, %19, %4
ret void
}