#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 /*<<< orphan*/);
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
scalar_t__ wait(int /*<<< orphan*/ *);
main() {
  pid_t pc, pr;
  pc = fork();
  if (pc < 0)
    printf("error ocurred!\n");
  else if (pc == 0) {
    printf("This is child process with pid of %d\n", getpid());
    sleep(10);
  } else {
    pr = wait(NULL);
    printf("I catched a child process with pid of %d\n", pr);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1198 <main+0x38>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ed <main+0x8d>
cmpq   $0x0,-0x10(%rbp)
jne    11c9 <main+0x69>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1060 <sleep@plt>
jmp    11e8 <main+0x88>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ed <main+0x8d>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
jns    1190 <main+0x20>
lea    0xecc(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1060 <exit@plt>
jne    11ba <main+0x4a>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe60(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1070 <sleep@plt>
xor    %edi,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1080 <wait@plt>
lea    0xe5e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"error ocurred!\0A\00"
@.str.1 = [38 x i8] c"This is child process with pid of %d\0A\00"
@.str.2 = [42 x i8] c"I catched a child process with pid of %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
store i32 0, i32* %1
%4 = call i64 (...) @fork()
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %21
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 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 @sleep(i32 10)
br label %20
16: ; preds = %9
%17 = call i64 @wait(i32* null)
store i64 %17, i64* %3
%18 = load i64, i64* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i64 %18)
br label %20
20: ; preds = %16, %12
br label %21
21: ; preds = %20, %7
%22 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [38 x i8] c"This is child process with pid of %d\0A\00"
@.str.2 = [42 x i8] c"I catched a child process with pid of %d\0A\00"
@str = [15 x i8] c"error ocurred!\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 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %14
5: ; preds = %0
%6 = icmp eq i64 %1, 0
br i1 %6, label %7, label %11
7: ; preds = %5
%8 = tail call i32 (...) @getpid()
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = tail call i32 @sleep(i32 10)
br label %14
11: ; preds = %5
%12 = tail call i64 @wait(i32* null)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i64 %12)
br label %14
14: ; preds = %7, %11, %3
%15 = tail call i32 @exit(i32 0)
unreachable
}