#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 */
char EOF;
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  char fname[100];
  int offset;
  printf("Enter the Name of File With Extension: ");
  scanf("%s", fname);
  printf("Enter the Value of Offset: ");
  scanf("%d", &offset);
  FILE *f1;
  f1 = fopen(fname, "r");
  int line = 0;
  char ch;
  while (1) {
    ch = getc(f1);
    if (ch == EOF) {
      break;
    }
    if (ch == '\n')
      line++;
    else
      continue;
  }
  rewind(f1);
  if (offset < 0)
    offset = line + offset;
  if (offset > line)
    printf("ERROR");
  else {
    int n = offset;
    while (n) {
      ch = getc(f1);
      if (ch == '\n')
        n--;
    }
    while ((ch = getc(f1)) != EOF)
      putchar(ch);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
lea    0xea4(%rip),%rdi
lea    -0x74(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x80(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x80(%rbp),%rdi
call   1080 <getc@plt>
mov    %al,-0x85(%rbp)
movsbl -0x85(%rbp),%eax
mov    0x2dff(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11f9 <main+0x99>
jmp    1227 <main+0xc7>
movsbl -0x85(%rbp),%eax
cmp    $0xa,%eax
jne    121d <main+0xbd>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1222 <main+0xc2>
jmp    11cc <main+0x6c>
jmp    11cc <main+0x6c>
mov    -0x80(%rbp),%rdi
call   1050 <rewind@plt>
cmpl   $0x0,-0x74(%rbp)
jge    1246 <main+0xe6>
mov    -0x84(%rbp),%eax
add    -0x74(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x84(%rbp),%eax
jle    1266 <main+0x106>
lea    0xdf0(%rip),%rdi
call   1040 <printf@plt>
jmp    12ee <main+0x18e>
mov    -0x74(%rbp),%eax
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
je     12af <main+0x14f>
mov    -0x80(%rbp),%rdi
call   1080 <getc@plt>
mov    %al,-0x85(%rbp)
movsbl -0x85(%rbp),%eax
cmp    $0xa,%eax
jne    12aa <main+0x14a>
mov    -0x8c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8c(%rbp)
jmp    126f <main+0x10f>
jmp    12b4 <main+0x154>
mov    -0x80(%rbp),%rdi
call   1080 <getc@plt>
mov    %al,-0x85(%rbp)
movsbl %al,%eax
mov    0x2d1b(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12e9 <main+0x189>
movsbl -0x85(%rbp),%edi
call   1030 <putchar@plt>
jmp    12b4 <main+0x154>
jmp    12ee <main+0x18e>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
lea    0xeab(%rip),%rdi
xor    %ebp,%ebp
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xe96(%rip),%rdi
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xe96(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <getc@plt>
mov    0x2e1a(%rip),%r14
cmp    (%r14),%al
je     11f6 <main+0x96>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
add    %ecx,%ebp
mov    %r15,%rdi
call   1080 <getc@plt>
cmp    (%r14),%al
jne    11e0 <main+0x80>
mov    %r15,%rdi
call   1050 <rewind@plt>
mov    0xc(%rsp),%ebx
test   %ebx,%ebx
js     1218 <main+0xb8>
cmp    %ebp,%ebx
jle    1222 <main+0xc2>
lea    0xe3b(%rip),%rdi
call   1040 <printf@plt>
jmp    1265 <main+0x105>
add    %ebp,%ebx
mov    %ebx,0xc(%rsp)
cmp    %ebp,%ebx
jg     120a <main+0xaa>
test   %ebx,%ebx
je     1258 <main+0xf8>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1080 <getc@plt>
xor    %ecx,%ecx
cmp    $0xa,%al
sete   %cl
sub    %ecx,%ebx
jne    1230 <main+0xd0>
jmp    1258 <main+0xf8>
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1080 <getc@plt>
cmp    (%r14),%al
jne    1250 <main+0xf0>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Enter the Name of File With Extension: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [28 x i8] c"Enter the Value of Offset: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.5 = [6 x i8] c"ERROR\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %14, i32** %4
store i32 0, i32* %5
br label %15
15: ; preds = %0, %31, %32
%16 = load i32*, i32** %4
%17 = call signext i8 @getc(i32* %16)
store i8 %17, i8* %6
%18 = load i8, i8* %6
%19 = sext i8 %18 to i32
%20 = load i8, i8* @EOF
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %19, %21
br i1 %22, label %23, label %24
23: ; preds = %15
br label %33
24: ; preds = %15
%25 = load i8, i8* %6
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %32
31: ; preds = %24
br label %15
32: ; preds = %28
br label %15
33: ; preds = %23
%34 = load i32*, i32** %4
%35 = call i32 @rewind(i32* %34)
%36 = load i32, i32* %3
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load i32, i32* %5
%40 = load i32, i32* %3
%41 = add nsw i32 %39, %40
store i32 %41, i32* %3
br label %42
42: ; preds = %38, %33
%43 = load i32, i32* %3
%44 = load i32, i32* %5
%45 = icmp sgt i32 %43, %44
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %75
48: ; preds = %42
%49 = load i32, i32* %3
store i32 %49, i32* %7
br label %50
50: ; preds = %62, %48
%51 = load i32, i32* %7
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %63
53: ; preds = %50
%54 = load i32*, i32** %4
%55 = call signext i8 @getc(i32* %54)
store i8 %55, i8* %6
%56 = load i8, i8* %6
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 10
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = load i32, i32* %7
%61 = add nsw i32 %60, -1
store i32 %61, i32* %7
br label %62
62: ; preds = %59, %53
br label %50
63: ; preds = %50
br label %64
64: ; preds = %71, %63
%65 = load i32*, i32** %4
%66 = call signext i8 @getc(i32* %65)
store i8 %66, i8* %6
%67 = sext i8 %66 to i32
%68 = load i8, i8* @EOF
%69 = sext i8 %68 to i32
%70 = icmp ne i32 %67, %69
br i1 %70, label %71, label %74
71: ; preds = %64
%72 = load i8, i8* %6
%73 = call i32 @putchar(i8 signext %72)
br label %64
74: ; preds = %64
br label %75
75: ; preds = %74, %46
ret i32 0
}

LLVM IR (-O2):
@.str = [40 x i8] c"Enter the Name of File With Extension: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [28 x i8] c"Enter the Value of Offset: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.5 = [6 x i8] c"ERROR\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%9 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%10 = call signext i8 @getc(i32* %9)
%11 = load i8, i8* @EOF
%12 = icmp eq i8 %10, %11
br i1 %12, label %22, label %13
13: ; preds = %0, %13
%14 = phi i8 [ %19, %13 ], [ %10, %0 ]
%15 = phi i32 [ %18, %13 ], [ 0, %0 ]
%16 = icmp eq i8 %14, 10
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %15, %17
%19 = call signext i8 @getc(i32* %9)
%20 = load i8, i8* @EOF
%21 = icmp eq i8 %19, %20
br i1 %21, label %22, label %13
22: ; preds = %13, %0
%23 = phi i32 [ 0, %0 ], [ %18, %13 ]
%24 = call i32 @rewind(i32* %9)
%25 = load i32, i32* %2
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = add nsw i32 %25, %23
store i32 %28, i32* %2
br label %29
29: ; preds = %27, %22
%30 = phi i32 [ %28, %27 ], [ %25, %22 ]
%31 = icmp sgt i32 %30, %23
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = icmp eq i32 %30, 0
br i1 %33, label %36, label %40
34: ; preds = %29
%35 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %53
36: ; preds = %40, %32
%37 = call signext i8 @getc(i32* %9)
%38 = load i8, i8* @EOF
%39 = icmp eq i8 %37, %38
br i1 %39, label %53, label %47
40: ; preds = %32, %40
%41 = phi i32 [ %45, %40 ], [ %30, %32 ]
%42 = call signext i8 @getc(i32* %9)
%43 = icmp eq i8 %42, 10
%44 = sext i1 %43 to i32
%45 = add nsw i32 %41, %44
%46 = icmp eq i32 %45, 0
br i1 %46, label %36, label %40
47: ; preds = %36, %47
%48 = phi i8 [ %50, %47 ], [ %37, %36 ]
%49 = call i32 @putchar(i8 signext %48)
%50 = call signext i8 @getc(i32* %9)
%51 = load i8, i8* @EOF
%52 = icmp eq i8 %50, %51
br i1 %52, label %53, label %47
53: ; preds = %47, %36, %34
ret i32 0
}