#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 int pid_t;

/* Variables and functions */
int fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int main(void) {
  pid_t p = fork();
  printf("Fork na watku %d \n", p);
  if (p == 0) {
    printf("Child process \n");
  } else if (p < 0) {
    printf("Failed fork \n");
  } else {
    printf("Parent process \n");
  }
  sleep(2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1177 <main+0x47>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a7 <main+0x77>
cmpl   $0x0,-0x8(%rbp)
jge    1194 <main+0x64>
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a2 <main+0x72>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a7 <main+0x77>
mov    $0x2,%edi
call   1040 <sleep@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,%ebx
lea    0xeaf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
lea    0xec0(%rip),%rax
lea    0xea9(%rip),%rcx
cmovs  %rax,%rcx
lea    0xebb(%rip),%rdi
cmovne %rcx,%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Fork na watku %d \0A\00"
@.str.1 = [16 x i8] c"Child process \0A\00"
@.str.2 = [14 x i8] c"Failed fork \0A\00"
@.str.3 = [17 x i8] c"Parent process \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @fork()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %18
10: ; preds = %0
%11 = load i32, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %17
15: ; preds = %10
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %15, %13
br label %18
18: ; preds = %17, %8
%19 = call i32 @sleep(i32 2)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"Fork na watku %d \0A\00"
@str = [16 x i8] c"Parent process \00"
@str.4 = [13 x i8] c"Failed fork \00"
@str.5 = [15 x i8] c"Child process \00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %1, 0
%4 = icmp slt i32 %1, 0
%5 = select i1 %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0)
%6 = select i1 %3, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @str.5, i64 0, i64 0), i8* %5
%7 = tail call i32 @puts(i8* dereferenceable(1) %6)
%8 = tail call i32 @sleep(i32 2)
ret i32 0
}