#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__ WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int /*<<< orphan*/ errx(int, char *, ...);
int /*<<< orphan*/ failmsg(char *);
int /*<<< orphan*/ puts(char *);
void expect_ok_status(int status) {
  if (WIFEXITED(status)) {
    if (WEXITSTATUS(status)) {
      errx(1,
           "Subprocess exited with %d status: "
           "\e[0;31m"
           "BROKEN"
           "\e[m",
           WEXITSTATUS(status));
    } else {
      puts("Exited normally: "
           "\e[0;32m"
           "OK"
           "\e[m");
    }
  } else if (WIFSIGNALED(status)) {
    failmsg("Unexpected sandbox violation: "
            "\e[0;31m"
            "FAIL"
            "\e[m");
  } else {
    errx(1, "Subprocess neither exited nor stopped: "
            "\e[0;31m"
            "BROKEN"
            "\e[m");
  }
}


x86 assembly (clang, -O0):
<expect_ok_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11c3 <expect_ok_status+0x63>
mov    -0x4(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     11b2 <expect_ok_status+0x52>
mov    -0x4(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %rax,%rdx
mov    $0x1,%edi
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
jmp    11be <expect_ok_status+0x5e>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
jmp    11fe <expect_ok_status+0x9e>
mov    -0x4(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     11e6 <expect_ok_status+0x86>
lea    0xe75(%rip),%rdi
call   1080 <failmsg@plt>
jmp    11f9 <expect_ok_status+0x99>
mov    $0x1,%edi
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
jmp    11fe <expect_ok_status+0x9e>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expect_ok_status>:
push   %rbx
mov    %edi,%ebx
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     1197 <expect_ok_status+0x37>
mov    %ebx,%edi
call   1060 <WEXITSTATUS@plt>
test   %rax,%rax
je     11b0 <expect_ok_status+0x50>
mov    %ebx,%edi
call   1060 <WEXITSTATUS@plt>
lea    0xe79(%rip),%rsi
mov    $0x1,%edi
mov    %rax,%rdx
xor    %eax,%eax
pop    %rbx
jmp    1040 <errx@plt>
mov    %ebx,%edi
call   1050 <WIFSIGNALED@plt>
test   %rax,%rax
je     11bd <expect_ok_status+0x5d>
lea    0xea7(%rip),%rdi
pop    %rbx
jmp    1080 <failmsg@plt>
lea    0xe7c(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
lea    0xeba(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
pop    %rbx
jmp    1040 <errx@plt>

LLVM IR (-O0):
@.str = [51 x i8] c"Subprocess exited with %d status: \1B[0;31mBROKEN\1B[m\00"
@.str.1 = [30 x i8] c"Exited normally: \1B[0;32mOK\1B[m\00"
@.str.2 = [45 x i8] c"Unexpected sandbox violation: \1B[0;31mFAIL\1B[m\00"
@.str.3 = [56 x i8] c"Subprocess neither exited nor stopped: \1B[0;31mBROKEN\1B[m\00"
define void @expect_ok_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 %17
6: ; preds = %1
%7 = load i32, i32* %2
%8 = call i64 @WEXITSTATUS(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i32, i32* %2
%12 = call i64 @WEXITSTATUS(i32 %11)
%13 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i64 %12)
br label %16
14: ; preds = %6
%15 = call i32 @puts(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
br label %26
17: ; preds = %1
%18 = load i32, i32* %2
%19 = call i64 @WIFSIGNALED(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @failmsg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %25
23: ; preds = %17
%24 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
br label %26
26: ; preds = %25, %16
ret void
}

LLVM IR (-O2):
@.str = [51 x i8] c"Subprocess exited with %d status: \1B[0;31mBROKEN\1B[m\00"
@.str.1 = [30 x i8] c"Exited normally: \1B[0;32mOK\1B[m\00"
@.str.2 = [45 x i8] c"Unexpected sandbox violation: \1B[0;31mFAIL\1B[m\00"
@.str.3 = [56 x i8] c"Subprocess neither exited nor stopped: \1B[0;31mBROKEN\1B[m\00"
define void @expect_ok_status(i32 %0) {
%2 = tail call i64 @WIFEXITED(i32 %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i64 @WEXITSTATUS(i32 %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %4
%8 = tail call i64 @WEXITSTATUS(i32 %0)
%9 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i64 %8)
br label %19
10: ; preds = %4
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %19
12: ; preds = %1
%13 = tail call i64 @WIFSIGNALED(i32 %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 @failmsg(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %19
17: ; preds = %12
%18 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %15, %17, %7, %10
ret void
}