#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;
};
typedef TYPE_1__ siginfo_t;
typedef scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ CLD_TRAPPED;
int /*<<< orphan*/ P_PID;
int WEXITED;
int WSTOPPED;
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ errx(int, char *, ...);
scalar_t__ waitid(int /*<<< orphan*/, scalar_t__, TYPE_1__ *, int);
void wait_trap(pid_t chld) {
  siginfo_t si;
  if (waitid(P_PID, chld, &si, WEXITED | WSTOPPED) != 0)
    err(1, "waitid");
  if (si.si_pid != chld)
    errx(1, "got unexpected pid in event\n");
  if (si.si_code != CLD_TRAPPED)
    errx(1, "got unexpected event type %d\n", si.si_code);
}


x86 assembly (clang, -O0):
<wait_trap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    0x2e80(%rip),%rax
mov    (%rax),%ecx
mov    0x2e97(%rip),%rax
or     (%rax),%ecx
lea    -0x18(%rbp),%rdx
call   1050 <waitid@plt>
cmp    $0x0,%rax
je     117f <wait_trap+0x4f>
mov    $0x1,%edi
lea    0xe86(%rip),%rsi
call   1040 <err@plt>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     11a0 <wait_trap+0x70>
mov    $0x1,%edi
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
mov    -0x10(%rbp),%rax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
je     11cb <wait_trap+0x9b>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_trap>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
mov    0x2e88(%rip),%rax
mov    0x2ea1(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %rsp,%rdx
mov    %rbx,%rsi
call   1050 <waitid@plt>
test   %rax,%rax
je     1174 <wait_trap+0x44>
lea    0xe96(%rip),%rsi
mov    $0x1,%edi
call   1040 <err@plt>
cmp    %rbx,(%rsp)
je     118d <wait_trap+0x5d>
lea    0xe86(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <errx@plt>
mov    0x8(%rsp),%rdx
mov    0x2e47(%rip),%rax
cmp    (%rax),%rdx
je     11b1 <wait_trap+0x81>
lea    0xe7f(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <errx@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i64 }
@P_PID = global i32 0
@WEXITED = global i32 0
@WSTOPPED = global i32 0
@.str = [7 x i8] c"waitid\00"
@.str.1 = [29 x i8] c"got unexpected pid in event\0A\00"
@CLD_TRAPPED = global i64 0
@.str.2 = [30 x i8] c"got unexpected event type %d\0A\00"
define void @wait_trap(i64 %0) {
%2 = alloca i64
%3 = alloca %struct.TYPE_3__
store i64 %0, i64* %2
%4 = load i32, i32* @P_PID
%5 = load i64, i64* %2
%6 = load i32, i32* @WEXITED
%7 = load i32, i32* @WSTOPPED
%8 = or i32 %6, %7
%9 = call i64 @waitid(i32 %4, i64 %5, %struct.TYPE_3__* %3, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 0
%15 = load i64, i64* %14
%16 = load i64, i64* %2
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 1
%22 = load i64, i64* %21
%23 = load i64, i64* @CLD_TRAPPED
%24 = icmp ne i64 %22, %23
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i32 0, i32 1
%27 = load i64, i64* %26
%28 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %27)
br label %29
29: ; preds = %25, %20
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64 }
@P_PID = global i32 0
@WEXITED = global i32 0
@WSTOPPED = global i32 0
@.str = [7 x i8] c"waitid\00"
@.str.1 = [29 x i8] c"got unexpected pid in event\0A\00"
@CLD_TRAPPED = global i64 0
@.str.2 = [30 x i8] c"got unexpected event type %d\0A\00"
define void @wait_trap(i64 %0) {
%2 = alloca %struct.TYPE_3__
%3 = bitcast %struct.TYPE_3__* %2 to i8*
%4 = load i32, i32* @P_PID
%5 = load i32, i32* @WEXITED
%6 = load i32, i32* @WSTOPPED
%7 = or i32 %6, %5
%8 = call i64 @waitid(i32 %4, i64 %0, %struct.TYPE_3__* %2, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 0
%14 = load i64, i64* %13
%15 = icmp eq i64 %14, %0
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %2, i64 0, i32 1
%20 = load i64, i64* %19
%21 = load i64, i64* @CLD_TRAPPED
%22 = icmp eq i64 %20, %21
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %20)
br label %25
25: ; preds = %23, %18
ret void
}