#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);
int WTERMSIG(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ stderr;
void handle_wait_status(const char *cmd, int wstatus) {
  if (wstatus < 0) {
    fprintf(stderr,
            "scubainit"
            ": "
            "Failed to execute %s: %m\n",
            cmd);
    exit(99);
  } else if (WIFEXITED(wstatus)) {
    int es = WEXITSTATUS(wstatus);
    if (es != 0) {
      fprintf(stderr,
              "scubainit"
              ": "
              "%s exited with status %d\n",
              cmd, es);
      exit(99);
    }
  } else if (WIFSIGNALED(wstatus)) {
    int sig = WTERMSIG(wstatus);
    fprintf(stderr,
            "scubainit"
            ": "
            "%s terminated by signal %d\n",
            cmd, sig);
    exit(99);
  } else {
    fprintf(stderr,
            "scubainit"
            ": "
            "%s exited for an unknown reason! (wstatus=0x%X)\n",
            cmd, wstatus);
    exit(99);
  }
}


x86 assembly (clang, -O0):
<handle_wait_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    119e <handle_wait_status+0x3e>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x63,%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11f2 <handle_wait_status+0x92>
mov    -0xc(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11ed <handle_wait_status+0x8d>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%ecx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x63,%edi
call   1080 <exit@plt>
jmp    125f <handle_wait_status+0xff>
mov    -0xc(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1237 <handle_wait_status+0xd7>
mov    -0xc(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x63,%edi
call   1080 <exit@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x63,%edi
call   1080 <exit@plt>
jmp    1264 <handle_wait_status+0x104>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_wait_status>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %esi,%esi
js     118a <handle_wait_status+0x2a>
mov    %esi,%ebp
mov    %esi,%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     11ae <handle_wait_status+0x4e>
mov    %ebp,%edi
call   1060 <WEXITSTATUS@plt>
test   %eax,%eax
jne    11d1 <handle_wait_status+0x71>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x63,%edi
call   1080 <exit@plt>
mov    %ebp,%edi
call   1030 <WIFSIGNALED@plt>
test   %rax,%rax
jne    11e3 <handle_wait_status+0x83>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
mov    %rbx,%rdx
mov    %ebp,%ecx
jmp    11ff <handle_wait_status+0x9f>
mov    0x2e08(%rip),%rcx
mov    (%rcx),%edi
lea    0xe44(%rip),%rsi
jmp    11fa <handle_wait_status+0x9a>
mov    %ebp,%edi
call   1050 <WTERMSIG@plt>
mov    0x2def(%rip),%rcx
mov    (%rcx),%edi
lea    0xe50(%rip),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x63,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"scubainit: Failed to execute %s: %m\0A\00"
@.str.1 = [37 x i8] c"scubainit: %s exited with status %d\0A\00"
@.str.2 = [39 x i8] c"scubainit: %s terminated by signal %d\0A\00"
@.str.3 = [60 x i8] c"scubainit: %s exited for an unknown reason! (wstatus=0x%X)\0A\00"
define void @handle_wait_status(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %3
%12 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32 @exit(i32 99)
unreachable
14: ; preds = %2
%15 = load i32, i32* %4
%16 = call i64 @WIFEXITED(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %30
18: ; preds = %14
%19 = load i32, i32* %4
%20 = call i32 @WEXITSTATUS(i32 %19)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %25, i32 %26)
%28 = call i32 @exit(i32 99)
unreachable
29: ; preds = %18
br label %48
30: ; preds = %14
%31 = load i32, i32* %4
%32 = call i64 @WIFSIGNALED(i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %30
%35 = load i32, i32* %4
%36 = call i32 @WTERMSIG(i32 %35)
store i32 %36, i32* %6
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %3
%39 = load i32, i32* %6
%40 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %38, i32 %39)
%41 = call i32 @exit(i32 99)
unreachable
42: ; preds = %30
%43 = load i32, i32* @stderr
%44 = load i8*, i8** %3
%45 = load i32, i32* %4
%46 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i8* %44, i32 %45)
%47 = call i32 @exit(i32 99)
unreachable
48: ; preds = %29
br label %49
49: ; preds = %48
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"scubainit: Failed to execute %s: %m\0A\00"
@.str.1 = [37 x i8] c"scubainit: %s exited with status %d\0A\00"
@.str.2 = [39 x i8] c"scubainit: %s terminated by signal %d\0A\00"
@.str.3 = [60 x i8] c"scubainit: %s exited for an unknown reason! (wstatus=0x%X)\0A\00"
define void @handle_wait_status(i8* %0, i32 %1) {
%3 = icmp slt i32 %1, 0
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32 @exit(i32 99)
unreachable
8: ; preds = %2
%9 = tail call i64 @WIFEXITED(i32 %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %8
%12 = tail call i32 @WEXITSTATUS(i32 %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %12)
%17 = tail call i32 @exit(i32 99)
unreachable
18: ; preds = %11
ret void
19: ; preds = %8
%20 = tail call i64 @WIFSIGNALED(i32 %1)
%21 = icmp eq i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = tail call i32 @WTERMSIG(i32 %1)
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %23)
%26 = tail call i32 @exit(i32 99)
unreachable
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %1)
%30 = tail call i32 @exit(i32 99)
unreachable
}