#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 */
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ printf(char *, int, int);
void explain_exit(pid_t p, int e) {
  if (WIFEXITED(e)) {
    printf("%d exit %d\n", p, WEXITSTATUS(e));
  } else if (WIFSIGNALED(e)) {
    printf("%d killed by signal %d\n", p, WTERMSIG(e));
  }
}


x86 assembly (clang, -O0):
<explain_exit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1194 <explain_exit+0x44>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
jmp    11ca <explain_exit+0x7a>
mov    -0x8(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     11c5 <explain_exit+0x75>
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
jmp    11ca <explain_exit+0x7a>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<explain_exit>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    %esi,%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     1173 <explain_exit+0x23>
mov    %ebp,%edi
call   1060 <WEXITSTATUS@plt>
lea    0xe8f(%rip),%rdi
jmp    118d <explain_exit+0x3d>
mov    %ebp,%edi
call   1040 <WIFSIGNALED@plt>
test   %rax,%rax
je     119c <explain_exit+0x4c>
mov    %ebp,%edi
call   1050 <WTERMSIG@plt>
lea    0xe7f(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d exit %d\0A\00"
@.str.1 = [24 x i8] c"%d killed by signal %d\0A\00"
define void @explain_exit(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = call i64 @WIFEXITED(i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = call i32 @WEXITSTATUS(i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %11)
br label %23
13: ; preds = %2
%14 = load i32, i32* %4
%15 = call i64 @WIFSIGNALED(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%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 %18, i32 %20)
br label %22
22: ; preds = %17, %13
br label %23
23: ; preds = %22, %8
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d exit %d\0A\00"
@.str.1 = [24 x i8] c"%d killed by signal %d\0A\00"
define void @explain_exit(i32 %0, i32 %1) {
%3 = tail call i64 @WIFEXITED(i32 %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @WEXITSTATUS(i32 %1)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %6)
br label %14
8: ; preds = %2
%9 = tail call i64 @WIFSIGNALED(i32 %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = tail call i32 @WTERMSIG(i32 %1)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %12)
br label %14
14: ; preds = %8, %11, %5
ret void
}