#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 */

/* Variables and functions */
int char_to_int(char const);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(void) {
  const size_t n_len =
      sizeof("73167176531330624919225119674426574742355349194934"
             "96983520312774506326239578318016984801869478851843"
             "85861560789112949495459501737958331952853208805511"
             "12540698747158523863050715693290963295227443043557"
             "66896648950445244523161731856403098711121722383113"
             "62229893423380308135336276614282806444486645238749"
             "30358907296290491560440772390713810515859307960866"
             "70172427121883998797908792274921901699720888093776"
             "65727333001053367881220235421809751254540594752243"
             "52584907711670556013604839586446706324415722155397"
             "53697817977846174064955149290862569321978468622482"
             "83972241375657056057490261407972968652414535100474"
             "82166370484403199890008895243450658541227588666881"
             "16427171479924442928230863465674813919123162824586"
             "17866458359124566529476545682848912883142607690042"
             "24219022671055626321111109370544217506941658960408"
             "07198403850962455444362981230987879927244284909188"
             "84580156166097919133875499200524063689912560717606"
             "05886116467109405077541002256983155200055935729725"
             "71636269561882670428252483600823257530420752963450") /
          sizeof(char) -
      1;
  const size_t vals_len = 5;
  if (n_len < vals_len) {
    fprintf(stderr, "n_len < vals_len, bye\n");
    return -1;
  }
  const char *n = "73167176531330624919225119674426574742355349194934"
                  "96983520312774506326239578318016984801869478851843"
                  "85861560789112949495459501737958331952853208805511"
                  "12540698747158523863050715693290963295227443043557"
                  "66896648950445244523161731856403098711121722383113"
                  "62229893423380308135336276614282806444486645238749"
                  "30358907296290491560440772390713810515859307960866"
                  "70172427121883998797908792274921901699720888093776"
                  "65727333001053367881220235421809751254540594752243"
                  "52584907711670556013604839586446706324415722155397"
                  "53697817977846174064955149290862569321978468622482"
                  "83972241375657056057490261407972968652414535100474"
                  "82166370484403199890008895243450658541227588666881"
                  "16427171479924442928230863465674813919123162824586"
                  "17866458359124566529476545682848912883142607690042"
                  "24219022671055626321111109370544217506941658960408"
                  "07198403850962455444362981230987879927244284909188"
                  "84580156166097919133875499200524063689912560717606"
                  "05886116467109405077541002256983155200055935729725"
                  "71636269561882670428252483600823257530420752963450";
  int vals[vals_len];
  int vals_product_cur = 1, vals_product_max = 0;
  for (size_t i = 0; i < vals_len; ++i) {
    vals[i] = char_to_int(n[i]);
    vals_product_cur *= vals[i];
  }
  vals_product_max = vals_product_cur;
  for (size_t i = vals_len; i < n_len; ++i) {
    size_t vals_idx = i % vals_len;
    if (vals[vals_idx] == 0) {
      vals[vals_idx] = char_to_int(n[i]);
      vals_product_cur = 1;
      for (size_t i_v = 0; i_v < vals_len; ++i_v) {
        vals_product_cur *= vals[i_v];
      }
    } else {
      vals_product_cur /= vals[vals_idx];
      vals[vals_idx] = char_to_int(n[i]);
      vals_product_cur *= vals[vals_idx];
    }
    if (vals_product_cur > vals_product_max) {
      vals_product_max = vals_product_cur;
    }
  }
  printf("max: %d\n", vals_product_max);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x3e8,-0x10(%rbp)
movq   $0x5,-0x18(%rbp)
lea    0xeba(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    %rsp,%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x5,-0x38(%rbp)
jae    11ad <main+0x8d>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <char_to_int@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x38(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%eax
imul   -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1167 <main+0x47>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
movq   $0x5,-0x40(%rbp)
cmpq   $0x3e8,-0x40(%rbp)
jae    12a7 <main+0x187>
mov    -0x40(%rbp),%rax
mov    $0x5,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmpl   $0x0,-0x70(%rbp,%rax,4)
jne    1244 <main+0x124>
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <char_to_int@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
mov    %ecx,-0x70(%rbp,%rax,4)
movl   $0x1,-0x2c(%rbp)
movq   $0x0,-0x50(%rbp)
cmpq   $0x5,-0x50(%rbp)
jae    123f <main+0x11f>
mov    -0x50(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%eax
imul   -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    1214 <main+0xf4>
jmp    127f <main+0x15f>
mov    -0x48(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%ecx
mov    -0x2c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <char_to_int@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
mov    %ecx,-0x70(%rbp,%rax,4)
mov    -0x48(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%eax
imul   -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jle    1291 <main+0x171>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1296 <main+0x176>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11bb <main+0x9b>
mov    -0x30(%rbp),%esi
lea    0x1138(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x37,%edi
call   1040 <char_to_int@plt>
mov    %eax,%ebx
mov    %eax,(%rsp)
mov    $0x33,%edi
call   1040 <char_to_int@plt>
mov    %eax,%ebp
mov    %eax,0x4(%rsp)
imul   %ebx,%ebp
mov    $0x31,%edi
call   1040 <char_to_int@plt>
mov    %eax,%r14d
mov    %eax,0x8(%rsp)
mov    $0x36,%edi
call   1040 <char_to_int@plt>
mov    %eax,0xc(%rsp)
imul   %eax,%r14d
imul   %ebp,%r14d
mov    $0x37,%edi
call   1040 <char_to_int@plt>
mov    %eax,0x10(%rsp)
imul   %eax,%r14d
mov    $0x5,%ebx
movabs $0xcccccccccccccccd,%r15
cc cc cc
lea    0xe61(%rip),%r12
mov    %r14d,%ebp
jmp    11dd <main+0xbd>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%eax
cltd
idiv   %ecx
movsbl (%rbx,%r12,1),%edi
mov    %eax,%ebp
call   1040 <char_to_int@plt>
mov    %eax,0x0(%r13,%rbx,4)
imul   %eax,%ebp
cmp    %r14d,%ebp
cmovg  %ebp,%r14d
add    $0x1,%rbx
cmp    $0x3e8,%rbx
je     1223 <main+0x103>
mov    %rbx,%rax
mul    %r15
and    $0xfffffffffffffffc,%rdx
lea    (%rdx,%rdx,4),%rax
neg    %rax
lea    (%rsp,%rax,1),%r13
mov    0x0(%r13,%rbx,4),%ecx
test   %ecx,%ecx
jne    11b0 <main+0x90>
movsbl (%rbx,%r12,1),%edi
call   1040 <char_to_int@plt>
mov    %eax,0x0(%r13,%rbx,4)
mov    0x4(%rsp),%ebp
imul   (%rsp),%ebp
imul   0x8(%rsp),%ebp
imul   0xc(%rsp),%ebp
imul   0x10(%rsp),%ebp
jmp    11c9 <main+0xa9>
lea    0x11bf(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1001 x i8] c"7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450\00"
@.str.1 = [9 x i8] c"max: %d\0A\00"
@stderr = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %1
store i64 1000, i64* %2
store i64 5, i64* %3
store i8* getelementptr inbounds ([1001 x i8], [1001 x i8]* @.str, i64 0, i64 0), i8** %4
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %5
%13 = alloca i32, i64 5
store i32 1, i32* %6
store i32 0, i32* %7
store i64 0, i64* %8
br label %14
14: ; preds = %30, %0
%15 = load i64, i64* %8
%16 = icmp ult i64 %15, 5
br i1 %16, label %17, label %33
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = load i64, i64* %8
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i8, i8* %20
%22 = call i32 @char_to_int(i8 signext %21)
%23 = load i64, i64* %8
%24 = getelementptr inbounds i32, i32* %13, i64 %23
store i32 %22, i32* %24
%25 = load i64, i64* %8
%26 = getelementptr inbounds i32, i32* %13, i64 %25
%27 = load i32, i32* %26
%28 = load i32, i32* %6
%29 = mul nsw i32 %28, %27
store i32 %29, i32* %6
br label %30
30: ; preds = %17
%31 = load i64, i64* %8
%32 = add i64 %31, 1
store i64 %32, i64* %8
br label %14
33: ; preds = %14
%34 = load i32, i32* %6
store i32 %34, i32* %7
store i64 5, i64* %9
br label %35
35: ; preds = %91, %33
%36 = load i64, i64* %9
%37 = icmp ult i64 %36, 1000
br i1 %37, label %38, label %94
38: ; preds = %35
%39 = load i64, i64* %9
%40 = urem i64 %39, 5
store i64 %40, i64* %10
%41 = load i64, i64* %10
%42 = getelementptr inbounds i32, i32* %13, i64 %41
%43 = load i32, i32* %42
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %66
45: ; preds = %38
%46 = load i8*, i8** %4
%47 = load i64, i64* %9
%48 = getelementptr inbounds i8, i8* %46, i64 %47
%49 = load i8, i8* %48
%50 = call i32 @char_to_int(i8 signext %49)
%51 = load i64, i64* %10
%52 = getelementptr inbounds i32, i32* %13, i64 %51
store i32 %50, i32* %52
store i32 1, i32* %6
store i64 0, i64* %11
br label %53
53: ; preds = %62, %45
%54 = load i64, i64* %11
%55 = icmp ult i64 %54, 5
br i1 %55, label %56, label %65
56: ; preds = %53
%57 = load i64, i64* %11
%58 = getelementptr inbounds i32, i32* %13, i64 %57
%59 = load i32, i32* %58
%60 = load i32, i32* %6
%61 = mul nsw i32 %60, %59
store i32 %61, i32* %6
br label %62
62: ; preds = %56
%63 = load i64, i64* %11
%64 = add i64 %63, 1
store i64 %64, i64* %11
br label %53
65: ; preds = %53
br label %84
66: ; preds = %38
%67 = load i64, i64* %10
%68 = getelementptr inbounds i32, i32* %13, i64 %67
%69 = load i32, i32* %68
%70 = load i32, i32* %6
%71 = sdiv i32 %70, %69
store i32 %71, i32* %6
%72 = load i8*, i8** %4
%73 = load i64, i64* %9
%74 = getelementptr inbounds i8, i8* %72, i64 %73
%75 = load i8, i8* %74
%76 = call i32 @char_to_int(i8 signext %75)
%77 = load i64, i64* %10
%78 = getelementptr inbounds i32, i32* %13, i64 %77
store i32 %76, i32* %78
%79 = load i64, i64* %10
%80 = getelementptr inbounds i32, i32* %13, i64 %79
%81 = load i32, i32* %80
%82 = load i32, i32* %6
%83 = mul nsw i32 %82, %81
store i32 %83, i32* %6
br label %84
84: ; preds = %66, %65
%85 = load i32, i32* %6
%86 = load i32, i32* %7
%87 = icmp sgt i32 %85, %86
br i1 %87, label %88, label %90
88: ; preds = %84
%89 = load i32, i32* %6
store i32 %89, i32* %7
br label %90
90: ; preds = %88, %84
br label %91
91: ; preds = %90
%92 = load i64, i64* %9
%93 = add i64 %92, 1
store i64 %93, i64* %9
br label %35
94: ; preds = %35
%95 = load i32, i32* %7
%96 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %95)
store i32 0, i32* %1
%97 = load i8*, i8** %5
%98 = load i32, i32* %1
ret i32 %98
}

LLVM IR (-O2):
@.str = [1001 x i8] c"7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450\00"
@.str.1 = [9 x i8] c"max: %d\0A\00"
@stderr = global i32 0
define i32 @main() {
%1 = alloca [5 x i32]
%2 = tail call i32 @char_to_int(i8 signext 55)
%3 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
store i32 %2, i32* %3
%4 = tail call i32 @char_to_int(i8 signext 51)
%5 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 1
store i32 %4, i32* %5
%6 = mul nsw i32 %4, %2
%7 = tail call i32 @char_to_int(i8 signext 49)
%8 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 2
store i32 %7, i32* %8
%9 = mul nsw i32 %7, %6
%10 = tail call i32 @char_to_int(i8 signext 54)
%11 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 3
store i32 %10, i32* %11
%12 = mul nsw i32 %10, %9
%13 = tail call i32 @char_to_int(i8 signext 55)
%14 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 4
store i32 %13, i32* %14
%15 = mul nsw i32 %13, %12
br label %18
16: ; preds = %47
%17 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %50)
ret i32 0
18: ; preds = %0, %47
%19 = phi i64 [ %51, %47 ], [ 5, %0 ]
%20 = phi i32 [ %50, %47 ], [ %15, %0 ]
%21 = phi i32 [ %48, %47 ], [ %15, %0 ]
%22 = trunc i64 %19 to i16
%23 = urem i16 %22, 5
%24 = zext i16 %23 to i64
%25 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %41
28: ; preds = %18
%29 = getelementptr inbounds [1001 x i8], [1001 x i8]* @.str, i64 0, i64 %19
%30 = load i8, i8* %29
%31 = tail call i32 @char_to_int(i8 signext %30)
store i32 %31, i32* %25
%32 = load i32, i32* %3
%33 = load i32, i32* %5
%34 = mul nsw i32 %33, %32
%35 = load i32, i32* %8
%36 = mul nsw i32 %35, %34
%37 = load i32, i32* %11
%38 = mul nsw i32 %37, %36
%39 = load i32, i32* %14
%40 = mul nsw i32 %39, %38
br label %47
41: ; preds = %18
%42 = sdiv i32 %21, %26
%43 = getelementptr inbounds [1001 x i8], [1001 x i8]* @.str, i64 0, i64 %19
%44 = load i8, i8* %43
%45 = tail call i32 @char_to_int(i8 signext %44)
store i32 %45, i32* %25
%46 = mul nsw i32 %45, %42
br label %47
47: ; preds = %28, %41
%48 = phi i32 [ %46, %41 ], [ %40, %28 ]
%49 = icmp sgt i32 %48, %20
%50 = select i1 %49, i32 %48, i32 %20
%51 = add nuw nsw i64 %19, 1
%52 = icmp eq i64 %51, 1000
br i1 %52, label %16, label %18
}