#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*/ fprintf(int /*<<< orphan*/ *, char *, char *);
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 : %s", filename);
  tmpfp = tmpfile();
  if (tmpfp)
    printf("Opened a temporary file OK.\n");
  else
    perror("tmpfile");
  fprintf(tmpfp, "This is a temporary file %s", filename);
  while (1)
    ;
  return 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    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d7 <main+0x87>
lea    0xe64(%rip),%rdi
call   1060 <perror@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe58(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11f0 <main+0xa0>
jmp    11eb <main+0x9b>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rdi
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdi
mov    %rdi,%rsp
call   1080 <tmpnam@plt>
mov    %rax,%r14
lea    0xe70(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <tmpfile@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d2 <main+0x72>
lea    0xe8d(%rip),%rdi
call   1030 <puts@plt>
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <fprintf@plt>
nopw   0x0(%rax,%rax,1)
jmp    11d0 <main+0x70>
lea    0xe40(%rip),%rdi
call   1070 <perror@plt>
jmp    11b5 <main+0x55>

LLVM IR (-O0):
@L_tmpnam = global i32 0
@.str = [25 x i8] c"Temporary file name : %s\00"
@.str.1 = [29 x i8] c"Opened a temporary file OK.\0A\00"
@.str.2 = [8 x i8] c"tmpfile\00"
@.str.3 = [28 x i8] c"This is a temporary file %s\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 ([25 x i8], [25 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 ([29 x i8], [29 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 = load i32*, i32** %5
%22 = load i8*, i8** %4
%23 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %25, %20
br label %25
25: ; preds = %24
br label %24
}

LLVM IR (-O2):
@L_tmpnam = global i32 0
@.str = [25 x i8] c"Temporary file name : %s\00"
@.str.2 = [8 x i8] c"tmpfile\00"
@.str.3 = [28 x i8] c"This is a temporary file %s\00"
@str = [28 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 ([25 x i8], [25 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 ([28 x i8], [28 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 @fprintf(i32* %6, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %14
14: ; preds = %14, %12
br label %14
}