#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fdopen(int, char *);
char *getFilename(char *);
int /*<<< orphan*/ logM(char *, char *);
int mkstemp(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strlen(char *);
FILE *createTempFile(char *basename) {
  char tempName[strlen(basename) + 8];
  int fd;
  FILE *toRet;
  sprintf(tempName, ".%s-XXXXXX", getFilename(basename));
  fd = mkstemp(tempName);
  if (fd < 0) {
    perror("Mkstemp: ");
    return NULL;
  }
  logM("[Cache] Creato temp file: '%s'\n", tempName);
  toRet = fdopen(fd, "w+b");
  return toRet;
}


x86 assembly (clang, -O0):
<createTempFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x8,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <getFilename@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rdx
lea    0xe3e(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x40(%rbp),%rdi
call   1050 <mkstemp@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11fd <createTempFile+0x8d>
lea    0xe27(%rip),%rdi
call   1070 <perror@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    122f <createTempFile+0xbf>
mov    -0x40(%rbp),%rsi
lea    0xe0d(%rip),%rdi
call   1040 <logM@plt>
mov    -0x24(%rbp),%edi
lea    0xe1e(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createTempFile>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
add    $0x8,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r14,%rdi
call   1090 <getFilename@plt>
lea    0xe5e(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <mkstemp@plt>
test   %eax,%eax
js     11e3 <createTempFile+0x73>
mov    %eax,%r14d
lea    0xe52(%rip),%rdi
mov    %rbx,%rsi
call   1040 <logM@plt>
lea    0xe63(%rip),%rsi
mov    %r14d,%edi
call   1060 <fdopen@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe21(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
jmp    11da <createTempFile+0x6a>

LLVM IR (-O0):
@.str = [11 x i8] c".%s-XXXXXX\00"
@.str.1 = [10 x i8] c"Mkstemp: \00"
@.str.2 = [32 x i8] c"[Cache] Creato temp file: '%s'\0A\00"
@.str.3 = [4 x i8] c"w+b\00"
define i32* @createTempFile(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = add nsw i32 %10, 8
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %4
%14 = alloca i8, i64 %12
store i64 %12, i64* %5
%15 = load i8*, i8** %3
%16 = call i8* @getFilename(i8* %15)
%17 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @mkstemp(i8* %14)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %1
%22 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32* null, i32** %2
store i32 1, i32* %8
br label %28
23: ; preds = %1
%24 = call i32 @logM(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%25 = load i32, i32* %6
%26 = call i32* @fdopen(i32 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i32* %26, i32** %7
%27 = load i32*, i32** %7
store i32* %27, i32** %2
store i32 1, i32* %8
br label %28
28: ; preds = %23, %21
%29 = load i8*, i8** %4
%30 = load i32*, i32** %2
ret i32* %30
}

LLVM IR (-O2):
@.str = [11 x i8] c".%s-XXXXXX\00"
@.str.1 = [10 x i8] c"Mkstemp: \00"
@.str.2 = [32 x i8] c"[Cache] Creato temp file: '%s'\0A\00"
@.str.3 = [4 x i8] c"w+b\00"
define noalias i32* @createTempFile(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 8
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i8* @getFilename(i8* %0)
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = call i32 @mkstemp(i8* %5)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %15
12: ; preds = %1
%13 = call i32 @logM(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%14 = call i32* @fdopen(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %12, %10
%16 = phi i32* [ null, %10 ], [ %14, %12 ]
ret i32* %16
}