#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*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(long long *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(long long *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long long);
int main() {
  FILE *fp;
  fp = fopen("testfile.txt", "w+");
  if (fp == NULL) {
    perror("fopen()");
  }
  long long n = 5000;
  fwrite(&n, sizeof(long long), 1, fp);
  fseek(fp, 0, SEEK_END);
  long loc1 = ftell(fp);
  printf("Endbyte: %ld\n", loc1);
  fseek(fp, -sizeof(long long), SEEK_END);
  long loc2 = ftell(fp);
  printf("Location: %ld\n", loc2);
  long long num;
  fread(&num, sizeof(long long), 1, fp);
  printf("Number: %lld\n", num);
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe6a(%rip),%rdi
lea    0xe70(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11bd <main+0x3d>
lea    0xe58(%rip),%rdi
call   1090 <perror@plt>
movq   $0x1388,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe10(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dd0(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffff8,%esi
call   1070 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xdea(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x30(%rbp),%rsi
lea    0xdd2(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xe72(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1252 <main+0xd2>
movq   $0x1388,0x10(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   10a0 <fwrite@plt>
mov    0x2e1b(%rip),%r14
mov    (%r14),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
lea    0xe2f(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0xfffffff8,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
lea    0xe16(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    0x8(%rsp),%rsi
lea    0xdfa(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdb7(%rip),%rdi
call   1090 <perror@plt>
jmp    11a6 <main+0x26>

LLVM IR (-O0):
@.str = [13 x i8] c"testfile.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [8 x i8] c"fopen()\00"
@SEEK_END = global i32 0
@.str.3 = [14 x i8] c"Endbyte: %ld\0A\00"
@.str.4 = [15 x i8] c"Location: %ld\0A\00"
@.str.5 = [14 x i8] c"Number: %lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = load i32*, i32** %2
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
store i64 5000, i64* %3
%13 = load i32*, i32** %2
%14 = call i32 @fwrite(i64* %3, i32 8, i32 1, i32* %13)
%15 = load i32*, i32** %2
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i32 0, i32 %16)
%18 = load i32*, i32** %2
%19 = call i64 @ftell(i32* %18)
store i64 %19, i64* %4
%20 = load i64, i64* %4
%21 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i64 %20)
%22 = load i32*, i32** %2
%23 = load i32, i32* @SEEK_END
%24 = call i32 @fseek(i32* %22, i32 -8, i32 %23)
%25 = load i32*, i32** %2
%26 = call i64 @ftell(i32* %25)
store i64 %26, i64* %5
%27 = load i64, i64* %5
%28 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i64 %27)
%29 = load i32*, i32** %2
%30 = call i32 @fread(i64* %6, i32 8, i32 1, i32* %29)
%31 = load i64, i64* %6
%32 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i64 %31)
%33 = load i32*, i32** %2
%34 = call i32 @fclose(i32* %33)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"testfile.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [8 x i8] c"fopen()\00"
@SEEK_END = global i32 0
@.str.3 = [14 x i8] c"Endbyte: %ld\0A\00"
@.str.4 = [15 x i8] c"Location: %ld\0A\00"
@.str.5 = [14 x i8] c"Number: %lld\0A\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = bitcast i64* %1 to i8*
store i64 5000, i64* %1
%9 = call i32 @fwrite(i64* %1, i32 8, i32 1, i32* %3)
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %3, i32 0, i32 %10)
%12 = tail call i64 @ftell(i32* %3)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i64 %12)
%14 = load i32, i32* @SEEK_END
%15 = tail call i32 @fseek(i32* %3, i32 -8, i32 %14)
%16 = tail call i64 @ftell(i32* %3)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i64 %16)
%18 = bitcast i64* %2 to i8*
%19 = call i32 @fread(i64* %2, i32 8, i32 1, i32* %3)
%20 = load i64, i64* %2
%21 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i64 %20)
%22 = tail call i32 @fclose(i32* %3)
ret i32 0
}