#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*/ F_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
int strlen(char const *);
void set_trip_conf() {
  char const *rel = ".trip";
  char const *home = getenv("HOME");
  char *conf;
  int len;
  if (!home)
    return;
  len = strlen(rel) + strlen(home) + 2;
  conf = (char *)malloc(len * sizeof(char));
  sprintf(conf, "%s/%s", home, rel);
  if (0 == access(conf, F_OK)) {
    setenv("TRIP_CONFIG_DIR", conf, 1);
  }
  free(conf);
}


x86 assembly (clang, -O0):
<set_trip_conf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe81(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xe7c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a3 <set_trip_conf+0x33>
jmp    122e <set_trip_conf+0xbe>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe20(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
call   1080 <access@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1225 <set_trip_conf+0xb5>
mov    -0x18(%rbp),%rsi
lea    0xdf6(%rip),%rdi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_trip_conf>:
push   %r15
push   %r14
push   %rbx
lea    0xe8a(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11fe <set_trip_conf+0x8e>
mov    %rax,%rbx
lea    0xe70(%rip),%r15
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    (%r14,%rax,1),%edi
add    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe52(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1090 <sprintf@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1080 <access@plt>
test   %rax,%rax
jne    11f1 <set_trip_conf+0x81>
lea    0xe2d(%rip),%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <setenv@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <free@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c".trip\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@F_OK = global i32 0
@.str.3 = [16 x i8] c"TRIP_CONFIG_DIR\00"
define void @set_trip_conf() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %1
%5 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %5, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %0
br label %36
9: ; preds = %0
%10 = load i8*, i8** %1
%11 = call i32 @strlen(i8* %10)
%12 = load i8*, i8** %2
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %11, %13
%15 = add nsw i32 %14, 2
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %3
%22 = load i8*, i8** %3
%23 = load i8*, i8** %2
%24 = load i8*, i8** %1
%25 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %24)
%26 = load i8*, i8** %3
%27 = load i32, i32* @F_OK
%28 = call i64 @access(i8* %26, i32 %27)
%29 = icmp eq i64 0, %28
br i1 %29, label %30, label %33
30: ; preds = %9
%31 = load i8*, i8** %3
%32 = call i32 @setenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %31, i32 1)
br label %33
33: ; preds = %30, %9
%34 = load i8*, i8** %3
%35 = call i32 @free(i8* %34)
br label %36
36: ; preds = %33, %8
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c".trip\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@F_OK = global i32 0
@.str.3 = [16 x i8] c"TRIP_CONFIG_DIR\00"
define void @set_trip_conf() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %18, label %3
3: ; preds = %0
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @strlen(i8* %1)
%6 = add i32 %4, 2
%7 = add i32 %6, %5
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @F_OK
%12 = tail call i64 @access(i8* %9, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %3
%15 = tail call i32 @setenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %9, i32 1)
br label %16
16: ; preds = %14, %3
%17 = tail call i32 @free(i8* %9)
br label %18
18: ; preds = %0, %16
ret void
}