#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  long max = 0;
  int meja;
  printf("Please insert number of adjacent digits:\n");
  scanf("%d", &meja);
  char tabela[1000] =
      "731671765313306249192251196744265747423553491949349698352031277450632623"
      "957831801698480186947885184385861560789112949495459501737958331952853208"
      "805511125406987471585238630507156932909632952274430435576689664895044524"
      "452316173185640309871112172238311362229893423380308135336276614282806444"
      "486645238749303589072962904915604407723907138105158593079608667017242712"
      "188399879790879227492190169972088809377665727333001053367881220235421809"
      "751254540594752243525849077116705560136048395864467063244157221553975369"
      "781797784617406495514929086256932197846862248283972241375657056057490261"
      "407972968652414535100474821663704844031998900088952434506585412275886668"
      "811642717147992444292823086346567481391912316282458617866458359124566529"
      "476545682848912883142607690042242190226710556263211111093705442175069416"
      "589604080719840385096245544436298123098787992724428490918884580156166097"
      "919133875499200524063689912560717606058861164671094050775410022569831552"
      "0005593572972571636269561882670428252483600823257530420752963450";
  int i, x;
  for (i = 0; i < 1000 - meja; i++) {
    long produkt = 1;
    for (x = i; x < i + meja; x++) {
      char trenutn = tabela[x];
      produkt *= trenutn - '0';
    }
    if (produkt > max) {
      max = produkt;
    }
  }
  printf("The greatest product of %d adjacent numbers in the 1000-digit number "
         "is:\n",
         meja);
  printf("%ld\n", max);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
