#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 *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
char *get_tmp_file_path(const char *path_suffix) {
  const char *tmpdir = getenv("TMPDIR");
  if (tmpdir == NULL) {
    tmpdir = "/tmp";
  }
  int path_len = strlen(tmpdir) + strlen(path_suffix);
  char *path = (char *)malloc((path_len + 1) * sizeof(char));
  memset(path, '\0', path_len + 1);
  strncat(path, tmpdir, strlen(tmpdir));
  strncat(path, path_suffix, strlen(path_suffix));
  return path;
}


x86 assembly (clang, -O0):
<get_tmp_file_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe9d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1182 <get_tmp_file_path+0x32>
lea    0xe89(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_tmp_file_path>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe9f(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe97(%rip),%rbx
cmovne %rax,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %eax,%r15d
add    $0x1,%r15d
mov    %r15d,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <strncat@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [5 x i8] c"/tmp\00"
define i8* @get_tmp_file_path(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %10
10: ; preds = %9, %1
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
%15 = add nsw i32 %12, %14
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 1
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %5
%23 = load i8*, i8** %5
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
%26 = call i32 @memset(i8* %23, i8 signext 0, i32 %25)
%27 = load i8*, i8** %5
%28 = load i8*, i8** %3
%29 = load i8*, i8** %3
%30 = call i32 @strlen(i8* %29)
%31 = call i32 @strncat(i8* %27, i8* %28, i32 %30)
%32 = load i8*, i8** %5
%33 = load i8*, i8** %2
%34 = load i8*, i8** %2
%35 = call i32 @strlen(i8* %34)
%36 = call i32 @strncat(i8* %32, i8* %33, i32 %35)
%37 = load i8*, i8** %5
ret i8* %37
}

LLVM IR (-O2):
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [5 x i8] c"/tmp\00"
define i8* @get_tmp_file_path(i8* %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
%4 = select i1 %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %2
%5 = tail call i32 @strlen(i8* %4)
%6 = tail call i32 @strlen(i8* %0)
%7 = add i32 %5, 1
%8 = add i32 %7, %6
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @memset(i8* %10, i8 signext 0, i32 %8)
%12 = tail call i32 @strlen(i8* %4)
%13 = tail call i32 @strncat(i8* %10, i8* %4, i32 %12)
%14 = tail call i32 @strlen(i8* %0)
%15 = tail call i32 @strncat(i8* %10, i8* %0, i32 %14)
ret i8* %10
}