#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 */
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ execve(char *, char **, char **);
int /*<<< orphan*/ fork();
pid_t run_test() {
  char *path = "./test-exec";
  char *argv[] = {path, "recursive exec", NULL};
  char *envp[] = {"envvar=val2", NULL};
  pid_t pid;
  if ((pid = fork()) == 0) {
    execve(path, argv, envp);
    _exit(EXIT_FAILURE);
  }
  return pid;
}


x86 assembly (clang, -O0):
<run_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xec1(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2c9b(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c98(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jne    11a6 <run_test+0x76>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <execve@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_test>:
sub    $0x38,%rsp
lea    0xec5(%rip),%rax
mov    %rax,(%rsp)
lea    0xec6(%rip),%rax
mov    %rax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
movaps 0x2ca5(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
xor    %eax,%eax
call   1050 <fork@plt>
test   %eax,%eax
je     1170 <run_test+0x40>
add    $0x38,%rsp
ret
lea    0xe89(%rip),%rdi
mov    %rsp,%rsi
lea    0x20(%rsp),%rdx
call   1040 <execve@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"./test-exec\00"
@.str.1 = [15 x i8] c"recursive exec\00"
@.str.2 = [12 x i8] c"envvar=val2\00"
@__const.run_test.envp = [2 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0), i8* null]
@EXIT_FAILURE = global i32 0
define i32 @run_test() {
%1 = alloca i8*
%2 = alloca [3 x i8*]
%3 = alloca [2 x i8*]
%4 = alloca i32
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %1
%5 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%6 = load i8*, i8** %1
store i8* %6, i8** %5
%7 = getelementptr inbounds i8*, i8** %5, i64 1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds i8*, i8** %7, i64 1
store i8* null, i8** %8
%9 = bitcast [2 x i8*]* %3 to i8*
%10 = call i32 (...) @fork()
store i32 %10, i32* %4
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %0
%13 = load i8*, i8** %1
%14 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%16 = call i32 @execve(i8* %13, i8** %14, i8** %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @_exit(i32 %17)
unreachable
19: ; preds = %0
%20 = load i32, i32* %4
ret i32 %20
}

LLVM IR (-O2):
@.str = [12 x i8] c"./test-exec\00"
@.str.1 = [15 x i8] c"recursive exec\00"
@.str.2 = [12 x i8] c"envvar=val2\00"
@__const.run_test.envp = [2 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i32 0, i32 0), i8* null]
@EXIT_FAILURE = global i32 0
define i32 @run_test() {
%1 = alloca [3 x i8*]
%2 = alloca [2 x i8*]
%3 = bitcast [3 x i8*]* %1 to i8*
%4 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [3 x i8*], [3 x i8*]* %1, i64 0, i64 2
store i8* null, i8** %6
%7 = bitcast [2 x i8*]* %2 to i8*
%8 = tail call i32 (...) @fork()
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %0
%11 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%12 = call i32 @execve(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %4, i8** %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @_exit(i32 %13)
unreachable
15: ; preds = %0
ret i32 %8
}