#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 atoi(char *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  if (argc < 3)
    return 0;
  int line = atoi(argv[1]);
  FILE *afile = fopen(argv[2], "r");
  if (afile == NULL)
    return 1;
  int cur;
  char *ans = (char *)malloc(3 * 300);
  for (cur = 1; cur <= line; cur++) {
    ans = fgets(ans, 3 * 300, afile);
    if (ans == NULL && cur != line - 1)
      return 0;
  }
  printf("%s", ans);
  return line;
}


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)
cmpl   $0x3,-0x8(%rbp)
jge    117c <main+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    1243 <main+0xf3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe65(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bb <main+0x6b>
movl   $0x1,-0x4(%rbp)
jmp    1243 <main+0xf3>
mov    $0x384,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     122d <main+0xdd>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x384,%esi
call   1040 <fgets@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    121a <main+0xca>
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     121a <main+0xca>
movl   $0x0,-0x4(%rbp)
jmp    1243 <main+0xf3>
jmp    121f <main+0xcf>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11d0 <main+0x80>
mov    -0x30(%rbp),%rsi
lea    0xdca(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x3,%edi
jge    115e <main+0xe>
xor    %r14d,%r14d
jmp    11d8 <main+0x88>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d2 <main+0x82>
mov    %rax,%rbx
mov    $0x384,%edi
call   1050 <malloc@plt>
test   %r14d,%r14d
jle    11c1 <main+0x71>
mov    %r14d,%ebp
jmp    11a5 <main+0x55>
nopl   0x0(%rax)
add    $0xffffffff,%ebp
je     11c1 <main+0x71>
mov    %rax,%rdi
mov    $0x384,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    11a0 <main+0x50>
cmp    $0x2,%ebp
je     11a0 <main+0x50>
jmp    1159 <main+0x9>
lea    0xe3a(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
jmp    11d8 <main+0x88>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %52
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %7
%22 = load i32*, i32** %7
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %13
store i32 1, i32* %3
br label %52
25: ; preds = %13
%26 = call i64 @malloc(i32 900)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %9
store i32 1, i32* %8
br label %28
28: ; preds = %45, %25
%29 = load i32, i32* %8
%30 = load i32, i32* %6
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %48
32: ; preds = %28
%33 = load i8*, i8** %9
%34 = load i32*, i32** %7
%35 = call i8* @fgets(i8* %33, i32 900, i32* %34)
store i8* %35, i8** %9
%36 = load i8*, i8** %9
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %44
38: ; preds = %32
%39 = load i32, i32* %8
%40 = load i32, i32* %6
%41 = sub nsw i32 %40, 1
%42 = icmp ne i32 %39, %41
br i1 %42, label %43, label %44
43: ; preds = %38
store i32 0, i32* %3
br label %52
44: ; preds = %38, %32
br label %45
45: ; preds = %44
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %28
48: ; preds = %28
%49 = load i8*, i8** %9
%50 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %49)
%51 = load i32, i32* %6
store i32 %51, i32* %3
br label %52
52: ; preds = %48, %43, %24, %12
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %31, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %31, label %12
12: ; preds = %4
%13 = tail call i64 @malloc(i32 900)
%14 = inttoptr i64 %13 to i8*
%15 = icmp slt i32 %7, 1
br i1 %15, label %28, label %16
16: ; preds = %12
%17 = add nsw i32 %7, -1
br label %21
18: ; preds = %21
%19 = add nuw i32 %23, 1
%20 = icmp eq i32 %23, %7
br i1 %20, label %28, label %21
21: ; preds = %16, %18
%22 = phi i8* [ %14, %16 ], [ %24, %18 ]
%23 = phi i32 [ 1, %16 ], [ %19, %18 ]
%24 = tail call i8* @fgets(i8* %22, i32 900, i32* %10)
%25 = icmp ne i8* %24, null
%26 = icmp eq i32 %23, %17
%27 = select i1 %25, i1 true, i1 %26
br i1 %27, label %18, label %31
28: ; preds = %18, %12
%29 = phi i8* [ %14, %12 ], [ %24, %18 ]
%30 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %21, %4, %28, %2
%32 = phi i32 [ 0, %2 ], [ 1, %4 ], [ %7, %28 ], [ 0, %21 ]
ret i32 %32
}