#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 */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ SIGCHLD;
scalar_t__ SIG_ERR;
int /*<<< orphan*/ WNOHANG;
int /*<<< orphan*/ die(char *);
scalar_t__ signal(int /*<<< orphan*/, void (*)(int));
scalar_t__ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
void sigchld(int unused) {
  if (signal(SIGCHLD, sigchld) == SIG_ERR)
    die("Can't install SIGCHLD handler");
  while (0 < waitpid(-1, NULL, WNOHANG))
    ;
}


x86 assembly (clang, -O0):
<sigchld>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e9e(%rip),%rax
mov    (%rax),%edi
mov    0x2e75(%rip),%rsi
call   1030 <signal@plt>
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%rax
jne    116c <sigchld+0x3c>
lea    0xe99(%rip),%rdi
call   1050 <die@plt>
jmp    1171 <sigchld+0x41>
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <waitpid@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jge    119b <sigchld+0x6b>
jmp    1171 <sigchld+0x41>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigchld>:
push   %rbx
mov    0x2ea8(%rip),%rax
mov    (%rax),%edi
mov    0x2e7f(%rip),%rsi
call   1030 <signal@plt>
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%rax
jne    115e <sigchld+0x2e>
lea    0xea7(%rip),%rdi
call   1050 <die@plt>
mov    0x2e83(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rbx),%edx
mov    $0xffffffff,%edi
xor    %esi,%esi
call   1040 <waitpid@plt>
test   %rax,%rax
jg     1170 <sigchld+0x40>
pop    %rbx
ret

LLVM IR (-O0):
@SIGCHLD = global i32 0
@SIG_ERR = global i64 0
@.str = [30 x i8] c"Can't install SIGCHLD handler\00"
@WNOHANG = global i32 0
define void @sigchld(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @SIGCHLD
%4 = call i64 @signal(i32 %3, void (i32)* @sigchld)
%5 = load i64, i64* @SIG_ERR
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @die(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
br label %10
10: ; preds = %14, %9
%11 = load i32, i32* @WNOHANG
%12 = call i64 @waitpid(i32 -1, i32* null, i32 %11)
%13 = icmp slt i64 0, %12
br i1 %13, label %14, label %15
14: ; preds = %10
br label %10
15: ; preds = %10
ret void
}

LLVM IR (-O2):
@SIGCHLD = global i32 0
@SIG_ERR = global i64 0
@.str = [30 x i8] c"Can't install SIGCHLD handler\00"
@WNOHANG = global i32 0
define void @sigchld(i32 %0) {
%2 = load i32, i32* @SIGCHLD
%3 = tail call i64 @signal(i32 %2, void (i32)* @sigchld)
%4 = load i64, i64* @SIG_ERR
%5 = icmp eq i64 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @die(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
br label %9
9: ; preds = %8, %9
%10 = load i32, i32* @WNOHANG
%11 = tail call i64 @waitpid(i32 -1, i32* null, i32 %10)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %9, label %13
13: ; preds = %9
ret void
}