#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int getpid();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ wait(int *);
int test1() {
  int pid;
  int i = 10;
  int status;
  pid = fork();
  if (pid < 0) {
    printf("[%d] fork yapilamadi\n", getpid());
    return -1;
  }
  if (pid > 0) {
    printf("parent process calisiyor\n");
    printf("child id: %d\n", pid);
    wait(&status);
  } else if (pid == 0) {
    printf("child process calisiyor\n");
    sleep(1);
  }
  printf("%d\n", ++i);
  exit(0);
  return 0;
}


x86 assembly (clang, -O0):
<test1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0xa,-0x8(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11a5 <test1+0x45>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbp
ret
cmpl   $0x0,-0x4(%rbp)
jle    11dc <test1+0x7c>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1070 <wait@plt>
jmp    1203 <test1+0xa3>
cmpl   $0x0,-0x4(%rbp)
jne    11fe <test1+0x9e>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    1203 <test1+0xa3>
mov    -0x8(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x8(%rbp)
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<test1>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
jns    11a2 <test1+0x32>
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe72(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
jne    11bc <test1+0x4c>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
jmp    11e4 <test1+0x74>
mov    %eax,%ebx
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
lea    0xe45(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xc(%rsp),%rdi
call   1080 <wait@plt>
lea    0xe35(%rip),%rdi
mov    $0xb,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"[%d] fork yapilamadi\0A\00"
@.str.1 = [26 x i8] c"parent process calisiyor\0A\00"
@.str.2 = [14 x i8] c"child id: %d\0A\00"
@.str.3 = [25 x i8] c"child process calisiyor\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @test1() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 10, i32* %2
%4 = call i32 (...) @fork()
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 (...) @getpid()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %8)
ret i32 -1
10: ; preds = %0
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* %1
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = call i32 @wait(i32* %3)
br label %25
18: ; preds = %10
%19 = load i32, i32* %1
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @sleep(i32 1)
br label %24
24: ; preds = %21, %18
br label %25
25: ; preds = %24, %13
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [22 x i8] c"[%d] fork yapilamadi\0A\00"
@.str.2 = [14 x i8] c"child id: %d\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@str = [24 x i8] c"child process calisiyor\00"
@str.5 = [25 x i8] c"parent process calisiyor\00"
define i32 @test1() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %6)
ret i32 -1
8: ; preds = %0
%9 = icmp eq i32 %3, 0
br i1 %9, label %14, label %10
10: ; preds = %8
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.5, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%13 = call i32 @wait(i32* %1)
br label %17
14: ; preds = %8
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @sleep(i32 1)
br label %17
17: ; preds = %14, %10
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 11)
%19 = call i32 @exit(i32 0)
unreachable
}