#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 */

/* Variables and functions */
int fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int main() {
  printf("create process before...\n");
  int pid = fork();
  if (pid == 0) {
    while (1) {
      printf("sub process execute...\n");
      sleep(1);
    }
  } else if (pid == -1) {
    printf("create process fail!\n");
    sleep(1);
  } else {
    while (1) {
      printf("factory process execute...\n");
      sleep(1);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    117f <main+0x4f>
jmp    1164 <main+0x34>
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <sleep@plt>
jmp    1164 <main+0x34>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11a4 <main+0x74>
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <sleep@plt>
jmp    11c4 <main+0x94>
jmp    11a9 <main+0x79>
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <sleep@plt>
jmp    11a9 <main+0x79>
jmp    11c9 <main+0x99>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <fork@plt>
cmp    $0xffffffff,%eax
je     1174 <main+0x44>
test   %eax,%eax
jne    118e <main+0x5e>
lea    0xef5(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <sleep@plt>
jmp    1160 <main+0x30>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <sleep@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe84(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <sleep@plt>
jmp    11a0 <main+0x70>

LLVM IR (-O0):
@.str = [26 x i8] c"create process before...\0A\00"
@.str.1 = [24 x i8] c"sub process execute...\0A\00"
@.str.2 = [22 x i8] c"create process fail!\0A\00"
@.str.3 = [28 x i8] c"factory process execute...\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%4 = call i32 (...) @fork()
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %0
br label %8
8: ; preds = %7, %8
%9 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @sleep(i32 1)
br label %8
11: ; preds = %0
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @sleep(i32 1)
br label %21
17: ; preds = %11
br label %18
18: ; preds = %17, %18
%19 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @sleep(i32 1)
br label %18
21: ; preds = %14
br label %22
22: ; preds = %21
ret i32 0
}

LLVM IR (-O2):
@str = [25 x i8] c"create process before...\00"
@str.4 = [27 x i8] c"factory process execute...\00"
@str.5 = [21 x i8] c"create process fail!\00"
@str.6 = [23 x i8] c"sub process execute...\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (...) @fork()
switch i32 %2, label %9 [
i32 0, label %3
i32 -1, label %6
]
3: ; preds = %0, %3
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.6, i64 0, i64 0))
%5 = tail call i32 @sleep(i32 1)
br label %3
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%8 = tail call i32 @sleep(i32 1)
ret i32 0
9: ; preds = %0, %9
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.4, i64 0, i64 0))
%11 = tail call i32 @sleep(i32 1)
br label %9
}