#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 BUFSIZ;
int /*<<< orphan*/ R_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ stderr;
int set_condor_config() {
  char *homedir = getenv("HOME");
  if (homedir == NULL) {
    fprintf(stderr, "ERROR HOME is not set in environment");
    return -1;
  }
  char config_file[BUFSIZ];
  snprintf(config_file, BUFSIZ, "%s/%s", homedir,
           ".rvgahp/condor_config.rvgahp");
  if (access(config_file, R_OK) < 0) {
    fprintf(stderr, "ERROR Cannot find config file %s", config_file);
    return -1;
  }
  setenv("CONDOR_CONFIG", config_file, 1);
  return 0;
}


x86 assembly (clang, -O0):
<set_condor_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1196 <set_condor_config+0x46>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1256 <set_condor_config+0x106>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rcx
lea    0xe54(%rip),%rdx
lea    0xe53(%rip),%r8
call   1050 <snprintf@plt>
mov    -0x30(%rbp),%rdi
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
jge    122c <set_condor_config+0xdc>
mov    -0x30(%rbp),%rdx
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    124f <set_condor_config+0xff>
mov    -0x30(%rbp),%rsi
lea    0xe37(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_condor_config>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
lea    0xea2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11ce <set_condor_config+0x7e>
mov    %rsp,%r14
mov    0x2e66(%rip),%rcx
mov    (%rcx),%edx
mov    %rsp,%rbx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
sub    %rdx,%rbx
mov    %rbx,%rsp
mov    (%rcx),%esi
lea    0xe9c(%rip),%rdx
lea    0xe9b(%rip),%r8
mov    %rbx,%rdi
mov    %rax,%rcx
call   1050 <snprintf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <access@plt>
test   %rax,%rax
js     11ec <set_condor_config+0x9c>
lea    0xeb1(%rip),%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
xor    %eax,%eax
jmp    120b <set_condor_config+0xbb>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    120e <set_condor_config+0xbe>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
mov    %r14,%rsp
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"HOME\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"ERROR HOME is not set in environment\00"
@BUFSIZ = global i32 0
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [29 x i8] c".rvgahp/condor_config.rvgahp\00"
@R_OK = global i32 0
@.str.4 = [33 x i8] c"ERROR Cannot find config file %s\00"
@.str.5 = [14 x i8] c"CONDOR_CONFIG\00"
define i32 @set_condor_config() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %30
12: ; preds = %0
%13 = load i32, i32* @BUFSIZ
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %3
%16 = alloca i8, i64 %14
store i64 %14, i64* %4
%17 = load i32, i32* @BUFSIZ
%18 = load i8*, i8** %2
%19 = call i32 @snprintf(i8* %16, i32 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* @R_OK
%21 = call i64 @access(i8* %16, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %12
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %16)
store i32 -1, i32* %1
store i32 1, i32* %5
br label %28
26: ; preds = %12
%27 = call i32 @setenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %16, i32 1)
store i32 0, i32* %1
store i32 1, i32* %5
br label %28
28: ; preds = %26, %23
%29 = load i8*, i8** %3
br label %30
30: ; preds = %28, %9
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [5 x i8] c"HOME\00"
@stderr = global i32 0
@.str.1 = [37 x i8] c"ERROR HOME is not set in environment\00"
@BUFSIZ = global i32 0
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [29 x i8] c".rvgahp/condor_config.rvgahp\00"
@R_OK = global i32 0
@.str.4 = [33 x i8] c"ERROR Cannot find config file %s\00"
@.str.5 = [14 x i8] c"CONDOR_CONFIG\00"
define i32 @set_condor_config() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %23
6: ; preds = %0
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = load i32, i32* @BUFSIZ
%12 = call i32 @snprintf(i8* %10, i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%13 = load i32, i32* @R_OK
%14 = call i64 @access(i8* %10, i32 %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %6
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %10)
br label %21
19: ; preds = %6
%20 = call i32 @setenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %10, i32 1)
br label %21
21: ; preds = %19, %16
%22 = phi i32 [ -1, %16 ], [ 0, %19 ]
br label %23
23: ; preds = %21, %3
%24 = phi i32 [ -1, %3 ], [ %22, %21 ]
ret i32 %24
}