#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 */
scalar_t__ fork();
int getpid();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(void) {
  pid_t pid;
  int i;
  for (i = 0; i < 10; i++) {
    pid = fork();
    if (pid > 0)
      break;
    else if (pid == 0)
      continue;
  }
  wait(NULL);
  printf("pid : %d\n", getpid());
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11a3 <main+0x63>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    117b <main+0x3b>
jmp    11a3 <main+0x63>
cmpq   $0x0,-0x10(%rbp)
jne    118b <main+0x4b>
jmp    1195 <main+0x55>
jmp    1190 <main+0x50>
jmp    1195 <main+0x55>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <main+0x16>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <wait@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jg     11b4 <main+0x74>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jg     11b4 <main+0x74>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jg     11b4 <main+0x74>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jg     11b4 <main+0x74>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jg     11b4 <main+0x74>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jg     11b4 <main+0x74>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jg     11b4 <main+0x74>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jg     11b4 <main+0x74>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
jg     11b4 <main+0x74>
xor    %eax,%eax
call   1060 <fork@plt>
xor    %edi,%edi
call   1050 <wait@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe37(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"pid : %d\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp sgt i64 %1, 0
br i1 %2, label %29, label %3
3: ; preds = %0
%4 = tail call i64 (...) @fork()
%5 = icmp sgt i64 %4, 0
br i1 %5, label %29, label %6
6: ; preds = %3
%7 = tail call i64 (...) @fork()
%8 = icmp sgt i64 %7, 0
br i1 %8, label %29, label %9
9: ; preds = %6
%10 = tail call i64 (...) @fork()
%11 = icmp sgt i64 %10, 0
br i1 %11, label %29, label %12
12: ; preds = %9
%13 = tail call i64 (...) @fork()
%14 = icmp sgt i64 %13, 0
br i1 %14, label %29, label %15
15: ; preds = %12
%16 = tail call i64 (...) @fork()
%17 = icmp sgt i64 %16, 0
br i1 %17, label %29, label %18
18: ; preds = %15
%19 = tail call i64 (...) @fork()
%20 = icmp sgt i64 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %18
%22 = tail call i64 (...) @fork()
%23 = icmp sgt i64 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %21
%25 = tail call i64 (...) @fork()
%26 = icmp sgt i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = tail call i64 (...) @fork()
br label %29
29: ; preds = %27, %24, %21, %18, %15, %12, %9, %6, %3, %0
%30 = tail call i32 @wait(i32* null)
%31 = tail call i32 (...) @getpid()
%32 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %31)
ret i32 0
}