#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
char *removeSpace(char *);
int strlen(char *);
void listInstruction(char *filepath, int n) {
  FILE *fp;
  fp = fopen(filepath, "r");
  char *buffer = (char *)malloc(300 * sizeof(char));
  if (fp == NULL) {
    perror("ERROR in opening file");
    exit(EXIT_FAILURE);
  }
  while (!feof(fp) && 0 < n) {
    memset(buffer, 0, ((sizeof(char)) * 300));
    fgets(buffer, 300, fp);
    if (strlen(buffer) > 1)
      n--;
  }
  if (n == 0) {
    printf("%s", removeSpace(buffer));
  } else {
    perror("End of file reached before line");
  }
  free(buffer);
  fclose(fp);
}


x86 assembly (clang, -O0):
<listInstruction>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    $0x12c,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1216 <listInstruction+0x56>
lea    0xdff(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
jmp    121b <listInstruction+0x5b>
mov    -0x18(%rbp),%rdi
call   1090 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
jne    123f <listInstruction+0x7f>
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    124f <listInstruction+0x8f>
jmp    1291 <listInstruction+0xd1>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x12c,%edx
call   1070 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x12c,%esi
call   1080 <fgets@plt>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x1,%eax
jle    128c <listInstruction+0xcc>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    121b <listInstruction+0x5b>
cmpl   $0x0,-0xc(%rbp)
jne    12b8 <listInstruction+0xf8>
mov    -0x20(%rbp),%rdi
call   10b0 <removeSpace@plt>
mov    %rax,%rsi
lea    0xd6a(%rip),%rdi
call   1060 <printf@plt>
jmp    12c4 <listInstruction+0x104>
lea    0xd5c(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listInstruction>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
lea    0xe33(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r14
mov    $0x12c,%edi
call   10a0 <malloc@plt>
test   %r14,%r14
je     127e <listInstruction+0xbe>
mov    %rax,%rbx
mov    %r14,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1241 <listInstruction+0x81>
test   %ebp,%ebp
jle    1241 <listInstruction+0x81>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x12c,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    $0x12c,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %ecx,%ecx
cmp    $0x2,%eax
setge  %cl
sub    %ecx,%ebp
mov    %r14,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1241 <listInstruction+0x81>
test   %ebp,%ebp
jne    1200 <listInstruction+0x40>
test   %ebp,%ebp
jne    1270 <listInstruction+0xb0>
mov    %rbx,%rdi
call   10b0 <removeSpace@plt>
lea    0xdc4(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fclose@plt>
lea    0xda4(%rip),%rdi
call   10d0 <perror@plt>
jmp    125c <listInstruction+0x9c>
lea    0xd7d(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"ERROR in opening file\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [32 x i8] c"End of file reached before line\00"
define void @listInstruction(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = call i64 @malloc(i32 300)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %6
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
br label %18
18: ; preds = %39, %17
%19 = load i32*, i32** %5
%20 = call i32 @feof(i32* %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i32, i32* %4
%24 = icmp slt i32 0, %23
br label %25
25: ; preds = %22, %18
%26 = phi i1 [ false, %18 ], [ %24, %22 ]
br i1 %26, label %27, label %40
27: ; preds = %25
%28 = load i8*, i8** %6
%29 = call i32 @memset(i8* %28, i32 0, i32 300)
%30 = load i8*, i8** %6
%31 = load i32*, i32** %5
%32 = call i32 @fgets(i8* %30, i32 300, i32* %31)
%33 = load i8*, i8** %6
%34 = call i32 @strlen(i8* %33)
%35 = icmp sgt i32 %34, 1
br i1 %35, label %36, label %39
36: ; preds = %27
%37 = load i32, i32* %4
%38 = add nsw i32 %37, -1
store i32 %38, i32* %4
br label %39
39: ; preds = %36, %27
br label %18
40: ; preds = %25
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i8*, i8** %6
%45 = call i8* @removeSpace(i8* %44)
%46 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %45)
br label %49
47: ; preds = %40
%48 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %43
%50 = load i8*, i8** %6
%51 = call i32 @free(i8* %50)
%52 = load i32*, i32** %5
%53 = call i32 @fclose(i32* %52)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"ERROR in opening file\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [32 x i8] c"End of file reached before line\00"
define void @listInstruction(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @malloc(i32 300)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i32* %3, null
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = tail call i32 @feof(i32* %3)
%9 = icmp eq i32 %8, 0
%10 = icmp sgt i32 %1, 0
%11 = and i1 %9, %10
br i1 %11, label %16, label %28
12: ; preds = %2
%13 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %7, %16
%17 = phi i32 [ %23, %16 ], [ %1, %7 ]
%18 = tail call i32 @memset(i8* %5, i32 0, i32 300)
%19 = tail call i32 @fgets(i8* %5, i32 300, i32* %3)
%20 = tail call i32 @strlen(i8* %5)
%21 = icmp sgt i32 %20, 1
%22 = sext i1 %21 to i32
%23 = add nsw i32 %17, %22
%24 = tail call i32 @feof(i32* %3)
%25 = icmp eq i32 %24, 0
%26 = icmp ne i32 %23, 0
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %16, label %28
28: ; preds = %16, %7
%29 = phi i32 [ %1, %7 ], [ %23, %16 ]
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = tail call i8* @removeSpace(i8* %5)
%33 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %36
34: ; preds = %28
%35 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = tail call i32 @free(i8* %5)
%38 = tail call i32 @fclose(i32* %3)
ret void
}