#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 /*<<< orphan*/ WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ WIFSTOPPED(int);
int /*<<< orphan*/ WSTOPSIG(int);
int /*<<< orphan*/ WTERMSIG(int);
int /*<<< orphan*/ execl(char *, char *, char *);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ genPassMessage(int /*<<< orphan*/);
int /*<<< orphan*/ genSignalMessage(int /*<<< orphan*/);
int getpid();
int /*<<< orphan*/ print_help();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int status;
  if (argc < 2) {
    print_help();
    exit(1);
  }
  pid_t pid = fork();
  if (pid == 0) {
    printf("=======CHILD START=======\n");
    execl(argv[1], argv[1], (char *)0);
  } else if (pid < 0) {
    status = -1;
  } else {
    printf("Parent pid = %d\n", getpid());
    waitpid(pid, &status, 0);
    printf("=======SIGNAL START=======\n");
    printf("Receiving signal from child.\n");
    if (WIFSIGNALED(status)) {
      genSignalMessage(WTERMSIG(status));
    } else if (WIFSTOPPED(status)) {
      genSignalMessage(WSTOPSIG(status));
    } else if (WIFEXITED(status)) {
      genPassMessage(WEXITSTATUS(status));
    }
    printf("=======SIGNAL   END=======\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1221 <main+0x31>
mov    $0x0,%al
call   10c0 <print_help@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1263 <main+0x73>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10f0 <execl@plt>
jmp    1346 <main+0x156>
cmpq   $0x0,-0x20(%rbp)
jge    127a <main+0x8a>
movl   $0xffffffff,-0x14(%rbp)
jmp    1341 <main+0x151>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   10b0 <waitpid@plt>
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     12e2 <main+0xf2>
mov    -0x14(%rbp),%edi
call   1080 <WTERMSIG@plt>
mov    %eax,%edi
call   1040 <genSignalMessage@plt>
jmp    1333 <main+0x143>
mov    -0x14(%rbp),%edi
call   1070 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     1308 <main+0x118>
mov    -0x14(%rbp),%edi
call   1100 <WSTOPSIG@plt>
mov    %eax,%edi
call   1040 <genSignalMessage@plt>
jmp    132e <main+0x13e>
mov    -0x14(%rbp),%edi
call   10d0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1329 <main+0x139>
mov    -0x14(%rbp),%edi
call   10a0 <WEXITSTATUS@plt>
mov    %eax,%edi
call   1090 <genPassMessage@plt>
jmp    132e <main+0x13e>
jmp    1333 <main+0x143>
lea    0xd2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1346 <main+0x156>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    12e4 <main+0xe4>
mov    %rsi,%r14
xor    %eax,%eax
call   1120 <fork@plt>
test   %rax,%rax
je     127c <main+0x7c>
js     12be <main+0xbe>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xdcd(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   10c0 <waitpid@plt>
lea    0xdbf(%rip),%rdi
call   1030 <puts@plt>
lea    0xdce(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%edi
call   1070 <WIFSIGNALED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     1298 <main+0x98>
call   1090 <WTERMSIG@plt>
jmp    12ab <main+0xab>
lea    0xde1(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%r14),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1100 <execl@plt>
jmp    12be <main+0xbe>
call   1080 <WIFSTOPPED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     12c8 <main+0xc8>
call   1110 <WSTOPSIG@plt>
mov    %eax,%edi
call   1050 <genSignalMessage@plt>
lea    0xd90(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
call   10e0 <WIFEXITED@plt>
test   %rax,%rax
je     12b2 <main+0xb2>
mov    0x4(%rsp),%edi
call   10b0 <WEXITSTATUS@plt>
mov    %eax,%edi
call   10a0 <genPassMessage@plt>
jmp    12b2 <main+0xb2>
xor    %eax,%eax
call   10d0 <print_help@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"=======CHILD START=======\0A\00"
@.str.1 = [17 x i8] c"Parent pid = %d\0A\00"
@.str.2 = [28 x i8] c"=======SIGNAL START=======\0A\00"
@.str.3 = [30 x i8] c"Receiving signal from child.\0A\00"
@.str.4 = [28 x i8] c"=======SIGNAL END=======\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (...) @print_help()
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i64 (...) @fork()
store i64 %14, i64* %7
%15 = load i64, i64* %7
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @execl(i8* %21, i8* %24, i8* null)
br label %65
26: ; preds = %13
%27 = load i64, i64* %7
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 -1, i32* %6
br label %64
30: ; preds = %26
%31 = call i32 (...) @getpid()
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i64, i64* %7
%34 = call i32 @waitpid(i64 %33, i32* %6, i32 0)
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* %6
%38 = call i64 @WIFSIGNALED(i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %30
%41 = load i32, i32* %6
%42 = call i32 @WTERMSIG(i32 %41)
%43 = call i32 @genSignalMessage(i32 %42)
br label %62
44: ; preds = %30
%45 = load i32, i32* %6
%46 = call i64 @WIFSTOPPED(i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = load i32, i32* %6
%50 = call i32 @WSTOPSIG(i32 %49)
%51 = call i32 @genSignalMessage(i32 %50)
br label %61
52: ; preds = %44
%53 = load i32, i32* %6
%54 = call i64 @WIFEXITED(i32 %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %52
%57 = load i32, i32* %6
%58 = call i32 @WEXITSTATUS(i32 %57)
%59 = call i32 @genPassMessage(i32 %58)
br label %60
60: ; preds = %56, %52
br label %61
61: ; preds = %60, %48
br label %62
62: ; preds = %61, %40
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %64
64: ; preds = %62, %29
br label %65
65: ; preds = %64, %17
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"Parent pid = %d\0A\00"
@str = [27 x i8] c"=======SIGNAL START=======\00"
@str.5 = [29 x i8] c"Receiving signal from child.\00"
@str.6 = [27 x i8] c"=======SIGNAL END=======\00"
@str.7 = [26 x i8] c"=======CHILD START=======\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 (...) @print_help()
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.7, i64 0, i64 0))
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @execl(i8* %15, i8* %15, i8* null)
br label %48
17: ; preds = %9
%18 = icmp slt i64 %10, 0
br i1 %18, label %48, label %19
19: ; preds = %17
%20 = tail call i32 (...) @getpid()
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 @waitpid(i64 %10, i32* %3, i32 0)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.5, i64 0, i64 0))
%25 = load i32, i32* %3
%26 = call i64 @WIFSIGNALED(i32 %25)
%27 = icmp eq i64 %26, 0
%28 = load i32, i32* %3
br i1 %27, label %32, label %29
29: ; preds = %19
%30 = call i32 @WTERMSIG(i32 %28)
%31 = call i32 @genSignalMessage(i32 %30)
br label %46
32: ; preds = %19
%33 = call i64 @WIFSTOPPED(i32 %28)
%34 = icmp eq i64 %33, 0
%35 = load i32, i32* %3
br i1 %34, label %39, label %36
36: ; preds = %32
%37 = call i32 @WSTOPSIG(i32 %35)
%38 = call i32 @genSignalMessage(i32 %37)
br label %46
39: ; preds = %32
%40 = call i64 @WIFEXITED(i32 %35)
%41 = icmp eq i64 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %39
%43 = load i32, i32* %3
%44 = call i32 @WEXITSTATUS(i32 %43)
%45 = call i32 @genPassMessage(i32 %44)
br label %46
46: ; preds = %36, %42, %39, %29
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
br label %48
48: ; preds = %17, %46, %12
ret i32 0
}