#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_pid;
};
typedef TYPE_1__ siginfo_t;

/* Variables and functions */
scalar_t__ CLD_DUMPED;
scalar_t__ CLD_EXITED;
scalar_t__ CLD_KILLED;
int SIGCHLD;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pid_remove(int);
int /*<<< orphan*/ printf(char *, scalar_t__);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
void sig_cld(int signo, siginfo_t *info, void *param) {
  int status = 0;
  if (signo == SIGCHLD) {
    if (info->si_code == CLD_EXITED || info->si_code == CLD_KILLED ||
        info->si_code == CLD_DUMPED) {
      if (waitpid(info->si_pid, &status, 0) < 0)
        perror("wait(in signal) error");
      printf("pid (wait in signal) = %d\n", info->si_pid);
      pid_remove(info->si_pid);
    } else {
      printf("unknown signal code %d\n", info->si_code);
    }
  }
}


x86 assembly (clang, -O0):
<sig_cld>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e7c(%rip),%rcx
cmp    (%rcx),%eax
jne    121a <sig_cld+0xda>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%rax
je     11b1 <sig_cld+0x71>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
je     11b1 <sig_cld+0x71>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%rax
jne    1202 <sig_cld+0xc2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0x0,%rax
jge    11da <sig_cld+0x9a>
lea    0xe2b(%rip),%rdi
call   1060 <perror@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%edi
call   1040 <pid_remove@plt>
jmp    1215 <sig_cld+0xd5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
jmp    121a <sig_cld+0xda>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sig_cld>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
mov    0x2e8c(%rip),%rax
cmp    %edi,(%rax)
jne    11c0 <sig_cld+0x80>
mov    %rsi,%rbx
mov    (%rsi),%rsi
mov    0x2e6b(%rip),%rax
cmp    (%rax),%rsi
je     1193 <sig_cld+0x53>
mov    0x2e87(%rip),%rax
cmp    (%rax),%rsi
je     1193 <sig_cld+0x53>
mov    0x2e4b(%rip),%rax
cmp    (%rax),%rsi
je     1193 <sig_cld+0x53>
lea    0xea8(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <printf@plt>
mov    0x8(%rbx),%rdi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
test   %rax,%rax
js     11c6 <sig_cld+0x86>
mov    0x8(%rbx),%rsi
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
mov    0x8(%rbx),%edi
call   1040 <pid_remove@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe33(%rip),%rdi
call   1060 <perror@plt>
jmp    11a8 <sig_cld+0x68>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i64, i64 }
@SIGCHLD = global i32 0
@CLD_EXITED = global i64 0
@CLD_KILLED = global i64 0
@CLD_DUMPED = global i64 0
@.str = [22 x i8] c"wait(in signal) error\00"
@.str.1 = [27 x i8] c"pid (wait in signal) = %d\0A\00"
@.str.2 = [24 x i8] c"unknown signal code %d\0A\00"
define void @sig_cld(i32 %0, %struct.TYPE_3__* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_3__*
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = load i32, i32* @SIGCHLD
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %53
11: ; preds = %3
%12 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%13 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %12, i32 0, i32 0
%14 = load i64, i64* %13
%15 = load i64, i64* @CLD_EXITED
%16 = icmp eq i64 %14, %15
br i1 %16, label %29, label %17
17: ; preds = %11
%18 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i32 0, i32 0
%20 = load i64, i64* %19
%21 = load i64, i64* @CLD_KILLED
%22 = icmp eq i64 %20, %21
br i1 %22, label %29, label %23
23: ; preds = %17
%24 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = load i64, i64* @CLD_DUMPED
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %47
29: ; preds = %23, %17, %11
%30 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%31 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %30, i32 0, i32 1
%32 = load i64, i64* %31
%33 = call i64 @waitpid(i64 %32, i32* %7, i32 0)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
%38 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %38, i32 0, i32 1
%40 = load i64, i64* %39
%41 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %40)
%42 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%43 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %42, i32 0, i32 1
%44 = load i64, i64* %43
%45 = trunc i64 %44 to i32
%46 = call i32 @pid_remove(i32 %45)
br label %52
47: ; preds = %23
%48 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%49 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %48, i32 0, i32 0
%50 = load i64, i64* %49
%51 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i64 %50)
br label %52
52: ; preds = %47, %37
br label %53
53: ; preds = %52, %3
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i64, i64 }
@SIGCHLD = global i32 0
@CLD_EXITED = global i64 0
@CLD_KILLED = global i64 0
@CLD_DUMPED = global i64 0
@.str = [22 x i8] c"wait(in signal) error\00"
@.str.1 = [27 x i8] c"pid (wait in signal) = %d\0A\00"
@.str.2 = [24 x i8] c"unknown signal code %d\0A\00"
define void @sig_cld(i32 %0, %struct.TYPE_3__* nocapture %1, i8* nocapture readnone %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%6 = load i32, i32* @SIGCHLD
%7 = icmp eq i32 %6, %0
br i1 %7, label %8, label %34
8: ; preds = %3
%9 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%10 = load i64, i64* %9
%11 = load i64, i64* @CLD_EXITED
%12 = icmp eq i64 %10, %11
%13 = load i64, i64* @CLD_KILLED
%14 = icmp eq i64 %10, %13
%15 = select i1 %12, i1 true, i1 %14
%16 = load i64, i64* @CLD_DUMPED
%17 = icmp eq i64 %10, %16
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %19, label %32
19: ; preds = %8
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%21 = load i64, i64* %20
%22 = call i64 @waitpid(i64 %21, i32* %4, i32 0)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %19
%27 = load i64, i64* %20
%28 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %27)
%29 = load i64, i64* %20
%30 = trunc i64 %29 to i32
%31 = call i32 @pid_remove(i32 %30)
br label %34
32: ; preds = %8
%33 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i64 %10)
br label %34
34: ; preds = %26, %32, %3
ret void
}