#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 /*<<< orphan*/ mktemp(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void mkfntemp(char *fn, size_t length) {
  int l;
  char *c;
  fn[0] = '\0';
  c = getenv("TEMP");
  if (c)
    strcpy(fn, c);
  l = strlen(fn);
  if (l)
    if (fn[l - 1] != '/') {
      fn[l] = '/';
      fn[l + 1] = '\0';
    }
  strcat(fn, "OXXXXXX");
  mktemp(fn);
}


x86 assembly (clang, -O0):
<mkfntemp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
lea    0xe92(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     118f <mkfntemp+0x3f>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11e1 <mkfntemp+0x91>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11dc <mkfntemp+0x8c>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11e1 <mkfntemp+0x91>
mov    -0x8(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rdi
call   1070 <mktemp@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mkfntemp>:
push   %rbx
mov    %rdi,%rbx
movb   $0x0,(%rdi)
lea    0xea2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1173 <mkfntemp+0x23>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     118e <mkfntemp+0x3e>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     118e <mkfntemp+0x3e>
movw   $0x2f,(%rbx,%rax,1)
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1070 <mktemp@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"TEMP\00"
@.str.1 = [8 x i8] c"OXXXXXX\00"
define void @mkfntemp(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 0
store i8 0, i8* %8
%9 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = load i8*, i8** %6
%15 = call i32 @strcpy(i8* %13, i8* %14)
br label %16
16: ; preds = %12, %2
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %41
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 47
br i1 %29, label %30, label %40
30: ; preds = %21
%31 = load i8*, i8** %3
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 47, i8* %34
%35 = load i8*, i8** %3
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 0, i8* %39
br label %40
40: ; preds = %30, %21
br label %41
41: ; preds = %40, %16
%42 = load i8*, i8** %3
%43 = call i32 @strcat(i8* %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%44 = load i8*, i8** %3
%45 = call i32 @mktemp(i8* %44)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"TEMP\00"
@.str.1 = [8 x i8] c"OXXXXXX\00"
define void @mkfntemp(i8* %0, i64 %1) {
store i8 0, i8* %0
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @strcpy(i8* %0, i8* %3)
br label %7
7: ; preds = %5, %2
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %22, label %10
10: ; preds = %7
%11 = add nsw i32 %8, -1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 47
br i1 %15, label %22, label %16
16: ; preds = %10
%17 = sext i32 %8 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 47, i8* %18
%19 = add nsw i32 %8, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %10, %16, %7
%23 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @mktemp(i8* %0)
ret void
}