#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 *getTmpDir(void) {
  char *tmpdir = NULL;
  if ((tmpdir = getenv("TEMP")))
    return tmpdir;
  else if ((tmpdir = getenv("TMP")))
    return tmpdir;
  else if ((tmpdir = getenv("TMPDIR")))
    return tmpdir;
  else
    return "/tmp/";
}


x86 assembly (clang, -O0):
<getTmpDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x10(%rbp)
lea    0xed9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1147 <getTmpDir+0x37>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a0 <getTmpDir+0x90>
lea    0xeb7(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     116e <getTmpDir+0x5e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a0 <getTmpDir+0x90>
lea    0xe94(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1195 <getTmpDir+0x85>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a0 <getTmpDir+0x90>
lea    0xe74(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getTmpDir>:
push   %rax
lea    0xee8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1124 <getTmpDir+0x14>
pop    %rcx
ret
lea    0xeda(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1122 <getTmpDir+0x12>
lea    0xecd(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rcx
test   %rax,%rax
lea    0xec2(%rip),%rax
cmovne %rcx,%rax
pop    %rcx
ret

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

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