#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 *, ...);
int /*<<< orphan*/ stderr;
void check_status(char *args[], int status) {
  if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
    return;
  fprintf(stderr, "Command '%s %s' failed", args[0], args[1]);
  if (WIFEXITED(status)) {
    fprintf(stderr, " with status %d", WEXITSTATUS(status));
  } else if (WIFSIGNALED(status)) {
    fprintf(stderr, " with signal %d", WTERMSIG(status));
  }
  fprintf(stderr, "\n");
  exit(1);
}


x86 assembly (clang, -O0):
<check_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1198 <check_status+0x38>
mov    -0xc(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x0,%eax
jne    1198 <check_status+0x38>
add    $0x20,%rsp
pop    %rbp
ret
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11fc <check_status+0x9c>
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%edx
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    123a <check_status+0xda>
mov    -0xc(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1235 <check_status+0xd5>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%edx
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    123a <check_status+0xda>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<check_status>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%rbp
mov    %esi,%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     1185 <check_status+0x25>
mov    %ebx,%edi
call   1060 <WEXITSTATUS@plt>
test   %eax,%eax
jne    1185 <check_status+0x25>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e54(%rip),%r14
mov    (%r14),%edi
mov    0x0(%rbp),%rdx
mov    0x8(%rbp),%rcx
lea    0xe62(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %ebx,%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
jne    11d0 <check_status+0x70>
mov    %ebx,%edi
call   1030 <WIFSIGNALED@plt>
test   %rax,%rax
je     11ec <check_status+0x8c>
mov    (%r14),%ebp
mov    %ebx,%edi
call   1050 <WTERMSIG@plt>
lea    0xe59(%rip),%rsi
jmp    11e1 <check_status+0x81>
mov    (%r14),%ebp
mov    %ebx,%edi
call   1060 <WEXITSTATUS@plt>
lea    0xe36(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r14),%edi
lea    0xe41(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Command '%s %s' failed\00"
@.str.1 = [16 x i8] c" with status %d\00"
@.str.2 = [16 x i8] c" with signal %d\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @check_status(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
store i8** %0, i8*** %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* %4
%10 = call i32 @WEXITSTATUS(i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
ret void
13: ; preds = %8, %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %3
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %3
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %20)
%22 = load i32, i32* %4
%23 = call i64 @WIFEXITED(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %13
%26 = load i32, i32* @stderr
%27 = load i32, i32* %4
%28 = call i32 @WEXITSTATUS(i32 %27)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %40
30: ; preds = %13
%31 = load i32, i32* %4
%32 = call i64 @WIFSIGNALED(i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = load i32, i32* %4
%37 = call i32 @WTERMSIG(i32 %36)
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %34, %30
br label %40
40: ; preds = %39, %25
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Command '%s %s' failed\00"
@.str.1 = [16 x i8] c" with status %d\00"
@.str.2 = [16 x i8] c" with signal %d\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @check_status(i8** nocapture %0, i32 %1) {
%3 = tail call i64 @WIFEXITED(i32 %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = tail call i32 @WEXITSTATUS(i32 %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %5
ret void
9: ; preds = %5, %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %0
%12 = getelementptr inbounds i8*, i8** %0, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %13)
%15 = tail call i64 @WIFEXITED(i32 %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = tail call i32 @WEXITSTATUS(i32 %1)
br label %26
20: ; preds = %9
%21 = tail call i64 @WIFSIGNALED(i32 %1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %31, label %23
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = tail call i32 @WTERMSIG(i32 %1)
br label %26
26: ; preds = %17, %23
%27 = phi i32 [ %25, %23 ], [ %19, %17 ]
%28 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %23 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %17 ]
%29 = phi i32 [ %24, %23 ], [ %18, %17 ]
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* %28, i32 %27)
br label %31
31: ; preds = %26, %20
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%34 = tail call i32 @exit(i32 1)
unreachable
}