#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 *getenv(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ strstr(char *, char *);
char *epk_gfile() {
  static char *epk_conf_path = NULL;
  char *tmp;
  if (epk_conf_path == NULL) {
    tmp = getenv("EPK_CONF");
    if (tmp) {
      if (strstr(tmp, "EPIK.CONF")) {
        epk_conf_path = malloc(strlen(tmp) + 1);
        strcpy(epk_conf_path, tmp);
      } else {
        epk_conf_path = malloc(strlen(tmp) + strlen("EPIK.CONF") + 2);
        strcpy(epk_conf_path, tmp);
        strcat(epk_conf_path, "/"
                              "EPIK.CONF");
      }
    }
  }
  return epk_conf_path;
}


x86 assembly (clang, -O0):
<epk_gfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpq   $0x0,0x2ee8(%rip)
jne    1239 <epk_gfile+0xd9>
lea    0xe83(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1234 <epk_gfile+0xd4>
mov    -0x8(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     11dc <epk_gfile+0x7c>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,0x2e91(%rip)
mov    0x2e8a(%rip),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    122f <epk_gfile+0xcf>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe1a(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x10(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   1060 <malloc@plt>
mov    %rax,0x2e4c(%rip)
mov    0x2e45(%rip),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    0x2e35(%rip),%rdi
lea    0xddf(%rip),%rsi
call   1070 <strcat@plt>
jmp    1234 <epk_gfile+0xd4>
jmp    1239 <epk_gfile+0xd9>
mov    0x2e18(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<epk_gfile>:
push   %r14
push   %rbx
push   %rax
cmpq   $0x0,0x2eec(%rip)
je     117d <epk_gfile+0x1d>
mov    0x2ee3(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe7c(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116e <epk_gfile+0xe>
mov    %rax,%rbx
lea    0xe72(%rip),%rsi
mov    %rax,%rdi
call   1080 <strstr@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
test   %r14,%r14
je     11d0 <epk_gfile+0x70>
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,0x2e95(%rip)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
jmp    116e <epk_gfile+0xe>
add    $0xb,%rdi
call   1060 <malloc@plt>
mov    %rax,0x2e78(%rip)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
mov    0x2e66(%rip),%rdi
lea    0xe10(%rip),%rsi
call   1070 <strcat@plt>
jmp    116e <epk_gfile+0xe>

LLVM IR (-O0):
@epk_gfile.epk_conf_path = internal global i8* null
@.str = [9 x i8] c"EPK_CONF\00"
@.str.1 = [10 x i8] c"EPIK.CONF\00"
@.str.2 = [11 x i8] c"/EPIK.CONF\00"
define i8* @epk_gfile() {
%1 = alloca i8*
%2 = load i8*, i8** @epk_gfile.epk_conf_path
%3 = icmp eq i8* %2, null
br i1 %3, label %4, label %34
4: ; preds = %0
%5 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %1
%6 = load i8*, i8** %1
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %33
8: ; preds = %4
%9 = load i8*, i8** %1
%10 = call i64 @strstr(i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = load i8*, i8** %1
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %14, 1
%16 = call i8* @malloc(i64 %15)
store i8* %16, i8** @epk_gfile.epk_conf_path
%17 = load i8*, i8** @epk_gfile.epk_conf_path
%18 = load i8*, i8** %1
%19 = call i32 @strcpy(i8* %17, i8* %18)
br label %32
20: ; preds = %8
%21 = load i8*, i8** %1
%22 = call i64 @strlen(i8* %21)
%23 = call i64 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%24 = add nsw i64 %22, %23
%25 = add nsw i64 %24, 2
%26 = call i8* @malloc(i64 %25)
store i8* %26, i8** @epk_gfile.epk_conf_path
%27 = load i8*, i8** @epk_gfile.epk_conf_path
%28 = load i8*, i8** %1
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = load i8*, i8** @epk_gfile.epk_conf_path
%31 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %20, %12
br label %33
33: ; preds = %32, %4
br label %34
34: ; preds = %33, %0
%35 = load i8*, i8** @epk_gfile.epk_conf_path
ret i8* %35
}

LLVM IR (-O2):
@epk_gfile.epk_conf_path = internal unnamed_addr global i8* null
@.str = [9 x i8] c"EPK_CONF\00"
@.str.1 = [10 x i8] c"EPIK.CONF\00"
@.str.2 = [11 x i8] c"/EPIK.CONF\00"
define i8* @epk_gfile() {
%1 = load i8*, i8** @epk_gfile.epk_conf_path
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %20
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %20, label %6
6: ; preds = %3
%7 = tail call i64 @strstr(i8* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
%9 = tail call i64 @strlen(i8* %4)
br i1 %8, label %14, label %10
10: ; preds = %6
%11 = add nsw i64 %9, 1
%12 = tail call i8* @malloc(i64 %11)
store i8* %12, i8** @epk_gfile.epk_conf_path
%13 = tail call i32 @strcpy(i8* %12, i8* %4)
br label %20
14: ; preds = %6
%15 = add nsw i64 %9, 11
%16 = tail call i8* @malloc(i64 %15)
store i8* %16, i8** @epk_gfile.epk_conf_path
%17 = tail call i32 @strcpy(i8* %16, i8* %4)
%18 = load i8*, i8** @epk_gfile.epk_conf_path
%19 = tail call i32 @strcat(i8* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %3, %14, %10, %0
%21 = load i8*, i8** @epk_gfile.epk_conf_path
ret i8* %21
}