#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 f_digs(int, int *);
int /*<<< orphan*/ in(int, int *, int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int f[10] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880};
  int non_repeats;
  int arr[65];
  int i, n, counter;
  int temp_n;
  counter = 0;
  for (n = 2; n < 1000000; n++) {
    temp_n = n;
    non_repeats = 0;
    for (i = 0; i < 65; i++) {
      arr[i] = -1;
    }
    while (!in(temp_n, arr, 65)) {
      arr[non_repeats++] = temp_n;
      temp_n = f_digs(temp_n, f);
      if (non_repeats > 60) {
        non_repeats = 0;
        break;
      }
    }
    if (non_repeats == 60)
      counter++;
  }
  printf("counter: %d\n", counter);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x14c(%rbp)
movl   $0x2,-0x148(%rbp)
cmpl   $0xf4240,-0x148(%rbp)
jge    1288 <main+0x148>
mov    -0x148(%rbp),%eax
mov    %eax,-0x150(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x144(%rbp)
cmpl   $0x41,-0x144(%rbp)
jge    11db <main+0x9b>
movslq -0x144(%rbp),%rax
movl   $0xffffffff,-0x140(%rbp,%rax,4)
ff ff ff ff
mov    -0x144(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x144(%rbp)
jmp    11a8 <main+0x68>
jmp    11e0 <main+0xa0>
mov    -0x150(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x41,%edx
call   1060 <in@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    120c <main+0xcc>
jmp    1256 <main+0x116>
mov    -0x150(%rbp),%ecx
mov    -0x34(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x34(%rbp)
cltq
mov    %ecx,-0x140(%rbp,%rax,4)
mov    -0x150(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1030 <f_digs@plt>
mov    %eax,-0x150(%rbp)
cmpl   $0x3c,-0x34(%rbp)
jle    1251 <main+0x111>
movl   $0x0,-0x34(%rbp)
jmp    1256 <main+0x116>
jmp    11e0 <main+0xa0>
cmpl   $0x3c,-0x34(%rbp)
jne    126f <main+0x12f>
mov    -0x14c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14c(%rbp)
jmp    1274 <main+0x134>
mov    -0x148(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x148(%rbp)
jmp    117b <main+0x3b>
mov    -0x14c(%rbp),%esi
lea    0xd93(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    0xec8(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe90(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    $0x2,%r12d
xor    %r14d,%r14d
lea    0x30(%rsp),%r13
mov    %rsp,%r15
jmp    11a8 <main+0x68>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
cmp    $0xffffffff,%ebx
sete   %al
add    %eax,%r14d
add    $0x1,%r12d
cmp    $0xf4240,%r12d
je     11fd <main+0xbd>
mov    $0x104,%edx
mov    %r13,%rdi
mov    $0xff,%esi
call   1050 <memset@plt>
mov    $0xffffffffffffffc3,%rbx
mov    %r12d,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x41,%edx
call   1060 <in@plt>
test   %eax,%eax
jne    1190 <main+0x50>
mov    %ebp,0x124(%rsp,%rbx,4)
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <f_digs@plt>
mov    %eax,%ebp
inc    %rbx
jne    11d0 <main+0x90>
jmp    119b <main+0x5b>
lea    0xe24(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.f = [10 x i32] [i32 1, i32 1, i32 2, i32 6, i32 24, i32 120, i32 720, i32 5040, i32 40320, i32 362880]
@.str = [13 x i8] c"counter: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca [65 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = bitcast [10 x i32]* %2 to i8*
store i32 0, i32* %7
store i32 2, i32* %6
br label %10
10: ; preds = %52, %0
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 1000000
br i1 %12, label %13, label %55
13: ; preds = %10
%14 = load i32, i32* %6
store i32 %14, i32* %8
store i32 0, i32* %3
store i32 0, i32* %5
br label %15
15: ; preds = %22, %13
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 65
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [65 x i32], [65 x i32]* %4, i64 0, i64 %20
store i32 -1, i32* %21
br label %22
22: ; preds = %18
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %15
25: ; preds = %15
br label %26
26: ; preds = %44, %25
%27 = load i32, i32* %8
%28 = getelementptr inbounds [65 x i32], [65 x i32]* %4, i64 0, i64 0
%29 = call i32 @in(i32 %27, i32* %28, i32 65)
%30 = icmp ne i32 %29, 0
%31 = xor i1 %30, true
br i1 %31, label %32, label %45
32: ; preds = %26
%33 = load i32, i32* %8
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds [65 x i32], [65 x i32]* %4, i64 0, i64 %36
store i32 %33, i32* %37
%38 = load i32, i32* %8
%39 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%40 = call i32 @f_digs(i32 %38, i32* %39)
store i32 %40, i32* %8
%41 = load i32, i32* %3
%42 = icmp sgt i32 %41, 60
br i1 %42, label %43, label %44
43: ; preds = %32
store i32 0, i32* %3
br label %45
44: ; preds = %32
br label %26
45: ; preds = %43, %26
%46 = load i32, i32* %3
%47 = icmp eq i32 %46, 60
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %51
51: ; preds = %48, %45
br label %52
52: ; preds = %51
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %10
55: ; preds = %10
%56 = load i32, i32* %7
%57 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %56)
ret i32 0
}

LLVM IR (-O2):
@__const.main.f = [10 x i32] [i32 1, i32 1, i32 2, i32 6, i32 24, i32 120, i32 720, i32 5040, i32 40320, i32 362880]
@.str = [13 x i8] c"counter: %d\0A\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = alloca [65 x i32]
%3 = bitcast [65 x i32]* %2 to i8*
%4 = bitcast [10 x i32]* %1 to i8*
%5 = getelementptr inbounds [65 x i32], [65 x i32]* %2, i64 0, i64 0
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
br label %7
7: ; preds = %0, %25
%8 = phi i32 [ 0, %0 ], [ %26, %25 ]
%9 = phi i32 [ 2, %0 ], [ %27, %25 ]
br label %10
10: ; preds = %7, %15
%11 = phi i64 [ 0, %7 ], [ %16, %15 ]
%12 = phi i32 [ %9, %7 ], [ %18, %15 ]
%13 = call i32 @in(i32 %12, i32* %5, i32 65)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = add nuw nsw i64 %11, 1
%17 = getelementptr inbounds [65 x i32], [65 x i32]* %2, i64 0, i64 %11
store i32 %12, i32* %17
%18 = call i32 @f_digs(i32 %12, i32* %6)
%19 = icmp eq i64 %16, 61
br i1 %19, label %25, label %10
20: ; preds = %10
%21 = trunc i64 %11 to i32
%22 = icmp eq i32 %21, 60
%23 = zext i1 %22 to i32
%24 = add nsw i32 %8, %23
br label %25
25: ; preds = %15, %20
%26 = phi i32 [ %24, %20 ], [ %8, %15 ]
%27 = add nuw nsw i32 %9, 1
%28 = icmp eq i32 %27, 1000000
br i1 %28, label %29, label %7
29: ; preds = %25
%30 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %26)
ret i32 0
}