#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 int pid_t;

/* Variables and functions */
int WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int wait(int *);
void waitForChild(int error_range) {
  int status;
  pid_t pid = wait(&status);
  if (pid == -1) {
    fprintf(stderr, "Unable to wait for child");
    exit(1);
  }
  if (!WIFEXITED(status) || WEXITSTATUS(status) >= error_range) {
    fprintf(stderr, "Child terminated abnormally\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<waitForChild>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1070 <wait@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1190 <waitForChild+0x40>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%edi
call   1050 <WIFEXITED@plt>
cmp    $0x0,%eax
je     11b2 <waitForChild+0x62>
mov    -0x8(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    -0x4(%rbp),%eax
jl     11d1 <waitForChild+0x81>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitForChild>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
cmp    $0xffffffff,%eax
je     1198 <waitForChild+0x48>
mov    0xc(%rsp),%edi
call   1050 <WIFEXITED@plt>
test   %eax,%eax
je     1186 <waitForChild+0x36>
mov    0xc(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
cmp    %ebx,%eax
jge    1186 <waitForChild+0x36>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
jmp    11a8 <waitForChild+0x58>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Unable to wait for child\00"
@.str.1 = [29 x i8] c"Child terminated abnormally\0A\00"
define void @waitForChild(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 @wait(i32* %3)
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = load i32, i32* %3
%14 = call i32 @WIFEXITED(i32 %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i32, i32* %3
%18 = call i32 @WEXITSTATUS(i32 %17)
%19 = load i32, i32* %2
%20 = icmp sge i32 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %16, %12
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %16
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Unable to wait for child\00"
@.str.1 = [29 x i8] c"Child terminated abnormally\0A\00"
define void @waitForChild(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @wait(i32* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = load i32, i32* %2
%12 = call i32 @WIFEXITED(i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = load i32, i32* %2
%16 = call i32 @WEXITSTATUS(i32 %15)
%17 = icmp slt i32 %16, %0
br i1 %17, label %22, label %18
18: ; preds = %14, %10
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %14
ret void
}