#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_SET;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ print(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(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();
  }
  if (fseek(read, 9, SEEK_SET) != 0) {
    abort();
  }
  print(read);
  if (fseek(read, 0, SEEK_SET) != 0) {
    abort();
  }
  print(read);
  if (fseek(read, 1000, SEEK_SET) != 0) {
    abort();
  }
  print(read);
  fclose(read);
  unlink(name);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x8(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x10(%rbp)
call   10b0 <tmpnam@plt>
mov    %rax,%rdi
lea    0xe2d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fa <main+0x6a>
lea    0xe14(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x18(%rbp),%rsi
lea    0xe12(%rip),%rdi
call   1070 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1245 <main+0xb5>
lea    0xdc9(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d88(%rip),%rax
mov    (%rax),%edx
mov    $0x9,%esi
call   1090 <fseek@plt>
cmp    $0x0,%rax
je     126d <main+0xdd>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rdi
call   1080 <print@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d57(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
cmp    $0x0,%rax
je     129b <main+0x10b>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rdi
call   1080 <print@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d29(%rip),%rax
mov    (%rax),%edx
mov    $0x3e8,%esi
call   1090 <fseek@plt>
cmp    $0x0,%rax
je     12cc <main+0x13c>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rdi
call   1080 <print@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x8(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%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    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
call   10b0 <tmpnam@plt>
lea    0xe3d(%rip),%rsi
mov    %rax,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1287 <main+0xf7>
mov    %rax,%rbx
lea    0xe24(%rip),%rdi
mov    $0x25,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xe29(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1287 <main+0xf7>
mov    %rax,%rbx
mov    0x2dc2(%rip),%r15
mov    (%r15),%edx
mov    %rax,%rdi
mov    $0x9,%esi
call   1080 <fseek@plt>
test   %rax,%rax
jne    1293 <main+0x103>
mov    %rbx,%rdi
call   1070 <print@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
test   %rax,%rax
jne    1293 <main+0x103>
mov    %rbx,%rdi
call   1070 <print@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1080 <fseek@plt>
test   %rax,%rax
jne    1293 <main+0x103>
mov    %rbx,%rdi
call   1070 <print@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1040 <unlink@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9c(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1030 <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_SET = global i32 0
define i32 @main() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i32*
%4 = alloca i32*
%5 = load i32, i32* @L_tmpnam
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
store i8* %7, i8** %1
%8 = alloca i8, i64 %6
store i64 %6, i64* %2
%9 = call i8* @tmpnam(i8* %8)
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %0
%17 = load i32*, i32** %3
%18 = call i32 @fputs(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32* %17)
%19 = load i32*, i32** %3
%20 = call i32 @fclose(i32* %19)
%21 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %21, i32** %4
%22 = load i32*, i32** %4
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 (...) @abort()
unreachable
27: ; preds = %16
%28 = load i32*, i32** %4
%29 = load i32, i32* @SEEK_SET
%30 = call i64 @fseek(i32* %28, i32 9, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %27
%35 = load i32*, i32** %4
%36 = call i32 @print(i32* %35)
%37 = load i32*, i32** %4
%38 = load i32, i32* @SEEK_SET
%39 = call i64 @fseek(i32* %37, i32 0, i32 %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 (...) @abort()
unreachable
43: ; preds = %34
%44 = load i32*, i32** %4
%45 = call i32 @print(i32* %44)
%46 = load i32*, i32** %4
%47 = load i32, i32* @SEEK_SET
%48 = call i64 @fseek(i32* %46, i32 1000, i32 %47)
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %43
%51 = call i32 (...) @abort()
unreachable
52: ; preds = %43
%53 = load i32*, i32** %4
%54 = call i32 @print(i32* %53)
%55 = load i32*, i32** %4
%56 = call i32 @fclose(i32* %55)
%57 = call i32 @unlink(i8* %8)
%58 = load i8*, i8** %1
ret i32 0
}

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_SET = 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_SET
%20 = call i64 @fseek(i32* %13, i32 9, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = call i32 (...) @abort()
unreachable
24: ; preds = %18
%25 = call i32 @print(i32* %13)
%26 = load i32, i32* @SEEK_SET
%27 = call i64 @fseek(i32* %13, i32 0, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %24
%30 = call i32 (...) @abort()
unreachable
31: ; preds = %24
%32 = call i32 @print(i32* %13)
%33 = load i32, i32* @SEEK_SET
%34 = call i64 @fseek(i32* %13, i32 1000, i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %31
%37 = call i32 (...) @abort()
unreachable
38: ; preds = %31
%39 = call i32 @print(i32* %13)
%40 = call i32 @fclose(i32* %13)
%41 = call i32 @unlink(i8* %3)
ret i32 0
}