#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*/ SIGINT;
scalar_t__ fork();
int /*<<< orphan*/ kill(scalar_t__, int /*<<< orphan*/);
scalar_t__ pause();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int main(void) {
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    perror("fork");
  } else if (pid == 0) {
    printf("I am child processm, I will PAUSE now\n");
    if (pause() < 0) {
      perror("pause");
    }
    while (1) {
      printf("hello i am child process\n");
      sleep(1);
    }
  } else {
    sleep(3);
    printf("i am a father process,i will send signal now\n");
    kill(pid, SIGINT);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1196 <main+0x36>
lea    0xe74(%rip),%rdi
call   1060 <perror@plt>
jmp    1217 <main+0xb7>
cmpq   $0x0,-0x10(%rbp)
jne    11ea <main+0x8a>
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <pause@plt>
cmp    $0x0,%rax
jge    11ca <main+0x6a>
lea    0xe67(%rip),%rdi
call   1060 <perror@plt>
jmp    11cf <main+0x6f>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    11cf <main+0x6f>
mov    $0x3,%edi
call   1070 <sleep@plt>
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
jmp    1217 <main+0xb7>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
js     11d4 <main+0x74>
je     119d <main+0x3d>
mov    %rax,%rbx
mov    $0x3,%edi
call   1070 <sleep@plt>
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <kill@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <pause@plt>
test   %rax,%rax
js     11e2 <main+0x82>
lea    0xea2(%rip),%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    11c0 <main+0x60>
lea    0xe25(%rip),%rdi
call   1060 <perror@plt>
jmp    1199 <main+0x39>
lea    0xe1c(%rip),%rdi
call   1060 <perror@plt>
jmp    11b5 <main+0x55>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [39 x i8] c"I am child processm, I will PAUSE now\0A\00"
@.str.2 = [6 x i8] c"pause\00"
@.str.3 = [26 x i8] c"hello i am child process\0A\00"
@.str.4 = [46 x i8] c"i am a father process,i will send signal now\0A\00"
@SIGINT = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %28
8: ; preds = %0
%9 = load i64, i64* %2
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%13 = call i64 (...) @pause()
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
br label %18
18: ; preds = %17, %18
%19 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @sleep(i32 1)
br label %18
21: ; preds = %8
%22 = call i32 @sleep(i32 3)
%23 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0))
%24 = load i64, i64* %2
%25 = load i32, i32* @SIGINT
%26 = call i32 @kill(i64 %24, i32 %25)
br label %27
27: ; preds = %21
br label %28
28: ; preds = %27, %6
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.2 = [6 x i8] c"pause\00"
@SIGINT = global i32 0
@str = [45 x i8] c"i am a father process,i will send signal now\00"
@str.5 = [38 x i8] c"I am child processm, I will PAUSE now\00"
@str.6 = [25 x i8] c"hello i am child process\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %22
5: ; preds = %0
%6 = icmp eq i64 %1, 0
br i1 %6, label %7, label %17
7: ; preds = %5
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.5, i64 0, i64 0))
%9 = tail call i64 (...) @pause()
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
br label %14
14: ; preds = %13, %14
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0))
%16 = tail call i32 @sleep(i32 1)
br label %14
17: ; preds = %5
%18 = tail call i32 @sleep(i32 3)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%20 = load i32, i32* @SIGINT
%21 = tail call i32 @kill(i64 %1, i32 %20)
br label %22
22: ; preds = %17, %3
ret i32 0
}