#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_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ ftell(int /*<<< orphan*/ *);
int getw(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putw(int, int /*<<< orphan*/ *);
int main() {
  int ch, i;
  FILE *fp = fopen("Divyansh.txt", "w");
  for (i = 1; i < 50; i++)
    putw(i, fp);
  fclose(fp);
  FILE *fp2 = fopen("Divyansh.txt", "r");
  fseek(fp2, -4, SEEK_END);
  i = 1;
  while (i++ != 50) {
    printf("%d\t%ld\n", ch, ftell(fp2));
    fseek(fp2, -8, SEEK_CUR);
    ch = getw(fp2);
  }
  if (feof(fp2))
    printf("\n End of file reached.");
  else
    printf("\n Something went wrong.");
  fclose(fp2);
  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   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x32,-0xc(%rbp)
jge    11d1 <main+0x51>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1050 <putw@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ad <main+0x2d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe1f(%rip),%rdi
lea    0xe27(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2dec(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffffc,%esi
call   1080 <fseek@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x32,%eax
je     126d <main+0xed>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d90(%rip),%rax
mov    (%rax),%edx
mov    $0xfffffff8,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1090 <getw@plt>
mov    %eax,-0x8(%rbp)
jmp    120f <main+0x8f>
mov    -0x20(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     1293 <main+0x113>
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a1 <main+0x121>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xe71(%rip),%rdi
lea    0xe77(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <putw@plt>
add    $0x1,%ebp
cmp    $0x32,%ebp
jne    11b0 <main+0x30>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe2f(%rip),%rdi
lea    0xe37(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r15
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
mov    $0xfffffffc,%esi
call   1080 <fseek@plt>
mov    $0x31,%ebx
lea    0xe0f(%rip),%r14
mov    0x2dd7(%rip),%r12
nopl   0x0(%rax)
mov    %r15,%rdi
call   1060 <ftell@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    $0xfffffff8,%esi
call   1080 <fseek@plt>
mov    %r15,%rdi
call   1090 <getw@plt>
mov    %eax,%ebp
add    $0xffffffff,%ebx
jne    1210 <main+0x90>
mov    %r15,%rdi
call   1070 <feof@plt>
test   %rax,%rax
lea    0xdd8(%rip),%rax
lea    0xdba(%rip),%rdi
cmove  %rax,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Divyansh.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.3 = [8 x i8] c"%d\09%ld\0A\00"
@SEEK_CUR = global i32 0
@.str.4 = [23 x i8] c"\0A End of file reached.\00"
@.str.5 = [24 x i8] c"\0A Something went wrong.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %4
store i32 1, i32* %3
br label %7
7: ; preds = %14, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 50
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = load i32, i32* %3
%12 = load i32*, i32** %4
%13 = call i32 @putw(i32 %11, i32* %12)
br label %14
14: ; preds = %10
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %7
17: ; preds = %7
%18 = load i32*, i32** %4
%19 = call i32 @fclose(i32* %18)
%20 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %5
%21 = load i32*, i32** %5
%22 = load i32, i32* @SEEK_END
%23 = call i32 @fseek(i32* %21, i32 -4, i32 %22)
store i32 1, i32* %3
br label %24
24: ; preds = %28, %17
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
%27 = icmp ne i32 %25, 50
br i1 %27, label %28, label %38
28: ; preds = %24
%29 = load i32, i32* %2
%30 = load i32*, i32** %5
%31 = call i32 @ftell(i32* %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %29, i32 %31)
%33 = load i32*, i32** %5
%34 = load i32, i32* @SEEK_CUR
%35 = call i32 @fseek(i32* %33, i32 -8, i32 %34)
%36 = load i32*, i32** %5
%37 = call i32 @getw(i32* %36)
store i32 %37, i32* %2
br label %24
38: ; preds = %24
%39 = load i32*, i32** %5
%40 = call i64 @feof(i32* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %46
44: ; preds = %38
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %44, %42
%47 = load i32*, i32** %5
%48 = call i32 @fclose(i32* %47)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"Divyansh.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.3 = [8 x i8] c"%d\09%ld\0A\00"
@SEEK_CUR = global i32 0
@.str.4 = [23 x i8] c"\0A End of file reached.\00"
@.str.5 = [24 x i8] c"\0A Something went wrong.\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 1, %0 ], [ %5, %2 ]
%4 = tail call i32 @putw(i32 %3, i32* %1)
%5 = add nuw nsw i32 %3, 1
%6 = icmp eq i32 %5, 50
br i1 %6, label %7, label %2
7: ; preds = %2
%8 = tail call i32 @fclose(i32* %1)
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %9, i32 -4, i32 %10)
br label %12
12: ; preds = %7, %12
%13 = phi i32 [ undef, %7 ], [ %20, %12 ]
%14 = phi i32 [ 1, %7 ], [ %15, %12 ]
%15 = add nuw nsw i32 %14, 1
%16 = tail call i32 @ftell(i32* %9)
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %13, i32 %16)
%18 = load i32, i32* @SEEK_CUR
%19 = tail call i32 @fseek(i32* %9, i32 -8, i32 %18)
%20 = tail call i32 @getw(i32* %9)
%21 = icmp eq i32 %15, 50
br i1 %21, label %22, label %12
22: ; preds = %12
%23 = tail call i64 @feof(i32* %9)
%24 = icmp eq i64 %23, 0
%25 = select i1 %24, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %25)
%27 = tail call i32 @fclose(i32* %9)
ret i32 0
}