#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 atoi(char *);
int fork();
int getpid();
int /*<<< orphan*/ printf(char *, int, int, int, int);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  int i = 11, j = 0;
  int retval;
  retval = fork();
  if (retval > 0) {
    for (i = 0; i < atoi(argv[1]); i++) {
      if (retval == 0) {
      } else {
        printf("i=%d, retval = %d, parent %d and  my child is %d \n", i, retval,
               getpid(), retval);
        sleep(1);
        retval = fork();
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xb,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1215 <main+0xc5>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    1210 <main+0xc0>
cmpl   $0x0,-0x1c(%rbp)
jne    11be <main+0x6e>
jmp    11fd <main+0xad>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1c(%rbp)
jmp    1202 <main+0xb2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118f <main+0x3f>
jmp    1215 <main+0xc5>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jle    11de <main+0x8e>
mov    %eax,%ebx
mov    0x8(%r15),%r12
mov    %r12,%rdi
call   1050 <atoi@plt>
test   %eax,%eax
jle    11de <main+0x8e>
lea    0xe7e(%rip),%r14
xor    %ebp,%ebp
jmp    11a2 <main+0x52>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %r12,%rdi
call   1050 <atoi@plt>
mov    %r13d,%ebx
cmp    %eax,%ebp
jge    11de <main+0x8e>
mov    $0x0,%r13d
test   %ebx,%ebx
je     1190 <main+0x40>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
mov    %ebx,%r8d
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%r13d
mov    0x8(%r15),%r12
jmp    1190 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [51 x i8] c"i=%d, retval = %d, parent %d and my child is %d \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 11, i32* %6
store i32 0, i32* %7
%9 = call i32 (...) @fork()
store i32 %9, i32* %8
%10 = load i32, i32* %8
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %37
12: ; preds = %2
store i32 0, i32* %6
br label %13
13: ; preds = %33, %12
%14 = load i32, i32* %6
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
%19 = icmp slt i32 %14, %18
br i1 %19, label %20, label %36
20: ; preds = %13
%21 = load i32, i32* %8
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
br label %32
24: ; preds = %20
%25 = load i32, i32* %6
%26 = load i32, i32* %8
%27 = call i32 (...) @getpid()
%28 = load i32, i32* %8
%29 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26, i32 %27, i32 %28)
%30 = call i32 @sleep(i32 1)
%31 = call i32 (...) @fork()
store i32 %31, i32* %8
br label %32
32: ; preds = %24, %23
br label %33
33: ; preds = %32
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %13
36: ; preds = %13
br label %37
37: ; preds = %36, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [51 x i8] c"i=%d, retval = %d, parent %d and my child is %d \0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %27
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %5, %21
%11 = phi i8* [ %22, %21 ], [ %7, %5 ]
%12 = phi i32 [ %23, %21 ], [ %3, %5 ]
%13 = phi i32 [ %24, %21 ], [ 0, %5 ]
%14 = icmp eq i32 %12, 0
br i1 %14, label %21, label %15
15: ; preds = %10
%16 = tail call i32 (...) @getpid()
%17 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %12, i32 %16, i32 %12)
%18 = tail call i32 @sleep(i32 1)
%19 = tail call i32 (...) @fork()
%20 = load i8*, i8** %6
br label %21
21: ; preds = %15, %10
%22 = phi i8* [ %11, %10 ], [ %20, %15 ]
%23 = phi i32 [ 0, %10 ], [ %19, %15 ]
%24 = add nuw nsw i32 %13, 1
%25 = tail call i32 @atoi(i8* %22)
%26 = icmp slt i32 %24, %25
br i1 %26, label %10, label %27
27: ; preds = %21, %5, %2
ret i32 0
}