lea    -0x400(%rbp),%rdi
lea    0xf0a(%rip),%rsi
mov    $0x3e8,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x404(%rbp)
mov    -0x404(%rbp),%eax
mov    $0x3e8,%ecx
sub    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jge    1246 <main+0x116>
movq   $0x1,-0x410(%rbp)
mov    -0x404(%rbp),%eax
mov    %eax,-0x408(%rbp)
mov    -0x408(%rbp),%eax
mov    -0x404(%rbp),%ecx
add    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jge    1211 <main+0xe1>
movslq -0x408(%rbp),%rax
mov    -0x400(%rbp,%rax,1),%al
mov    %al,-0x411(%rbp)
movsbl -0x411(%rbp),%eax
sub    $0x30,%eax
cltq
imul   -0x410(%rbp),%rax
ff
mov    %rax,-0x410(%rbp)
mov    -0x408(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x408(%rbp)
jmp    11b7 <main+0x87>
mov    -0x410(%rbp),%rax
cmp    -0x10(%rbp),%rax
jle    122d <main+0xfd>
mov    -0x410(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1232 <main+0x102>
mov    -0x404(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x404(%rbp)
jmp    118a <main+0x5a>
mov    -0x14(%rbp),%esi
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xf17(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb9(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
movslq 0x4(%rsp),%rsi
cmp    $0x3e7,%rsi
jg     11bb <main+0x8b>
mov    $0x3e8,%eax
sub    %esi,%eax
mov    $0x1,%r8d
cmp    $0x2,%eax
cmovge %eax,%r8d
jge    11c3 <main+0x93>
xor    %r10d,%r10d
xor    %r14d,%r14d
test   $0x1,%r8b
je     1277 <main+0x147>
test   %esi,%esi
jle    126b <main+0x13b>
lea    (%r10,%rsi,1),%rdx
mov    $0x1,%ecx
lea    0xee3(%rip),%rdi
nopl   (%rax)
movsbq (%r10,%rdi,1),%rax
add    $0xffffffffffffffd0,%rax
imul   %rax,%rcx
add    $0x1,%r10
cmp    %rdx,%r10
jl     11a0 <main+0x70>
jmp    1270 <main+0x140>
xor    %r14d,%r14d
jmp    1277 <main+0x147>
mov    %r8d,%r9d
and    $0x7ffffffe,%r9d
xor    %r10d,%r10d
lea    0xea9(%rip),%r11
xor    %r14d,%r14d
jmp    11f0 <main+0xc0>
nopl   0x0(%rax)
cmp    %r14,%rcx
cmovg  %rcx,%r14
add    $0x2,%r10
cmp    %r9,%r10
je     117b <main+0x4b>
mov    $0x1,%ecx
mov    $0x1,%edx
test   %esi,%esi
jle    1226 <main+0xf6>
lea    (%r10,%rsi,1),%rbx
mov    $0x1,%edx
mov    %r10,%rax
nopw   0x0(%rax,%rax,1)
movsbq (%rax,%r11,1),%rdi
add    $0xffffffffffffffd0,%rdi
imul   %rdi,%rdx
add    $0x1,%rax
cmp    %rbx,%rax
jl     1210 <main+0xe0>
cmp    %r14,%rdx
cmovg  %rdx,%r14
test   %esi,%esi
jle    11e0 <main+0xb0>
mov    %r10,%rdx
or     $0x1,%rdx
lea    (%rdx,%rsi,1),%rbx
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbq (%rdx,%r11,1),%rax
add    $0xffffffffffffffd0,%rax
imul   %rax,%rcx
add    $0x1,%rdx
cmp    %rbx,%rdx
jl     1250 <main+0x120>
jmp    11e0 <main+0xb0>
mov    $0x1,%ecx
cmp    %r14,%rcx
cmovg  %rcx,%r14
lea    0xd85(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdc1(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Please insert number of adjacent digits:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@__const.main.tabela = [1000 x i8] c"7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
@.str.2 = [74 x i8] c"The greatest product of %d adjacent numbers in the 1000-digit number is:\0A\00"
@.str.3 = [5 x i8] c"%ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca [1000 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8
store i32 0, i32* %1
store i64 0, i64* %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%11 = bitcast [1000 x i8]* %4 to i8*
store i32 0, i32* %5
br label %12
12: ; preds = %46, %0
%13 = load i32, i32* %5
%14 = load i32, i32* %3
%15 = sub nsw i32 1000, %14
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %49
17: ; preds = %12
store i64 1, i64* %7
%18 = load i32, i32* %5
store i32 %18, i32* %6
br label %19
19: ; preds = %36, %17
%20 = load i32, i32* %6
%21 = load i32, i32* %5
%22 = load i32, i32* %3
%23 = add nsw i32 %21, %22
%24 = icmp slt i32 %20, %23
br i1 %24, label %25, label %39
25: ; preds = %19
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %27
%29 = load i8, i8* %28
store i8 %29, i8* %8
%30 = load i8, i8* %8
%31 = sext i8 %30 to i32
%32 = sub nsw i32 %31, 48
%33 = sext i32 %32 to i64
%34 = load i64, i64* %7
%35 = mul nsw i64 %34, %33
store i64 %35, i64* %7
br label %36
36: ; preds = %25
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %6
br label %19
39: ; preds = %19
%40 = load i64, i64* %7
%41 = load i64, i64* %2
%42 = icmp sgt i64 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = load i64, i64* %7
store i64 %44, i64* %2
br label %45
45: ; preds = %43, %39
br label %46
46: ; preds = %45
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %12
49: ; preds = %12
%50 = load i32, i32* %3
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0), i32 %50)
%52 = load i64, i64* %2
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %52)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@__const.main.tabela = [1000 x i8] c"7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
@.str.2 = [74 x i8] c"The greatest product of %d adjacent numbers in the 1000-digit number is:\0A\00"
@.str.3 = [5 x i8] c"%ld\0A\00"
@str = [41 x i8] c"Please insert number of adjacent digits:\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 1000
br i1 %6, label %7, label %76
7: ; preds = %0
%8 = sub i32 1000, %5
%9 = sext i32 %5 to i64
%10 = call i32 @llvm.smax.i32(i32 %8, i32 1)
%11 = zext i32 %10 to i64
%12 = icmp sgt i32 %5, 0
%13 = and i64 %11, 1
%14 = icmp slt i32 %8, 2
br i1 %14, label %55, label %15
15: ; preds = %7
%16 = and i64 %11, 2147483646
br label %17
17: ; preds = %48, %15
%18 = phi i64 [ 0, %15 ], [ %52, %48 ]
%19 = phi i64 [ 0, %15 ], [ %51, %48 ]
%20 = phi i64 [ 0, %15 ], [ %53, %48 ]
%21 = add nsw i64 %18, %9
br i1 %12, label %22, label %32
22: ; preds = %17, %22
%23 = phi i64 [ %30, %22 ], [ %18, %17 ]
%24 = phi i64 [ %29, %22 ], [ 1, %17 ]
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* @__const.main.tabela, i64 0, i64 %23
%26 = load i8, i8* %25
%27 = sext i8 %26 to i64
%28 = add nsw i64 %27, -48
%29 = mul nsw i64 %28, %24
%30 = add nuw nsw i64 %23, 1
%31 = icmp slt i64 %30, %21
br i1 %31, label %22, label %32
32: ; preds = %22, %17
%33 = phi i64 [ 1, %17 ], [ %29, %22 ]
%34 = icmp sgt i64 %33, %19
%35 = select i1 %34, i64 %33, i64 %19
%36 = or i64 %18, 1
%37 = add nsw i64 %36, %9
br i1 %12, label %38, label %48
38: ; preds = %32, %38
%39 = phi i64 [ %46, %38 ], [ %36, %32 ]
%40 = phi i64 [ %45, %38 ], [ 1, %32 ]
%41 = getelementptr inbounds [1000 x i8], [1000 x i8]* @__const.main.tabela, i64 0, i64 %39
%42 = load i8, i8* %41
%43 = sext i8 %42 to i64
%44 = add nsw i64 %43, -48
%45 = mul nsw i64 %44, %40
%46 = add nuw nsw i64 %39, 1
%47 = icmp slt i64 %46, %37
br i1 %47, label %38, label %48
48: ; preds = %38, %32
%49 = phi i64 [ 1, %32 ], [ %45, %38 ]
%50 = icmp sgt i64 %49, %35
%51 = select i1 %50, i64 %49, i64 %35
%52 = add nuw nsw i64 %18, 2
%53 = add i64 %20, 2
%54 = icmp eq i64 %53, %16
br i1 %54, label %55, label %17
55: ; preds = %48, %7
%56 = phi i64 [ undef, %7 ], [ %51, %48 ]
%57 = phi i64 [ 0, %7 ], [ %52, %48 ]
%58 = phi i64 [ 0, %7 ], [ %51, %48 ]
%59 = icmp eq i64 %13, 0
br i1 %59, label %76, label %60
60: ; preds = %55
%61 = add nsw i64 %57, %9
br i1 %12, label %62, label %72
62: ; preds = %60, %62
%63 = phi i64 [ %70, %62 ], [ %57, %60 ]
%64 = phi i64 [ %69, %62 ], [ 1, %60 ]
%65 = getelementptr inbounds [1000 x i8], [1000 x i8]* @__const.main.tabela, i64 0, i64 %63
%66 = load i8, i8* %65
%67 = sext i8 %66 to i64
%68 = add nsw i64 %67, -48
%69 = mul nsw i64 %68, %64
%70 = add nuw nsw i64 %63, 1
%71 = icmp slt i64 %70, %61
br i1 %71, label %62, label %72
72: ; preds = %62, %60
%73 = phi i64 [ 1, %60 ], [ %69, %62 ]
%74 = icmp sgt i64 %73, %58
%75 = select i1 %74, i64 %73, i64 %58
br label %76
76: ; preds = %72, %55, %0
%77 = phi i64 [ 0, %0 ], [ %56, %55 ], [ %75, %72 ]
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %77)
ret i32 0
}