#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*/ _exit(int);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ puts(char *);
scalar_t__ vfork();
int main() {
  char *exe[] = {"aa", "bb", "cc"};
  char *argv[] = {"", NULL};
  int i;
  for (i = 0; i < 3; i++) {
    if (vfork() == 0) {
      argv[0] = exe[i];
      execv(exe[i], argv);
      _exit(1);
      return 1;
    }
  }
  puts("hello");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2c9a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c97(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2c94(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0x2c99(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c96(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x3,-0x34(%rbp)
jge    11e4 <main+0xa4>
mov    $0x0,%al
call   1050 <vfork@plt>
cmp    $0x0,%rax
jne    11d1 <main+0x91>
movslq -0x34(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rax
mov    %rax,-0x30(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <execv@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
jmp    11d6 <main+0x96>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    118d <main+0x4d>
lea    0xe1e(%rip),%rdi
call   1040 <puts@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movaps 0x2cc4(%rip),%xmm0
movaps %xmm0,(%rsp)
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <vfork@plt>
test   %rax,%rax
je     1196 <main+0x56>
xor    %eax,%eax
call   1050 <vfork@plt>
test   %rax,%rax
je     118a <main+0x4a>
xor    %eax,%eax
call   1050 <vfork@plt>
test   %rax,%rax
je     1191 <main+0x51>
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    $0x1,%ebx
jmp    1196 <main+0x56>
mov    $0x2,%ebx
lea    0x2c53(%rip),%rax
mov    (%rax,%rbx,8),%rdi
mov    %rdi,(%rsp)
mov    %rsp,%rsi
call   1060 <execv@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"aa\00"
@.str.1 = [3 x i8] c"bb\00"
@.str.2 = [3 x i8] c"cc\00"
@__const.main.exe = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [1 x i8] zeroinitializer
@__const.main.argv = [2 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.4 = [6 x i8] c"hello\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x i8*]
%3 = alloca [2 x i8*]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [3 x i8*]* %2 to i8*
%6 = bitcast [2 x i8*]* %3 to i8*
store i32 0, i32* %4
br label %7
7: ; preds = %27, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %30
10: ; preds = %7
%11 = call i64 (...) @vfork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 %15
%17 = load i8*, i8** %16
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
store i8* %17, i8** %18
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 %20
%22 = load i8*, i8** %21
%23 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%24 = call i32 @execv(i8* %22, i8** %23)
%25 = call i32 @_exit(i32 1)
unreachable
26: ; preds = %10
br label %27
27: ; preds = %26
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %7
30: ; preds = %7
%31 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [3 x i8] c"aa\00"
@.str.1 = [3 x i8] c"bb\00"
@.str.2 = [3 x i8] c"cc\00"
@__const.main.exe = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0)]
@.str.3 = [1 x i8] zeroinitializer
@__const.main.argv = [2 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i32 0, i32 0), i8* null]
@.str.4 = [6 x i8] c"hello\00"
define i32 @main() {
%1 = alloca [2 x i8*]
%2 = bitcast [2 x i8*]* %1 to i8*
%3 = tail call i64 (...) @vfork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %15, %12, %0
%6 = phi i64 [ 0, %0 ], [ 1, %12 ], [ 2, %15 ]
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* @__const.main.exe, i64 0, i64 %6
%8 = load i8*, i8** %7
%9 = getelementptr inbounds [2 x i8*], [2 x i8*]* %1, i64 0, i64 0
store i8* %8, i8** %9
%10 = call i32 @execv(i8* %8, i8** %9)
%11 = call i32 @_exit(i32 1)
unreachable
12: ; preds = %0
%13 = tail call i64 (...) @vfork()
%14 = icmp eq i64 %13, 0
br i1 %14, label %5, label %15
15: ; preds = %12
%16 = tail call i64 (...) @vfork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %5, label %18
18: ; preds = %15
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}