#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 */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *tempnam(int /*<<< orphan*/ *, char *);
void get_temp_fname(char *out, const char *ext) {
  char *tmp = tempnam(NULL, "rcomage_tmp");
  if (tmp) {
    strcpy(out, tmp);
    free(tmp);
  } else
    strcpy(out, "rcomage_tmp");
  if (ext)
    sprintf(out + strlen(out), ".%s", ext);
}


x86 assembly (clang, -O0):
<get_temp_fname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe95(%rip),%rsi
call   1060 <tempnam@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119a <get_temp_fname+0x4a>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
jmp    11aa <get_temp_fname+0x5a>
mov    -0x8(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1040 <strcpy@plt>
cmpq   $0x0,-0x10(%rbp)
je     11df <get_temp_fname+0x8f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x20(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
lea    0xe32(%rip),%rsi
call   1070 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_temp_fname>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe9e(%rip),%rsi
xor    %edi,%edi
call   1060 <tempnam@plt>
test   %rax,%rax
je     11ab <get_temp_fname+0x5b>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     11bf <get_temp_fname+0x6f>
mov    %r15,%rdi
call   1050 <strlen@plt>
movslq %eax,%rdi
add    %r15,%rdi
lea    0xe6e(%rip),%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <sprintf@plt>
lea    0xe4e(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
test   %r14,%r14
jne    1189 <get_temp_fname+0x39>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"rcomage_tmp\00"
@.str.1 = [4 x i8] c".%s\00"
define void @get_temp_fname(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = call i8* @tempnam(i32* null, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = load i8*, i8** %5
%12 = call i32 @strcpy(i8* %10, i8* %11)
%13 = load i8*, i8** %5
%14 = call i32 @free(i8* %13)
br label %18
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %15, %9
%19 = load i8*, i8** %4
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = load i8*, i8** %3
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8*, i8** %4
%28 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %21, %18
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"rcomage_tmp\00"
@.str.1 = [4 x i8] c".%s\00"
define void @get_temp_fname(i8* %0, i8* %1) {
%3 = tail call i8* @tempnam(i32* null, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @strcpy(i8* %0, i8* %3)
%7 = tail call i32 @free(i8* %3)
br label %10
8: ; preds = %2
%9 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
%11 = icmp eq i8* %1, null
br i1 %11, label %17, label %12
12: ; preds = %10
%13 = tail call i32 @strlen(i8* %0)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %17
17: ; preds = %12, %10
ret void
}