#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_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  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);
siginfo_t 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);
  return si;
}


x86 assembly (clang, -O0):
<wait_trap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x18(%rbp)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    0x2e80(%rip),%rax
mov    (%rax),%ecx
mov    0x2e97(%rip),%rax
or     (%rax),%ecx
lea    -0x10(%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    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     11a0 <wait_trap+0x70>
mov    $0x1,%edi
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
mov    -0x8(%rbp),%rax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
je     11cb <wait_trap+0x9b>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rdx
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     11b6 <wait_trap+0x86>
lea    0xe7f(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <errx@plt>
mov    0x8(%rsp),%rdx
mov    (%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.TYPE_4__ = 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 { i64, i64 } @wait_trap(i64 %0) {
%2 = alloca %struct.TYPE_4__
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i32, i32* @P_PID
%5 = load i64, i64* %3
%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_4__* %2, 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_4__, %struct.TYPE_4__* %2, i32 0, i32 0
%15 = load i64, i64* %14
%16 = load i64, i64* %3
%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_4__, %struct.TYPE_4__* %2, 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_4__, %struct.TYPE_4__* %2, 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
%30 = bitcast %struct.TYPE_4__* %2 to { i64, i64 }*
%31 = load { i64, i64 }, { i64, i64 }* %30
ret { i64, i64 } %31
}

LLVM IR (-O2):
%struct.TYPE_4__ = 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 { i64, i64 } @wait_trap(i64 %0) {
%2 = alloca %struct.TYPE_4__
%3 = load i32, i32* @P_PID
%4 = load i32, i32* @WEXITED
%5 = load i32, i32* @WSTOPPED
%6 = or i32 %5, %4
%7 = call i64 @waitid(i32 %3, i64 %0, %struct.TYPE_4__* %2, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 0
%13 = load i64, i64* %12
%14 = icmp eq i64 %13, %0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %2, i64 0, i32 1
%19 = load i64, i64* %18
%20 = load i64, i64* @CLD_TRAPPED
%21 = icmp eq i64 %19, %20
br i1 %21, label %25, label %22
22: ; preds = %17
%23 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i64 %19)
%24 = load i64, i64* %18
br label %25
25: ; preds = %22, %17
%26 = phi i64 [ %24, %22 ], [ %19, %17 ]
%27 = load i64, i64* %12
%28 = insertvalue { i64, i64 } poison, i64 %27, 0
%29 = insertvalue { i64, i64 } %28, i64 %26, 1
ret { i64, i64 } %29
}