#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 WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ WIFSTOPPED(int);
int WSTOPSIG(int);
int WTERMSIG(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdout;
int wait(int *);
void sigChldHandler() {
  int status;
  pid_t pid = wait(&status);
  if (pid == -1)
    return;
  if (WIFEXITED(status))
    printf("\nProcess '%d' exited with status code %d\n", pid,
           WEXITSTATUS(status));
  else if (WIFSIGNALED(status))
    printf("\nProcess '%d' was terminated by a signal %d\n", pid,
           WTERMSIG(status));
  else if (WIFSTOPPED(status))
    printf("\nProcess '%d' was stoppedby a signal %d\n", pid, WSTOPSIG(status));
  putchar('$');
  putchar(' ');
  fflush(stdout);
}


x86 assembly (clang, -O0):
<sigChldHandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x4(%rbp),%rdi
call   10c0 <wait@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11c3 <sigChldHandler+0x23>
jmp    128c <sigChldHandler+0xec>
mov    -0x4(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11f9 <sigChldHandler+0x59>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe11(%rip),%rdi
call   1040 <printf@plt>
jmp    126a <sigChldHandler+0xca>
mov    -0x4(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     122f <sigChldHandler+0x8f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1080 <WTERMSIG@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe05(%rip),%rdi
call   1040 <printf@plt>
jmp    1265 <sigChldHandler+0xc5>
mov    -0x4(%rbp),%edi
call   1060 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     1260 <sigChldHandler+0xc0>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   10b0 <WSTOPSIG@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xdfc(%rip),%rdi
call   1040 <printf@plt>
jmp    1265 <sigChldHandler+0xc5>
jmp    126a <sigChldHandler+0xca>
mov    $0x24,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigChldHandler>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdi
call   10c0 <wait@plt>
cmp    $0xffffffff,%eax
je     123b <sigChldHandler+0x9b>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
call   10a0 <WIFEXITED@plt>
mov    0xc(%rsp),%edi
test   %rax,%rax
je     11da <sigChldHandler+0x3a>
call   1090 <WEXITSTATUS@plt>
lea    0xe28(%rip),%rdi
jmp    1210 <sigChldHandler+0x70>
call   1050 <WIFSIGNALED@plt>
mov    0xc(%rsp),%edi
test   %rax,%rax
je     11f6 <sigChldHandler+0x56>
call   1080 <WTERMSIG@plt>
lea    0xe36(%rip),%rdi
jmp    1210 <sigChldHandler+0x70>
call   1060 <WIFSTOPPED@plt>
test   %rax,%rax
je     1219 <sigChldHandler+0x79>
mov    0xc(%rsp),%edi
call   10b0 <WSTOPSIG@plt>
lea    0xe47(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    $0x24,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [42 x i8] c"\0AProcess '%d' exited with status code %d\0A\00"
@.str.1 = [45 x i8] c"\0AProcess '%d' was terminated by a signal %d\0A\00"
@.str.2 = [41 x i8] c"\0AProcess '%d' was stoppedby a signal %d\0A\00"
@stdout = global i32 0
define void @sigChldHandler() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 @wait(i32* %1)
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %7
6: ; preds = %0
br label %41
7: ; preds = %0
%8 = load i32, i32* %1
%9 = call i64 @WIFEXITED(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i32, i32* %2
%13 = load i32, i32* %1
%14 = call i32 @WEXITSTATUS(i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %14)
br label %36
16: ; preds = %7
%17 = load i32, i32* %1
%18 = call i64 @WIFSIGNALED(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* %2
%22 = load i32, i32* %1
%23 = call i32 @WTERMSIG(i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %23)
br label %35
25: ; preds = %16
%26 = load i32, i32* %1
%27 = call i64 @WIFSTOPPED(i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = load i32, i32* %2
%31 = load i32, i32* %1
%32 = call i32 @WSTOPSIG(i32 %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %32)
br label %34
34: ; preds = %29, %25
br label %35
35: ; preds = %34, %20
br label %36
36: ; preds = %35, %11
%37 = call i32 @putchar(i8 signext 36)
%38 = call i32 @putchar(i8 signext 32)
%39 = load i32, i32* @stdout
%40 = call i32 @fflush(i32 %39)
br label %41
41: ; preds = %36, %6
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"\0AProcess '%d' exited with status code %d\0A\00"
@.str.1 = [45 x i8] c"\0AProcess '%d' was terminated by a signal %d\0A\00"
@.str.2 = [41 x i8] c"\0AProcess '%d' was stoppedby a signal %d\0A\00"
@stdout = global i32 0
define void @sigChldHandler() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @wait(i32* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %32, label %5
5: ; preds = %0
%6 = load i32, i32* %1
%7 = call i64 @WIFEXITED(i32 %6)
%8 = icmp eq i64 %7, 0
%9 = load i32, i32* %1
br i1 %8, label %13, label %10
10: ; preds = %5
%11 = call i32 @WEXITSTATUS(i32 %9)
%12 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %11)
br label %27
13: ; preds = %5
%14 = call i64 @WIFSIGNALED(i32 %9)
%15 = icmp eq i64 %14, 0
%16 = load i32, i32* %1
br i1 %15, label %20, label %17
17: ; preds = %13
%18 = call i32 @WTERMSIG(i32 %16)
%19 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %18)
br label %27
20: ; preds = %13
%21 = call i64 @WIFSTOPPED(i32 %16)
%22 = icmp eq i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = load i32, i32* %1
%25 = call i32 @WSTOPSIG(i32 %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %3, i32 %25)
br label %27
27: ; preds = %17, %23, %20, %10
%28 = call i32 @putchar(i8 signext 36)
%29 = call i32 @putchar(i8 signext 32)
%30 = load i32, i32* @stdout
%31 = call i32 @fflush(i32 %30)
br label %32
32: ; preds = %0, %27
ret void
}