#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*/ err_ret(char *, scalar_t__);
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)
        err_ret("wait(in signal) %u error", info->si_pid);
      else
        printf("pid (wait in signal) = %d\n", 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    0x2e8c(%rip),%rcx
cmp    (%rcx),%eax
jne    1208 <sig_cld+0xd8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
je     11a1 <sig_cld+0x71>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e77(%rip),%rcx
cmp    (%rcx),%rax
je     11a1 <sig_cld+0x71>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%rax
jne    11f0 <sig_cld+0xc0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0x0,%rax
jge    11d7 <sig_cld+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe33(%rip),%rdi
call   1050 <err_ret@plt>
jmp    11eb <sig_cld+0xbb>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
jmp    1203 <sig_cld+0xd3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe36(%rip),%rdi
call   1030 <printf@plt>
jmp    1208 <sig_cld+0xd8>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sig_cld>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
mov    0x2e9c(%rip),%rax
cmp    %edi,(%rax)
jne    11b6 <sig_cld+0x86>
mov    %rsi,%rbx
mov    (%rsi),%rsi
mov    0x2e7b(%rip),%rax
cmp    (%rax),%rsi
je     1183 <sig_cld+0x53>
mov    0x2e97(%rip),%rax
cmp    (%rax),%rsi
je     1183 <sig_cld+0x53>
mov    0x2e5b(%rip),%rax
cmp    (%rax),%rsi
je     1183 <sig_cld+0x53>
lea    0xebb(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <printf@plt>
mov    0x8(%rbx),%rdi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    0x8(%rbx),%rsi
test   %rax,%rax
js     11aa <sig_cld+0x7a>
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
jmp    11b6 <sig_cld+0x86>
lea    0xe4f(%rip),%rdi
call   1050 <err_ret@plt>
add    $0x10,%rsp
pop    %rbx
ret

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 = [25 x i8] c"wait(in signal) %u 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 %52
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 %46
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 %40
35: ; preds = %29
%36 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%37 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %36, i32 0, i32 1
%38 = load i64, i64* %37
%39 = call i32 @err_ret(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %38)
br label %45
40: ; preds = %29
%41 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%42 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %41, i32 0, i32 1
%43 = load i64, i64* %42
%44 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %43)
br label %45
45: ; preds = %40, %35
br label %51
46: ; preds = %23
%47 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%48 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %47, i32 0, i32 0
%49 = load i64, i64* %48
%50 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i64 %49)
br label %51
51: ; preds = %46, %45
br label %52
52: ; preds = %51, %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 = [25 x i8] c"wait(in signal) %u 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 %31
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 %29
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
%24 = load i64, i64* %20
br i1 %23, label %25, label %27
25: ; preds = %19
%26 = call i32 @err_ret(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %24)
br label %31
27: ; preds = %19
%28 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 %24)
br label %31
29: ; preds = %8
%30 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i64 %10)
br label %31
31: ; preds = %29, %27, %25, %3
ret void
}