#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 EXIT_SUCCESS;
int nfork(int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int p;
  int i = 1;
  int N = 3;
  do {
    p = nfork(i);
    if (p != 0)
      printf("%d \n", p);
  } while ((p == 0) && (++i <= N));
  printf("FIN \n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x3,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <nfork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1163 <main+0x43>
mov    -0x8(%rbp),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1168 <main+0x48>
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x11(%rbp)
jne    1189 <main+0x69>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmp    -0x10(%rbp),%eax
setle  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    113d <main+0x1d>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x1,%edi
call   1040 <nfork@plt>
test   %eax,%eax
jne    115b <main+0x2b>
mov    $0x2,%edi
call   1040 <nfork@plt>
test   %eax,%eax
jne    115b <main+0x2b>
mov    $0x3,%edi
call   1040 <nfork@plt>
test   %eax,%eax
je     116b <main+0x3b>
lea    0xe9e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%d \0A\00"
@EXIT_SUCCESS = global i32 0
@str = [5 x i8] c"FIN \00"
define i32 @main() {
%1 = tail call i32 @nfork(i32 1)
%2 = icmp eq i32 %1, 0
br i1 %2, label %6, label %3
3: ; preds = %9, %6, %0
%4 = phi i32 [ %1, %0 ], [ %7, %6 ], [ %10, %9 ]
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %12
6: ; preds = %0
%7 = tail call i32 @nfork(i32 2)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %3
9: ; preds = %6
%10 = tail call i32 @nfork(i32 3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %3
12: ; preds = %9, %3
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_SUCCESS
ret i32 %14
}