#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*/ close(int);
int /*<<< orphan*/ *fdopen(int, char *);
int mkstemp(char *);
int /*<<< orphan*/ unlink(char *);
FILE *tmpfile(void) {
  char filename[] = "/tmp/tmpfileXXXXXX";
  int fd = mkstemp(filename);
  if (fd < 0)
    return NULL;
  unlink(filename);
  FILE *file = fdopen(fd, "");
  if (!file) {
    close(fd);
  }
  return file;
}


x86 assembly (clang, -O0):
<tmpfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xeb1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeae(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeab(%rip),%ax
mov    %ax,-0x10(%rbp)
mov    0xea3(%rip),%al
mov    %al,-0xe(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <mkstemp@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1195 <tmpfile+0x55>
movq   $0x0,-0x8(%rbp)
jmp    11cc <tmpfile+0x8c>
lea    -0x20(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x24(%rbp),%edi
lea    0xe6b(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11c4 <tmpfile+0x84>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmpfile>:
push   %rbx
sub    $0x20,%rsp
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x585858,0xf(%rsp)
mov    %rsp,%rdi
call   1050 <mkstemp@plt>
test   %eax,%eax
js     1188 <tmpfile+0x48>
mov    %eax,%ebx
mov    %rsp,%rdi
call   1030 <unlink@plt>
lea    0xe9e(%rip),%rsi
mov    %ebx,%edi
call   1060 <fdopen@plt>
test   %rax,%rax
jne    118a <tmpfile+0x4a>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.tmpfile.filename = [19 x i8] c"/tmp/tmpfileXXXXXX\00"
@.str = [1 x i8] zeroinitializer
define i32* @tmpfile() {
%1 = alloca i32*
%2 = alloca [19 x i8]
%3 = alloca i32
%4 = alloca i32*
%5 = bitcast [19 x i8]* %2 to i8*
%6 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%7 = call i32 @mkstemp(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32* null, i32** %1
br label %23
11: ; preds = %0
%12 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%13 = call i32 @unlink(i8* %12)
%14 = load i32, i32* %3
%15 = call i32* @fdopen(i32 %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %4
%16 = load i32*, i32** %4
%17 = icmp ne i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %11
%19 = load i32, i32* %3
%20 = call i32 @close(i32 %19)
br label %21
21: ; preds = %18, %11
%22 = load i32*, i32** %4
store i32* %22, i32** %1
br label %23
23: ; preds = %21, %10
%24 = load i32*, i32** %1
ret i32* %24
}

LLVM IR (-O2):
@__const.tmpfile.filename = [19 x i8] c"/tmp/tmpfileXXXXXX\00"
@.str = [1 x i8] zeroinitializer
define noalias i32* @tmpfile() {
%1 = alloca [19 x i8]
%2 = getelementptr inbounds [19 x i8], [19 x i8]* %1, i64 0, i64 0
%3 = call i32 @mkstemp(i8* %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %0
%6 = call i32 @unlink(i8* %2)
%7 = call i32* @fdopen(i32 %3, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = call i32 @close(i32 %3)
br label %11
11: ; preds = %5, %9, %0
%12 = phi i32* [ null, %0 ], [ null, %9 ], [ %7, %5 ]
ret i32* %12
}