#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int L_tmpnam;
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ *tmpfile();
char *tmpnam(char *);
int main(int argc, char **argv) {
  char name[L_tmpnam], line[4096];
  FILE *fp;
  printf("%s\n", tmpnam(NULL));
  tmpnam(name);
  printf("%s\n", name);
  if ((fp = tmpfile()) == NULL) {
    err_sys("tmpfile error");
  }
  fputs("one line of output\n", fp);
  rewind(fp);
  if (fgets(line, sizeof(line), fp) == NULL) {
    err_sys("fgets error");
  }
  fputs(line, stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x1030(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <tmpnam@plt>
mov    %rax,%rsi
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
mov    -0x1030(%rbp),%rdi
call   1090 <tmpnam@plt>
mov    -0x1030(%rbp),%rsi
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <tmpfile@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
jne    1213 <main+0xa3>
lea    0xdf6(%rip),%rdi
call   1030 <err_sys@plt>
mov    -0x1028(%rbp),%rsi
lea    0xdf1(%rip),%rdi
call   1060 <fputs@plt>
mov    -0x1028(%rbp),%rdi
call   1050 <rewind@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x1028(%rbp),%rdx
mov    $0x1000,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    1260 <main+0xf0>
lea    0xdcb(%rip),%rdi
call   1030 <err_sys@plt>
lea    -0x1020(%rbp),%rdi
mov    0x2d6a(%rip),%rax
mov    (%rax),%rsi
call   1060 <fputs@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
xor    %edi,%edi
call   10a0 <tmpnam@plt>
lea    0xe4a(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   10a0 <tmpnam@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <tmpfile@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11ef <main+0x6f>
lea    0xe1a(%rip),%rdi
call   1030 <err_sys@plt>
lea    0xe1c(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <rewind@plt>
lea    -0x1010(%rbp),%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1235 <main+0xb5>
lea    0xdf6(%rip),%rdi
call   1030 <err_sys@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%rsi
lea    -0x1010(%rbp),%rdi
call   1060 <fputs@plt>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@L_tmpnam = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [14 x i8] c"tmpfile error\00"
@.str.2 = [20 x i8] c"one line of output\0A\00"
@.str.3 = [12 x i8] c"fgets error\00"
@stdout = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [4096 x i8]
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @L_tmpnam
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
%14 = call i8* @tmpnam(i8* null)
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i8* @tmpnam(i8* %13)
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
%18 = call i32* (...) @tmpfile()
store i32* %18, i32** %9
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = load i32*, i32** %9
%24 = call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32* %23)
%25 = load i32*, i32** %9
%26 = call i32 @rewind(i32* %25)
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%28 = load i32*, i32** %9
%29 = call i32* @fgets(i8* %27, i32 4096, i32* %28)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %22
%32 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %33
33: ; preds = %31, %22
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%35 = load i32*, i32** @stdout
%36 = call i32 @fputs(i8* %34, i32* %35)
store i32 0, i32* %3
%37 = load i8*, i8** %6
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@L_tmpnam = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [14 x i8] c"tmpfile error\00"
@.str.2 = [20 x i8] c"one line of output\0A\00"
@.str.3 = [12 x i8] c"fgets error\00"
@stdout = global i32* null
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = load i32, i32* @L_tmpnam
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%8 = tail call i8* @tmpnam(i8* null)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = call i8* @tmpnam(i8* %6)
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %6)
%12 = call i32* (...) @tmpfile()
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @err_sys(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = call i64 @fwrite(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i64 19, i64 1, i32* %12)
%18 = call i32 @rewind(i32* %12)
%19 = call i32* @fgets(i8* %7, i32 4096, i32* %12)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = load i32*, i32** @stdout
%25 = call i32 @fputs(i8* %7, i32* %24)
ret i32 0
}