#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_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, long *);
int main(void) {
  char *fname = "test.txt";
  long position;
  int ch;
  FILE *fp;
  if ((fp = fopen(fname, "r")) == NULL) {
    printf("File Open Error\n");
    exit(-1);
  }
  printf("Input number >> ");
  scanf("%ld", &position);
  fseek(fp, position - 1L, SEEK_SET);
  ch = getc(fp);
  printf("%ldth character => %c\n", position, ch);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11b0 <main+0x50>
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe68(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe84(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ee <main+0x7e>
mov    %rax,%rbx
lea    0xe72(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe75(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%rsi
add    $0xffffffffffffffff,%rsi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1050 <fseek@plt>
mov    %rbx,%rdi
call   1090 <getc@plt>
mov    0x8(%rsp),%rsi
lea    0xe41(%rip),%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe40(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"File Open Error\0A\00"
@.str.3 = [17 x i8] c"Input number >> \00"
@.str.4 = [4 x i8] c"%ld\00"
@SEEK_SET = global i32 0
@.str.5 = [23 x i8] c"%ldth character => %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32*
store i32 0, i32* %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64* %3)
%15 = load i32*, i32** %5
%16 = load i64, i64* %3
%17 = sub nsw i64 %16, 1
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @fseek(i32* %15, i64 %17, i32 %18)
%20 = load i32*, i32** %5
%21 = call i32 @getc(i32* %20)
store i32 %21, i32* %4
%22 = load i64, i64* %3
%23 = load i32, i32* %4
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 %22, i32 %23)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [17 x i8] c"Input number >> \00"
@.str.4 = [4 x i8] c"%ld\00"
@SEEK_SET = global i32 0
@.str.5 = [23 x i8] c"%ldth character => %c\0A\00"
@str = [16 x i8] c"File Open Error\00"
define i32 @main() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i64* %1)
%11 = load i64, i64* %1
%12 = add nsw i64 %11, -1
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @fseek(i32* %3, i64 %12, i32 %13)
%15 = call i32 @getc(i32* %3)
%16 = load i64, i64* %1
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 %16, i32 %15)
ret i32 0
}