#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*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
unsigned long largest_prod(int, int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, unsigned long);
int main() {
  FILE *fptr;
  fptr = fopen("input.txt", "r");
  int *num_arr = (int *)malloc(1000 * sizeof(int));
  int trace = 0;
  do {
    num_arr[trace] = (int)(fgetc(fptr) - 48);
    trace++;
  } while (trace != 1000);
  int i;
  long unsigned temp = largest_prod(13, num_arr, 1000);
  printf("%lu\n", temp);
  fclose(fptr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    $0xfa0,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,%edx
sub    $0x30,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jne    119b <main+0x3b>
mov    -0x18(%rbp),%rsi
mov    $0xd,%edi
mov    $0x3e8,%edx
call   1060 <largest_prod@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xe94(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    $0xfa0,%edi
call   1070 <malloc@plt>
mov    %rax,%r15
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <fgetc@plt>
add    $0xffffffd0,%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    $0x3e8,%rbx
jne    1190 <main+0x30>
mov    $0xd,%edi
mov    %r15,%rsi
mov    $0x3e8,%edx
call   1060 <largest_prod@plt>
lea    0xe47(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%lu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %2
%8 = call i64 @malloc(i32 4000)
%9 = inttoptr i64 %8 to i32*
store i32* %9, i32** %3
store i32 0, i32* %4
br label %10
10: ; preds = %20, %0
%11 = load i32*, i32** %2
%12 = call i32 @fgetc(i32* %11)
%13 = sub nsw i32 %12, 48
%14 = load i32*, i32** %3
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
store i32 %13, i32* %17
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %20
20: ; preds = %10
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 1000
br i1 %22, label %10, label %23
23: ; preds = %20
%24 = load i32*, i32** %3
%25 = call i64 @largest_prod(i32 13, i32* %24, i32 1000)
store i64 %25, i64* %6
%26 = load i64, i64* %6
%27 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %26)
%28 = load i32*, i32** %2
%29 = call i32 @fclose(i32* %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"input.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"%lu\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i64 @malloc(i32 4000)
%3 = inttoptr i64 %2 to i32*
br label %4
4: ; preds = %4, %0
%5 = phi i64 [ %9, %4 ], [ 0, %0 ]
%6 = tail call i32 @fgetc(i32* %1)
%7 = add nsw i32 %6, -48
%8 = getelementptr inbounds i32, i32* %3, i64 %5
store i32 %7, i32* %8
%9 = add nuw nsw i64 %5, 1
%10 = icmp eq i64 %9, 1000
br i1 %10, label %11, label %4
11: ; preds = %4
%12 = tail call i64 @largest_prod(i32 13, i32* %3, i32 1000)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %12)
%14 = tail call i32 @fclose(i32* %1)
ret i32 0
}