#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_SUCCESS;
long atol(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(long *);
long *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, long);
long *realloc(long *, int);
int main() {
  FILE *input = fopen("input3.txt", "r");
  long *ptr;
  int ii = 0;
  int jump = sizeof(long);
  int bytes = 10 * jump;
  char holder[256 + 1];
  memset(holder, 0, 256 + 1);
  ptr = malloc(bytes);
  while (fgets(holder, 256 + 1, input) != NULL) {
    if (ii >= bytes) {
      bytes *= 2;
      ptr = realloc(ptr, bytes);
    }
    ptr[ii] = atol(holder);
    ii += jump;
    memset(holder, 0, 256 + 1);
  }
  for (ii -= jump * 2; ii >= 0; ii -= jump) {
    printf("%ld\n", ptr[ii]);
  }
  free(ptr);
  fclose(input);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe47(%rip),%rdi
lea    0xe4b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x8,-0x20(%rbp)
imul   $0xa,-0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1060 <memset@plt>
mov    -0x24(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x101,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     127d <main+0xdd>
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jl     1241 <main+0xa1>
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1090 <realloc@plt>
mov    %rax,-0x18(%rbp)
lea    -0x130(%rbp),%rdi
call   10a0 <atol@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1060 <memset@plt>
jmp    11fd <main+0x5d>
mov    -0x20(%rbp),%ecx
shl    $0x1,%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     12bd <main+0x11d>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd65(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    128b <main+0xeb>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x110,%rsp
lea    0xe4a(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1060 <memset@plt>
mov    $0x50,%ebp
mov    $0x50,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %r15,%rdi
mov    $0x101,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1286 <main+0xe6>
xor    %ebx,%ebx
mov    %rsp,%r15
jmp    1244 <main+0xa4>
nopl   0x0(%rax)
mov    %r15,%rdi
call   10a0 <atol@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x8,%rbx
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    $0x101,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     125d <main+0xbd>
movslq %ebp,%rax
cmp    %rax,%rbx
jl     1210 <main+0x70>
add    %ebp,%ebp
mov    %r12,%rdi
mov    %ebp,%esi
call   1090 <realloc@plt>
mov    %rax,%r12
jmp    1210 <main+0x70>
cmp    $0x10,%ebx
jl     1286 <main+0xe6>
add    $0xfffffff0,%ebx
lea    0xda1(%rip),%rbp
nopl   0x0(%rax)
mov    %ebx,%eax
mov    (%r12,%rax,8),%rsi
mov    %rbp,%rdi
call   1050 <printf@plt>
add    $0xfffffff8,%ebx
cmp    $0xfffffff8,%ebx
jne    1270 <main+0xd0>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"input3.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [257 x i8]
store i32 0, i32* %1
%8 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %2
store i32 0, i32* %4
store i32 8, i32* %5
%9 = load i32, i32* %5
%10 = mul nsw i32 10, %9
store i32 %10, i32* %6
%11 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 257)
%13 = load i32, i32* %6
%14 = call i64* @malloc(i32 %13)
store i64* %14, i64** %3
br label %15
15: ; preds = %30, %0
%16 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%17 = load i32*, i32** %2
%18 = call i32* @fgets(i8* %16, i32 257, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %42
20: ; preds = %15
%21 = load i32, i32* %4
%22 = load i32, i32* %6
%23 = icmp sge i32 %21, %22
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i32, i32* %6
%26 = mul nsw i32 %25, 2
store i32 %26, i32* %6
%27 = load i64*, i64** %3
%28 = load i32, i32* %6
%29 = call i64* @realloc(i64* %27, i32 %28)
store i64* %29, i64** %3
br label %30
30: ; preds = %24, %20
%31 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%32 = call i64 @atol(i8* %31)
%33 = load i64*, i64** %3
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i64, i64* %33, i64 %35
store i64 %32, i64* %36
%37 = load i32, i32* %5
%38 = load i32, i32* %4
%39 = add nsw i32 %38, %37
store i32 %39, i32* %4
%40 = getelementptr inbounds [257 x i8], [257 x i8]* %7, i64 0, i64 0
%41 = call i32 @memset(i8* %40, i32 0, i32 257)
br label %15
42: ; preds = %15
%43 = load i32, i32* %5
%44 = mul nsw i32 %43, 2
%45 = load i32, i32* %4
%46 = sub nsw i32 %45, %44
store i32 %46, i32* %4
br label %47
47: ; preds = %57, %42
%48 = load i32, i32* %4
%49 = icmp sge i32 %48, 0
br i1 %49, label %50, label %61
50: ; preds = %47
%51 = load i64*, i64** %3
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i64, i64* %51, i64 %53
%55 = load i64, i64* %54
%56 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %55)
br label %57
57: ; preds = %50
%58 = load i32, i32* %5
%59 = load i32, i32* %4
%60 = sub nsw i32 %59, %58
store i32 %60, i32* %4
br label %47
61: ; preds = %47
%62 = load i64*, i64** %3
%63 = call i32 @free(i64* %62)
%64 = load i32*, i32** %2
%65 = call i32 @fclose(i32* %64)
%66 = load i32, i32* @EXIT_SUCCESS
%67 = call i32 @exit(i32 %66)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"input3.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [257 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = getelementptr inbounds [257 x i8], [257 x i8]* %1, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 257)
%5 = call i64* @malloc(i32 80)
%6 = call i32* @fgets(i8* %3, i32 257, i32* %2)
%7 = icmp eq i32* %6, null
br i1 %7, label %39, label %8
8: ; preds = %0, %17
%9 = phi i64 [ %22, %17 ], [ 0, %0 ]
%10 = phi i32 [ %19, %17 ], [ 80, %0 ]
%11 = phi i64* [ %18, %17 ], [ %5, %0 ]
%12 = sext i32 %10 to i64
%13 = icmp slt i64 %9, %12
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = shl nsw i32 %10, 1
%16 = call i64* @realloc(i64* %11, i32 %15)
br label %17
17: ; preds = %14, %8
%18 = phi i64* [ %16, %14 ], [ %11, %8 ]
%19 = phi i32 [ %15, %14 ], [ %10, %8 ]
%20 = call i64 @atol(i8* %3)
%21 = getelementptr inbounds i64, i64* %18, i64 %9
store i64 %20, i64* %21
%22 = add nuw i64 %9, 8
%23 = call i32 @memset(i8* %3, i32 0, i32 257)
%24 = call i32* @fgets(i8* %3, i32 257, i32* %2)
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %8
26: ; preds = %17
%27 = trunc i64 %22 to i32
%28 = icmp sgt i32 %27, 15
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = add nsw i32 %27, -16
br label %31
31: ; preds = %29, %31
%32 = phi i32 [ %37, %31 ], [ %30, %29 ]
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i64, i64* %18, i64 %33
%35 = load i64, i64* %34
%36 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %35)
%37 = add nsw i32 %32, -8
%38 = icmp eq i32 %32, 0
br i1 %38, label %39, label %31
39: ; preds = %31, %0, %26
%40 = phi i64* [ %18, %26 ], [ %5, %0 ], [ %18, %31 ]
%41 = call i32 @free(i64* %40)
%42 = call i32 @fclose(i32* %2)
%43 = load i32, i32* @EXIT_SUCCESS
%44 = call i32 @exit(i32 %43)
unreachable
}