#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 *am_strdup(char *);
char *getenv(char *);
char *get_temp_folder(void) {
  char *dir = NULL;
  if (!dir) {
    if (getenv("TEMPDIR")) {
      dir = am_strdup(getenv("TEMPDIR"));
    } else if (getenv("TMPDIR")) {
      dir = am_strdup(getenv("TMPDIR"));
    } else {
      dir = am_strdup("/tmp");
    }
  }
  return dir;
}


x86 assembly (clang, -O0):
<get_temp_folder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11bb <get_temp_folder+0x9b>
lea    0xebe(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     116e <get_temp_folder+0x4e>
lea    0xea8(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <am_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11b6 <get_temp_folder+0x96>
lea    0xe93(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11a1 <get_temp_folder+0x81>
lea    0xe7d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rdi
call   1040 <am_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11b1 <get_temp_folder+0x91>
lea    0xe67(%rip),%rdi
call   1040 <am_strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    11b6 <get_temp_folder+0x96>
jmp    11bb <get_temp_folder+0x9b>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_temp_folder>:
push   %rax
lea    0xed8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    1143 <get_temp_folder+0x23>
lea    0xecf(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     114c <get_temp_folder+0x2c>
mov    %rax,%rdi
pop    %rax
jmp    1040 <am_strdup@plt>
lea    0xebc(%rip),%rdi
pop    %rax
jmp    1040 <am_strdup@plt>

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

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