#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*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    perror("fork");
  }
  if (pid == 0) {
    while (1) {
      sleep(1);
      printf("hello world\n");
    }
  } else {
    sleep(3);
    kill(pid, SIGINT);
  }
  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)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1188 <main+0x38>
lea    0xe7d(%rip),%rdi
call   1050 <perror@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11b3 <main+0x63>
jmp    1198 <main+0x48>
mov    $0x1,%edi
call   1060 <sleep@plt>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
jmp    1198 <main+0x48>
mov    $0x3,%edi
call   1060 <sleep@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
mov    %rax,%rbx
test   %rax,%rax
js     11a4 <main+0x54>
je     1181 <main+0x31>
mov    $0x3,%edi
call   1060 <sleep@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <kill@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe7d(%rip),%rbx
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
jmp    1190 <main+0x40>
lea    0xe55(%rip),%rdi
call   1050 <perror@plt>
jmp    1162 <main+0x12>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [13 x i8] c"hello world\0A\00"
@SIGINT = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 (...) @fork()
store i64 %7, i64* %6
%8 = load i64, i64* %6
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i64, i64* %6
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
br label %16
16: ; preds = %15, %16
%17 = call i32 @sleep(i32 1)
%18 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %16
19: ; preds = %12
%20 = call i32 @sleep(i32 3)
%21 = load i64, i64* %6
%22 = load i32, i32* @SIGINT
%23 = call i32 @kill(i64 %21, i32 %22)
br label %24
24: ; preds = %19
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@SIGINT = global i32 0
@str = [12 x i8] c"hello world\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %12
7: ; preds = %2
%8 = icmp eq i64 %3, 0
br i1 %8, label %9, label %12
9: ; preds = %7, %9
%10 = tail call i32 @sleep(i32 1)
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %9
12: ; preds = %5, %7
%13 = tail call i32 @sleep(i32 3)
%14 = load i32, i32* @SIGINT
%15 = tail call i32 @kill(i64 %3, i32 %14)
ret i32 0
}