#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*/ SEEK_END;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
char *tmpnam(char *);
int /*<<< orphan*/ unlink(char *);
int main() {
  char name[L_tmpnam];
  FILE *file = fopen(tmpnam(name), "w");
  if (file == NULL) {
    printf("Failed to open file\n");
    abort();
  }
  fputs("a asd a xdfasdf abn asdfasdf asdfdfaa", file);
  fclose(file);
  FILE *read = fopen(name, "r");
  if (read == NULL) {
    printf("Failed to open file\n");
    abort();
  }
  fseek(read, 0, SEEK_END);
  while (1) {
    int c = fgetc(read);
    if (feof(read)) {
      break;
    }
    putchar(c);
  }
  putchar('\n');
  fclose(read);
  unlink(name);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e12(%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,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
call   10d0 <tmpnam@plt>
mov    %rax,%rdi
lea    0xe06(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1221 <main+0x71>
lea    0xded(%rip),%rdi
call   1070 <printf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x20(%rbp),%rsi
lea    0xdeb(%rip),%rdi
call   1080 <fputs@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x38(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    126c <main+0xbc>
lea    0xda2(%rip),%rdi
call   1070 <printf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x28(%rbp),%rdi
mov    0x2d71(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10b0 <fseek@plt>
jmp    1285 <main+0xd5>
mov    -0x28(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%rax
je     12a9 <main+0xf9>
jmp    12b9 <main+0x109>
mov    -0x2c(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    1280 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1050 <unlink@plt>
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   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
call   10d0 <tmpnam@plt>
lea    0xe1d(%rip),%rsi
mov    %rax,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1298 <main+0xe8>
mov    %rax,%rbx
lea    0xe04(%rip),%rdi
mov    $0x25,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
lea    0xe09(%rip),%rsi
mov    %r14,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1298 <main+0xe8>
mov    %rax,%r15
mov    0x2db2(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
call   1080 <fgetc@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    1271 <main+0xc1>
movsbl %bl,%edi
call   1030 <putchar@plt>
jmp    1250 <main+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1070 <fclose@plt>
mov    %r14,%rdi
call   1050 <unlink@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8b(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@L_tmpnam = global i32 0
@.str = [2 x i8] c"w\00"
@.str.1 = [21 x i8] c"Failed to open file\0A\00"
@.str.2 = [38 x i8] c"a asd a xdfasdf abn asdfasdf asdfdfaa\00"
@.str.3 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @L_tmpnam
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %2
%10 = alloca i8, i64 %8
store i64 %8, i64* %3
%11 = call i8* @tmpnam(i8* %10)
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %4
%13 = load i32*, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %0
%19 = load i32*, i32** %4
%20 = call i32 @fputs(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32* %19)
%21 = load i32*, i32** %4
%22 = call i32 @fclose(i32* %21)
%23 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %23, i32** %5
%24 = load i32*, i32** %5
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 (...) @abort()
unreachable
29: ; preds = %18
%30 = load i32*, i32** %5
%31 = load i32, i32* @SEEK_END
%32 = call i32 @fseek(i32* %30, i32 0, i32 %31)
br label %33
33: ; preds = %41, %29
br label %34
34: ; preds = %33
%35 = load i32*, i32** %5
%36 = call i32 @fgetc(i32* %35)
store i32 %36, i32* %6
%37 = load i32*, i32** %5
%38 = call i64 @feof(i32* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %34
br label %45
41: ; preds = %34
%42 = load i32, i32* %6
%43 = trunc i32 %42 to i8
%44 = call i32 @putchar(i8 signext %43)
br label %33
45: ; preds = %40
%46 = call i32 @putchar(i8 signext 10)
%47 = load i32*, i32** %5
%48 = call i32 @fclose(i32* %47)
%49 = call i32 @unlink(i8* %10)
%50 = load i8*, i8** %2
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@L_tmpnam = global i32 0
@.str = [2 x i8] c"w\00"
@.str.2 = [38 x i8] c"a asd a xdfasdf abn asdfasdf asdfdfaa\00"
@.str.3 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@str.4 = [20 x i8] c"Failed to open file\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* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
%9 = call i32 (...) @abort()
unreachable
10: ; preds = %0
%11 = call i64 @fwrite(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i64 37, i64 1, i32* %5)
%12 = call i32 @fclose(i32* %5)
%13 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %10
%19 = load i32, i32* @SEEK_END
%20 = call i32 @fseek(i32* %13, i32 0, i32 %19)
%21 = call i32 @fgetc(i32* %13)
%22 = call i64 @feof(i32* %13)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %18, %24
%25 = phi i32 [ %28, %24 ], [ %21, %18 ]
%26 = trunc i32 %25 to i8
%27 = call i32 @putchar(i8 signext %26)
%28 = call i32 @fgetc(i32* %13)
%29 = call i64 @feof(i32* %13)
%30 = icmp eq i64 %29, 0
br i1 %30, label %24, label %31
31: ; preds = %24, %18
%32 = call i32 @putchar(i8 signext 10)
%33 = call i32 @fclose(i32* %13)
%34 = call i32 @unlink(i8* %3)
ret i32 0
}