#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int fd, rd, zaehler = 0, top, end, offset = 0;
  char buffer[1];
  if (argc < 3) {
    fprintf(stderr, "Zu wenig Argumente eingegeben\n");
    exit(1);
  }
  top = atoi(argv[2]);
  if ((fd = (open(argv[1], O_RDONLY))) == -1) {
    perror("open");
    exit(1);
  }
  end = lseek(fd, offset, SEEK_END);
  offset = end;
  lseek(fd, --offset, SEEK_SET);
  while ((rd = read(fd, buffer, 1)) >= 0) {
    lseek(fd, --offset, SEEK_SET);
    if (buffer[0] == '\n')
      zaehler++;
    if (offset == 0)
      zaehler = top;
    if (zaehler >= top) {
      while (offset < end && rd != -1) {
        lseek(fd, offset++, SEEK_SET);
        rd = read(fd, buffer, 1);
        printf("%c", buffer[0]);
      }
      if (rd == -1) {
        perror("read");
        exit(1);
      }
      break;
    }
  }
  if (close(fd) == -1) {
    perror("close");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11dd <main+0x4d>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1225 <main+0x95>
lea    0xe09(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%esi
add    $0xffffffff,%esi
mov    %esi,-0x28(%rbp)
mov    0x2d73(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jl     1364 <main+0x1d4>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%esi
add    $0xffffffff,%esi
mov    %esi,-0x28(%rbp)
mov    0x2d3c(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
movsbl -0x29(%rbp),%eax
cmp    $0xa,%eax
jne    12a9 <main+0x119>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    12b9 <main+0x129>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jl     135f <main+0x1cf>
jmp    12ca <main+0x13a>
mov    -0x28(%rbp),%ecx
xor    %eax,%eax
cmp    -0x24(%rbp),%ecx
mov    %al,-0x2a(%rbp)
jge    12e5 <main+0x155>
cmpl   $0xffffffff,-0x18(%rbp)
setne  %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    12f5 <main+0x165>
jmp    133a <main+0x1aa>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    0x2cbe(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,-0x18(%rbp)
lea    0xcf8(%rip),%rdi
movsbl -0x29(%rbp),%esi
call   1030 <printf@plt>
jmp    12ca <main+0x13a>
cmpl   $0xffffffff,-0x18(%rbp)
jne    135a <main+0x1ca>
lea    0xcdc(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1364 <main+0x1d4>
jmp    125c <main+0xcc>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    138b <main+0x1fb>
lea    0xcb0(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jle    12c0 <main+0x130>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r15d
mov    0x8(%rbx),%rdi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     12df <main+0x14f>
mov    %eax,%r13d
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %r13d,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%esi
mov    0x2dd3(%rip),%r14
mov    (%r14),%edx
mov    %r13d,%edi
call   1040 <lseek@plt>
mov    %rbx,%rax
mov    %rbx,0x10(%rsp)
add    $0xfffffffe,%ebx
lea    0xf(%rsp),%r12
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %eax,%eax
js     12a2 <main+0x112>
mov    (%r14),%edx
mov    %r13d,%edi
mov    %ebx,%esi
call   1040 <lseek@plt>
xor    %eax,%eax
cmpb   $0xa,0xf(%rsp)
sete   %al
add    %eax,%ebp
sub    $0x1,%ebx
cmovb  %r15d,%ebp
cmp    %r15d,%ebp
jl     1210 <main+0x80>
add    $0x2,%ebx
cmp    0x10(%rsp),%ebx
jg     12a2 <main+0x112>
lea    0xf(%rsp),%r15
lea    0xdc6(%rip),%r12
xchg   %ax,%ax
lea    -0x1(%rbx),%esi
mov    (%r14),%edx
mov    %r13d,%edi
call   1040 <lseek@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,%ebp
movsbl 0xf(%rsp),%esi
mov    %r12,%rdi
call   1030 <printf@plt>
cmp    $0xffffffff,%ebp
je     129d <main+0x10d>
lea    0x1(%rbx),%eax
cmp    0x10(%rsp),%ebx
mov    %eax,%ebx
jl     1260 <main+0xd0>
cmp    $0xffffffff,%ebp
je     12f1 <main+0x161>
mov    %r13d,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     12e8 <main+0x158>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
lea    0xd30(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd39(%rip),%rdi
jmp    12f8 <main+0x168>
lea    0xd3d(%rip),%rdi
jmp    12f8 <main+0x168>
lea    0xd2f(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"Zu wenig Argumente eingegeben\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [6 x i8] c"close\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [1 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %11
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %9
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %26, i32 %27)
store i32 %28, i32* %6
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %19
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %19
%34 = load i32, i32* %6
%35 = load i32, i32* %11
%36 = load i32, i32* @SEEK_END
%37 = call i32 @lseek(i32 %34, i32 %35, i32 %36)
store i32 %37, i32* %10
%38 = load i32, i32* %10
store i32 %38, i32* %11
%39 = load i32, i32* %6
%40 = load i32, i32* %11
%41 = add nsw i32 %40, -1
store i32 %41, i32* %11
%42 = load i32, i32* @SEEK_SET
%43 = call i32 @lseek(i32 %39, i32 %41, i32 %42)
br label %44
44: ; preds = %100, %33
%45 = load i32, i32* %6
%46 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
%47 = call i32 @read(i32 %45, i8* %46, i32 1)
store i32 %47, i32* %7
%48 = icmp sge i32 %47, 0
br i1 %48, label %49, label %101
49: ; preds = %44
%50 = load i32, i32* %6
%51 = load i32, i32* %11
%52 = add nsw i32 %51, -1
store i32 %52, i32* %11
%53 = load i32, i32* @SEEK_SET
%54 = call i32 @lseek(i32 %50, i32 %52, i32 %53)
%55 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 10
br i1 %58, label %59, label %62
59: ; preds = %49
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %62
62: ; preds = %59, %49
%63 = load i32, i32* %11
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = load i32, i32* %9
store i32 %66, i32* %8
br label %67
67: ; preds = %65, %62
%68 = load i32, i32* %8
%69 = load i32, i32* %9
%70 = icmp sge i32 %68, %69
br i1 %70, label %71, label %100
71: ; preds = %67
br label %72
72: ; preds = %81, %71
%73 = load i32, i32* %11
%74 = load i32, i32* %10
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %79
76: ; preds = %72
%77 = load i32, i32* %7
%78 = icmp ne i32 %77, -1
br label %79
79: ; preds = %76, %72
%80 = phi i1 [ false, %72 ], [ %78, %76 ]
br i1 %80, label %81, label %93
81: ; preds = %79
%82 = load i32, i32* %6
%83 = load i32, i32* %11
%84 = add nsw i32 %83, 1
store i32 %84, i32* %11
%85 = load i32, i32* @SEEK_SET
%86 = call i32 @lseek(i32 %82, i32 %83, i32 %85)
%87 = load i32, i32* %6
%88 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
%89 = call i32 @read(i32 %87, i8* %88, i32 1)
store i32 %89, i32* %7
%90 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
%91 = load i8, i8* %90
%92 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %91)
br label %72
93: ; preds = %79
%94 = load i32, i32* %7
%95 = icmp eq i32 %94, -1
br i1 %95, label %96, label %99
96: ; preds = %93
%97 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%98 = call i32 @exit(i32 1)
unreachable
99: ; preds = %93
br label %101
100: ; preds = %67
br label %44
101: ; preds = %99, %44
%102 = load i32, i32* %6
%103 = call i32 @close(i32 %102)
%104 = icmp eq i32 %103, -1
br i1 %104, label %105, label %108
105: ; preds = %101
%106 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%107 = call i32 @exit(i32 1)
unreachable
108: ; preds = %101
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"Zu wenig Argumente eingegeben\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [6 x i8] c"close\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1 x i8]
%4 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 @open(i8* %15, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %10
%20 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %10
%23 = load i32, i32* @SEEK_END
%24 = tail call i32 @lseek(i32 %17, i32 0, i32 %23)
%25 = add nsw i32 %24, -1
%26 = load i32, i32* @SEEK_SET
%27 = tail call i32 @lseek(i32 %17, i32 %25, i32 %26)
br label %28
28: ; preds = %33, %22
%29 = phi i32 [ 0, %22 ], [ %42, %33 ]
%30 = phi i32 [ %25, %22 ], [ %34, %33 ]
%31 = call i32 @read(i32 %17, i8* %4, i32 1)
%32 = icmp sgt i32 %31, -1
br i1 %32, label %33, label %62
33: ; preds = %28
%34 = add nsw i32 %30, -1
%35 = load i32, i32* @SEEK_SET
%36 = tail call i32 @lseek(i32 %17, i32 %34, i32 %35)
%37 = load i8, i8* %4
%38 = icmp eq i8 %37, 10
%39 = zext i1 %38 to i32
%40 = add nsw i32 %29, %39
%41 = icmp eq i32 %34, 0
%42 = select i1 %41, i32 %13, i32 %40
%43 = icmp slt i32 %42, %13
br i1 %43, label %28, label %44
44: ; preds = %33
%45 = icmp sgt i32 %30, %24
br i1 %45, label %62, label %46
46: ; preds = %44, %46
%47 = phi i32 [ %48, %46 ], [ %34, %44 ]
%48 = add nsw i32 %47, 1
%49 = load i32, i32* @SEEK_SET
%50 = tail call i32 @lseek(i32 %17, i32 %47, i32 %49)
%51 = call i32 @read(i32 %17, i8* %4, i32 1)
%52 = load i8, i8* %4
%53 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %52)
%54 = icmp slt i32 %48, %24
%55 = icmp ne i32 %51, -1
%56 = and i1 %55, %54
br i1 %56, label %46, label %57
57: ; preds = %46
%58 = icmp eq i32 %51, -1
br i1 %58, label %59, label %62
59: ; preds = %57
%60 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%61 = tail call i32 @exit(i32 1)
unreachable
62: ; preds = %28, %44, %57
%63 = tail call i32 @close(i32 %17)
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %68
65: ; preds = %62
%66 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%67 = tail call i32 @exit(i32 1)
unreachable
68: ; preds = %62
ret i32 0
}