#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 *);
char *strdup(char *);
char *get_tmp_dir() {
  char *tmp;
  tmp = getenv("TMP");
  if (tmp == NULL) {
    tmp = getenv("TMPDIR");
    if (tmp == NULL) {
      tmp = getenv("TEMP");
      if (tmp == NULL) {
        tmp = getenv("TEMPDIR");
        if (tmp == NULL) {
          tmp = "/tmp";
        }
      }
    }
  }
  return strdup(tmp);
}


x86 assembly (clang, -O0):
<get_tmp_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11ae <get_tmp_dir+0x8e>
lea    0xeba(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a9 <get_tmp_dir+0x89>
lea    0xea6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a4 <get_tmp_dir+0x84>
lea    0xe90(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    119f <get_tmp_dir+0x7f>
lea    0xe7d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a4 <get_tmp_dir+0x84>
jmp    11a9 <get_tmp_dir+0x89>
jmp    11ae <get_tmp_dir+0x8e>
mov    -0x8(%rbp),%rdi
call   1040 <strdup@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_tmp_dir>:
push   %rax
lea    0xed8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1171 <get_tmp_dir+0x51>
lea    0xecb(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1171 <get_tmp_dir+0x51>
lea    0xec1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1171 <get_tmp_dir+0x51>
lea    0xeb5(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rcx
test   %rax,%rax
lea    0xeab(%rip),%rax
cmovne %rcx,%rax
mov    %rax,%rdi
pop    %rax
jmp    1040 <strdup@plt>

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

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