#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 EXIT_FAILURE;
int /*<<< orphan*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ execv(char *, char **);
scalar_t__ getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ set_trip_conf();
int /*<<< orphan*/ setenv(char *, char *, int);
int main(int argc, char **argv) {
  if (getenv("TRIP_CONFIG_DIR")) {
  } else if (0 == access("/etc/trip", F_OK)) {
    setenv("TRIP_CONFIG_DIR", "/etc/trip", 1);
  } else {
    set_trip_conf();
  }
  argv[0] = "/usr/bin/trip.sh";
  argv[argc] = 0;
  execv("/usr/bin/trip.sh", argv);
  perror("execv failed");
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1191 <main+0x31>
jmp    11dd <main+0x7d>
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1060 <access@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11d1 <main+0x71>
lea    0xe45(%rip),%rdi
lea    0xe4e(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
jmp    11d8 <main+0x78>
mov    $0x0,%al
call   1050 <set_trip_conf@plt>
jmp    11dd <main+0x7d>
mov    -0x10(%rbp),%rax
lea    0xe32(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rsi
lea    0xe14(%rip),%rdi
call   1080 <execv@plt>
lea    0xe19(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    11b4 <main+0x54>
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1060 <access@plt>
test   %rax,%rax
jne    11ad <main+0x4d>
lea    0xe66(%rip),%rdi
lea    0xe6f(%rip),%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
jmp    11b4 <main+0x54>
xor    %eax,%eax
call   1050 <set_trip_conf@plt>
lea    0xe5f(%rip),%rdi
mov    %rdi,(%rbx)
movslq %ebp,%rax
movq   $0x0,(%rbx,%rax,8)
mov    %rbx,%rsi
call   1080 <execv@plt>
lea    0xe53(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"TRIP_CONFIG_DIR\00"
@.str.1 = [10 x i8] c"/etc/trip\00"
@F_OK = global i32 0
@.str.2 = [17 x i8] c"/usr/bin/trip.sh\00"
@.str.3 = [13 x i8] c"execv failed\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = call i64 @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
br label %18
9: ; preds = %2
%10 = load i32, i32* @F_OK
%11 = call i64 @access(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = icmp eq i64 0, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @setenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %17
15: ; preds = %9
%16 = call i32 (...) @set_trip_conf()
br label %17
17: ; preds = %15, %13
br label %18
18: ; preds = %17, %8
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %20
%21 = load i8**, i8*** %5
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
store i8* null, i8** %24
%25 = load i8**, i8*** %5
%26 = call i32 @execv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %25)
%27 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
ret i32 %28
}

LLVM IR (-O2):
@.str = [16 x i8] c"TRIP_CONFIG_DIR\00"
@.str.1 = [10 x i8] c"/etc/trip\00"
@F_OK = global i32 0
@.str.2 = [17 x i8] c"/usr/bin/trip.sh\00"
@.str.3 = [13 x i8] c"execv failed\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i64 @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = load i32, i32* @F_OK
%7 = tail call i64 @access(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @setenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %13
11: ; preds = %5
%12 = tail call i32 (...) @set_trip_conf()
br label %13
13: ; preds = %9, %11, %2
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %1
%14 = sext i32 %0 to i64
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
store i8* null, i8** %15
%16 = tail call i32 @execv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %1)
%17 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
ret i32 %18
}