#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*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ stderr;
int wait(int *);
int check_wait(pid_t child_pid) {
  int status = 0;
  pid_t ret = wait(&status);
  if (ret != child_pid) {
    fprintf(stderr, "ERROR: wait() returned %d, expected %d\n", ret, child_pid);
    return -1;
  }
  return WEXITSTATUS(status);
}


x86 assembly (clang, -O0):
<check_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <wait@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     1181 <check_wait+0x51>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe90(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118c <check_wait+0x5c>
mov    -0xc(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_wait>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1050 <wait@plt>
cmp    %ebx,%eax
jne    1158 <check_wait+0x28>
mov    0xc(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
jmp    1176 <check_wait+0x46>
mov    0x2e81(%rip),%rcx
mov    (%rcx),%edi
lea    0xe98(%rip),%rsi
mov    %eax,%edx
mov    %ebx,%ecx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"ERROR: wait() returned %d, expected %d\0A\00"
define i32 @check_wait(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
%6 = call i32 @wait(i32* %4)
store i32 %6, i32* %5
%7 = load i32, i32* %5
%8 = load i32, i32* %3
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
store i32 -1, i32* %2
br label %18
15: ; preds = %1
%16 = load i32, i32* %4
%17 = call i32 @WEXITSTATUS(i32 %16)
store i32 %17, i32* %2
br label %18
18: ; preds = %15, %10
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"ERROR: wait() returned %d, expected %d\0A\00"
define i32 @check_wait(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = call i32 @wait(i32* %2)
%5 = icmp eq i32 %4, %0
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %0)
br label %12
9: ; preds = %1
%10 = load i32, i32* %2
%11 = call i32 @WEXITSTATUS(i32 %10)
br label %12
12: ; preds = %9, %6
%13 = phi i32 [ -1, %6 ], [ %11, %9 ]
ret i32 %13
}