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

/* Variables and functions */
int SIGCHLD;
int SIGINT;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ signal(int, void (*)(int));
int wait(int /*<<< orphan*/ *);
void handle(int status) {
  signal(SIGCHLD, handle);
  signal(SIGINT, handle);
  if (status == SIGCHLD) {
    pid_t pid = wait(NULL);
    printf("client : %d exit.....\n", pid);
  } else {
    printf("child process server exit......\n");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<handle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    0x2e75(%rip),%rsi
call   1040 <signal@plt>
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
mov    0x2e60(%rip),%rsi
call   1040 <signal@plt>
mov    -0x4(%rbp),%eax
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%eax
jne    11a9 <handle+0x69>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11be <handle+0x7e>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
mov    0x2e82(%rip),%r15
mov    (%r15),%edi
mov    0x2e68(%rip),%r14
mov    %r14,%rsi
call   1050 <signal@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    %r14,%rsi
call   1050 <signal@plt>
cmp    %ebx,(%r15)
jne    11a2 <handle+0x52>
xor    %edi,%edi
call   1070 <wait@plt>
lea    0xe6c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <printf@plt>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@SIGCHLD = global i32 0
@SIGINT = global i32 0
@.str = [23 x i8] c"client : %d exit.....\0A\00"
@.str.1 = [33 x i8] c"child process server exit......\0A\00"
define void @handle(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* @SIGCHLD
%5 = call i32 @signal(i32 %4, void (i32)* @handle)
%6 = load i32, i32* @SIGINT
%7 = call i32 @signal(i32 %6, void (i32)* @handle)
%8 = load i32, i32* %2
%9 = load i32, i32* @SIGCHLD
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = call i32 @wait(i32* null)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %18
15: ; preds = %1
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %11
ret void
}

LLVM IR (-O2):
@SIGCHLD = global i32 0
@SIGINT = global i32 0
@.str = [23 x i8] c"client : %d exit.....\0A\00"
@str = [32 x i8] c"child process server exit......\00"
define void @handle(i32 %0) {
%2 = load i32, i32* @SIGCHLD
%3 = tail call i32 @signal(i32 %2, void (i32)* @handle)
%4 = load i32, i32* @SIGINT
%5 = tail call i32 @signal(i32 %4, void (i32)* @handle)
%6 = load i32, i32* @SIGCHLD
%7 = icmp eq i32 %6, %0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = tail call i32 @wait(i32* null)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %9)
ret void
11: ; preds = %1
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
}