#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ unlink(char *);
FILE *tmpfile() {
  FILE *fp;
  char *f, *tmpnam();
  if (!(f = tmpnam((char *)NULL)) || !(fp = fopen(f, "w+"))) {
    fprintf(stderr, "tmpfile: cannot open %s.\n", f);
    return (NULL);
  }
  (void)unlink(f);
  return (fp);
}


x86 assembly (clang, -O0):
<tmpfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xor    %eax,%eax
mov    %eax,%edi
mov    $0x0,%al
call   1060 <tmpnam@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     117f <tmpfile+0x3f>
mov    -0x18(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11a5 <tmpfile+0x65>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe70(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b6 <tmpfile+0x76>
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmpfile>:
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
xor    %eax,%eax
call   1060 <tmpnam@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1176 <tmpfile+0x36>
lea    0xea4(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     1176 <tmpfile+0x36>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <unlink@plt>
jmp    1191 <tmpfile+0x51>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"tmpfile: cannot open %s.\0A\00"
define i32* @tmpfile() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca i8*
%4 = call i8* (i8*, ...) bitcast (i8* (...)* @tmpnam to i8* (i8*, ...)*)(i8* null)
store i8* %4, i8** %3
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %2
%9 = icmp ne i32* %8, null
br i1 %9, label %14, label %10
10: ; preds = %6, %0
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %3
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %12)
store i32* null, i32** %1
br label %18
14: ; preds = %6
%15 = load i8*, i8** %3
%16 = call i32 @unlink(i8* %15)
%17 = load i32*, i32** %2
store i32* %17, i32** %1
br label %18
18: ; preds = %14, %10
%19 = load i32*, i32** %1
ret i32* %19
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@stderr = global i32 0
@.str.1 = [26 x i8] c"tmpfile: cannot open %s.\0A\00"
define i32* @tmpfile() {
%1 = tail call i8* (i8*, ...) bitcast (i8* (...)* @tmpnam to i8* (i8*, ...)*)(i8* null)
%2 = icmp eq i8* %1, null
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %3, %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %11
9: ; preds = %3
%10 = tail call i32 @unlink(i8* %1)
br label %11
11: ; preds = %9, %6
%12 = phi i32* [ %4, %9 ], [ null, %6 ]
ret i32* %12
}