#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 */
char **build_child_argv(char *, int, char **, int, char **);
char **build_user_argv(int *);
int execv(char *, char **);
char *find_base_path(char *);
char *find_driver_name(char *);
int /*<<< orphan*/ update_environment(char *);
int main(int orig_argc, char **orig_argv) {
  char *path_to_cmd;
  char **child_argv, **user_argv;
  int user_argc = 0;
  char *base_path;
  char *driver_name;
  driver_name = find_driver_name(orig_argv[0]);
  base_path = find_base_path(driver_name);
  update_environment(base_path);
  user_argv = build_user_argv(&user_argc);
  child_argv =
      build_child_argv(base_path, orig_argc, orig_argv, user_argc, user_argv);
  path_to_cmd = child_argv[0];
  return execv(path_to_cmd, child_argv);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <find_driver_name@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1070 <find_base_path@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <update_environment@plt>
lea    -0x2c(%rbp),%rdi
call   1050 <build_user_argv@plt>
mov    %rax,-0x28(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%r8
call   1030 <build_child_argv@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <execv@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
movl   $0x0,0xc(%rsp)
mov    (%rsi),%rdi
call   1060 <find_driver_name@plt>
mov    %rax,%rdi
call   1070 <find_base_path@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <update_environment@plt>
lea    0xc(%rsp),%rdi
call   1050 <build_user_argv@plt>
mov    0xc(%rsp),%ecx
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
mov    %rax,%r8
call   1030 <build_child_argv@plt>
mov    (%rax),%rdi
mov    %rax,%rsi
call   1080 <execv@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i8* @find_driver_name(i8* %14)
store i8* %15, i8** %11
%16 = load i8*, i8** %11
%17 = call i8* @find_base_path(i8* %16)
store i8* %17, i8** %10
%18 = load i8*, i8** %10
%19 = call i32 @update_environment(i8* %18)
%20 = call i8** @build_user_argv(i32* %9)
store i8** %20, i8*** %8
%21 = load i8*, i8** %10
%22 = load i32, i32* %4
%23 = load i8**, i8*** %5
%24 = load i32, i32* %9
%25 = load i8**, i8*** %8
%26 = call i8** @build_child_argv(i8* %21, i32 %22, i8** %23, i32 %24, i8** %25)
store i8** %26, i8*** %7
%27 = load i8**, i8*** %7
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
store i8* %29, i8** %6
%30 = load i8*, i8** %6
%31 = load i8**, i8*** %7
%32 = call i32 @execv(i8* %30, i8** %31)
ret i32 %32
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = load i8*, i8** %1
%6 = tail call i8* @find_driver_name(i8* %5)
%7 = tail call i8* @find_base_path(i8* %6)
%8 = tail call i32 @update_environment(i8* %7)
%9 = call i8** @build_user_argv(i32* %3)
%10 = load i32, i32* %3
%11 = call i8** @build_child_argv(i8* %7, i32 %0, i8** %1, i32 %10, i8** %9)
%12 = load i8*, i8** %11
%13 = call i32 @execv(i8* %12, i8** %11)
ret i32 %13
}