#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*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ system(char *);
int main() {
  char str[100];
  int i;
  setbuf(stdout, 0);
  fork();
  for (i = 0; i < 2; i++) {
    if (fork() != 0) {
      sprintf(str, "echo system with i=%d", i);
      system(str);
    } else {
      sprintf(str, "exec with i=%d", i);
      execlp("echo", "myPgrm", str, NULL);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <setbuf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
movl   $0x0,-0x74(%rbp)
cmpl   $0x2,-0x74(%rbp)
jge    11fd <main+0xad>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     11bc <main+0x6c>
lea    -0x70(%rbp),%rdi
mov    -0x74(%rbp),%edx
lea    0xe57(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <system@plt>
jmp    11ea <main+0x9a>
lea    -0x70(%rbp),%rdi
mov    -0x74(%rbp),%edx
lea    0xe4c(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x70(%rbp),%rdx
lea    0xe4b(%rip),%rdi
lea    0xe49(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1060 <execlp@plt>
jmp    11ef <main+0x9f>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1180 <main+0x30>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <setbuf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1196 <main+0x46>
lea    0xe81(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
jmp    11c2 <main+0x72>
lea    0xe79(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <sprintf@plt>
lea    0xe74(%rip),%rdi
lea    0xe72(%rip),%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1060 <execlp@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11ef <main+0x9f>
lea    0xe2b(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1,%edx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
jmp    121e <main+0xce>
lea    0xe20(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1,%edx
call   1050 <sprintf@plt>
lea    0xe18(%rip),%rdi
lea    0xe16(%rip),%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1060 <execlp@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@stdout = global i32 0
@.str = [22 x i8] c"echo system with i=%d\00"
@.str.1 = [15 x i8] c"exec with i=%d\00"
@.str.2 = [5 x i8] c"echo\00"
@.str.3 = [7 x i8] c"myPgrm\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdout
%4 = tail call i32 @setbuf(i32 %3, i32 0)
%5 = tail call i64 (...) @fork()
%6 = call i64 (...) @fork()
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 0)
%10 = call i32 @system(i8* %2)
br label %14
11: ; preds = %0
%12 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 0)
%13 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %2, i32* null)
br label %14
14: ; preds = %8, %11
%15 = call i64 (...) @fork()
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 1)
%19 = call i32 @system(i8* %2)
br label %23
20: ; preds = %14
%21 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 1)
%22 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %2, i32* null)
br label %23
23: ; preds = %20, %17
ret i32 0
}