#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 *);
const char *cfile_get_tempdir() {
  static const char *tempdir = NULL;
  static const char tmp_fallback[] = "/tmp";
  if (!tempdir) {
    tempdir = getenv("TEMP");
    if (!tempdir)
      tempdir = getenv("TMP");
    if (!tempdir)
      tempdir = getenv("TMPDIR");
    if (!tempdir)
      tempdir = tmp_fallback;
  }
  return tempdir;
}


x86 assembly (clang, -O0):
<cfile_get_tempdir>:
push   %rbp
mov    %rsp,%rbp
cmpq   $0x0,0x2f14(%rip)
jne    1198 <cfile_get_tempdir+0x88>
lea    0xedc(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2efb(%rip)
cmpq   $0x0,0x2ef3(%rip)
jne    1156 <cfile_get_tempdir+0x46>
lea    0xec0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2eda(%rip)
cmpq   $0x0,0x2ed2(%rip)
jne    1177 <cfile_get_tempdir+0x67>
lea    0xea3(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2eb9(%rip)
cmpq   $0x0,0x2eb1(%rip)
jne    1193 <cfile_get_tempdir+0x83>
lea    0xe74(%rip),%rax
mov    %rax,0x2e9d(%rip)
jmp    1198 <cfile_get_tempdir+0x88>
mov    0x2e91(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<cfile_get_tempdir>:
push   %rax
mov    0x2f18(%rip),%rax
test   %rax,%rax
je     111f <cfile_get_tempdir+0xf>
pop    %rcx
ret
lea    0xedf(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2efe(%rip)
test   %rax,%rax
jne    111d <cfile_get_tempdir+0xd>
lea    0xecc(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,0x2ee6(%rip)
test   %rax,%rax
jne    111d <cfile_get_tempdir+0xd>
lea    0xeb8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rcx
test   %rax,%rax
lea    0xe98(%rip),%rax
cmovne %rcx,%rax
mov    %rax,0x2ebd(%rip)
pop    %rcx
ret

LLVM IR (-O0):
@cfile_get_tempdir.tempdir = internal global i8* null
@cfile_get_tempdir.tmp_fallback = internal constant [5 x i8] c"/tmp\00"
@.str = [5 x i8] c"TEMP\00"
@.str.1 = [4 x i8] c"TMP\00"
@.str.2 = [7 x i8] c"TMPDIR\00"
define i8* @cfile_get_tempdir() {
%1 = load i8*, i8** @cfile_get_tempdir.tempdir
%2 = icmp ne i8* %1, null
br i1 %2, label %19, label %3
3: ; preds = %0
%4 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** @cfile_get_tempdir.tempdir
%5 = load i8*, i8** @cfile_get_tempdir.tempdir
%6 = icmp ne i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %8, i8** @cfile_get_tempdir.tempdir
br label %9
9: ; preds = %7, %3
%10 = load i8*, i8** @cfile_get_tempdir.tempdir
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i8* %13, i8** @cfile_get_tempdir.tempdir
br label %14
14: ; preds = %12, %9
%15 = load i8*, i8** @cfile_get_tempdir.tempdir
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @cfile_get_tempdir.tmp_fallback, i64 0, i64 0), i8** @cfile_get_tempdir.tempdir
br label %18
18: ; preds = %17, %14
br label %19
19: ; preds = %18, %0
%20 = load i8*, i8** @cfile_get_tempdir.tempdir
ret i8* %20
}

LLVM IR (-O2):
@cfile_get_tempdir.tempdir = internal unnamed_addr global i8* null
@cfile_get_tempdir.tmp_fallback = internal constant [5 x i8] c"/tmp\00"
@.str = [5 x i8] c"TEMP\00"
@.str.1 = [4 x i8] c"TMP\00"
@.str.2 = [7 x i8] c"TMPDIR\00"
define i8* @cfile_get_tempdir() {
%1 = load i8*, i8** @cfile_get_tempdir.tempdir
%2 = icmp eq i8* %1, null
br i1 %2, label %3, label %13
3: ; preds = %0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** @cfile_get_tempdir.tempdir
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %7, i8** @cfile_get_tempdir.tempdir
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i8* %10, null
%12 = select i1 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @cfile_get_tempdir.tmp_fallback, i64 0, i64 0), i8* %10
store i8* %12, i8** @cfile_get_tempdir.tempdir
br label %13
13: ; preds = %9, %3, %6, %0
%14 = phi i8* [ %12, %9 ], [ %4, %3 ], [ %7, %6 ], [ %1, %0 ]
ret i8* %14
}