#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 *, unsigned int);
int main(int argc, char *argv[]) {
  unsigned max_len = 0;
  unsigned max_index = 0;
  for (unsigned i = 2; i <= 1000; i++) {
    unsigned check[1000] = {0};
    unsigned len = 0;
    unsigned n = 1;
    unsigned d = i;
    unsigned rem = 0;
    while (!check[n] && n != 0) {
      check[n] = 1;
      rem = (n * 10) % d;
      n = rem;
      len++;
    }
    if (len > max_len)
      max_len = len, max_index = i;
  }
  printf("Max index: %d\n", max_index);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x2,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
ja     124d <main+0x12d>
lea    -0xfc0(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa0,%edx
call   1040 <memset@plt>
movl   $0x0,-0xfc4(%rbp)
movl   $0x1,-0xfc8(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0xfcc(%rbp)
movl   $0x0,-0xfd0(%rbp)
mov    -0xfc8(%rbp),%eax
mov    %eax,%ecx
xor    %eax,%eax
cmpl   $0x0,-0xfc0(%rbp,%rcx,4)
mov    %al,-0xfd1(%rbp)
jne    11c3 <main+0xa3>
cmpl   $0x0,-0xfc8(%rbp)
setne  %al
mov    %al,-0xfd1(%rbp)
mov    -0xfd1(%rbp),%al
test   $0x1,%al
jne    11d6 <main+0xb6>
jmp    121c <main+0xfc>
mov    -0xfc8(%rbp),%eax
movl   $0x1,-0xfc0(%rbp,%rax,4)
imul   $0xa,-0xfc8(%rbp),%eax
xor    %edx,%edx
divl   -0xfcc(%rbp)
mov    %edx,-0xfd0(%rbp)
mov    -0xfd0(%rbp),%eax
mov    %eax,-0xfc8(%rbp)
mov    -0xfc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfc4(%rbp)
jmp    1195 <main+0x75>
mov    -0xfc4(%rbp),%eax
cmp    -0x14(%rbp),%eax
jbe    123a <main+0x11a>
mov    -0xfc4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    123f <main+0x11f>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114e <main+0x2e>
mov    -0x18(%rbp),%esi
lea    0xda9(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xfe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xfa0,%rsp
mov    $0x2,%ebp
xor    %ebx,%ebx
lea    0x4(%rsp),%r12
mov    %rsp,%r14
xor    %r15d,%r15d
jmp    1164 <main+0x44>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %ebx,%ecx
cmova  %ebp,%r15d
cmova  %ecx,%ebx
add    $0x1,%ebp
cmp    $0x3e9,%ebp
je     11a2 <main+0x82>
mov    $0xfa0,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    $0x1,%edx
mov    %r12,%rax
xor    %ecx,%ecx
nopl   (%rax)
movl   $0x1,(%rax)
add    %edx,%edx
lea    (%rdx,%rdx,4),%eax
xor    %edx,%edx
div    %ebp
add    $0x1,%ecx
cmpl   $0x0,(%rsp,%rdx,4)
jne    1150 <main+0x30>
lea    (%rsp,%rdx,4),%rax
test   %edx,%edx
jne    1180 <main+0x60>
jmp    1150 <main+0x30>
lea    0xe57(%rip),%rdi
mov    %r15d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0xfa0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [15 x i8] c"Max index: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1000 x i32]
%4 = bitcast [1000 x i32]* %3 to i8*
%5 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 1
br label %8
6: ; preds = %25
%7 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %27)
ret i32 0
8: ; preds = %25, %2
%9 = phi i32 [ 0, %2 ], [ %28, %25 ]
%10 = phi i32 [ 2, %2 ], [ %29, %25 ]
%11 = phi i32 [ 0, %2 ], [ %27, %25 ]
br label %12
12: ; preds = %8, %12
%13 = phi i32* [ %20, %12 ], [ %5, %8 ]
%14 = phi i32 [ %17, %12 ], [ 1, %8 ]
%15 = phi i32 [ %18, %12 ], [ 0, %8 ]
store i32 1, i32* %13
%16 = mul i32 %14, 10
%17 = urem i32 %16, %10
%18 = add i32 %15, 1
%19 = zext i32 %17 to i64
%20 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 0
%23 = icmp ne i32 %17, 0
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %12, label %25
25: ; preds = %12
%26 = icmp ugt i32 %18, %9
%27 = select i1 %26, i32 %10, i32 %11
%28 = select i1 %26, i32 %18, i32 %9
%29 = add nuw nsw i32 %10, 1
%30 = icmp eq i32 %29, 1001
br i1 %30, label %6, label %8
}