#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 *);
int getpid();
int /*<<< orphan*/ sprintf(char *, char *, char *, int, int);
int /*<<< orphan*/ strcpy(char *, char *);
void temp_file_name(int type, char *d_name, char *f_name) {
  if ((getenv("TEMP") == NULL) && (getenv("GSFTMPDIR") == NULL))
    strcpy(d_name, "/tmp");
  else if (getenv("GSFTMPDIR") != NULL)
    strcpy(d_name, getenv("GSFTMPDIR"));
  else
    strcpy(d_name, getenv("TEMP"));
  sprintf(f_name, "%s/%05d%02d.ndx", d_name, getpid(), type);
  return;
}


x86 assembly (clang, -O0):
<temp_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xea6(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    1194 <temp_file_name+0x54>
lea    0xe95(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
jne    1194 <temp_file_name+0x54>
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1040 <strcpy@plt>
jmp    11f4 <temp_file_name+0xb4>
lea    0xe6a(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11cf <temp_file_name+0x8f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe4c(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x20(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
jmp    11ef <temp_file_name+0xaf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe22(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
jmp    11f4 <temp_file_name+0xb4>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
mov    -0x4(%rbp),%r8d
lea    0xdf4(%rip),%rsi
call   1060 <sprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<temp_file_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xea9(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1175 <temp_file_name+0x35>
lea    0xe9a(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1193 <temp_file_name+0x53>
lea    0xe89(%rip),%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     118e <temp_file_name+0x4e>
mov    %rax,%rsi
jmp    119d <temp_file_name+0x5d>
mov    %rbp,%rsi
jmp    119d <temp_file_name+0x5d>
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe64(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
mov    %r14d,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <sprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"TEMP\00"
@.str.1 = [10 x i8] c"GSFTMPDIR\00"
@.str.2 = [5 x i8] c"/tmp\00"
@.str.3 = [16 x i8] c"%s/%05d%02d.ndx\00"
define void @temp_file_name(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%7 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %15
9: ; preds = %3
%10 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i8*, i8** %5
%14 = call i32 @strcpy(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %27
15: ; preds = %9, %3
%16 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i8*, i8** %5
%20 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @strcpy(i8* %19, i8* %20)
br label %26
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @strcpy(i8* %23, i8* %24)
br label %26
26: ; preds = %22, %18
br label %27
27: ; preds = %26, %12
%28 = load i8*, i8** %6
%29 = load i8*, i8** %5
%30 = call i32 (...) @getpid()
%31 = load i32, i32* %4
%32 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %29, i32 %30, i32 %31)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"TEMP\00"
@.str.1 = [10 x i8] c"GSFTMPDIR\00"
@.str.2 = [5 x i8] c"/tmp\00"
@.str.3 = [16 x i8] c"%s/%05d%02d.ndx\00"
define void @temp_file_name(i32 %0, i8* %1, i8* nocapture writeonly %2) {
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %18
11: ; preds = %6, %3
%12 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @strcpy(i8* %1, i8* %12)
br label %18
16: ; preds = %11
%17 = tail call i32 @strcpy(i8* %1, i8* %4)
br label %18
18: ; preds = %14, %16, %9
%19 = tail call i32 (...) @getpid()
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %1, i32 %19, i32 %0)
ret void
}