#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(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp = fopen(argv[1], "r");
  if (!fp) {
    printf("Error with open file.");
    exit(1);
  }
  char text[1000][1000];
  int nlines = 0;
  size_t len = 1000;
  while (1) {
    char *line = text[nlines];
    if (getline(&line, &len, fp) == -1) {
      break;
    }
    nlines++;
  }
  for (int i = 0; i < nlines; i++) {
    printf("%s", text[i]);
  }
  printf("\n");
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf4280,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe88(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a4 <main+0x54>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0x0,-0xf4264(%rbp)
movq   $0x3e8,-0xf4270(%rbp)
movslq -0xf4264(%rbp),%rcx
lea    -0xf4260(%rbp),%rax
imul   $0x3e8,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0xf4278(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0xf4278(%rbp),%rdi
lea    -0xf4270(%rbp),%rsi
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
jne    11fd <main+0xad>
jmp    1211 <main+0xc1>
mov    -0xf4264(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf4264(%rbp)
jmp    11b9 <main+0x69>
movl   $0x0,-0xf427c(%rbp)
mov    -0xf427c(%rbp),%eax
cmp    -0xf4264(%rbp),%eax
jge    1267 <main+0x117>
movslq -0xf427c(%rbp),%rax
lea    -0xf4260(%rbp),%rsi
imul   $0x3e8,%rax,%rax
add    %rax,%rsi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xf427c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xf427c(%rbp)
jmp    121b <main+0xcb>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xf4280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xf4250,%rsp
mov    0x8(%rsi),%rdi
lea    0xe86(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     122e <main+0xce>
mov    %rax,%r15
movq   $0x3e8,0x8(%rsp)
mov    $0xffffffff,%ebp
lea    0x10(%rsp),%rbx
mov    %rsp,%r14
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,(%rsp)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1070 <getline@plt>
add    $0x1,%ebp
add    $0x3e8,%rbx
cmp    $0xffffffff,%eax
jne    11b0 <main+0x50>
test   %ebp,%ebp
je     120a <main+0xaa>
mov    %ebp,%ebp
lea    0x10(%rsp),%rbx
lea    0xe35(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x3e8,%rbx
add    $0xffffffffffffffff,%rbp
jne    11f0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xf4250,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdcd(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"Error with open file.\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1000 x [1000 x i8]]
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
store i32 0, i32* %8
store i64 1000, i64* %9
br label %22
22: ; preds = %21, %31
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1000 x [1000 x i8]], [1000 x [1000 x i8]]* %7, i64 0, i64 %24
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %25, i64 0, i64 0
store i8* %26, i8** %10
%27 = load i32*, i32** %6
%28 = call i32 @getline(i8** %10, i64* %9, i32* %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %31
30: ; preds = %22
br label %34
31: ; preds = %22
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %22
34: ; preds = %30
store i32 0, i32* %11
br label %35
35: ; preds = %45, %34
%36 = load i32, i32* %11
%37 = load i32, i32* %8
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %48
39: ; preds = %35
%40 = load i32, i32* %11
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [1000 x [1000 x i8]], [1000 x [1000 x i8]]* %7, i64 0, i64 %41
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %42, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %39
%46 = load i32, i32* %11
%47 = add nsw i32 %46, 1
store i32 %47, i32* %11
br label %35
48: ; preds = %35
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%50 = load i32*, i32** %6
%51 = call i32 @fclose(i32* %50)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [22 x i8] c"Error with open file.\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x [1000 x i8]]
%4 = alloca i64
%5 = alloca i8*
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds [1000 x [1000 x i8]], [1000 x [1000 x i8]]* %3, i64 0, i64 0, i64 0
%15 = bitcast i64* %4 to i8*
store i64 1000, i64* %4
%16 = bitcast i8** %5 to i8*
br label %17
17: ; preds = %17, %13
%18 = phi i64 [ %22, %17 ], [ 0, %13 ]
%19 = getelementptr inbounds [1000 x [1000 x i8]], [1000 x [1000 x i8]]* %3, i64 0, i64 %18, i64 0
store i8* %19, i8** %5
%20 = call i32 @getline(i8** %5, i64* %4, i32* %8)
%21 = icmp eq i32 %20, -1
%22 = add nuw i64 %18, 1
br i1 %21, label %23, label %17
23: ; preds = %17
%24 = trunc i64 %18 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = and i64 %18, 4294967295
br label %31
28: ; preds = %31, %23
%29 = call i32 @putchar(i32 10)
%30 = call i32 @fclose(i32* %8)
ret i32 0
31: ; preds = %26, %31
%32 = phi i64 [ 0, %26 ], [ %35, %31 ]
%33 = getelementptr inbounds [1000 x [1000 x i8]], [1000 x [1000 x i8]]* %3, i64 0, i64 %32, i64 0
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = add nuw nsw i64 %32, 1
%36 = icmp eq i64 %35, %27
br i1 %36, label %28, label %31
}