#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 L_tmpnam;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *tmpfile();
char *tmpnam(char *);
int main() {
  char tmpname[L_tmpnam];
  char *filename;
  FILE *tmpfp;
  filename = tmpnam(tmpname);
  printf("Temporary file name is: %s\n", filename);
  tmpfp = tmpfile();
  if (tmpfp)
    printf("Opened a temporary file OK\n");
  else
    perror("tmpfile");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
call   1070 <tmpnam@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <tmpfile@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11cb <main+0x7b>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d7 <main+0x87>
lea    0xe66(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rdi
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdi
mov    %rdi,%rsp
call   1080 <tmpnam@plt>
lea    0xe76(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <tmpfile@plt>
test   %rax,%rax
jne    11b3 <main+0x53>
lea    0xe75(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    0xe6a(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@L_tmpnam = global i32 0
@.str = [28 x i8] c"Temporary file name is: %s\0A\00"
@.str.1 = [28 x i8] c"Opened a temporary file OK\0A\00"
@.str.2 = [8 x i8] c"tmpfile\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32*
store i32 0, i32* %1
%6 = load i32, i32* @L_tmpnam
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %2
%9 = alloca i8, i64 %7
store i64 %7, i64* %3
%10 = call i8* @tmpnam(i8* %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i32* (...) @tmpfile()
store i32* %13, i32** %5
%14 = load i32*, i32** %5
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %20
18: ; preds = %0
%19 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@L_tmpnam = global i32 0
@.str = [28 x i8] c"Temporary file name is: %s\0A\00"
@.str.2 = [8 x i8] c"tmpfile\00"
@str = [27 x i8] c"Opened a temporary file OK\00"
define i32 @main() {
%1 = load i32, i32* @L_tmpnam
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = call i8* @tmpnam(i8* %3)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = call i32* (...) @tmpfile()
%7 = icmp eq i32* %6, null
br i1 %7, label %10, label %8
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %8
%13 = call i32 @exit(i32 0)
unreachable
}