#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 */
struct rusage {
  int dummy;
};
typedef scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_WARNING;
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WNOHANG;
int /*<<< orphan*/ exit_success(char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, long, int);
scalar_t__ wait3(int *, int /*<<< orphan*/, struct rusage *);
void sig_child(int sig) {
  int status;
  pid_t pid;
  pid = wait3(&status, WNOHANG, (struct rusage *)0);
  if (pid > 0 && WEXITSTATUS(status))
    syslog(LOG_WARNING, "child %ld exit status 0x%x", (long)pid, status);
  exit_success("terminate connection due to child termination");
}


x86 assembly (clang, -O0):
<sig_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <wait3@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    119e <sig_child+0x5e>
mov    -0x8(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     119e <sig_child+0x5e>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%ecx
lea    0xe67(%rip),%rsi
call   1050 <syslog@plt>
lea    0xe76(%rip),%rdi
call   1040 <exit_success@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sig_child>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdi
xor    %edx,%edx
call   1030 <wait3@plt>
test   %rax,%rax
jle    118c <sig_child+0x4c>
mov    %rax,%rbx
mov    0xc(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
test   %rax,%rax
je     118c <sig_child+0x4c>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    0xc(%rsp),%ecx
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdx
call   1050 <syslog@plt>
lea    0xe88(%rip),%rdi
call   1040 <exit_success@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.rusage = type { i32 }
@WNOHANG = global i32 0
@LOG_WARNING = global i32 0
@.str = [27 x i8] c"child %ld exit status 0x%x\00"
@.str.1 = [46 x i8] c"terminate connection due to child termination\00"
define void @sig_child(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
store i32 %0, i32* %2
%5 = load i32, i32* @WNOHANG
%6 = call i64 @wait3(i32* %3, i32 %5, %struct.rusage* null)
store i64 %6, i64* %4
%7 = load i64, i64* %4
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i64 @WEXITSTATUS(i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i32, i32* @LOG_WARNING
%15 = load i64, i64* %4
%16 = load i32, i32* %3
%17 = call i32 @syslog(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %15, i32 %16)
br label %18
18: ; preds = %13, %9, %1
%19 = call i32 @exit_success(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.rusage = type { i32 }
@WNOHANG = global i32 0
@LOG_WARNING = global i32 0
@.str = [27 x i8] c"child %ld exit status 0x%x\00"
@.str.1 = [46 x i8] c"terminate connection due to child termination\00"
define void @sig_child(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @WNOHANG
%5 = call i64 @wait3(i32* %2, i32 %4, %struct.rusage* null)
%6 = icmp sgt i64 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %1
%8 = load i32, i32* %2
%9 = call i64 @WEXITSTATUS(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = load i32, i32* @LOG_WARNING
%13 = load i32, i32* %2
%14 = call i32 @syslog(i32 %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %5, i32 %13)
br label %15
15: ; preds = %11, %7, %1
%16 = call i32 @exit_success(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
ret void
}