#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 /*<<< orphan*/, 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, j = 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, 0, SEEK_END);
  lseek(fd, 0, SEEK_SET);
  while ((rd = read(fd, buffer, 1)) > 0 && zaehler < top && j < end) {
    printf("%c", buffer[0]);
    if (buffer[0] == '\n')
      zaehler++;
    j++;
  }
  if (rd == -1) {
    perror("read");
    exit(1);
  }
  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    0x2db9(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d83(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
mov    -0x14(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2a(%rbp)
jle    128f <main+0xff>
mov    -0x1c(%rbp),%ecx
xor    %eax,%eax
cmp    -0x20(%rbp),%ecx
mov    %al,-0x2a(%rbp)
jge    128f <main+0xff>
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
setl   %al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    129f <main+0x10f>
jmp    12d3 <main+0x143>
lea    0xd7e(%rip),%rdi
movsbl -0x29(%rbp),%esi
call   1030 <printf@plt>
movsbl -0x29(%rbp),%eax
cmp    $0xa,%eax
jne    12c5 <main+0x135>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    124e <main+0xbe>
cmpl   $0xffffffff,-0x18(%rbp)
jne    12f3 <main+0x163>
lea    0xd43(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    131a <main+0x18a>
lea    0xd21(%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
push   %rax
cmp    $0x2,%edi
jle    129c <main+0x10c>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%rbx),%rdi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     12bb <main+0x12b>
mov    %eax,%r13d
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
mov    %eax,%ebp
mov    0x2dda(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
lea    0x3(%rsp),%rsi
mov    %r13d,%edi
mov    $0x1,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1279 <main+0xe9>
cmpl   $0x0,0x4(%rsp)
jle    1279 <main+0xe9>
test   %ebp,%ebp
jle    1279 <main+0xe9>
xor    %ebx,%ebx
mov    $0x1,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl 0x3(%rsp),%esi
xor    %r12d,%r12d
cmp    $0xa,%esi
sete   %r14b
lea    0xdde(%rip),%rdi
call   1030 <printf@plt>
mov    %r13d,%edi
lea    0x3(%rsp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    1279 <main+0xe9>
mov    %r14b,%r12b
add    %r12d,%ebx
cmp    0x4(%rsp),%ebx
jge    1279 <main+0xe9>
lea    0x1(%r15),%ecx
cmp    %ebp,%r15d
mov    %ecx,%r15d
jl     1230 <main+0xa0>
cmp    $0xffffffff,%eax
je     12c4 <main+0x134>
mov    %r13d,%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
je     12cd <main+0x13d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
lea    0xd54(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd5d(%rip),%rdi
jmp    12d4 <main+0x144>
lea    0xd5c(%rip),%rdi
jmp    12d4 <main+0x144>
lea    0xd58(%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* @SEEK_END
%36 = call i32 @lseek(i32 %34, i32 0, i32 %35)
store i32 %36, i32* %10
%37 = load i32, i32* %6
%38 = load i32, i32* @SEEK_SET
%39 = call i32 @lseek(i32 %37, i32 0, i32 %38)
br label %40
40: ; preds = %66, %33
%41 = load i32, i32* %6
%42 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
%43 = call i32 @read(i32 %41, i8* %42, i32 1)
store i32 %43, i32* %7
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %40
%46 = load i32, i32* %8
%47 = load i32, i32* %9
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %53
49: ; preds = %45
%50 = load i32, i32* %11
%51 = load i32, i32* %10
%52 = icmp slt i32 %50, %51
br label %53
53: ; preds = %49, %45, %40
%54 = phi i1 [ false, %45 ], [ false, %40 ], [ %52, %49 ]
br i1 %54, label %55, label %69
55: ; preds = %53
%56 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
%57 = load i8, i8* %56
%58 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %57)
%59 = getelementptr inbounds [1 x i8], [1 x i8]* %12, i64 0, i64 0
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 10
br i1 %62, label %63, label %66
63: ; preds = %55
%64 = load i32, i32* %8
%65 = add nsw i32 %64, 1
store i32 %65, i32* %8
br label %66
66: ; preds = %63, %55
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %40
69: ; preds = %53
%70 = load i32, i32* %7
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %75
72: ; preds = %69
%73 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %69
%76 = load i32, i32* %6
%77 = call i32 @close(i32 %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %82
79: ; preds = %75
%80 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %75
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 = load i32, i32* @SEEK_SET
%26 = tail call i32 @lseek(i32 %17, i32 0, i32 %25)
%27 = call i32 @read(i32 %17, i8* %4, i32 1)
%28 = icmp sgt i32 %27, 0
%29 = icmp sgt i32 %13, 0
%30 = select i1 %28, i1 %29, i1 false
%31 = icmp sgt i32 %24, 0
%32 = select i1 %30, i1 %31, i1 false
br i1 %32, label %33, label %48
33: ; preds = %22, %33
%34 = phi i32 [ %41, %33 ], [ 0, %22 ]
%35 = phi i32 [ %40, %33 ], [ 0, %22 ]
%36 = load i8, i8* %4
%37 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8 signext %36)
%38 = icmp eq i8 %36, 10
%39 = zext i1 %38 to i32
%40 = add nuw nsw i32 %35, %39
%41 = add nuw nsw i32 %34, 1
%42 = call i32 @read(i32 %17, i8* %4, i32 1)
%43 = icmp sgt i32 %42, 0
%44 = icmp slt i32 %40, %13
%45 = select i1 %43, i1 %44, i1 false
%46 = icmp slt i32 %41, %24
%47 = select i1 %45, i1 %46, i1 false
br i1 %47, label %33, label %48
48: ; preds = %33, %22
%49 = phi i32 [ %27, %22 ], [ %42, %33 ]
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%53 = tail call i32 @exit(i32 1)
unreachable
54: ; preds = %48
%55 = tail call i32 @close(i32 %17)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%59 = tail call i32 @exit(i32 1)
unreachable
60: ; preds = %54
ret i32 0
}