#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 getppid();
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  int i = 11, j = 0;
  int retval, flag = 0;
  retval = fork();
  if (retval == 0) {
    for (i = 0; i < atoi(argv[1]); i++) {
      if (retval > 0) {
      } else {
        printf("child id: %d and  my parent is %d\n", getpid(), getppid());
        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)
movl   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1223 <main+0xc3>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    121e <main+0xbe>
cmpl   $0x0,-0x1c(%rbp)
jle    11d5 <main+0x75>
jmp    120b <main+0xab>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x28(%rbp),%esi
mov    %eax,%edx
lea    0xe0e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x1c(%rbp)
jmp    1210 <main+0xb0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a6 <main+0x46>
jmp    1223 <main+0xc3>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1181 <main+0x21>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%r15),%r12
mov    %r12,%rdi
call   1050 <atoi@plt>
test   %eax,%eax
jle    1176 <main+0x16>
lea    0xe68(%rip),%r14
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    11af <main+0x4f>
xchg   %ax,%ax
add    $0x1,%ebx
mov    %r12,%rdi
call   1050 <atoi@plt>
cmp    %eax,%ebx
jge    1176 <main+0x16>
test   %ebp,%ebp
jg     11a0 <main+0x40>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <getppid@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ebp
mov    0x8(%r15),%r12
jmp    11a0 <main+0x40>

LLVM IR (-O0):
@.str = [35 x i8] c"child id: %d and my parent 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
%9 = 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
store i32 0, i32* %9
%10 = call i32 (...) @fork()
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %36
13: ; preds = %2
store i32 0, i32* %6
br label %14
14: ; preds = %32, %13
%15 = load i32, i32* %6
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
%20 = icmp slt i32 %15, %19
br i1 %20, label %21, label %35
21: ; preds = %14
%22 = load i32, i32* %8
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
br label %31
25: ; preds = %21
%26 = call i32 (...) @getpid()
%27 = call i32 (...) @getppid()
%28 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %27)
%29 = call i32 @sleep(i32 1)
%30 = call i32 (...) @fork()
store i32 %30, i32* %8
br label %31
31: ; preds = %25, %24
br label %32
32: ; preds = %31
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %14
35: ; preds = %14
br label %36
36: ; preds = %35, %2
ret i32 0
}

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