#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);
int /*<<< orphan*/ WTERMSIG(int);
char *alloc_printf(char *, ...);
void get_exit_status(int status, char **exit_status, int *exit_code) {
  if (WIFEXITED(status)) {
    *exit_status = alloc_printf("exited with code %d", WEXITSTATUS(status));
    if (exit_code)
      *exit_code = WEXITSTATUS(status);
  } else if (WIFSIGNALED(status)) {
    if (WCOREDUMP(status))
      *exit_status = alloc_printf("terminated by signal %d (core dumped)",
                                  WTERMSIG(status));
    else
      *exit_status = alloc_printf("terminated by signal %d (no core dump)",
                                  WTERMSIG(status));
  } else
    *exit_status =
        alloc_printf("exited for unknown reason (no exit code or singal)");
}


x86 assembly (clang, -O0):
<get_exit_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
call   1080 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11c7 <get_exit_status+0x67>
mov    -0x4(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <alloc_printf@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11c2 <get_exit_status+0x62>
mov    -0x4(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1256 <get_exit_status+0xf6>
mov    -0x4(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1239 <get_exit_status+0xd9>
mov    -0x4(%rbp),%edi
call   1040 <WCOREDUMP@plt>
cmp    $0x0,%rax
je     1212 <get_exit_status+0xb2>
mov    -0x4(%rbp),%edi
call   1060 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <alloc_printf@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1234 <get_exit_status+0xd4>
mov    -0x4(%rbp),%edi
call   1060 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <alloc_printf@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1251 <get_exit_status+0xf1>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <alloc_printf@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1256 <get_exit_status+0xf6>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_exit_status>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
call   1080 <WIFEXITED@plt>
mov    %ebp,%edi
test   %rax,%rax
je     11a0 <get_exit_status+0x40>
call   1070 <WEXITSTATUS@plt>
lea    0xe7c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <alloc_printf@plt>
mov    %rax,(%r14)
test   %rbx,%rbx
je     11ec <get_exit_status+0x8c>
mov    %ebp,%edi
call   1070 <WEXITSTATUS@plt>
mov    %eax,(%rbx)
jmp    11ec <get_exit_status+0x8c>
call   1050 <WIFSIGNALED@plt>
test   %rax,%rax
je     11cb <get_exit_status+0x6b>
mov    %ebp,%edi
call   1040 <WCOREDUMP@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1060 <WTERMSIG@plt>
mov    %eax,%esi
test   %rbx,%rbx
je     11db <get_exit_status+0x7b>
lea    0xe4b(%rip),%rdi
jmp    11e2 <get_exit_status+0x82>
lea    0xe8f(%rip),%rdi
xor    %eax,%eax
call   1030 <alloc_printf@plt>
jmp    11e9 <get_exit_status+0x89>
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1030 <alloc_printf@plt>
mov    %rax,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"exited with code %d\00"
@.str.1 = [38 x i8] c"terminated by signal %d (core dumped)\00"
@.str.2 = [39 x i8] c"terminated by signal %d (no core dump)\00"
@.str.3 = [51 x i8] c"exited for unknown reason (no exit code or singal)\00"
define void @get_exit_status(i32 %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
%7 = load i32, i32* %4
%8 = call i64 @WIFEXITED(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %22
10: ; preds = %3
%11 = load i32, i32* %4
%12 = call i32 @WEXITSTATUS(i32 %11)
%13 = call i8* (i8*, ...) @alloc_printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i8**, i8*** %5
store i8* %13, i8** %14
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = load i32, i32* %4
%19 = call i32 @WEXITSTATUS(i32 %18)
%20 = load i32*, i32** %6
store i32 %19, i32* %20
br label %21
21: ; preds = %17, %10
br label %45
22: ; preds = %3
%23 = load i32, i32* %4
%24 = call i64 @WIFSIGNALED(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %41
26: ; preds = %22
%27 = load i32, i32* %4
%28 = call i64 @WCOREDUMP(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i32, i32* %4
%32 = call i32 @WTERMSIG(i32 %31)
%33 = call i8* (i8*, ...) @alloc_printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %32)
%34 = load i8**, i8*** %5
store i8* %33, i8** %34
br label %40
35: ; preds = %26
%36 = load i32, i32* %4
%37 = call i32 @WTERMSIG(i32 %36)
%38 = call i8* (i8*, ...) @alloc_printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = load i8**, i8*** %5
store i8* %38, i8** %39
br label %40
40: ; preds = %35, %30
br label %44
41: ; preds = %22
%42 = call i8* (i8*, ...) @alloc_printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
%43 = load i8**, i8*** %5
store i8* %42, i8** %43
br label %44
44: ; preds = %41, %40
br label %45
45: ; preds = %44, %21
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"exited with code %d\00"
@.str.1 = [38 x i8] c"terminated by signal %d (core dumped)\00"
@.str.2 = [39 x i8] c"terminated by signal %d (no core dump)\00"
@.str.3 = [51 x i8] c"exited for unknown reason (no exit code or singal)\00"
define void @get_exit_status(i32 %0, i8** nocapture writeonly %1, i32* writeonly %2) {
%4 = tail call i64 @WIFEXITED(i32 %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %3
%7 = tail call i32 @WEXITSTATUS(i32 %0)
%8 = tail call i8* (i8*, ...) @alloc_printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %7)
store i8* %8, i8** %1
%9 = icmp eq i32* %2, null
br i1 %9, label %25, label %10
10: ; preds = %6
%11 = tail call i32 @WEXITSTATUS(i32 %0)
store i32 %11, i32* %2
br label %25
12: ; preds = %3
%13 = tail call i64 @WIFSIGNALED(i32 %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %12
%16 = tail call i64 @WCOREDUMP(i32 %0)
%17 = icmp eq i64 %16, 0
%18 = tail call i32 @WTERMSIG(i32 %0)
br i1 %17, label %21, label %19
19: ; preds = %15
%20 = tail call i8* (i8*, ...) @alloc_printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %18)
store i8* %20, i8** %1
br label %25
21: ; preds = %15
%22 = tail call i8* (i8*, ...) @alloc_printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %18)
store i8* %22, i8** %1
br label %25
23: ; preds = %12
%24 = tail call i8* (i8*, ...) @alloc_printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
store i8* %24, i8** %1
br label %25
25: ; preds = %23, %21, %19, %6, %10
ret void
}