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


x86 assembly (clang, -O0):
<XauFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe93(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     119a <XauFileName+0x3a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1289 <XauFileName+0x129>
lea    0xe77(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c2 <XauFileName+0x62>
movq   $0x0,-0x8(%rbp)
jmp    1289 <XauFileName+0x129>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    0x2e6f(%rip),%eax
jle    1244 <XauFileName+0xe4>
cmpq   $0x0,0x2e59(%rip)
je     1211 <XauFileName+0xb1>
mov    0x2e4c(%rip),%rdi
call   1040 <free@plt>
mov    -0x1c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,0x2e38(%rip)
cmpq   $0x0,0x2e30(%rip)
jne    123b <XauFileName+0xdb>
movq   $0x0,-0x8(%rbp)
jmp    1289 <XauFileName+0x129>
mov    -0x1c(%rbp),%eax
mov    %eax,0x2e1c(%rip)
mov    0x2e0d(%rip),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcpy@plt>
mov    0x2dfd(%rip),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmove  %ecx,%eax
cltq
add    %rax,%rsi
call   1080 <strcat@plt>
mov    0x2dd3(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XauFileName>:
push   %rbp
push   %rbx
push   %rax
lea    0xea3(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    120a <XauFileName+0xaa>
lea    0xe99(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1208 <XauFileName+0xa8>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
lea    0xe64(%rip),%rdi
call   1060 <strlen@plt>
add    %eax,%ebp
add    $0x2,%ebp
mov    0x2eaa(%rip),%rdi
cmp    0x2eac(%rip),%ebp
jle    11dc <XauFileName+0x7c>
test   %rdi,%rdi
je     11c0 <XauFileName+0x60>
call   1040 <free@plt>
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,0x2e8a(%rip)
test   %rax,%rax
je     1208 <XauFileName+0xa8>
mov    %rax,%rdi
mov    %ebp,0x2e84(%rip)
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    0x2e6d(%rip),%rdi
lea    0xe0e(%rip),%rsi
cmpb   $0x1,0x1(%rbx)
adc    $0x0,%rsi
call   1080 <strcat@plt>
mov    0x2e52(%rip),%rax
jmp    120a <XauFileName+0xaa>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"/.Xauthority\00"
@XauFileName.buf = internal unnamed_addr global i8* null
@XauFileName.bsize = internal unnamed_addr global i32 0
@.str.1 = [11 x i8] c"XAUTHORITY\00"
@.str.2 = [5 x i8] c"HOME\00"
define i8* @XauFileName() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, 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.2, 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 ([13 x i8], [13 x i8]* @.str, i64 0, i64 1))
%9 = add i32 %7, 2
%10 = add i32 %9, %8
%11 = load i32, i32* @XauFileName.bsize
%12 = icmp sgt i32 %10, %11
%13 = load i8*, i8** @XauFileName.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** @XauFileName.buf
%20 = icmp eq i8* %19, null
br i1 %20, label %33, label %21
21: ; preds = %18
store i32 %10, i32* @XauFileName.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** @XauFileName.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 [13 x i8], [13 x i8]* @.str, i64 0, i64 %29
%31 = tail call i32 @strcat(i8* %25, i8* %30)
%32 = load i8*, i8** @XauFileName.buf
br label %33
33: ; preds = %18, %3, %0, %22
%34 = phi i8* [ %32, %22 ], [ %1, %0 ], [ null, %3 ], [ null, %18 ]
ret i8* %34
}