#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 *cgetenv(char *);
char const *tmp() {
  static char const *s;
  if (!s && !(s = cgetenv("TMPDIR")) && !(s = cgetenv("TMP")) &&
      !(s = cgetenv("TEMP")))
    s = "/tmp";
  return s;
}


x86 assembly (clang, -O0):
<tmp>:
push   %rbp
mov    %rsp,%rbp
cmpq   $0x0,0x2f14(%rip)
jne    1187 <tmp+0x77>
lea    0xed7(%rip),%rdi
call   1030 <cgetenv@plt>
mov    %rax,0x2efb(%rip)
cmp    $0x0,%rax
jne    1187 <tmp+0x77>
lea    0xec1(%rip),%rdi
call   1030 <cgetenv@plt>
mov    %rax,0x2ede(%rip)
cmp    $0x0,%rax
jne    1187 <tmp+0x77>
lea    0xea8(%rip),%rdi
call   1030 <cgetenv@plt>
mov    %rax,0x2ec1(%rip)
cmp    $0x0,%rax
jne    1187 <tmp+0x77>
lea    0xe90(%rip),%rax
mov    %rax,0x2ea9(%rip)
mov    0x2ea2(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmp>:
push   %rax
mov    0x2f18(%rip),%rax
test   %rax,%rax
je     111f <tmp+0xf>
pop    %rcx
ret
lea    0xeda(%rip),%rdi
call   1030 <cgetenv@plt>
mov    %rax,0x2efe(%rip)
test   %rax,%rax
jne    111d <tmp+0xd>
lea    0xec9(%rip),%rdi
call   1030 <cgetenv@plt>
mov    %rax,0x2ee6(%rip)
test   %rax,%rax
jne    111d <tmp+0xd>
lea    0xeb5(%rip),%rdi
call   1030 <cgetenv@plt>
mov    %rax,%rcx
test   %rax,%rax
lea    0xea8(%rip),%rax
cmovne %rcx,%rax
mov    %rax,0x2ebd(%rip)
pop    %rcx
ret

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

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