#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 SIGCHLD;
scalar_t__ WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int /*<<< orphan*/ abort();
int /*<<< orphan*/ puts(char *);
scalar_t__ wait(int *);
void sig_child_cb(int sig) {
  if (sig != SIGCHLD)
    abort();
  int s;
  while (wait(&s) > 0) {
    if (WIFEXITED(s)) {
      if (WEXITSTATUS(s) != 0)
        puts("Command exited abnormally");
      else
        puts("Command exited normally");
    } else if (WIFSIGNALED(s))
      puts("Terminated by a signal");
  }
}


x86 assembly (clang, -O0):
<sig_child_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%eax
je     1184 <sig_child_cb+0x24>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1189 <sig_child_cb+0x29>
lea    -0x8(%rbp),%rdi
call   1080 <wait@plt>
cmp    $0x0,%rax
jle    120a <sig_child_cb+0xaa>
mov    -0x8(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11e2 <sig_child_cb+0x82>
mov    -0x8(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     11d1 <sig_child_cb+0x71>
lea    0xe39(%rip),%rdi
call   1040 <puts@plt>
jmp    11dd <sig_child_cb+0x7d>
lea    0xe42(%rip),%rdi
call   1040 <puts@plt>
jmp    1205 <sig_child_cb+0xa5>
mov    -0x8(%rbp),%edi
call   1050 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1200 <sig_child_cb+0xa0>
lea    0xe37(%rip),%rdi
call   1040 <puts@plt>
jmp    1205 <sig_child_cb+0xa5>
jmp    1189 <sig_child_cb+0x29>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sig_child_cb>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2e79(%rip),%rax
cmp    %edi,(%rax)
jne    11ef <sig_child_cb+0x8f>
lea    0x4(%rsp),%rdi
call   1080 <wait@plt>
test   %rax,%rax
jle    11e3 <sig_child_cb+0x83>
lea    0xea9(%rip),%r14
lea    0x4(%rsp),%rbx
lea    0xe85(%rip),%r15
lea    0xe64(%rip),%r12
jmp    11bf <sig_child_cb+0x5f>
xchg   %ax,%ax
call   1050 <WIFSIGNALED@plt>
mov    %r14,%rdi
test   %rax,%rax
je     11b2 <sig_child_cb+0x52>
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1080 <wait@plt>
test   %rax,%rax
jle    11e3 <sig_child_cb+0x83>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     11a0 <sig_child_cb+0x40>
call   1060 <WEXITSTATUS@plt>
mov    %r15,%rdi
test   %rax,%rax
je     11ad <sig_child_cb+0x4d>
mov    %r12,%rdi
jmp    11ad <sig_child_cb+0x4d>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@SIGCHLD = global i32 0
@.str = [26 x i8] c"Command exited abnormally\00"
@.str.1 = [24 x i8] c"Command exited normally\00"
@.str.2 = [23 x i8] c"Terminated by a signal\00"
define void @sig_child_cb(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @SIGCHLD
%6 = icmp ne i32 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 (...) @abort()
unreachable
9: ; preds = %1
br label %10
10: ; preds = %33, %9
%11 = call i64 @wait(i32* %3)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %10
%14 = load i32, i32* %3
%15 = call i64 @WIFEXITED(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i32, i32* %3
%19 = call i64 @WEXITSTATUS(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %25
23: ; preds = %17
%24 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
br label %33
26: ; preds = %13
%27 = load i32, i32* %3
%28 = call i64 @WIFSIGNALED(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %26
br label %33
33: ; preds = %32, %25
br label %10
34: ; preds = %10
ret void
}

LLVM IR (-O2):
@SIGCHLD = global i32 0
@.str = [26 x i8] c"Command exited abnormally\00"
@.str.1 = [24 x i8] c"Command exited normally\00"
@.str.2 = [23 x i8] c"Terminated by a signal\00"
define void @sig_child_cb(i32 %0) {
%2 = alloca i32
%3 = load i32, i32* @SIGCHLD
%4 = icmp eq i32 %3, %0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 (...) @abort()
unreachable
7: ; preds = %1
%8 = bitcast i32* %2 to i8*
%9 = call i64 @wait(i32* %2)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %29
11: ; preds = %7, %26
%12 = load i32, i32* %2
%13 = call i64 @WIFEXITED(i32 %12)
%14 = icmp eq i64 %13, 0
%15 = load i32, i32* %2
br i1 %14, label %20, label %16
16: ; preds = %11
%17 = call i64 @WEXITSTATUS(i32 %15)
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0)
br label %23
20: ; preds = %11
%21 = call i64 @WIFSIGNALED(i32 %15)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20, %16
%24 = phi i8* [ %19, %16 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %20 ]
%25 = call i32 @puts(i8* dereferenceable(1) %24)
br label %26
26: ; preds = %23, %20
%27 = call i64 @wait(i32* %2)
%28 = icmp sgt i64 %27, 0
br i1 %28, label %11, label %29
29: ; preds = %26, %7
ret void
}