#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 */
scalar_t__ fork();
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) {
      printf("in son process\n");
      sleep(1);
    }
  } else {
    while (1) {
      printf("in father  process\n");
      sleep(1);
    }
  }
  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   1060 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1178 <main+0x38>
lea    0xe8d(%rip),%rdi
call   1040 <perror@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11a3 <main+0x63>
jmp    1188 <main+0x48>
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1188 <main+0x48>
jmp    11a8 <main+0x68>
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    11a8 <main+0x68>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
js     1184 <main+0x44>
je     1168 <main+0x28>
nop
lea    0xeae(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1150 <main+0x10>
lea    0xea9(%rip),%rbx
nop
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
jmp    1170 <main+0x30>
lea    0xe75(%rip),%rdi
call   1040 <perror@plt>
jmp    1150 <main+0x10>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [16 x i8] c"in son process\0A\00"
@.str.2 = [20 x i8] c"in father process\0A\00"
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 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @sleep(i32 1)
br label %16
19: ; preds = %12
br label %20
20: ; preds = %19, %20
%21 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @sleep(i32 1)
br label %20
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@str = [19 x i8] c"in father process\00"
@str.3 = [15 x i8] c"in son process\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 %9
7: ; preds = %2
%8 = icmp eq i64 %3, 0
br i1 %8, label %10, label %9
9: ; preds = %5, %7
br label %13
10: ; preds = %7, %10
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.3, i64 0, i64 0))
%12 = tail call i32 @sleep(i32 1)
br label %10
13: ; preds = %9, %13
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @sleep(i32 1)
br label %13
}