#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*/ sprintf(char *, char *, 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;
  }
  sprintf(buf, "%s%s", name, slashDotXauthority + (name[1] == '\0' ? 1 : 0));
  return buf;
}


x86 assembly (clang, -O0):
<XauFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xea2(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     118a <XauFileName+0x3a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1276 <XauFileName+0x126>
lea    0xe86(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b2 <XauFileName+0x62>
movq   $0x0,-0x8(%rbp)
jmp    1276 <XauFileName+0x126>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    0x2e77(%rip),%eax
jle    1234 <XauFileName+0xe4>
cmpq   $0x0,0x2e61(%rip)
je     1201 <XauFileName+0xb1>
mov    0x2e54(%rip),%rdi
call   1040 <free@plt>
mov    -0x1c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,0x2e40(%rip)
cmpq   $0x0,0x2e38(%rip)
jne    122b <XauFileName+0xdb>
movq   $0x0,-0x8(%rbp)
jmp    1276 <XauFileName+0x126>
mov    -0x1c(%rbp),%eax
mov    %eax,0x2e24(%rip)
mov    0x2e15(%rip),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%r8d
xor    %eax,%eax
mov    $0x1,%esi
cmp    $0x0,%r8d
cmove  %esi,%eax
cltq
add    %rax,%rcx
lea    0xdb6(%rip),%rsi
call   1070 <sprintf@plt>
mov    0x2dde(%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    0xeb2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    11f5 <XauFileName+0xa5>
lea    0xea8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11f3 <XauFileName+0xa3>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0xe74(%rip),%rdi
call   1050 <strlen@plt>
add    %eax,%ebp
add    $0x2,%ebp
mov    0x2eb2(%rip),%rdi
cmp    0x2eb4(%rip),%ebp
jle    11cc <XauFileName+0x7c>
test   %rdi,%rdi
je     11b0 <XauFileName+0x60>
call   1040 <free@plt>
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,0x2e92(%rip)
test   %rax,%rax
je     11f3 <XauFileName+0xa3>
mov    %rax,%rdi
mov    %ebp,0x2e8c(%rip)
lea    0xe2d(%rip),%rcx
cmpb   $0x1,0x1(%rbx)
adc    $0x0,%rcx
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdx
call   1070 <sprintf@plt>
mov    0x2e5f(%rip),%rax
jmp    11f5 <XauFileName+0xa5>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 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"
@.str.3 = [5 x i8] c"%s%s\00"
define i8* @XauFileName() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* getelementptr inbounds ([12 x i8], [12 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 %54
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 %54
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 %54
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 = load i8*, i8** %2
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 0
%48 = zext i1 %47 to i64
%49 = select i1 %47, i32 1, i32 0
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %42, i64 %50
%52 = call i32 @sprintf(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %41, i8* %51)
%53 = load i8*, i8** @XauFileName.buf
store i8* %53, i8** %1
br label %54
54: ; preds = %39, %36, %13, %7
%55 = load i8*, i8** %1
ret i8* %55
}

LLVM IR (-O2):
@.str = [12 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"
@.str.3 = [5 x i8] c"%s%s\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 %31
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 %31, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %4)
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 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 %31, 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 = getelementptr inbounds i8, i8* %4, i64 1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
%27 = zext i1 %26 to i64
%28 = getelementptr inbounds [12 x i8], [12 x i8]* @.str, i64 0, i64 %27
%29 = tail call i32 @sprintf(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %4, i8* %28)
%30 = load i8*, i8** @XauFileName.buf
br label %31
31: ; preds = %18, %3, %0, %22
%32 = phi i8* [ %30, %22 ], [ %1, %0 ], [ null, %3 ], [ null, %18 ]
ret i8* %32
}