#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 /*<<< orphan*/ execlp(char *, char *, char *, char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ system(char *);
int main() {
  int i;
  i = 0;
  while (i <= 2 && fork()) {
    if (!fork()) {
      fprintf(stdout, "Running Exec ...");
      fflush(stdout);
      execlp("echo", "echo", "i*i", (char *)0);
    }
    i++;
    fprintf(stdout, "Running System ...");
    fflush(stdout);
    system("echo i+i");
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x2,-0x8(%rbp)
mov    %al,-0x9(%rbp)
jg     1186 <main+0x36>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1196 <main+0x46>
jmp    1221 <main+0xd1>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
jne    11e4 <main+0x94>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    0xe40(%rip),%rsi
lea    0xe3e(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   1060 <execlp@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    0xe16(%rip),%rdi
call   1030 <system@plt>
jmp    1166 <main+0x16>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1299 <main+0x149>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    11a1 <main+0x51>
mov    0x2e6c(%rip),%rbx
mov    (%rbx),%edi
lea    0xe83(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
lea    0xe81(%rip),%rdi
lea    0xe7f(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1060 <execlp@plt>
mov    0x2e38(%rip),%rbx
mov    (%rbx),%edi
lea    0xe69(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
lea    0xe69(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1299 <main+0x149>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    1212 <main+0xc2>
mov    (%rbx),%edi
lea    0xe12(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
lea    0xe10(%rip),%rdi
lea    0xe0e(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1060 <execlp@plt>
mov    (%rbx),%edi
lea    0xdff(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
lea    0xdff(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1299 <main+0x149>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    1278 <main+0x128>
mov    (%rbx),%edi
lea    0xdac(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
lea    0xdaa(%rip),%rdi
lea    0xda8(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1060 <execlp@plt>
mov    (%rbx),%edi
lea    0xd99(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
call   1050 <fflush@plt>
lea    0xd99(%rip),%rdi
call   1030 <system@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [17 x i8] c"Running Exec ...\00"
@.str.1 = [5 x i8] c"echo\00"
@.str.2 = [4 x i8] c"i*i\00"
@.str.3 = [19 x i8] c"Running System ...\00"
@.str.4 = [9 x i8] c"echo i+i\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %3
3: ; preds = %20, %0
%4 = load i32, i32* %2
%5 = icmp sle i32 %4, 2
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = call i64 (...) @fork()
%8 = icmp ne i64 %7, 0
br label %9
9: ; preds = %6, %3
%10 = phi i1 [ false, %3 ], [ %8, %6 ]
br i1 %10, label %11, label %28
11: ; preds = %9
%12 = call i64 (...) @fork()
%13 = icmp ne i64 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %11
%15 = load i32, i32* @stdout
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = call i32 @fflush(i32 %17)
%19 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* null)
br label %20
20: ; preds = %14, %11
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
%23 = load i32, i32* @stdout
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* @stdout
%26 = call i32 @fflush(i32 %25)
%27 = call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %3
28: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [17 x i8] c"Running Exec ...\00"
@.str.1 = [5 x i8] c"echo\00"
@.str.2 = [4 x i8] c"i*i\00"
@.str.3 = [19 x i8] c"Running System ...\00"
@.str.4 = [9 x i8] c"echo i+i\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %52, label %3
3: ; preds = %0
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = load i32, i32* @stdout
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stdout
%10 = tail call i32 @fflush(i32 %9)
%11 = tail call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* null)
br label %12
12: ; preds = %6, %3
%13 = load i32, i32* @stdout
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%15 = load i32, i32* @stdout
%16 = tail call i32 @fflush(i32 %15)
%17 = tail call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i64 (...) @fork()
%19 = icmp eq i64 %18, 0
br i1 %19, label %52, label %20
20: ; preds = %12
%21 = tail call i64 (...) @fork()
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32, i32* @stdout
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%26 = load i32, i32* @stdout
%27 = tail call i32 @fflush(i32 %26)
%28 = tail call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* null)
br label %29
29: ; preds = %23, %20
%30 = load i32, i32* @stdout
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%32 = load i32, i32* @stdout
%33 = tail call i32 @fflush(i32 %32)
%34 = tail call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%35 = tail call i64 (...) @fork()
%36 = icmp eq i64 %35, 0
br i1 %36, label %52, label %37
37: ; preds = %29
%38 = tail call i64 (...) @fork()
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = load i32, i32* @stdout
%42 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%43 = load i32, i32* @stdout
%44 = tail call i32 @fflush(i32 %43)
%45 = tail call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* null)
br label %46
46: ; preds = %40, %37
%47 = load i32, i32* @stdout
%48 = tail call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* @stdout
%50 = tail call i32 @fflush(i32 %49)
%51 = tail call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %52
52: ; preds = %46, %29, %12, %0
ret i32 0
}