#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 pid_t;

/* Variables and functions */
int SIGCHLD;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ printf(char *, int, int);
int wait(int *);
void signal_handler(int signo) {
  pid_t pid;
  int status;
  if (signo == SIGCHLD) {
    pid = wait(&status);
    if (WIFEXITED(status)) {
      printf("Child %d exited with status %u\n", pid, WEXITSTATUS(status));
    }
  }
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e93(%rip),%rcx
cmp    (%rcx),%eax
jne    119f <signal_handler+0x5f>
lea    -0xc(%rbp),%rdi
call   1060 <wait@plt>
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <WIFEXITED@plt>
cmp    $0x0,%rax
je     119a <signal_handler+0x5a>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe6b(%rip),%rdi
call   1030 <printf@plt>
jmp    119f <signal_handler+0x5f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rax
cmp    %edi,(%rax)
jne    1183 <signal_handler+0x43>
lea    0xc(%rsp),%rdi
call   1060 <wait@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
call   1050 <WIFEXITED@plt>
test   %rax,%rax
je     1183 <signal_handler+0x43>
mov    0xc(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
lea    0xe86(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SIGCHLD = global i32 0
@.str = [32 x i8] c"Child %d exited with status %u\0A\00"
define void @signal_handler(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* @SIGCHLD
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %19
8: ; preds = %1
%9 = call i32 @wait(i32* %4)
store i32 %9, i32* %3
%10 = load i32, i32* %4
%11 = call i64 @WIFEXITED(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = call i32 @WEXITSTATUS(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %16)
br label %18
18: ; preds = %13, %8
br label %19
19: ; preds = %18, %1
ret void
}

LLVM IR (-O2):
@SIGCHLD = global i32 0
@.str = [32 x i8] c"Child %d exited with status %u\0A\00"
define void @signal_handler(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @SIGCHLD
%5 = icmp eq i32 %4, %0
br i1 %5, label %6, label %15
6: ; preds = %1
%7 = call i32 @wait(i32* %2)
%8 = load i32, i32* %2
%9 = call i64 @WIFEXITED(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = load i32, i32* %2
%13 = call i32 @WEXITSTATUS(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %13)
br label %15
15: ; preds = %6, %11, %1
ret void
}