#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 */
typedef scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ WNOHANG;
scalar_t__ errno;
scalar_t__ waitpid(int, int *, int /*<<< orphan*/);
void sigchld_cb(int sig, short ev, void *data) {
  int status;
  pid_t pid;
  while ((pid = waitpid(-1, &status, WNOHANG)) > 0 ||
         (pid < 0 && errno == EINTR))
    ;
}


x86 assembly (clang, -O0):
<sigchld_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %rdx,-0x10(%rbp)
mov    0x2ebb(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
lea    -0x14(%rbp),%rsi
call   1030 <waitpid@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
jg     1183 <sigchld_cb+0x73>
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x22(%rbp)
jge    117d <sigchld_cb+0x6d>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1193 <sigchld_cb+0x83>
jmp    1198 <sigchld_cb+0x88>
jmp    1126 <sigchld_cb+0x16>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigchld_cb>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2ec9(%rip),%r14
lea    0x4(%rsp),%rbx
mov    0x2ead(%rip),%r15
mov    0x2e9e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14),%edx
mov    $0xffffffff,%edi
mov    %rbx,%rsi
call   1030 <waitpid@plt>
test   %rax,%rax
jg     1140 <sigchld_cb+0x30>
je     1160 <sigchld_cb+0x50>
mov    (%r12),%rax
cmp    %rax,(%r15)
je     1140 <sigchld_cb+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@WNOHANG = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define void @sigchld_cb(i32 %0, i16 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
store i32 %0, i32* %4
store i16 %1, i16* %5
store i8* %2, i8** %6
br label %9
9: ; preds = %24, %3
%10 = load i32, i32* @WNOHANG
%11 = call i64 @waitpid(i32 -1, i32* %7, i32 %10)
store i64 %11, i64* %8
%12 = icmp sgt i64 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %9
%14 = load i64, i64* %8
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i64, i64* @errno
%18 = load i64, i64* @EINTR
%19 = icmp eq i64 %17, %18
br label %20
20: ; preds = %16, %13
%21 = phi i1 [ false, %13 ], [ %19, %16 ]
br label %22
22: ; preds = %20, %9
%23 = phi i1 [ true, %9 ], [ %21, %20 ]
br i1 %23, label %24, label %25
24: ; preds = %22
br label %9
25: ; preds = %22
ret void
}

LLVM IR (-O2):
@WNOHANG = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define void @sigchld_cb(i32 %0, i16 signext %1, i8* nocapture readnone %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
br label %6
6: ; preds = %10, %3
%7 = load i32, i32* @WNOHANG
%8 = call i64 @waitpid(i32 -1, i32* %4, i32 %7)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %6, %11
br label %6
11: ; preds = %6
%12 = icmp ne i64 %8, 0
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp eq i64 %13, %14
%16 = select i1 %12, i1 %15, i1 false
br i1 %16, label %10, label %17
17: ; preds = %11
ret void
}