#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*/ SIGKILL;
int /*<<< orphan*/ SIGSTOP;
int /*<<< orphan*/ WNOHANG;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int getpid();
int getppid();
int kill(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ raise(int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
scalar_t__ waitpid(scalar_t__, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main() {
  pid_t pid = 0;
  int ret = 0;
  if ((pid = fork()) < 0) {
    printf("Fork error\n");
    exit(1);
  }
  if (pid == 0) {
    printf("I am child progress(pid:%d).I am waiting for any signal\n",
           getpid());
    raise(SIGSTOP);
    printf("I am child progress(pid:%d).I am killed by progress:%d\n", getpid(),
           getppid());
    exit(0);
  } else {
    sleep(2);
    if ((waitpid(pid, NULL, WNOHANG)) == 0) {
      if ((ret = kill(pid, SIGKILL)) == 0) {
        printf("I am parent progress(pid:%d).I kill %d\n", getpid(), pid);
      }
    }
    waitpid(pid, NULL, 0);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jge    11db <main+0x4b>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1236 <main+0xa6>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <getppid@plt>
mov    -0x18(%rbp),%esi
mov    %eax,%edx
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x2,%edi
call   10a0 <sleep@plt>
mov    -0x10(%rbp),%rdi
mov    0x2d9d(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <waitpid@plt>
cmp    $0x0,%rax
jne    129e <main+0x10e>
mov    -0x10(%rbp),%rdi
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jne    1299 <main+0x109>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    129e <main+0x10e>
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <waitpid@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   10c0 <fork@plt>
test   %rax,%rax
jns    11c3 <main+0x23>
lea    0xee5(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jne    1213 <main+0x73>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe2d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1030 <raise@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1090 <getppid@plt>
lea    0xe38(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    %rax,%rbx
mov    $0x2,%edi
call   10b0 <sleep@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <waitpid@plt>
test   %rax,%rax
jne    1267 <main+0xc7>
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <kill@plt>
test   %eax,%eax
jne    1267 <main+0xc7>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe16(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <waitpid@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"Fork error\0A\00"
@.str.1 = [57 x i8] c"I am child progress(pid:%d).I am waiting for any signal\0A\00"
@SIGSTOP = global i32 0
@.str.2 = [56 x i8] c"I am child progress(pid:%d).I am killed by progress:%d\0A\00"
@WNOHANG = global i32 0
@SIGKILL = global i32 0
@.str.3 = [40 x i8] c"I am parent progress(pid:%d).I kill %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %2
store i32 0, i32* %3
%4 = call i64 (...) @fork()
store i64 %4, i64* %2
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = load i64, i64* %2
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %9
%13 = call i32 (...) @getpid()
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @SIGSTOP
%16 = call i32 @raise(i32 %15)
%17 = call i32 (...) @getpid()
%18 = call i32 (...) @getppid()
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %18)
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %9
%22 = call i32 @sleep(i32 2)
%23 = load i64, i64* %2
%24 = load i32, i32* @WNOHANG
%25 = call i64 @waitpid(i64 %23, i32* null, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %21
%28 = load i64, i64* %2
%29 = load i32, i32* @SIGKILL
%30 = call i32 @kill(i64 %28, i32 %29)
store i32 %30, i32* %3
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = call i32 (...) @getpid()
%34 = load i64, i64* %2
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %33, i64 %34)
br label %36
36: ; preds = %32, %27
br label %37
37: ; preds = %36, %21
%38 = load i64, i64* %2
%39 = call i64 @waitpid(i64 %38, i32* null, i32 0)
%40 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [57 x i8] c"I am child progress(pid:%d).I am waiting for any signal\0A\00"
@SIGSTOP = global i32 0
@.str.2 = [56 x i8] c"I am child progress(pid:%d).I am killed by progress:%d\0A\00"
@WNOHANG = global i32 0
@SIGKILL = global i32 0
@.str.3 = [40 x i8] c"I am parent progress(pid:%d).I kill %d\0A\00"
@str = [11 x i8] c"Fork error\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = icmp eq i64 %1, 0
br i1 %7, label %8, label %17
8: ; preds = %6
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @SIGSTOP
%12 = tail call i32 @raise(i32 %11)
%13 = tail call i32 (...) @getpid()
%14 = tail call i32 (...) @getppid()
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14)
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %6
%18 = tail call i32 @sleep(i32 2)
%19 = load i32, i32* @WNOHANG
%20 = tail call i64 @waitpid(i64 %1, i32* null, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = load i32, i32* @SIGKILL
%24 = tail call i32 @kill(i64 %1, i32 %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = tail call i32 (...) @getpid()
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %27, i64 %1)
br label %29
29: ; preds = %22, %26, %17
%30 = tail call i64 @waitpid(i64 %1, i32* null, i32 0)
%31 = tail call i32 @exit(i32 0)
unreachable
}