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

/* Variables and functions */
scalar_t__ CLD_EXITED;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, scalar_t__);
int /*<<< orphan*/ stderr;
void sigchld_handler(int sig, siginfo_t *info, void *ucontext) {
  (void)sig;
  (void)ucontext;
  if (info->si_code == CLD_EXITED && info->si_status != 0) {
    fprintf(stderr, "child process exited with error code %d\n",
            info->si_status);
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<sigchld_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e97(%rip),%rcx
cmp    (%rcx),%rax
jne    1184 <sigchld_handler+0x64>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1184 <sigchld_handler+0x64>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe8f(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigchld_handler>:
push   %rax
mov    (%rsi),%rax
mov    0x2ead(%rip),%rcx
cmp    (%rcx),%rax
jne    1139 <sigchld_handler+0x19>
mov    0x8(%rsi),%rdx
test   %rdx,%rdx
jne    113b <sigchld_handler+0x1b>
pop    %rax
ret
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
lea    0xeb5(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i64 }
@CLD_EXITED = global i64 0
@stderr = global i32 0
@.str = [41 x i8] c"child process exited with error code %d\0A\00"
@EXIT_FAILURE = global i32 0
define void @sigchld_handler(i32 %0, %struct.TYPE_3__* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_3__*
%6 = alloca i8*
store i32 %0, i32* %4
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %5
store i8* %2, i8** %6
%7 = load i32, i32* %4
%8 = load i8*, i8** %6
%9 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* @CLD_EXITED
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %27
14: ; preds = %3
%15 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %15, i32 0, i32 1
%17 = load i64, i64* %16
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %21, i32 0, i32 1
%23 = load i64, i64* %22
%24 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %14, %3
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64 }
@CLD_EXITED = global i64 0
@stderr = global i32 0
@.str = [41 x i8] c"child process exited with error code %d\0A\00"
@EXIT_FAILURE = global i32 0
define void @sigchld_handler(i32 %0, %struct.TYPE_3__* nocapture %1, i8* nocapture readnone %2) {
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%5 = load i64, i64* %4
%6 = load i64, i64* @CLD_EXITED
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %17
8: ; preds = %3
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%10 = load i64, i64* %9
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i64 %10)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %8, %3
ret void
}