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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <setbuf@plt>
xor    %eax,%eax
cmpl   $0x2,-0x8(%rbp)
mov    %al,-0x9(%rbp)
jg     11a6 <main+0x46>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    11b6 <main+0x56>
jmp    122f <main+0xcf>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
jne    11f6 <main+0x96>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe2e(%rip),%rsi
lea    0xe2c(%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    $0x1,%edi
call   1070 <sleep@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe08(%rip),%rdi
call   1040 <system@plt>
jmp    1186 <main+0x26>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e78(%rip),%rbx
mov    (%rbx),%edi
xor    %esi,%esi
call   1030 <setbuf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1239 <main+0xd9>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    11b3 <main+0x53>
mov    (%rbx),%edi
lea    0xe6a(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe6f(%rip),%rdi
lea    0xe6d(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1060 <execlp@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    (%rbx),%edi
lea    0xe54(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe5b(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     1239 <main+0xd9>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    1215 <main+0xb5>
mov    (%rbx),%edi
lea    0xe08(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xe0d(%rip),%rdi
lea    0xe0b(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1060 <execlp@plt>
mov    $0x1,%edi
call   1070 <sleep@plt>
mov    (%rbx),%edi
lea    0xdf2(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xdf9(%rip),%rdi
call   1040 <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 = [10 x i8] c"echo i+i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
%3 = load i32, i32* @stdout
%4 = call i32 @setbuf(i32 %3, i32 0)
br label %5
5: ; preds = %20, %0
%6 = load i32, i32* %2
%7 = icmp sle i32 %6, 2
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = call i64 (...) @fork()
%10 = icmp ne i64 %9, 0
br label %11
11: ; preds = %8, %5
%12 = phi i1 [ false, %5 ], [ %10, %8 ]
br i1 %12, label %13, label %27
13: ; preds = %11
%14 = call i64 (...) @fork()
%15 = icmp ne i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i32, i32* @stdout
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%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), i32* null)
br label %20
20: ; preds = %16, %13
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
%23 = call i32 @sleep(i32 1)
%24 = load i32, i32* @stdout
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %5
27: ; preds = %11
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 = [10 x i8] c"echo i+i\0A\00"
define i32 @main() {
%1 = load i32, i32* @stdout
%2 = tail call i32 @setbuf(i32 %1, i32 0)
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %31, label %5
5: ; preds = %0
%6 = tail call i64 (...) @fork()
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = load i32, i32* @stdout
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%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), i32* null)
br label %12
12: ; preds = %8, %5
%13 = tail call i32 @sleep(i32 1)
%14 = load i32, i32* @stdout
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%16 = tail call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%17 = tail call i64 (...) @fork()
%18 = icmp eq i64 %17, 0
br i1 %18, label %31, label %19
19: ; preds = %12
%20 = tail call i64 (...) @fork()
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* @stdout
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%25 = 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), i32* null)
br label %26
26: ; preds = %22, %19
%27 = tail call i32 @sleep(i32 1)
%28 = load i32, i32* @stdout
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%30 = tail call i32 @system(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %26, %12, %0
ret i32 0
}