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

/* Variables and functions */
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ printf(char *, ...);
void print_child_end_reason(pid_t child_pid, const char *child_label,
                            int end_status) {
  printf("%s exit (pid = %d):", child_label, (int)child_pid);
  if (WIFSIGNALED(end_status)) {
    printf("signal termination %s(signal = %d)\n", (""), WTERMSIG(end_status));
  } else if (WIFEXITED(end_status)) {
    printf("normal termination (exit code = %d)\n", WEXITSTATUS(end_status));
  } else {
    printf("unknown type of termination\n");
  }
}


x86 assembly (clang, -O0):
<print_child_end_reason>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    %eax,%edx
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     11b1 <print_child_end_reason+0x61>
mov    -0x14(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,%edx
lea    0xe76(%rip),%rdi
lea    0xeb7(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f3 <print_child_end_reason+0xa3>
mov    -0x14(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11e0 <print_child_end_reason+0x90>
mov    -0x14(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    %eax,%esi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ee <print_child_end_reason+0x9e>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f3 <print_child_end_reason+0xa3>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_child_end_reason>:
push   %rbx
mov    %edx,%ebx
mov    %rdi,%rdx
lea    0xe93(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <WIFSIGNALED@plt>
test   %rax,%rax
je     119f <print_child_end_reason+0x3f>
mov    %ebx,%edi
call   1060 <WTERMSIG@plt>
lea    0xe86(%rip),%rdi
lea    0xec7(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
pop    %rbx
jmp    1040 <printf@plt>
mov    %ebx,%edi
call   1080 <WIFEXITED@plt>
test   %rax,%rax
je     11c3 <print_child_end_reason+0x63>
mov    %ebx,%edi
call   1070 <WEXITSTATUS@plt>
lea    0xe7f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
pop    %rbx
jmp    1040 <printf@plt>
lea    0xe93(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"%s exit (pid = %d):\00"
@.str.1 = [36 x i8] c"signal termination %s(signal = %d)\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [37 x i8] c"normal termination (exit code = %d)\0A\00"
@.str.4 = [29 x i8] c"unknown type of termination\0A\00"
define void @print_child_end_reason(i64 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i64 %0, i64* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i8*, i8** %5
%8 = load i64, i64* %4
%9 = trunc i64 %8 to i32
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %9)
%11 = load i32, i32* %6
%12 = call i64 @WIFSIGNALED(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i32, i32* %6
%16 = call i32 @WTERMSIG(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %29
18: ; preds = %3
%19 = load i32, i32* %6
%20 = call i64 @WIFEXITED(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* %6
%24 = call i32 @WEXITSTATUS(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %24)
br label %28
26: ; preds = %18
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
br label %29
29: ; preds = %28, %14
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"%s exit (pid = %d):\00"
@.str.1 = [36 x i8] c"signal termination %s(signal = %d)\0A\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [37 x i8] c"normal termination (exit code = %d)\0A\00"
@str = [28 x i8] c"unknown type of termination\00"
define void @print_child_end_reason(i64 %0, i8* %1, i32 %2) {
%4 = trunc i64 %0 to i32
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %4)
%6 = tail call i64 @WIFSIGNALED(i32 %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = tail call i32 @WTERMSIG(i32 %2)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %19
11: ; preds = %3
%12 = tail call i64 @WIFEXITED(i32 %2)
%13 = icmp eq i64 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = tail call i32 @WEXITSTATUS(i32 %2)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i32 %15)
br label %19
17: ; preds = %11
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %19
19: ; preds = %14, %17, %8
ret void
}