#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*/ exit(int);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    perror("fork error:");
    exit(1);
  } else if (pid == 0) {
    printf("Children:I am child process.My pid is %d. I am exiting.\n",
           getpid());
    exit(0);
  }
  printf("Father:I am father process.My pid is %d.I will sleep long long ago\n",
         getpid());
  while (1)
    ;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    118b <main+0x3b>
lea    0xe84(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11b2 <main+0x62>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
jmp    11b7 <main+0x67>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
jmp    11cc <main+0x7c>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     1182 <main+0x32>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
test   %rbx,%rbx
je     1198 <main+0x48>
lea    0xed2(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
nopw   0x0(%rax,%rax,1)
jmp    1180 <main+0x30>
lea    0xe77(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe6d(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"fork error:\00"
@.str.1 = [57 x i8] c"Children:I am child process.My pid is %d. I am exiting.\0A\00"
@.str.2 = [68 x i8] c"Father:I am father process.My pid is %d.I will sleep long long ago\0A\00"
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 %9
6: ; preds = %0
%7 = call i32 @perror(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 %16
12: ; preds = %9
%13 = call i32 (...) @getpid()
%14 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %9
br label %17
17: ; preds = %16
%18 = call i32 (...) @getpid()
%19 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17, %20
br label %20
}

LLVM IR (-O2):
@.str = [12 x i8] c"fork error:\00"
@.str.1 = [57 x i8] c"Children:I am child process.My pid is %d. I am exiting.\0A\00"
@.str.2 = [68 x i8] c"Father:I am father process.My pid is %d.I will sleep long long ago\0A\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 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = icmp eq i64 %1, 0
%8 = tail call i32 (...) @getpid()
br i1 %7, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %6
%13 = tail call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0), i32 %8)
br label %14
14: ; preds = %14, %12
br label %14
}