#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 main(void) {
  pid_t pid;
  int i;
  for (i = 0; i < 10; i++) {
    printf("pid: %d\n", getpid());
    pid = fork();
    if (pid > 0)
      break;
    else if (pid == 0)
      continue;
  }
  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    11a8 <main+0x78>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jle    1180 <main+0x50>
jmp    11a8 <main+0x78>
cmpq   $0x0,-0x10(%rbp)
jne    1190 <main+0x60>
jmp    119a <main+0x6a>
jmp    1195 <main+0x65>
jmp    119a <main+0x6a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1146 <main+0x16>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xec1(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
jg     128a <main+0x15a>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe9c(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
jg     128a <main+0x15a>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe77(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
jg     128a <main+0x15a>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe52(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
jg     128a <main+0x15a>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe2d(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
jg     128a <main+0x15a>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe08(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
jg     128a <main+0x15a>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xde7(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
jg     128a <main+0x15a>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xdc6(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
jg     128a <main+0x15a>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xda5(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
test   %rax,%rax
jg     128a <main+0x15a>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xd84(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <fork@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [9 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 = %20, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 10
br i1 %6, label %7, label %23
7: ; preds = %4
%8 = call i32 (...) @getpid()
%9 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i64 (...) @fork()
store i64 %10, i64* %2
%11 = load i64, i64* %2
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %7
br label %23
14: ; preds = %7
%15 = load i64, i64* %2
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
br label %20
18: ; preds = %14
br label %19
19: ; preds = %18
br label %20
20: ; preds = %19, %17
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %4
23: ; preds = %13, %4
ret i32 0
}

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