#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*/ close(int);
int mkstemp(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
char *TempFile(char *dir, char *prfx) {
  int fd;
  static char fn[1024];
  sprintf(fn, "%s/%sXXXXXX", dir, prfx);
  if ((fd = mkstemp(fn)) == -1)
    perror("mkstemp");
  close(fd);
  return (fn);
}


x86 assembly (clang, -O0):
<TempFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0x2ef1(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1060 <sprintf@plt>
lea    0x2ede(%rip),%rdi
call   1040 <mkstemp@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    118f <TempFile+0x4f>
lea    0xe82(%rip),%rdi
call   1050 <perror@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
lea    0x2eb2(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TempFile>:
push   %rbx
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0x2f02(%rip),%rbx
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <mkstemp@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     117c <TempFile+0x3c>
mov    %ebx,%edi
call   1030 <close@plt>
lea    0x2ed6(%rip),%rax
pop    %rbx
ret
lea    0xe89(%rip),%rdi
call   1050 <perror@plt>
jmp    116c <TempFile+0x2c>

LLVM IR (-O0):
@TempFile.fn = internal global [1024 x i8] zeroinitializer
@.str = [12 x i8] c"%s/%sXXXXXX\00"
@.str.1 = [8 x i8] c"mkstemp\00"
define i8* @TempFile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = load i8*, i8** %4
%8 = call i32 @sprintf(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @TempFile.fn, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %7)
%9 = call i32 @mkstemp(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @TempFile.fn, i64 0, i64 0))
store i32 %9, i32* %5
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i32, i32* %5
%15 = call i32 @close(i32 %14)
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @TempFile.fn, i64 0, i64 0)
}

LLVM IR (-O2):
@TempFile.fn = internal global [1024 x i8] zeroinitializer
@.str = [12 x i8] c"%s/%sXXXXXX\00"
@.str.1 = [8 x i8] c"mkstemp\00"
define i8* @TempFile(i8* %0, i8* %1) {
%3 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @TempFile.fn, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%4 = tail call i32 @mkstemp(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @TempFile.fn, i64 0, i64 0))
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %2
%9 = tail call i32 @close(i32 %4)
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @TempFile.fn, i64 0, i64 0)
}