#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 */
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
void reap_test_signd() {
  int status;
  pid_t pid = waitpid(0, &status, 0);
  if (pid <= 0) {
    perror("waitpid");
    exit(1);
  }
  if (status) {
    fprintf(stderr, "test signd returned status 0x%x\n", status);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<reap_test_signd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edx,%edx
lea    -0x4(%rbp),%rsi
mov    %edx,%edi
call   1040 <waitpid@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jg     117a <reap_test_signd+0x3a>
lea    0xe95(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x4(%rbp)
je     11a6 <reap_test_signd+0x66>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe71(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reap_test_signd>:
push   %rax
lea    0x4(%rsp),%rsi
xor    %edi,%edi
xor    %edx,%edx
call   1040 <waitpid@plt>
test   %rax,%rax
jle    115e <reap_test_signd+0x1e>
mov    0x4(%rsp),%edx
test   %edx,%edx
jne    1174 <reap_test_signd+0x34>
pop    %rax
ret
lea    0xe9b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"waitpid\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"test signd returned status 0x%x\0A\00"
define void @reap_test_signd() {
%1 = alloca i32
%2 = alloca i64
%3 = call i64 @waitpid(i32 0, i32* %1, i32 0)
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp sle i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i32, i32* %1
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = load i32, i32* %1
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"waitpid\00"
@stderr = global i32 0
@.str.1 = [33 x i8] c"test signd returned status 0x%x\0A\00"
define void @reap_test_signd() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i64 @waitpid(i32 0, i32* %1, i32 0)
%4 = icmp slt i64 %3, 1
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = load i32, i32* %1
%10 = icmp eq i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %8
ret void
}