#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 /*<<< orphan*/ pid_t;

/* Variables and functions */
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, int, char *);
char *strsignal(int);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int check_zombie_child(int status, pid_t pid) {
  waitpid(pid, &status, 0);
  if (WIFEXITED(status)) {
    if (WEXITSTATUS(status) != 0xFF)
      exit(-1);
  } else if (WIFSIGNALED(status)) {
    printf("KERNEL Oops. Exit Code = %d.(%s)\n", WTERMSIG(status),
           strsignal(WTERMSIG(status)));
    return (WTERMSIG(status));
  }
}


x86 assembly (clang, -O0):
<check_zombie_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    -0x8(%rbp),%edi
call   1090 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11d0 <check_zombie_child+0x50>
mov    -0x8(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
cmp    $0xff,%eax
je     11cb <check_zombie_child+0x4b>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
jmp    1223 <check_zombie_child+0xa3>
mov    -0x8(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     121e <check_zombie_child+0x9e>
mov    -0x8(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,%edi
call   1060 <strsignal@plt>
mov    -0x10(%rbp),%esi
mov    %rax,%rdx
lea    0xdf7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,-0x4(%rbp)
jmp    1223 <check_zombie_child+0xa3>
jmp    1223 <check_zombie_child+0xa3>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_zombie_child>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%eax
mov    %edi,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1090 <WIFEXITED@plt>
mov    0xc(%rsp),%edi
test   %rax,%rax
je     11c4 <check_zombie_child+0x44>
call   1070 <WEXITSTATUS@plt>
mov    %eax,%ecx
cmp    $0xff,%ecx
je     1205 <check_zombie_child+0x85>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
call   1040 <WIFSIGNALED@plt>
test   %rax,%rax
je     1205 <check_zombie_child+0x85>
mov    0xc(%rsp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,%ebx
mov    0xc(%rsp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,%edi
call   1060 <strsignal@plt>
lea    0xe10(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
call   1030 <printf@plt>
mov    0xc(%rsp),%edi
call   1050 <WTERMSIG@plt>
jmp    1205 <check_zombie_child+0x85>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [34 x i8] c"KERNEL Oops. Exit Code = %d.(%s)\0A\00"
define i32 @check_zombie_child(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = call i32 @waitpid(i32 %6, i32* %4, i32 0)
%8 = load i32, i32* %4
%9 = call i64 @WIFEXITED(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* %4
%13 = call i32 @WEXITSTATUS(i32 %12)
%14 = icmp ne i32 %13, 255
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %11
br label %32
18: ; preds = %2
%19 = load i32, i32* %4
%20 = call i64 @WIFSIGNALED(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %18
%23 = load i32, i32* %4
%24 = call i32 @WTERMSIG(i32 %23)
%25 = load i32, i32* %4
%26 = call i32 @WTERMSIG(i32 %25)
%27 = call i8* @strsignal(i32 %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %24, i8* %27)
%29 = load i32, i32* %4
%30 = call i32 @WTERMSIG(i32 %29)
store i32 %30, i32* %3
br label %32
31: ; preds = %18
br label %32
32: ; preds = %22, %31, %17
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [34 x i8] c"KERNEL Oops. Exit Code = %d.(%s)\0A\00"
define i32 @check_zombie_child(i32 %0, i32 %1) {
%3 = alloca i32
store i32 %0, i32* %3
%4 = call i32 @waitpid(i32 %1, i32* %3, i32 0)
%5 = load i32, i32* %3
%6 = call i64 @WIFEXITED(i32 %5)
%7 = icmp eq i64 %6, 0
%8 = load i32, i32* %3
br i1 %7, label %14, label %9
9: ; preds = %2
%10 = call i32 @WEXITSTATUS(i32 %8)
%11 = icmp eq i32 %10, 255
br i1 %11, label %26, label %12
12: ; preds = %9
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = call i64 @WIFSIGNALED(i32 %8)
%16 = icmp eq i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %14
%18 = load i32, i32* %3
%19 = call i32 @WTERMSIG(i32 %18)
%20 = load i32, i32* %3
%21 = call i32 @WTERMSIG(i32 %20)
%22 = call i8* @strsignal(i32 %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %19, i8* %22)
%24 = load i32, i32* %3
%25 = call i32 @WTERMSIG(i32 %24)
br label %26
26: ; preds = %14, %9, %17
%27 = phi i32 [ undef, %9 ], [ %25, %17 ], [ undef, %14 ]
ret i32 %27
}