#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 *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int finddigits(void) {
  int numCases;
  int *divisors = malloc(sizeof(int) * 10);
  divisors[0] = 1;
  scanf("%d", &numCases);
  while (numCases--) {
    int number;
    int divisorDigits = 0;
    scanf("%d", &number);
    for (int i = 1; i < 10; i++) {
      divisors[i] = (number % (i + 1)) == 0;
    }
    while (number > 0) {
      if (divisors[(number % 10) - 1]) {
        divisorDigits++;
      }
      number /= 10;
    }
    printf("%d\n", divisorDigits);
  }
  return 0;
}


x86 assembly (clang, -O0):
<finddigits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x28,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
lea    0xea9(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     1232 <finddigits+0x102>
movl   $0x0,-0x18(%rbp)
lea    0xe7e(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x1,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    11cc <finddigits+0x9c>
mov    -0x14(%rbp),%eax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
sete   %al
and    $0x1,%al
movzbl %al,%edx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1192 <finddigits+0x62>
jmp    11d1 <finddigits+0xa1>
cmpl   $0x0,-0x14(%rbp)
jle    121e <finddigits+0xee>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%edx
movslq %edx,%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     120b <finddigits+0xdb>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
jmp    11d1 <finddigits+0xa1>
mov    -0x18(%rbp),%esi
lea    0xddb(%rip),%rdi
call   1030 <printf@plt>
jmp    1160 <finddigits+0x30>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<finddigits>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x28,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
movl   $0x1,(%rax)
lea    0xeab(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
subl   $0x1,0x4(%rsp)
jae    1177 <finddigits+0x47>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xcccccccd,%r13d
lea    0xe7f(%rip),%r12
jmp    119f <finddigits+0x6f>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <printf@plt>
subl   $0x1,0x4(%rsp)
jb     1166 <finddigits+0x36>
lea    0xe5a(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
movslq (%rsp),%rax
mov    %eax,%r11d
not    %r11d
and    $0x1,%r11d
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
mov    %eax,%r8d
sub    %ecx,%r8d
mov    %eax,%r9d
and    $0x3,%r9d
imul   $0x66666667,%rax,%rdi
mov    %rdi,%rcx
shr    $0x20,%rcx
sar    %ecx
mov    %rdi,%rsi
shr    $0x3f,%rsi
add    %esi,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%r10d
sub    %ecx,%r10d
imul   $0x2aaaaaab,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,2),%edx
mov    %eax,%ecx
sub    %edx,%ecx
imul   $0xffffffff92492493,%rax,%rdx
shr    $0x20,%rdx
add    %eax,%edx
mov    %edx,%ebp
shr    $0x1f,%ebp
sar    $0x2,%edx
add    %ebp,%edx
lea    0x0(,%rdx,8),%ebp
sub    %ebp,%edx
add    %eax,%edx
mov    %eax,%ebp
and    $0x7,%ebp
imul   $0x38e38e39,%rax,%rbx
mov    %rbx,%r14
shr    $0x3f,%r14
sar    $0x21,%rbx
add    %r14d,%ebx
lea    (%rbx,%rbx,8),%ebx
mov    %eax,%r14d
sub    %ebx,%r14d
sar    $0x22,%rdi
add    %esi,%edi
add    %edi,%edi
lea    (%rdi,%rdi,4),%esi
mov    %eax,%edi
sub    %esi,%edi
mov    %r11d,0x4(%r15)
movd   %ecx,%xmm0
movd   %r10d,%xmm1
punpckldq %xmm0,%xmm1
movd   %r8d,%xmm0
movd   %r9d,%xmm2
punpckldq %xmm2,%xmm0
punpcklqdq %xmm1,%xmm0
pxor   %xmm3,%xmm3
pcmpeqd %xmm3,%xmm0
psrld  $0x1f,%xmm0
movdqu %xmm0,0x8(%r15)
movd   %edx,%xmm0
movd   %ebp,%xmm1
punpckldq %xmm1,%xmm0
movd   %r14d,%xmm1
movd   %edi,%xmm2
punpckldq %xmm2,%xmm1
punpcklqdq %xmm1,%xmm0
pcmpeqd %xmm3,%xmm0
psrld  $0x1f,%xmm0
movdqu %xmm0,0x18(%r15)
xor    %esi,%esi
test   %rax,%rax
jle    1190 <finddigits+0x60>
mov    %eax,%ecx
mov    %eax,%eax
imul   %r13,%rax
shr    $0x23,%rax
lea    (%rax,%rax,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%edi
sub    %edx,%edi
movslq %edi,%rdx
cmpl   $0x1,-0x4(%r15,%rdx,4)
sbb    $0xffffffff,%esi
cmp    $0x9,%ecx
ja     12e0 <finddigits+0x1b0>
mov    %eax,(%rsp)
jmp    1190 <finddigits+0x60>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @finddigits() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = tail call i32* @malloc(i32 40)
store i32 1, i32* %4
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp eq i32 %6, 0
br i1 %8, label %62, label %9
9: ; preds = %0
%10 = bitcast i32* %2 to i8*
%11 = getelementptr inbounds i32, i32* %4, i64 1
%12 = getelementptr inbounds i32, i32* %4, i64 2
%13 = getelementptr inbounds i32, i32* %4, i64 6
%14 = bitcast i32* %12 to <4 x i32>*
%15 = bitcast i32* %13 to <4 x i32>*
br label %16
16: ; preds = %9, %56
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%18 = load i32, i32* %2
%19 = and i32 %18, 1
%20 = xor i32 %19, 1
store i32 %20, i32* %11
%21 = srem i32 %18, 3
%22 = and i32 %18, 3
%23 = srem i32 %18, 5
%24 = srem i32 %18, 6
%25 = insertelement <4 x i32> poison, i32 %21, i64 0
%26 = insertelement <4 x i32> %25, i32 %22, i64 1
%27 = insertelement <4 x i32> %26, i32 %23, i64 2
%28 = insertelement <4 x i32> %27, i32 %24, i64 3
%29 = icmp eq <4 x i32> %28, zeroinitializer
%30 = zext <4 x i1> %29 to <4 x i32>
store <4 x i32> %30, <4 x i32>* %14
%31 = srem i32 %18, 7
%32 = and i32 %18, 7
%33 = srem i32 %18, 9
%34 = srem i32 %18, 10
%35 = insertelement <4 x i32> poison, i32 %31, i64 0
%36 = insertelement <4 x i32> %35, i32 %32, i64 1
%37 = insertelement <4 x i32> %36, i32 %33, i64 2
%38 = insertelement <4 x i32> %37, i32 %34, i64 3
%39 = icmp eq <4 x i32> %38, zeroinitializer
%40 = zext <4 x i1> %39 to <4 x i32>
store <4 x i32> %40, <4 x i32>* %15
%41 = icmp sgt i32 %18, 0
br i1 %41, label %42, label %56
42: ; preds = %16, %42
%43 = phi i32 [ %52, %42 ], [ 0, %16 ]
%44 = phi i32 [ %53, %42 ], [ %18, %16 ]
%45 = urem i32 %44, 10
%46 = add nsw i32 %45, -1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %4, i64 %47
%49 = load i32, i32* %48
%50 = icmp ne i32 %49, 0
%51 = zext i1 %50 to i32
%52 = add nuw nsw i32 %43, %51
%53 = udiv i32 %44, 10
%54 = icmp ult i32 %44, 10
br i1 %54, label %55, label %42
55: ; preds = %42
store i32 %53, i32* %2
br label %56
56: ; preds = %55, %16
%57 = phi i32 [ %52, %55 ], [ 0, %16 ]
%58 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %1
%60 = add nsw i32 %59, -1
store i32 %60, i32* %1
%61 = icmp eq i32 %59, 0
br i1 %61, label %62, label %16
62: ; preds = %56, %0
ret i32 0
}