#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 *);
void main() {
  int n, i, a;
  printf("n=");
  scanf("%d", &n);
  printf("a=");
  scanf("%d", &a);
  i = 0;
  while (n > 0) {
    if (n % 10 == a)
      i++;
    n = n / 10;
  }
  printf("i=%d", i);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xead(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    11a5 <main+0x85>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    -0xc(%rbp),%edx
jne    1192 <main+0x72>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    116b <main+0x4b>
mov    -0x8(%rbp),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xed5(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xecd(%rip),%r14
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <scanf@plt>
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
call   1040 <scanf@plt>
mov    (%rsp),%eax
test   %eax,%eax
jle    11a8 <main+0x88>
xor    %ebx,%ebx
mov    0x4(%rsp),%ecx
mov    $0xcccccccd,%r8d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%edx
mov    %eax,%eax
imul   %r8,%rax
shr    $0x23,%rax
lea    (%rax,%rax,1),%edi
lea    (%rdi,%rdi,4),%edi
mov    %edx,%esi
sub    %edi,%esi
xor    %edi,%edi
cmp    %ecx,%esi
sete   %dil
add    %edi,%ebx
cmp    $0x9,%edx
ja     1180 <main+0x60>
mov    %eax,(%rsp)
lea    0xe57(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"n=\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"a=\00"
@.str.3 = [5 x i8] c"i=%d\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
store i32 0, i32* %2
br label %8
8: ; preds = %19, %0
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %8
%12 = load i32, i32* %1
%13 = srem i32 %12, 10
%14 = load i32, i32* %3
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
br label %19
19: ; preds = %16, %11
%20 = load i32, i32* %1
%21 = sdiv i32 %20, 10
store i32 %21, i32* %1
br label %8
22: ; preds = %8
%23 = load i32, i32* %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %23)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"n=\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [3 x i8] c"a=\00"
@.str.3 = [5 x i8] c"i=%d\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %0
%12 = load i32, i32* %2
br label %13
13: ; preds = %11, %13
%14 = phi i32 [ 0, %11 ], [ %19, %13 ]
%15 = phi i32 [ %9, %11 ], [ %20, %13 ]
%16 = urem i32 %15, 10
%17 = icmp eq i32 %16, %12
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %14, %18
%20 = udiv i32 %15, 10
%21 = icmp ult i32 %15, 10
br i1 %21, label %22, label %13
22: ; preds = %13
store i32 %20, i32* %1
br label %23
23: ; preds = %22, %0
%24 = phi i32 [ %19, %22 ], [ 0, %0 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %24)
ret void
}