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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
movl   $0x0,-0x74(%rbp)
cmpl   $0x2,-0x74(%rbp)
jge    11dd <main+0x9d>
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
je     11ae <main+0x6e>
lea    -0x70(%rbp),%rdi
mov    -0x74(%rbp),%edx
lea    0xe77(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdx
lea    0xe76(%rip),%rdi
lea    0xe74(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <execlp@plt>
jmp    11ca <main+0x8a>
lea    -0x70(%rbp),%rdi
mov    -0x74(%rbp),%edx
lea    0xe5f(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdi
call   1030 <system@plt>
jmp    11cf <main+0x8f>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1160 <main+0x20>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
xor    %eax,%eax
call   1060 <fork@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     1186 <main+0x46>
lea    0xea1(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <sprintf@plt>
lea    0xe9c(%rip),%rdi
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1050 <execlp@plt>
jmp    11a2 <main+0x62>
lea    0xe8e(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %rax,%rax
je     11df <main+0x9f>
lea    0xe4b(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1,%edx
call   1040 <sprintf@plt>
lea    0xe43(%rip),%rdi
lea    0xe41(%rip),%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1050 <execlp@plt>
jmp    11fe <main+0xbe>
lea    0xe35(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1,%edx
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

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

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