#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int si_code;
  int /*<<< orphan*/ si_status;
  int /*<<< orphan*/ si_pid;
};
typedef TYPE_1__ siginfo_t;

/* Variables and functions */
#define CLD_CONTINUED 133
#define CLD_DUMPED 132
#define CLD_EXITED 131
#define CLD_KILLED 130
#define CLD_STOPPED 129
#define CLD_TRAPPED 128
int /*<<< orphan*/ SIGCONT;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *format_num(int /*<<< orphan*/);
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
void manage(siginfo_t *si) {
  char buf[100];
  switch (si->si_code) {
  case CLD_STOPPED:
    write(1, "\tchild stopped, restarting\n", 27);
    kill(si->si_pid, SIGCONT);
    break;
  case CLD_CONTINUED:
    write(1, "\tchild continued\n", 17);
    break;
  case CLD_EXITED:
    strcpy(buf, "\tchild exited with status ");
    strcat(buf, format_num(si->si_status));
    strcat(buf, "\n");
    write(1, buf, strlen(buf));
    exit(0);
    break;
  case CLD_DUMPED:
    write(1, "\tchild dumped\n", 14);
    break;
  case CLD_KILLED:
    write(1, "\tchild killed\n", 14);
    break;
  case CLD_TRAPPED:
    write(1, "\tchild trapped\n", 15);
    break;
  }
}


x86 assembly (clang, -O0):
<manage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x78(%rbp)
sub    $0x5,%eax
ja     12b0 <manage+0x140>
mov    -0x78(%rbp),%rax
lea    0xe5e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x1,%edi
lea    0xe61(%rip),%rsi
mov    $0x1b,%edx
call   1050 <write@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
jmp    12b0 <manage+0x140>
mov    $0x1,%edi
lea    0xe4d(%rip),%rsi
mov    $0x11,%edx
call   1050 <write@plt>
jmp    12b0 <manage+0x140>
lea    -0x70(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <format_num@plt>
mov    -0x88(%rbp),%rdi
mov    %rax,%rsi
call   1080 <strcat@plt>
lea    -0x70(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1050 <write@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x1,%edi
lea    0xdf1(%rip),%rsi
mov    $0xe,%edx
call   1050 <write@plt>
jmp    12b0 <manage+0x140>
mov    $0x1,%edi
lea    0xde5(%rip),%rsi
mov    $0xe,%edx
call   1050 <write@plt>
jmp    12b0 <manage+0x140>
mov    $0x1,%edi
lea    0xdd9(%rip),%rsi
mov    $0xf,%edx
call   1050 <write@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<manage>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    (%rdi),%eax
add    $0xffffff80,%eax
cmp    $0x5,%eax
ja     11a7 <manage+0x37>
mov    %rdi,%rbx
lea    0xe75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xee4(%rip),%rsi
mov    $0x1,%edi
mov    $0xf,%edx
jmp    120a <manage+0x9a>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe62(%rip),%rsi
mov    $0x1,%edi
mov    $0x1b,%edx
call   1050 <write@plt>
mov    0x8(%rbx),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
add    $0x68,%rsp
pop    %rbx
pop    %r14
jmp    1070 <kill@plt>
lea    0xe8c(%rip),%rsi
jmp    11ed <manage+0x7d>
lea    0xe74(%rip),%rsi
mov    $0x1,%edi
mov    $0xe,%edx
jmp    120a <manage+0x9a>
lea    0xe34(%rip),%rsi
mov    $0x1,%edi
mov    $0x11,%edx
add    $0x68,%rsp
pop    %rbx
pop    %r14
jmp    1050 <write@plt>
lea    0xe29(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    0x4(%rbx),%edi
call   1030 <format_num@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1080 <strcat@plt>
lea    0xe3b(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <write@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32, i32 }
@.str = [28 x i8] c"\09child stopped, restarting\0A\00"
@SIGCONT = global i32 0
@.str.1 = [18 x i8] c"\09child continued\0A\00"
@.str.2 = [27 x i8] c"\09child exited with status \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [15 x i8] c"\09child dumped\0A\00"
@.str.5 = [15 x i8] c"\09child killed\0A\00"
@.str.6 = [16 x i8] c"\09child trapped\0A\00"
define void @manage(%struct.TYPE_3__* %0) {
%2 = alloca %struct.TYPE_3__*
%3 = alloca [100 x i8]
store %struct.TYPE_3__* %0, %struct.TYPE_3__** %2
%4 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%5 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i32 0, i32 0
%6 = load i32, i32* %5
switch i32 %6, label %38 [
i32 129, label %7
i32 133, label %14
i32 131, label %16
i32 132, label %32
i32 130, label %34
i32 128, label %36
]
7: ; preds = %1
%8 = call i32 @write(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 27)
%9 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 2
%11 = load i32, i32* %10
%12 = load i32, i32* @SIGCONT
%13 = call i32 @kill(i32 %11, i32 %12)
br label %38
14: ; preds = %1
%15 = call i32 @write(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 17)
br label %38
16: ; preds = %1
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%20 = load %struct.TYPE_3__*, %struct.TYPE_3__** %2
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = call i8* @format_num(i32 %22)
%24 = call i32 @strcat(i8* %19, i8* %23)
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%26 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = call i32 @write(i32 1, i8* %27, i32 %29)
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %1
%33 = call i32 @write(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 14)
br label %38
34: ; preds = %1
%35 = call i32 @write(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 14)
br label %38
36: ; preds = %1
%37 = call i32 @write(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 15)
br label %38
38: ; preds = %1, %36, %34, %32, %14, %7
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32, i32 }
@.str = [28 x i8] c"\09child stopped, restarting\0A\00"
@SIGCONT = global i32 0
@.str.1 = [18 x i8] c"\09child continued\0A\00"
@.str.2 = [27 x i8] c"\09child exited with status \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [15 x i8] c"\09child dumped\0A\00"
@.str.5 = [15 x i8] c"\09child killed\0A\00"
@.str.6 = [16 x i8] c"\09child trapped\0A\00"
define void @manage(%struct.TYPE_3__* nocapture %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 0
%5 = load i32, i32* %4
switch i32 %5, label %30 [
i32 129, label %6
i32 133, label %12
i32 131, label %14
i32 132, label %24
i32 130, label %26
i32 128, label %28
]
6: ; preds = %1
%7 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 27)
%8 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 2
%9 = load i32, i32* %8
%10 = load i32, i32* @SIGCONT
%11 = tail call i32 @kill(i32 %9, i32 %10)
br label %30
12: ; preds = %1
%13 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 17)
br label %30
14: ; preds = %1
%15 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %0, i64 0, i32 1
%17 = load i32, i32* %16
%18 = call i8* @format_num(i32 %17)
%19 = call i32 @strcat(i8* %3, i8* %18)
%20 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = call i32 @strlen(i8* %3)
%22 = call i32 @write(i32 1, i8* %3, i32 %21)
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %1
%25 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 14)
br label %30
26: ; preds = %1
%27 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 14)
br label %30
28: ; preds = %1
%29 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 15)
br label %30
30: ; preds = %1, %28, %26, %24, %12, %6
ret void
}