#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 */

/* Variables and functions */
int /*<<< orphan*/ AddEStr(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ SIGCHLD;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ signal(int /*<<< orphan*/, void (*)());
int /*<<< orphan*/ snprintf(char *, int, char *, int);
scalar_t__ wait(int *);
void SigChldCaught() {
  int status = 0;
  if (wait(&status) >= 0 && WIFEXITED(status) && WEXITSTATUS(status)) {
    char s[256];
    snprintf(s, 256, "Error: child exited with error code %d!\n",
             WEXITSTATUS(status));
    AddEStr(s, 0, 0);
  }
  signal(SIGCHLD, SigChldCaught);
}


x86 assembly (clang, -O0):
<SigChldCaught>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
call   1080 <wait@plt>
cmp    $0x0,%rax
jl     11e8 <SigChldCaught+0x88>
mov    -0x4(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11e8 <SigChldCaught+0x88>
mov    -0x4(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     11e8 <SigChldCaught+0x88>
lea    -0x110(%rbp),%rax
mov    %rax,-0x118(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    -0x118(%rbp),%rdi
mov    %eax,%ecx
mov    $0x100,%esi
lea    0xe2d(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x110(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <AddEStr@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
mov    0x2df0(%rip),%rsi
call   1050 <signal@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SigChldCaught>:
push   %rbx
sub    $0x110,%rsp
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   1080 <wait@plt>
test   %rax,%rax
js     11ca <SigChldCaught+0x6a>
mov    0xc(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     11ca <SigChldCaught+0x6a>
mov    0xc(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
test   %eax,%eax
je     11ca <SigChldCaught+0x6a>
mov    0xc(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
lea    0xe56(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %eax,%ecx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <AddEStr@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2e0e(%rip),%rsi
call   1050 <signal@plt>
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Error: child exited with error code %d!\0A\00"
@SIGCHLD = global i32 0
define void @SigChldCaught() {
%1 = alloca i32
%2 = alloca [256 x i8]
store i32 0, i32* %1
%3 = call i64 @wait(i32* %1)
%4 = icmp sge i64 %3, 0
br i1 %4, label %5, label %20
5: ; preds = %0
%6 = load i32, i32* %1
%7 = call i64 @WIFEXITED(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %5
%10 = load i32, i32* %1
%11 = call i32 @WEXITSTATUS(i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %9
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%15 = load i32, i32* %1
%16 = call i32 @WEXITSTATUS(i32 %15)
%17 = call i32 @snprintf(i8* %14, i32 256, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%19 = call i32 @AddEStr(i8* %18, i32 0, i32 0)
br label %20
20: ; preds = %13, %9, %5, %0
%21 = load i32, i32* @SIGCHLD
%22 = call i32 @signal(i32 %21, void (...)* bitcast (void ()* @SigChldCaught to void (...)*))
ret void
}

LLVM IR (-O2):
@.str = [41 x i8] c"Error: child exited with error code %d!\0A\00"
@SIGCHLD = global i32 0
define void @SigChldCaught() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = call i64 @wait(i32* %1)
%5 = icmp sgt i64 %4, -1
br i1 %5, label %6, label %20
6: ; preds = %0
%7 = load i32, i32* %1
%8 = call i64 @WIFEXITED(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %6
%11 = load i32, i32* %1
%12 = call i32 @WEXITSTATUS(i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %10
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%16 = load i32, i32* %1
%17 = call i32 @WEXITSTATUS(i32 %16)
%18 = call i32 @snprintf(i8* %15, i32 256, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = call i32 @AddEStr(i8* %15, i32 0, i32 0)
br label %20
20: ; preds = %14, %10, %6, %0
%21 = load i32, i32* @SIGCHLD
%22 = call i32 @signal(i32 %21, void (...)* bitcast (void ()* @SigChldCaught to void (...)*))
ret void
}