#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  scalar_t__ si_pid;
  scalar_t__ si_code;
  int si_status;
};
typedef TYPE_1__ siginfo_t;
typedef int /*<<< orphan*/ id_t;

/* Variables and functions */
scalar_t__ CLD_EXITED;
int /*<<< orphan*/ P_ALL;
int WEXITED;
int /*<<< orphan*/ waitid(int /*<<< orphan*/, int /*<<< orphan*/, TYPE_1__ *,
                          int);
int wait_for_child(int options) {
  id_t id_ignored = 0;
  siginfo_t infop;
  infop.si_pid = 0;
  waitid(P_ALL, id_ignored, &infop, WEXITED | options);
  if (infop.si_pid == 0) {
    return -1;
  }
  if (infop.si_code == CLD_EXITED) {
    return infop.si_status;
  }
  return 1;
}


x86 assembly (clang, -O0):
<wait_for_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%esi
mov    0x2eab(%rip),%rax
mov    (%rax),%ecx
or     -0x8(%rbp),%ecx
lea    -0x28(%rbp),%rdx
call   1030 <waitid@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1162 <wait_for_child+0x52>
movl   $0xffffffff,-0x4(%rbp)
jmp    1188 <wait_for_child+0x78>
mov    -0x20(%rbp),%rax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%rax
jne    1181 <wait_for_child+0x71>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1188 <wait_for_child+0x78>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_child>:
sub    $0x18,%rsp
mov    %edi,%ecx
movq   $0x0,(%rsp)
mov    0x2eab(%rip),%rax
mov    (%rax),%edi
mov    0x2eba(%rip),%rax
or     (%rax),%ecx
mov    %rsp,%rdx
xor    %esi,%esi
call   1030 <waitid@plt>
cmpq   $0x0,(%rsp)
je     1160 <wait_for_child+0x50>
mov    0x8(%rsp),%rcx
mov    0x2e8b(%rip),%rdx
mov    $0x1,%eax
cmp    (%rdx),%rcx
jne    115b <wait_for_child+0x4b>
mov    0x10(%rsp),%eax
add    $0x18,%rsp
ret
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i64, i32 }
@P_ALL = global i32 0
@WEXITED = global i32 0
@CLD_EXITED = global i64 0
define i32 @wait_for_child(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.TYPE_3__
store i32 %0, i32* %3
store i32 0, i32* %4
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 0
store i64 0, i64* %6
%7 = load i32, i32* @P_ALL
%8 = load i32, i32* %4
%9 = load i32, i32* @WEXITED
%10 = load i32, i32* %3
%11 = or i32 %9, %10
%12 = call i32 @waitid(i32 %7, i32 %8, %struct.TYPE_3__* %5, i32 %11)
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 0
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %1
store i32 -1, i32* %2
br label %26
17: ; preds = %1
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 1
%19 = load i64, i64* %18
%20 = load i64, i64* @CLD_EXITED
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 2
%24 = load i32, i32* %23
store i32 %24, i32* %2
br label %26
25: ; preds = %17
store i32 1, i32* %2
br label %26
26: ; preds = %25, %22, %16
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64, i32 }
@P_ALL = global i32 0
@WEXITED = global i32 0
@CLD_EXITED = global i64 0
define i32 @wait_for_child(i32 %0) {
%2 = alloca %struct.TYPE_3__
%3 = bitcast %struct.TYPE_3__* %2 to i8*
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 0
store i64 0, i64* %4
%5 = load i32, i32* @P_ALL
%6 = load i32, i32* @WEXITED
%7 = or i32 %6, %0
%8 = call i32 @waitid(i32 %5, i32 0, %struct.TYPE_3__* %2, i32 %7)
%9 = load i64, i64* %4
%10 = icmp eq i64 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %1
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 1
%13 = load i64, i64* %12
%14 = load i64, i64* @CLD_EXITED
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 2
%18 = load i32, i32* %17
br label %19
19: ; preds = %11, %1, %16
%20 = phi i32 [ %18, %16 ], [ -1, %1 ], [ 1, %11 ]
ret i32 %20
}