#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*/ free(char *);
char *getenv(char *);
char *malloc(unsigned int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *IceAuthFileName() {
  static char slashDotICEauthority[] = "/.ICEauthority";
  char *name;
  static char *buf;
  static int bsize;
  int size;
  if ((name = getenv("ICEAUTHORITY")))
    return (name);
  name = getenv("HOME");
  if (!name) {
    return (NULL);
  }
  size = strlen(name) + strlen(&slashDotICEauthority[1]) + 2;
  if (size > bsize) {
    if (buf)
      free(buf);
    buf = malloc((unsigned)size);
    if (!buf)
      return (NULL);
    bsize = size;
  }
  strcpy(buf, name);
  strcat(buf, slashDotICEauthority + (name[1] == '\0' ? 1 : 0));
  return (buf);
}


x86 assembly (clang, -O0):
<IceAuthFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     118f <IceAuthFileName+0x2f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1280 <IceAuthFileName+0x120>
lea    0xe77(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b7 <IceAuthFileName+0x57>
movq   $0x0,-0x8(%rbp)
jmp    1280 <IceAuthFileName+0x120>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x18(%rbp)
lea    0x2e87(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    0x2e8b(%rip),%eax
jle    1238 <IceAuthFileName+0xd8>
cmpq   $0x0,0x2e75(%rip)
je     1205 <IceAuthFileName+0xa5>
mov    0x2e68(%rip),%rdi
call   1040 <free@plt>
mov    -0x14(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,0x2e54(%rip)
cmpq   $0x0,0x2e4c(%rip)
jne    122f <IceAuthFileName+0xcf>
movq   $0x0,-0x8(%rbp)
jmp    1280 <IceAuthFileName+0x120>
mov    -0x14(%rbp),%eax
mov    %eax,0x2e38(%rip)
mov    0x2e29(%rip),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcpy@plt>
mov    0x2e19(%rip),%rdi
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
cltq
lea    0x2de3(%rip),%rsi
add    %rax,%rsi
call   1080 <strcat@plt>
mov    0x2dec(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IceAuthFileName>:
push   %rbp
push   %rbx
push   %rax
lea    0xe96(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    120a <IceAuthFileName+0xaa>
lea    0xe8e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1208 <IceAuthFileName+0xa8>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
lea    0x2eb4(%rip),%rdi
call   1060 <strlen@plt>
add    %eax,%ebp
add    $0x2,%ebp
mov    0x2eba(%rip),%rdi
cmp    0x2ebc(%rip),%ebp
jle    11dc <IceAuthFileName+0x7c>
test   %rdi,%rdi
je     11c0 <IceAuthFileName+0x60>
call   1040 <free@plt>
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,0x2e9a(%rip)
test   %rax,%rax
je     1208 <IceAuthFileName+0xa8>
mov    %rax,%rdi
mov    %ebp,0x2e94(%rip)
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    0x2e7d(%rip),%rdi
lea    0x2e5e(%rip),%rsi
cmpb   $0x1,0x1(%rbx)
adc    $0x0,%rsi
call   1080 <strcat@plt>
mov    0x2e62(%rip),%rax
jmp    120a <IceAuthFileName+0xaa>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@IceAuthFileName.slashDotICEauthority = internal global [15 x i8] c"/.ICEauthority\00"
@IceAuthFileName.buf = internal global i8* null
@IceAuthFileName.bsize = internal global i32 0
@.str = [13 x i8] c"ICEAUTHORITY\00"
@.str.1 = [5 x i8] c"HOME\00"
define i8* @IceAuthFileName() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = load i8*, i8** %2
store i8* %7, i8** %1
br label %52
8: ; preds = %0
%9 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %8
store i8* null, i8** %1
br label %52
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @IceAuthFileName.slashDotICEauthority, i64 0, i64 1))
%17 = add nsw i32 %15, %16
%18 = add nsw i32 %17, 2
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = load i32, i32* @IceAuthFileName.bsize
%21 = icmp sgt i32 %19, %20
br i1 %21, label %22, label %36
22: ; preds = %13
%23 = load i8*, i8** @IceAuthFileName.buf
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i8*, i8** @IceAuthFileName.buf
%27 = call i32 @free(i8* %26)
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* %3
%30 = call i8* @malloc(i32 %29)
store i8* %30, i8** @IceAuthFileName.buf
%31 = load i8*, i8** @IceAuthFileName.buf
%32 = icmp ne i8* %31, null
br i1 %32, label %34, label %33
33: ; preds = %28
store i8* null, i8** %1
br label %52
34: ; preds = %28
%35 = load i32, i32* %3
store i32 %35, i32* @IceAuthFileName.bsize
br label %36
36: ; preds = %34, %13
%37 = load i8*, i8** @IceAuthFileName.buf
%38 = load i8*, i8** %2
%39 = call i32 @strcpy(i8* %37, i8* %38)
%40 = load i8*, i8** @IceAuthFileName.buf
%41 = load i8*, i8** %2
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 0
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 1, i32 0
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @IceAuthFileName.slashDotICEauthority, i64 0, i64 0), i64 %48
%50 = call i32 @strcat(i8* %40, i8* %49)
%51 = load i8*, i8** @IceAuthFileName.buf
store i8* %51, i8** %1
br label %52
52: ; preds = %36, %33, %12, %6
%53 = load i8*, i8** %1
ret i8* %53
}

LLVM IR (-O2):
@IceAuthFileName.slashDotICEauthority = internal global [15 x i8] c"/.ICEauthority\00"
@IceAuthFileName.buf = internal unnamed_addr global i8* null
@IceAuthFileName.bsize = internal unnamed_addr global i32 0
@.str = [13 x i8] c"ICEAUTHORITY\00"
@.str.1 = [5 x i8] c"HOME\00"
define i8* @IceAuthFileName() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %33
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %33, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %4)
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @IceAuthFileName.slashDotICEauthority, i64 0, i64 1))
%9 = add i32 %7, 2
%10 = add i32 %9, %8
%11 = load i32, i32* @IceAuthFileName.bsize
%12 = icmp sgt i32 %10, %11
%13 = load i8*, i8** @IceAuthFileName.buf
br i1 %12, label %14, label %22
14: ; preds = %6
%15 = icmp eq i8* %13, null
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = tail call i32 @free(i8* %13)
br label %18
18: ; preds = %16, %14
%19 = tail call i8* @malloc(i32 %10)
store i8* %19, i8** @IceAuthFileName.buf
%20 = icmp eq i8* %19, null
br i1 %20, label %33, label %21
21: ; preds = %18
store i32 %10, i32* @IceAuthFileName.bsize
br label %22
22: ; preds = %6, %21
%23 = phi i8* [ %19, %21 ], [ %13, %6 ]
%24 = tail call i32 @strcpy(i8* %23, i8* %4)
%25 = load i8*, i8** @IceAuthFileName.buf
%26 = getelementptr inbounds i8, i8* %4, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
%29 = zext i1 %28 to i64
%30 = getelementptr inbounds [15 x i8], [15 x i8]* @IceAuthFileName.slashDotICEauthority, i64 0, i64 %29
%31 = tail call i32 @strcat(i8* %25, i8* %30)
%32 = load i8*, i8** @IceAuthFileName.buf
br label %33
33: ; preds = %18, %3, %0, %22
%34 = phi i8* [ %32, %22 ], [ %1, %0 ], [ null, %3 ], [ null, %18 ]
ret i8* %34
}