#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 */
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ WNOHANG;
int /*<<< orphan*/ printf(char *, ...);
int waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
void sighand(int signo) {
  int cpid;
  int status;
  cpid = waitpid(0, &status, WNOHANG);
  if (cpid)
    printf(" %d IS THE CHILD  PROCESS WHICH GOT KILLED\n\n", cpid);
  else
    printf(" THE CHILD PROCESS WAS INTERRUPTED DELIBERATELY \n\n");
  if (WIFEXITED(status))
    printf(" EXIT = %d\n\n", status);
}


x86 assembly (clang, -O0):
<sighand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
lea    -0xc(%rbp),%rsi
call   1040 <waitpid@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1172 <sighand+0x42>
mov    -0x8(%rbp),%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1180 <sighand+0x50>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <WIFEXITED@plt>
cmp    $0x0,%rax
je     11a3 <sighand+0x73>
mov    -0xc(%rbp),%esi
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sighand>:
push   %rax
mov    0x2ea0(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rsi
xor    %edi,%edi
call   1050 <waitpid@plt>
test   %eax,%eax
je     116c <sighand+0x2c>
lea    0xe9f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1178 <sighand+0x38>
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%edi
call   1060 <WIFEXITED@plt>
test   %rax,%rax
je     1198 <sighand+0x58>
mov    0x4(%rsp),%esi
lea    0xe9c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
pop    %rax
ret

LLVM IR (-O0):
@WNOHANG = global i32 0
@.str = [45 x i8] c" %d IS THE CHILD PROCESS WHICH GOT KILLED\0A\0A\00"
@.str.1 = [51 x i8] c" THE CHILD PROCESS WAS INTERRUPTED DELIBERATELY \0A\0A\00"
@.str.2 = [13 x i8] c" EXIT = %d\0A\0A\00"
define void @sighand(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* @WNOHANG
%6 = call i32 @waitpid(i32 0, i32* %4, i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %14
12: ; preds = %1
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = load i32, i32* %4
%16 = call i64 @WIFEXITED(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %18, %14
ret void
}

LLVM IR (-O2):
@WNOHANG = global i32 0
@.str = [45 x i8] c" %d IS THE CHILD PROCESS WHICH GOT KILLED\0A\0A\00"
@.str.2 = [13 x i8] c" EXIT = %d\0A\0A\00"
@str = [50 x i8] c" THE CHILD PROCESS WAS INTERRUPTED DELIBERATELY \0A\00"
define void @sighand(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @WNOHANG
%5 = call i32 @waitpid(i32 0, i32* %2, i32 %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %11
9: ; preds = %1
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
br label %11
11: ; preds = %9, %7
%12 = load i32, i32* %2
%13 = call i64 @WIFEXITED(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %11
ret void
}