#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 *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ strlen(char *);
char *ut_realloc(char *, scalar_t__);
char *cfg_fullpath() {
  static char *fullpath = NULL;
  char *usrpath;
  char *filename;
  if ((usrpath = getenv("HOME")))
    filename = "/."
               "omron++.cfg";
  else if ((usrpath = getenv("AppData")))
    filename = "\\"
               "omron++.cfg";
  else {
    usrpath = "";
    filename = "omron++.cfg";
  }
  fullpath = ut_realloc(fullpath, strlen(usrpath) + 42);
  *fullpath = '\0';
  sprintf(fullpath, "%s%s", usrpath, filename);
  return fullpath;
}


x86 assembly (clang, -O0):
<cfg_fullpath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     1172 <cfg_fullpath+0x32>
lea    0xe9c(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11b7 <cfg_fullpath+0x77>
lea    0xe9a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     119c <cfg_fullpath+0x5c>
lea    0xe88(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11b2 <cfg_fullpath+0x72>
lea    0xe61(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xe59(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11b7 <cfg_fullpath+0x77>
mov    0x2e8a(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    %rax,%rsi
add    $0x2a,%rsi
call   1050 <ut_realloc@plt>
mov    %rax,0x2e66(%rip)
mov    0x2e5f(%rip),%rax
movb   $0x0,(%rax)
mov    0x2e55(%rip),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe26(%rip),%rsi
call   1060 <sprintf@plt>
mov    0x2e3a(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cfg_fullpath>:
push   %r15
push   %r14
push   %rbx
lea    0xeb4(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1162 <cfg_fullpath+0x22>
mov    %rax,%rbx
lea    0xea5(%rip),%r14
jmp    118e <cfg_fullpath+0x4e>
lea    0xeaa(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe8c(%rip),%rbx
cmovne %rax,%rbx
lea    0xe84(%rip),%rax
lea    0xe91(%rip),%r14
cmove  %rax,%r14
mov    0x2eb3(%rip),%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x2a(%rax),%rsi
mov    %r15,%rdi
call   1050 <ut_realloc@plt>
mov    %rax,0x2e98(%rip)
movb   $0x0,(%rax)
lea    0xe6e(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1060 <sprintf@plt>
mov    0x2e79(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@cfg_fullpath.fullpath = internal global i8* null
@.str = [5 x i8] c"HOME\00"
@.str.1 = [14 x i8] c"/.omron++.cfg\00"
@.str.2 = [8 x i8] c"AppData\00"
@.str.3 = [13 x i8] c"\\omron++.cfg\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [12 x i8] c"omron++.cfg\00"
@.str.6 = [5 x i8] c"%s%s\00"
define i8* @cfg_fullpath() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %1
%4 = icmp ne i8* %3, null
br i1 %4, label %5, label %6
5: ; preds = %0
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %12
6: ; preds = %0
%7 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %7, i8** %1
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %6
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %11
10: ; preds = %6
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8** %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %11
11: ; preds = %10, %9
br label %12
12: ; preds = %11, %5
%13 = load i8*, i8** @cfg_fullpath.fullpath
%14 = load i8*, i8** %1
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 42
%17 = call i8* @ut_realloc(i8* %13, i64 %16)
store i8* %17, i8** @cfg_fullpath.fullpath
%18 = load i8*, i8** @cfg_fullpath.fullpath
store i8 0, i8* %18
%19 = load i8*, i8** @cfg_fullpath.fullpath
%20 = load i8*, i8** %1
%21 = load i8*, i8** %2
%22 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %20, i8* %21)
%23 = load i8*, i8** @cfg_fullpath.fullpath
ret i8* %23
}

LLVM IR (-O2):
@cfg_fullpath.fullpath = internal unnamed_addr global i8* null
@.str = [5 x i8] c"HOME\00"
@.str.1 = [14 x i8] c"/.omron++.cfg\00"
@.str.2 = [8 x i8] c"AppData\00"
@.str.3 = [13 x i8] c"\\omron++.cfg\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [12 x i8] c"omron++.cfg\00"
@.str.6 = [5 x i8] c"%s%s\00"
define i8* @cfg_fullpath() {
%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 %8
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i8* %4, null
%6 = select i1 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i8* %4
%7 = select i1 %5, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0)
br label %8
8: ; preds = %3, %0
%9 = phi i8* [ %1, %0 ], [ %6, %3 ]
%10 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), %0 ], [ %7, %3 ]
%11 = load i8*, i8** @cfg_fullpath.fullpath
%12 = tail call i64 @strlen(i8* dereferenceable(1) %9)
%13 = add nsw i64 %12, 42
%14 = tail call i8* @ut_realloc(i8* %11, i64 %13)
store i8* %14, i8** @cfg_fullpath.fullpath
store i8 0, i8* %14
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8* %9, i8* %10)
%16 = load i8*, i8** @cfg_fullpath.fullpath
ret i8* %16
}