#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*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
char *tmpnam(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  char *tmp_pathname;
  FILE *in = NULL;
  if ((tmp_pathname = tmpnam(NULL)) == NULL) {
    fprintf(stderr, "%s: generating a temp file name\n", strerror(errno));
    return 0;
  }
  printf("Using temp file: %s\n", tmp_pathname);
  if ((in = fopen(tmp_pathname, "r")) == NULL) {
    perror(tmp_pathname);
    return 0;
  }
  fclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <tmpnam@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11dd <main+0x6d>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe34(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1230 <main+0xc0>
mov    -0x18(%rbp),%rsi
lea    0xe39(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1220 <main+0xb0>
mov    -0x18(%rbp),%rdi
call   1070 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1230 <main+0xc0>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %edi,%edi
call   1080 <tmpnam@plt>
test   %rax,%rax
je     11ad <main+0x3d>
mov    %rax,%rbx
lea    0xe9a(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xea0(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d9 <main+0x69>
mov    %rax,%rdi
call   1030 <fclose@plt>
jmp    11d5 <main+0x65>
mov    0x2e2c(%rip),%rax
mov    (%rax),%ebx
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe35(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    %rbx,%rdi
call   1070 <perror@plt>
jmp    11d5 <main+0x65>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"%s: generating a temp file name\0A\00"
@errno = global i32 0
@.str.1 = [21 x i8] c"Using temp file: %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %7
%8 = call i8* @tmpnam(i32* null)
store i8* %8, i8** %6
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 0, i32* %3
br label %27
15: ; preds = %2
%16 = load i8*, i8** %6
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %6
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i8*, i8** %6
%23 = call i32 @perror(i8* %22)
store i32 0, i32* %3
br label %27
24: ; preds = %15
%25 = load i32*, i32** %7
%26 = call i32 @fclose(i32* %25)
store i32 0, i32* %3
br label %27
27: ; preds = %24, %21, %10
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"%s: generating a temp file name\0A\00"
@errno = global i32 0
@.str.1 = [21 x i8] c"Using temp file: %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i8* @tmpnam(i32* null)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %18
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%12 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @perror(i8* %3)
br label %18
16: ; preds = %10
%17 = tail call i32 @fclose(i32* %12)
br label %18
18: ; preds = %16, %14, %5
ret i32 0
}