#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*/ printf(char *, int);
int chk_exit(int status, int want) {
  if (WIFEXITED(status)) {
    if (WEXITSTATUS(status) == want)
      return 0;
    printf("   `- FAIL (exit %d)\n", WEXITSTATUS(status));
  } else if (WIFSIGNALED(status))
    printf("   `- FAIL (die %d)\n", WTERMSIG(status));
  else
    printf("   `- FAIL (%#x)\n", status);
  return 1;
}


x86 assembly (clang, -O0):
<chk_exit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11a8 <chk_exit+0x58>
mov    -0x8(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    -0xc(%rbp),%eax
jne    118d <chk_exit+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    11f0 <chk_exit+0xa0>
mov    -0x8(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
jmp    11e9 <chk_exit+0x99>
mov    -0x8(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     11d5 <chk_exit+0x85>
mov    -0x8(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
jmp    11e4 <chk_exit+0x94>
mov    -0x8(%rbp),%esi
lea    0xe4c(%rip),%rdi
call   1030 <printf@plt>
jmp    11e9 <chk_exit+0x99>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chk_exit>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
call   1070 <WIFEXITED@plt>
mov    %ebx,%edi
test   %rax,%rax
je     1182 <chk_exit+0x32>
call   1060 <WEXITSTATUS@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ebp,%ecx
je     11b1 <chk_exit+0x61>
mov    %ebx,%edi
call   1060 <WEXITSTATUS@plt>
lea    0xe82(%rip),%rdi
mov    %eax,%esi
jmp    11a7 <chk_exit+0x57>
call   1040 <WIFSIGNALED@plt>
test   %rax,%rax
je     119e <chk_exit+0x4e>
mov    %ebx,%edi
call   1050 <WTERMSIG@plt>
lea    0xe7c(%rip),%rdi
mov    %eax,%esi
jmp    11a7 <chk_exit+0x57>
lea    0xe86(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c" `- FAIL (exit %d)\0A\00"
@.str.1 = [21 x i8] c" `- FAIL (die %d)\0A\00"
@.str.2 = [18 x i8] c" `- FAIL (%#x)\0A\00"
define i32 @chk_exit(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
%7 = call i64 @WIFEXITED(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = load i32, i32* %4
%11 = call i32 @WEXITSTATUS(i32 %10)
%12 = load i32, i32* %5
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 0, i32* %3
br label %32
15: ; preds = %9
%16 = load i32, i32* %4
%17 = call i32 @WEXITSTATUS(i32 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %31
19: ; preds = %2
%20 = load i32, i32* %4
%21 = call i64 @WIFSIGNALED(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* %4
%25 = call i32 @WTERMSIG(i32 %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %30
27: ; preds = %19
%28 = load i32, i32* %4
%29 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %23
br label %31
31: ; preds = %30, %15
store i32 1, i32* %3
br label %32
32: ; preds = %31, %14
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [22 x i8] c" `- FAIL (exit %d)\0A\00"
@.str.1 = [21 x i8] c" `- FAIL (die %d)\0A\00"
@.str.2 = [18 x i8] c" `- FAIL (%#x)\0A\00"
define i32 @chk_exit(i32 %0, i32 %1) {
%3 = tail call i64 @WIFEXITED(i32 %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i32 @WEXITSTATUS(i32 %0)
%7 = icmp eq i32 %6, %1
br i1 %7, label %19, label %8
8: ; preds = %5
%9 = tail call i32 @WEXITSTATUS(i32 %0)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %19
11: ; preds = %2
%12 = tail call i64 @WIFSIGNALED(i32 %0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i32 @WTERMSIG(i32 %0)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %15)
br label %19
17: ; preds = %11
%18 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %19
19: ; preds = %8, %17, %14, %5
%20 = phi i32 [ 0, %5 ], [ 1, %14 ], [ 1, %17 ], [ 1, %8 ]
ret i32 %20
}