#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 int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ WAIT_ANY;
int WNOHANG;
int WUNTRACED;
int /*<<< orphan*/ print_status(int /*<<< orphan*/, int);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int);
void sigchld_handler() {
  int status;
  pid_t c_pid;
  while ((c_pid = waitpid(WAIT_ANY, &status, WUNTRACED | WNOHANG)) > 0) {
    print_status(c_pid, status);
  }
}


x86 assembly (clang, -O0):
<sigchld_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%edx
mov    0x2ea7(%rip),%rax
or     (%rax),%edx
lea    -0x4(%rbp),%rsi
call   1040 <waitpid@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1168 <sigchld_handler+0x48>
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1030 <print_status@plt>
jmp    1128 <sigchld_handler+0x8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigchld_handler>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2eb1(%rip),%r14
mov    (%r14),%edi
mov    0x2e97(%rip),%r15
mov    0x2ea8(%rip),%r12
mov    (%r12),%edx
or     (%r15),%edx
lea    0x4(%rsp),%rsi
call   1040 <waitpid@plt>
test   %eax,%eax
jle    1181 <sigchld_handler+0x61>
lea    0x4(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    0x4(%rsp),%esi
mov    %eax,%edi
call   1030 <print_status@plt>
mov    (%r14),%edi
mov    (%r12),%edx
or     (%r15),%edx
mov    %rbx,%rsi
call   1040 <waitpid@plt>
test   %eax,%eax
jg     1160 <sigchld_handler+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@WAIT_ANY = global i32 0
@WUNTRACED = global i32 0
@WNOHANG = global i32 0
define void @sigchld_handler() {
%1 = alloca i32
%2 = alloca i32
br label %3
3: ; preds = %10, %0
%4 = load i32, i32* @WAIT_ANY
%5 = load i32, i32* @WUNTRACED
%6 = load i32, i32* @WNOHANG
%7 = or i32 %5, %6
%8 = call i32 @waitpid(i32 %4, i32* %1, i32 %7)
store i32 %8, i32* %2
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* %2
%12 = load i32, i32* %1
%13 = call i32 @print_status(i32 %11, i32 %12)
br label %3
14: ; preds = %3
ret void
}

LLVM IR (-O2):
@WAIT_ANY = global i32 0
@WUNTRACED = global i32 0
@WNOHANG = global i32 0
define void @sigchld_handler() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @WAIT_ANY
%4 = load i32, i32* @WUNTRACED
%5 = load i32, i32* @WNOHANG
%6 = or i32 %5, %4
%7 = call i32 @waitpid(i32 %3, i32* %1, i32 %6)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %0, %9
%10 = phi i32 [ %17, %9 ], [ %7, %0 ]
%11 = load i32, i32* %1
%12 = call i32 @print_status(i32 %10, i32 %11)
%13 = load i32, i32* @WAIT_ANY
%14 = load i32, i32* @WUNTRACED
%15 = load i32, i32* @WNOHANG
%16 = or i32 %15, %14
%17 = call i32 @waitpid(i32 %13, i32* %1, i32 %16)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %9, label %19
19: ; preds = %9, %0
ret void
}