#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 /*<<< 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, 0 | 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    0x2ea7(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%ecx
or     $0x0,%ecx
lea    -0x28(%rbp),%rdx
call   1030 <waitid@plt>
cmpq   $0x0,-0x28(%rbp)
jne    115c <wait_for_child+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1182 <wait_for_child+0x72>
mov    -0x20(%rbp),%rax
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%rax
jne    117b <wait_for_child+0x6b>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1182 <wait_for_child+0x72>
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    0x2eb3(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rdx
xor    %esi,%esi
call   1030 <waitid@plt>
cmpq   $0x0,(%rsp)
je     1157 <wait_for_child+0x47>
mov    0x8(%rsp),%rcx
mov    0x2e9c(%rip),%rdx
mov    $0x1,%eax
cmp    (%rdx),%rcx
jne    1152 <wait_for_child+0x42>
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
@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* %3
%10 = or i32 0, %9
%11 = call i32 @waitid(i32 %7, i32 %8, %struct.TYPE_3__* %5, i32 %10)
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 0
%13 = load i64, i64* %12
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 -1, i32* %2
br label %25
16: ; preds = %1
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 1
%18 = load i64, i64* %17
%19 = load i64, i64* @CLD_EXITED
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i32 0, i32 2
%23 = load i32, i32* %22
store i32 %23, i32* %2
br label %25
24: ; preds = %16
store i32 1, i32* %2
br label %25
25: ; preds = %24, %21, %15
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64, i32 }
@P_ALL = 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 = call i32 @waitid(i32 %5, i32 0, %struct.TYPE_3__* %2, i32 %0)
%7 = load i64, i64* %4
%8 = icmp eq i64 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %1
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 1
%11 = load i64, i64* %10
%12 = load i64, i64* @CLD_EXITED
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 2
%16 = load i32, i32* %15
br label %17
17: ; preds = %9, %1, %14
%18 = phi i32 [ %16, %14 ], [ -1, %1 ], [ 1, %9 ]
ret i32 %18
}