#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;
char *tmpnam(char *);
int main(int argc, char **argv) {
  char name[256];
  char *pname;
  FILE *f;
  fprintf(stderr, "Prog:  %s\n", argv[0]);
  pname = tmpnam(NULL);
  f = fopen(pname, "w");
  fprintf(stderr, "Tmpnam:  %s\n", pname);
  pname = tmpnam(name);
  fprintf(stderr, "Tmpnam:  %s\n", pname);
  pname = tmpnam(name);
  fprintf(stderr, "Tmpnam:  %s\n", pname);
  pname = tmpnam(name);
  fprintf(stderr, "Tmpnam:  %s\n", pname);
  pname = tmpnam(name);
  fprintf(stderr, "Tmpnam:  %s\n", pname);
  pname = tmpnam(NULL);
  fprintf(stderr, "Tmpnam:  %s\n", pname);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xea7(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <tmpnam@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x120(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x118(%rbp),%rdx
lea    0xe6e(%rip),%rsi
call   1030 <fprintf@plt>
lea    -0x110(%rbp),%rdi
call   1050 <tmpnam@plt>
mov    %rax,-0x118(%rbp)
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    -0x118(%rbp),%rdx
lea    0xe3f(%rip),%rsi
call   1030 <fprintf@plt>
lea    -0x110(%rbp),%rdi
call   1050 <tmpnam@plt>
mov    %rax,-0x118(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    -0x118(%rbp),%rdx
lea    0xe10(%rip),%rsi
call   1030 <fprintf@plt>
lea    -0x110(%rbp),%rdi
call   1050 <tmpnam@plt>
mov    %rax,-0x118(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    -0x118(%rbp),%rdx
lea    0xde1(%rip),%rsi
call   1030 <fprintf@plt>
lea    -0x110(%rbp),%rdi
call   1050 <tmpnam@plt>
mov    %rax,-0x118(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    -0x118(%rbp),%rdx
lea    0xdb2(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <tmpnam@plt>
mov    %rax,-0x118(%rbp)
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
mov    -0x118(%rbp),%rdx
lea    0xd86(%rip),%rsi
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    0x2e9d(%rip),%r15
mov    (%r15),%edi
mov    (%rsi),%rdx
lea    0xeb0(%rip),%rsi
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <tmpnam@plt>
mov    %rax,%rbx
lea    0xea5(%rip),%rsi
mov    %rax,%rdi
call   1040 <fopen@plt>
mov    (%r15),%edi
lea    0xe95(%rip),%r14
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <tmpnam@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <tmpnam@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <tmpnam@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <tmpnam@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1050 <tmpnam@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rax,%rdx
call   1030 <fprintf@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [11 x i8] c"Prog: %s\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"Tmpnam: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [256 x i8]
%6 = alloca i8*
%7 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* @stderr
%9 = load i8**, i8*** %4
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = call i8* @tmpnam(i8* null)
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %6
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%20 = call i8* @tmpnam(i8* %19)
store i8* %20, i8** %6
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %6
%23 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%25 = call i8* @tmpnam(i8* %24)
store i8* %25, i8** %6
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %6
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%30 = call i8* @tmpnam(i8* %29)
store i8* %30, i8** %6
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %6
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%35 = call i8* @tmpnam(i8* %34)
store i8* %35, i8** %6
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %6
%38 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = call i8* @tmpnam(i8* null)
store i8* %39, i8** %6
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %6
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %41)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [11 x i8] c"Prog: %s\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [13 x i8] c"Tmpnam: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i8* @tmpnam(i8* null)
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%12 = call i8* @tmpnam(i8* %4)
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%15 = call i8* @tmpnam(i8* %4)
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%18 = call i8* @tmpnam(i8* %4)
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%21 = call i8* @tmpnam(i8* %4)
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%24 = call i8* @tmpnam(i8* null)
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %24)
ret i32 0
}