#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*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ *tmpfile();
char *tmpnam(char *);
int main(void) {
  char name[L_tmpnam], line[1024];
  FILE *fp;
  printf("%s\n", tmpnam(NULL));
  tmpnam(name);
  printf("%s\n", name);
  if ((fp = tmpfile()) == NULL) {
    fprintf(stderr, "tmpfile error\n");
    exit(1);
  }
  fputs("one line of output\n", fp);
  rewind(fp);
  if (fgets(line, sizeof(line), fp) == NULL) {
    fprintf(stderr, "fgets error\n");
    exit(1);
  }
  fputs(line, stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x430(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <tmpnam@plt>
mov    %rax,%rsi
lea    0xe2c(%rip),%rdi
call   1030 <printf@plt>
mov    -0x430(%rbp),%rdi
call   10a0 <tmpnam@plt>
mov    -0x430(%rbp),%rsi
lea    0xe0d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1070 <tmpfile@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jne    122f <main+0xaf>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x428(%rbp),%rsi
lea    0xdd6(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x428(%rbp),%rdi
call   1040 <rewind@plt>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    128f <main+0x10f>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xda7(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x420(%rbp),%rdi
mov    0x2d33(%rip),%rax
mov    (%rax),%rsi
call   1050 <fputs@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x10(%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    $0x400,%rsp
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
xor    %edi,%edi
call   10b0 <tmpnam@plt>
lea    0xe3a(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    %rbx,%rdi
call   10b0 <tmpnam@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1070 <tmpfile@plt>
test   %rax,%rax
je     124e <main+0xbe>
mov    %rax,%rbx
lea    0xe19(%rip),%rdi
mov    $0x13,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <rewind@plt>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1260 <main+0xd0>
mov    0x2d9c(%rip),%rax
mov    (%rax),%rsi
lea    -0x410(%rbp),%rdi
call   1050 <fputs@plt>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
jmp    1270 <main+0xe0>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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

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