#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 /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, int, int);
int main(void) {
  int k = 1000;
  int m = 5;
  char str[1001] = "73167176531330624919225119674426574742355349194934"
                   "96983520312774506326239578318016984801869478851843"
                   "85861560789112949495459501737958331952853208805511"
                   "12540698747158523863050715693290963295227443043557"
                   "66896648950445244523161731856403098711121722383113"
                   "62229893423380308135336276614282806444486645238749"
                   "30358907296290491560440772390713810515859307960866"
                   "70172427121883998797908792274921901699720888093776"
                   "65727333001053367881220235421809751254540594752243"
                   "52584907711670556013604839586446706324415722155397"
                   "53697817977846174064955149290862569321978468622482"
                   "83972241375657056057490261407972968652414535100474"
                   "82166370484403199890008895243450658541227588666881"
                   "16427171479924442928230863465674813919123162824586"
                   "17866458359124566529476545682848912883142607690042"
                   "24219022671055626321111109370544217506941658960408"
                   "07198403850962455444362981230987879927244284909188"
                   "84580156166097919133875499200524063689912560717606"
                   "05886116467109405077541002256983155200055935729725"
                   "71636269561882670428252483600823257530420752963450";
  int a[1000] = {0};
  memset(a, 0, k);
  int i = 0;
  for (i = 0; i < k; i++) {
    a[i] = (int)(str[i] - '0');
  }
  int p = 0;
  for (i = 0; i < k - m; i++) {
    if (a[i] == 0) {
      continue;
    }
    int t = a[i] * a[i + 1] * a[i + 2] * a[i + 3] * a[i + 4];
    if (p < t) {
      p = t;
    }
  }
  printf("biggest product of %d consecutive digits in %d-digit is %d\n", m, k,
         p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x13b0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0x8(%rbp)
movl   $0x5,-0xc(%rbp)
lea    -0x400(%rbp),%rdi
lea    0xea2(%rip),%rsi
mov    $0x3e9,%edx
call   1050 <memcpy@plt>
lea    -0x13a0(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa0,%edx
call   1040 <memset@plt>
lea    -0x13a0(%rbp),%rdi
mov    -0x8(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x13a4(%rbp)
movl   $0x0,-0x13a4(%rbp)
mov    -0x13a4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e3 <main+0xb3>
movslq -0x13a4(%rbp),%rax
movsbl -0x400(%rbp,%rax,1),%ecx
ff
sub    $0x30,%ecx
movslq -0x13a4(%rbp),%rax
mov    %ecx,-0x13a0(%rbp,%rax,4)
mov    -0x13a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13a4(%rbp)
jmp    11a0 <main+0x70>
movl   $0x0,-0x13a8(%rbp)
movl   $0x0,-0x13a4(%rbp)
mov    -0x13a4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    -0xc(%rbp),%ecx
cmp    %ecx,%eax
jge    12c0 <main+0x190>
movslq -0x13a4(%rbp),%rax
cmpl   $0x0,-0x13a0(%rbp,%rax,4)
jne    1225 <main+0xf5>
jmp    12ac <main+0x17c>
movslq -0x13a4(%rbp),%rax
mov    -0x13a0(%rbp,%rax,4),%eax
mov    -0x13a4(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
imul   -0x13a0(%rbp,%rcx,4),%eax
ff
mov    -0x13a4(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
imul   -0x13a0(%rbp,%rcx,4),%eax
ff
mov    -0x13a4(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
imul   -0x13a0(%rbp,%rcx,4),%eax
ff
mov    -0x13a4(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
imul   -0x13a0(%rbp,%rcx,4),%eax
ff
mov    %eax,-0x13ac(%rbp)
mov    -0x13a8(%rbp),%eax
cmp    -0x13ac(%rbp),%eax
jge    12a7 <main+0x177>
mov    -0x13ac(%rbp),%eax
mov    %eax,-0x13a8(%rbp)
jmp    12ac <main+0x17c>
mov    -0x13a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13a4(%rbp)
jmp    11f7 <main+0xc7>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x13a8(%rbp),%ecx
lea    0x1116(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x13b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0xfa0,%rsp
mov    %rsp,%rbx
mov    $0xfa0,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1040 <memset@plt>
mov    $0xc,%eax
lea    0xebb(%rip),%rcx
movdqa 0xea3(%rip),%xmm0
nopl   (%rax)
movd   -0x8(%rax,%rcx,1),%xmm1
punpcklbw %xmm1,%xmm1
punpcklwd %xmm1,%xmm1
punpcklbw -0xc(%rax,%rcx,1),%xmm2
punpcklwd %xmm2,%xmm2
psrad  $0x18,%xmm2
psrad  $0x18,%xmm1
paddd  %xmm0,%xmm2
paddd  %xmm0,%xmm1
movdqa %xmm2,-0x30(%rsp,%rax,4)
movdqa %xmm1,-0x20(%rsp,%rax,4)
cmp    $0x3ec,%rax
je     11dc <main+0xbc>
movq   -0x4(%rax,%rcx,1),%xmm1
punpcklbw %xmm1,%xmm1
punpcklwd %xmm1,%xmm1
movd   (%rax,%rcx,1),%xmm2
punpcklbw %xmm2,%xmm2
punpcklwd %xmm2,%xmm2
psrad  $0x18,%xmm1
psrad  $0x18,%xmm2
paddd  %xmm0,%xmm1
paddd  %xmm0,%xmm2
movdqa %xmm1,-0x10(%rsp,%rax,4)
movdqa %xmm2,(%rsp,%rax,4)
add    $0x10,%rax
jmp    1160 <main+0x40>
xor    %ecx,%ecx
mov    $0x4,%eax
jmp    11fc <main+0xdc>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rax
cmp    $0x3e7,%rax
je     121e <main+0xfe>
mov    -0x10(%rsp,%rax,4),%edx
test   %edx,%edx
je     11f0 <main+0xd0>
imul   -0xc(%rsp,%rax,4),%edx
imul   -0x8(%rsp,%rax,4),%edx
imul   -0x4(%rsp,%rax,4),%edx
imul   (%rsp,%rax,4),%edx
cmp    %edx,%ecx
cmovl  %edx,%ecx
jmp    11f0 <main+0xd0>
lea    0x11d4(%rip),%rdi
mov    $0x5,%esi
mov    $0x3e8,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xfa0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.str = [1001 x i8] c"7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450\00"
@.str = [60 x i8] c"biggest product of %d consecutive digits in %d-digit is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1001 x i8]
%5 = alloca [1000 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 1000, i32* %2
store i32 5, i32* %3
%9 = bitcast [1001 x i8]* %4 to i8*
%10 = bitcast [1000 x i32]* %5 to i8*
%11 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 0
%12 = load i32, i32* %2
%13 = call i32 @memset(i32* %11, i32 0, i32 %12)
store i32 0, i32* %6
store i32 0, i32* %6
br label %14
14: ; preds = %28, %0
%15 = load i32, i32* %6
%16 = load i32, i32* %2
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [1001 x i8], [1001 x i8]* %4, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = sub nsw i32 %23, 48
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 %26
store i32 %24, i32* %27
br label %28
28: ; preds = %18
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %14
31: ; preds = %14
store i32 0, i32* %7
store i32 0, i32* %6
br label %32
32: ; preds = %80, %31
%33 = load i32, i32* %6
%34 = load i32, i32* %2
%35 = load i32, i32* %3
%36 = sub nsw i32 %34, %35
%37 = icmp slt i32 %33, %36
br i1 %37, label %38, label %83
38: ; preds = %32
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 %40
%42 = load i32, i32* %41
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
br label %80
45: ; preds = %38
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 %52
%54 = load i32, i32* %53
%55 = mul nsw i32 %49, %54
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 2
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 %58
%60 = load i32, i32* %59
%61 = mul nsw i32 %55, %60
%62 = load i32, i32* %6
%63 = add nsw i32 %62, 3
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 %64
%66 = load i32, i32* %65
%67 = mul nsw i32 %61, %66
%68 = load i32, i32* %6
%69 = add nsw i32 %68, 4
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 %70
%72 = load i32, i32* %71
%73 = mul nsw i32 %67, %72
store i32 %73, i32* %8
%74 = load i32, i32* %7
%75 = load i32, i32* %8
%76 = icmp slt i32 %74, %75
br i1 %76, label %77, label %79
77: ; preds = %45
%78 = load i32, i32* %8
store i32 %78, i32* %7
br label %79
79: ; preds = %77, %45
br label %80
80: ; preds = %79, %44
%81 = load i32, i32* %6
%82 = add nsw i32 %81, 1
store i32 %82, i32* %6
br label %32
83: ; preds = %32
%84 = load i32, i32* %3
%85 = load i32, i32* %2
%86 = load i32, i32* %7
%87 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %84, i32 %85, i32 %86)
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [1001 x i8] c"7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450\00"
@.str = [60 x i8] c"biggest product of %d consecutive digits in %d-digit is %d\0A\00"
define i32 @main() {
%1 = alloca [1000 x i32]
%2 = bitcast [1000 x i32]* %1 to i8*
%3 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 0
%4 = call i32 @memset(i32* %3, i32 0, i32 1000)
br label %5
5: ; preds = %23, %0
%6 = phi i64 [ 0, %0 ], [ %38, %23 ]
%7 = getelementptr inbounds [1001 x i8], [1001 x i8]* @__const.main.str, i64 0, i64 %6
%8 = bitcast i8* %7 to <4 x i8>*
%9 = load <4 x i8>, <4 x i8>* %8
%10 = getelementptr inbounds i8, i8* %7, i64 4
%11 = bitcast i8* %10 to <4 x i8>*
%12 = load <4 x i8>, <4 x i8>* %11
%13 = sext <4 x i8> %9 to <4 x i32>
%14 = sext <4 x i8> %12 to <4 x i32>
%15 = add nsw <4 x i32> %13, <i32 -48, i32 -48, i32 -48, i32 -48>
%16 = add nsw <4 x i32> %14, <i32 -48, i32 -48, i32 -48, i32 -48>
%17 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %6
%18 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> %15, <4 x i32>* %18
%19 = getelementptr inbounds i32, i32* %17, i64 4
%20 = bitcast i32* %19 to <4 x i32>*
store <4 x i32> %16, <4 x i32>* %20
%21 = or i64 %6, 8
%22 = icmp eq i64 %21, 1000
br i1 %22, label %39, label %23
23: ; preds = %5
%24 = getelementptr inbounds [1001 x i8], [1001 x i8]* @__const.main.str, i64 0, i64 %21
%25 = bitcast i8* %24 to <4 x i8>*
%26 = load <4 x i8>, <4 x i8>* %25
%27 = getelementptr inbounds i8, i8* %24, i64 4
%28 = bitcast i8* %27 to <4 x i8>*
%29 = load <4 x i8>, <4 x i8>* %28
%30 = sext <4 x i8> %26 to <4 x i32>
%31 = sext <4 x i8> %29 to <4 x i32>
%32 = add nsw <4 x i32> %30, <i32 -48, i32 -48, i32 -48, i32 -48>
%33 = add nsw <4 x i32> %31, <i32 -48, i32 -48, i32 -48, i32 -48>
%34 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %21
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> %32, <4 x i32>* %35
%36 = getelementptr inbounds i32, i32* %34, i64 4
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> %33, <4 x i32>* %37
%38 = add nuw nsw i64 %6, 16
br label %5
39: ; preds = %5, %64
%40 = phi i64 [ %45, %64 ], [ 0, %5 ]
%41 = phi i32 [ %65, %64 ], [ 0, %5 ]
%42 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %40
%43 = load i32, i32* %42
%44 = icmp eq i32 %43, 0
%45 = add nuw nsw i64 %40, 1
br i1 %44, label %64, label %46
46: ; preds = %39
%47 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %45
%48 = load i32, i32* %47
%49 = mul nsw i32 %48, %43
%50 = add nuw nsw i64 %40, 2
%51 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %50
%52 = load i32, i32* %51
%53 = mul nsw i32 %49, %52
%54 = add nuw nsw i64 %40, 3
%55 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %54
%56 = load i32, i32* %55
%57 = mul nsw i32 %53, %56
%58 = add nuw nsw i64 %40, 4
%59 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %58
%60 = load i32, i32* %59
%61 = mul nsw i32 %57, %60
%62 = icmp slt i32 %41, %61
%63 = select i1 %62, i32 %61, i32 %41
br label %64
64: ; preds = %39, %46
%65 = phi i32 [ %63, %46 ], [ %41, %39 ]
%66 = icmp eq i64 %45, 995
br i1 %66, label %67, label %39
67: ; preds = %64
%68 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 5, i32 1000, i32 %65)
ret i32 0
}