#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*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int main(void) {
  FILE *fp;
  char *line;
  char *array[1000];
  int counter = 0;
  int len = 0;
  int read;
  printf("ok\n");
  fp = fopen("input.txt", "r");
  if (fp == NULL) {
    printf("Could not open\n");
    exit(EXIT_FAILURE);
  }
  printf("ok again\n");
  while ((read = getline(&line, &len, fp)) != -1) {
    printf("check\n");
    strcpy(array[counter], line);
    counter++;
    printf("%s", line);
  }
  for (int x = 0; x < counter; x++) {
    printf("%s\n", array[x]);
  }
  if (line)
    free(line);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1f70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x1f64(%rbp)
movl   $0x0,-0x1f68(%rbp)
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe69(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d2 <main+0x72>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x1f68(%rbp),%rsi
call   1070 <getline@plt>
mov    %eax,-0x1f6c(%rbp)
cmp    $0xffffffff,%eax
je     124f <main+0xef>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x1f64(%rbp),%rax
mov    -0x1f60(%rbp,%rax,8),%rdi
ff
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x1f64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f64(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11e0 <main+0x80>
movl   $0x0,-0x1f70(%rbp)
mov    -0x1f70(%rbp),%eax
cmp    -0x1f64(%rbp),%eax
jge    129c <main+0x13c>
movslq -0x1f70(%rbp),%rax
mov    -0x1f60(%rbp,%rax,8),%rsi
ff
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x1f70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1f70(%rbp)
jmp    1259 <main+0xf9>
cmpq   $0x0,-0x18(%rbp)
je     12b0 <main+0x150>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x1f70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f58,%rsp
movl   $0x0,0x4(%rsp)
lea    0xe7f(%rip),%rdi
call   1050 <puts@plt>
lea    0xe64(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1286 <main+0x116>
mov    %rax,%rbx
lea    0xe57(%rip),%rdi
call   1050 <puts@plt>
lea    0x8(%rsp),%rdi
lea    0x4(%rsp),%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1263 <main+0xf3>
lea    0xe39(%rip),%r14
lea    0xe23(%rip),%r15
lea    0x8(%rsp),%r12
lea    0x4(%rsp),%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1050 <puts@plt>
mov    0x10(%rsp,%rbp,8),%rdi
mov    0x8(%rsp),%rsi
call   1040 <strcpy@plt>
add    $0x1,%rbp
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
jne    1200 <main+0x90>
test   %ebp,%ebp
je     1263 <main+0xf3>
mov    %ebp,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x10(%rsp,%rbp,8),%rdi
call   1050 <puts@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1250 <main+0xe0>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     1272 <main+0x102>
call   1030 <free@plt>
xor    %eax,%eax
add    $0x1f58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd94(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

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

LLVM IR (-O2):
@.str.1 = [10 x i8] c"input.txt\00"
@.str.2 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [3 x i8] c"%s\00"
@str = [3 x i8] c"ok\00"
@str.8 = [9 x i8] c"ok again\00"
@str.9 = [6 x i8] c"check\00"
@str.10 = [15 x i8] c"Could not open\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca [1000 x i8*]
%3 = alloca i32
%4 = bitcast i8** %1 to i8*
%5 = bitcast [1000 x i8*]* %2 to i8*
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.10, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.8, i64 0, i64 0))
%16 = call i32 @getline(i8** %1, i32* %3, i32* %8)
%17 = icmp eq i32 %16, -1
br i1 %17, label %35, label %23
18: ; preds = %23
%19 = trunc i64 %30 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %35, label %21
21: ; preds = %18
%22 = and i64 %30, 4294967295
br label %38
23: ; preds = %14, %23
%24 = phi i64 [ %30, %23 ], [ 0, %14 ]
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.9, i64 0, i64 0))
%26 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %2, i64 0, i64 %24
%27 = load i8*, i8** %26
%28 = load i8*, i8** %1
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = add nuw i64 %24, 1
%31 = load i8*, i8** %1
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %31)
%33 = call i32 @getline(i8** %1, i32* %3, i32* %8)
%34 = icmp eq i32 %33, -1
br i1 %34, label %18, label %23
35: ; preds = %38, %14, %18
%36 = load i8*, i8** %1
%37 = icmp eq i8* %36, null
br i1 %37, label %47, label %45
38: ; preds = %21, %38
%39 = phi i64 [ 0, %21 ], [ %43, %38 ]
%40 = getelementptr inbounds [1000 x i8*], [1000 x i8*]* %2, i64 0, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 @puts(i8* dereferenceable(1) %41)
%43 = add nuw nsw i64 %39, 1
%44 = icmp eq i64 %43, %22
br i1 %44, label %35, label %38
45: ; preds = %35
%46 = call i32 @free(i8* %36)
br label %47
47: ; preds = %45, %35
ret i32 0
}