#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 uint8_t;
typedef scalar_t__ uint64_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ product(int *);
__attribute__((always_)) uint64_t f() {
  FILE *file = fopen("008.txt", "r");
  int pos = 0;
  uint64_t max = 0;
  uint8_t digits[13] = {0};
  int chr = fgetc(file);
  while (chr != EOF) {
    if (chr != '\n') {
      digits[pos] = chr - 48;
      uint64_t p = product(digits);
      if (p > max)
        max = p;
      pos = (pos + 1) % 13;
    }
    chr = fgetc(file);
  }
  fclose(file);
  return max;
}


x86 assembly (clang, -O0):
<f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    0xea1(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x34,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    0x2e44(%rip),%rcx
cmp    (%rcx),%eax
je     1209 <f+0xb9>
cmpl   $0xa,-0x54(%rbp)
je     11f8 <f+0xa8>
mov    -0x54(%rbp),%ecx
sub    $0x30,%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x50(%rbp,%rax,4)
lea    -0x50(%rbp),%rdi
call   1060 <product@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
cmp    -0x18(%rbp),%rax
jle    11e7 <f+0x97>
mov    -0x60(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    $0xd,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x54(%rbp)
jmp    119a <f+0x4a>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xeab(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x30(%rsp)
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    0x2e5c(%rip),%r12
xor    %r13d,%r13d
cmp    (%r12),%eax
jne    11b1 <f+0x71>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbp,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r15
xor    %ebp,%ebp
jmp    11ce <f+0x8e>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%r12),%eax
je     1197 <f+0x57>
cmp    $0xa,%eax
je     11c0 <f+0x80>
add    $0xffffffd0,%eax
movslq %r13d,%rbx
mov    %eax,(%rsp,%rbx,4)
mov    %r15,%rdi
call   1050 <product@plt>
cmp    %rbp,%rax
cmovg  %rax,%rbp
lea    0x1(%rbx),%eax
cltq
imul   $0x4ec4ec4f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
lea    (%rax,%rax,2),%ecx
lea    (%rax,%rcx,4),%eax
neg    %eax
lea    (%rbx,%rax,1),%r13d
add    $0x1,%r13d
jmp    11c0 <f+0x80>

LLVM IR (-O0):
@.str = [8 x i8] c"008.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define i64 @f() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i64
%4 = alloca [13 x i32]
%5 = alloca i32
%6 = alloca i64
%7 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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** %1
store i32 0, i32* %2
store i64 0, i64* %3
%8 = bitcast [13 x i32]* %4 to i8*
%9 = load i32*, i32** %1
%10 = call i32 @fgetc(i32* %9)
store i32 %10, i32* %5
br label %11
11: ; preds = %35, %0
%12 = load i32, i32* %5
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %38
15: ; preds = %11
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %35
18: ; preds = %15
%19 = load i32, i32* %5
%20 = sub nsw i32 %19, 48
%21 = load i32, i32* %2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [13 x i32], [13 x i32]* %4, i64 0, i64 %22
store i32 %20, i32* %23
%24 = getelementptr inbounds [13 x i32], [13 x i32]* %4, i64 0, i64 0
%25 = call i64 @product(i32* %24)
store i64 %25, i64* %6
%26 = load i64, i64* %6
%27 = load i64, i64* %3
%28 = icmp sgt i64 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = load i64, i64* %6
store i64 %30, i64* %3
br label %31
31: ; preds = %29, %18
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
%34 = srem i32 %33, 13
store i32 %34, i32* %2
br label %35
35: ; preds = %31, %15
%36 = load i32*, i32** %1
%37 = call i32 @fgetc(i32* %36)
store i32 %37, i32* %5
br label %11
38: ; preds = %11
%39 = load i32*, i32** %1
%40 = call i32 @fclose(i32* %39)
%41 = load i64, i64* %3
ret i64 %41
}

LLVM IR (-O2):
@.str = [8 x i8] c"008.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define i64 @f() {
%1 = alloca [13 x i32]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = bitcast [13 x i32]* %1 to i8*
%4 = tail call i32 @fgetc(i32* %2)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %29, label %7
7: ; preds = %0
%8 = getelementptr inbounds [13 x i32], [13 x i32]* %1, i64 0, i64 0
br label %9
9: ; preds = %7, %23
%10 = phi i32 [ 0, %7 ], [ %25, %23 ]
%11 = phi i32 [ %4, %7 ], [ %26, %23 ]
%12 = phi i64 [ 0, %7 ], [ %24, %23 ]
%13 = icmp eq i32 %11, 10
br i1 %13, label %23, label %14
14: ; preds = %9
%15 = add nsw i32 %11, -48
%16 = sext i32 %10 to i64
%17 = getelementptr inbounds [13 x i32], [13 x i32]* %1, i64 0, i64 %16
store i32 %15, i32* %17
%18 = call i64 @product(i32* %8)
%19 = icmp sgt i64 %18, %12
%20 = select i1 %19, i64 %18, i64 %12
%21 = add nsw i32 %10, 1
%22 = srem i32 %21, 13
br label %23
23: ; preds = %14, %9
%24 = phi i64 [ %20, %14 ], [ %12, %9 ]
%25 = phi i32 [ %22, %14 ], [ %10, %9 ]
%26 = call i32 @fgetc(i32* %2)
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %9
29: ; preds = %23, %0
%30 = phi i64 [ 0, %0 ], [ %24, %23 ]
%31 = call i32 @fclose(i32* %2)
ret i64 %30
}