#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, digits[10] = {0}, i;
  printf("Enter a number: ");
  scanf("%d", &n);
  while (n != 0) {
    digits[n % 10]++;
    n /= 10;
  }
  for (i = 0; i < 10; i++) {
    if (digits[i] != 0)
      printf("The digit %d is encountered %d time(s)\n", i, digits[i]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb4(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x4(%rbp)
je     119c <main+0x6c>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x30(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1166 <main+0x36>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    11e8 <main+0xb8>
movslq -0x34(%rbp),%rax
cmpl   $0x0,-0x30(%rbp,%rax,4)
je     11d5 <main+0xa5>
mov    -0x34(%rbp),%esi
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11da <main+0xaa>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a3 <main+0x73>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x38,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x30(%rsp)
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec2(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     11bd <main+0x9d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movslq %eax,%rcx
imul   $0x66666667,%rcx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rax
add    %edx,%eax
lea    (%rax,%rax,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
movslq %esi,%rdx
addl   $0x1,0x10(%rsp,%rdx,4)
add    $0x9,%ecx
cmp    $0x13,%ecx
jae    1170 <main+0x50>
mov    %eax,0xc(%rsp)
mov    0x10(%rsp),%edx
test   %edx,%edx
je     11bd <main+0x9d>
lea    0xe60(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x14(%rsp),%edx
test   %edx,%edx
je     11d8 <main+0xb8>
lea    0xe48(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x18(%rsp),%edx
test   %edx,%edx
je     11f3 <main+0xd3>
lea    0xe2d(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x1c(%rsp),%edx
test   %edx,%edx
je     120e <main+0xee>
lea    0xe12(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x20(%rsp),%edx
test   %edx,%edx
je     1229 <main+0x109>
lea    0xdf7(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x24(%rsp),%edx
test   %edx,%edx
je     1244 <main+0x124>
lea    0xddc(%rip),%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x28(%rsp),%edx
test   %edx,%edx
je     125f <main+0x13f>
lea    0xdc1(%rip),%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2c(%rsp),%edx
test   %edx,%edx
je     127a <main+0x15a>
lea    0xda6(%rip),%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x30(%rsp),%edx
test   %edx,%edx
je     1295 <main+0x175>
lea    0xd8b(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x34(%rsp),%edx
test   %edx,%edx
je     12b0 <main+0x190>
lea    0xd70(%rip),%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x38,%rsp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [40 x i8] c"The digit %d is encountered %d time(s)\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = bitcast [10 x i32]* %2 to i8*
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 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)
br label %7
7: ; preds = %10, %0
%8 = load i32, i32* %1
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = load i32, i32* %1
%12 = srem i32 %11, 10
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
store i32 %16, i32* %14
%17 = load i32, i32* %1
%18 = sdiv i32 %17, 10
store i32 %18, i32* %1
br label %7
19: ; preds = %7
store i32 0, i32* %3
br label %20
20: ; preds = %37, %19
%21 = load i32, i32* %3
%22 = icmp slt i32 %21, 10
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %23
%30 = load i32, i32* %3
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %34)
br label %36
36: ; preds = %29, %23
br label %37
37: ; preds = %36
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %20
40: ; preds = %20
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [40 x i8] c"The digit %d is encountered %d time(s)\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [10 x i32]* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 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 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
br i1 %8, label %25, label %13
9: ; preds = %13
store i32 %20, i32* %1
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 0
br i1 %12, label %25, label %23
13: ; preds = %0, %13
%14 = phi i32 [ %20, %13 ], [ %7, %0 ]
%15 = srem i32 %14, 10
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %17
%20 = sdiv i32 %14, 10
%21 = add i32 %14, 9
%22 = icmp ult i32 %21, 19
br i1 %22, label %9, label %13
23: ; preds = %9
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 %11)
br label %25
25: ; preds = %0, %9, %23
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 1
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %27)
br label %31
31: ; preds = %29, %25
%32 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 2
%33 = load i32, i32* %32
%34 = icmp eq i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 %33)
br label %37
37: ; preds = %35, %31
%38 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 3
%39 = load i32, i32* %38
%40 = icmp eq i32 %39, 0
br i1 %40, label %43, label %41
41: ; preds = %37
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 %39)
br label %43
43: ; preds = %41, %37
%44 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 4
%45 = load i32, i32* %44
%46 = icmp eq i32 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %43
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 4, i32 %45)
br label %49
49: ; preds = %47, %43
%50 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 5
%51 = load i32, i32* %50
%52 = icmp eq i32 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %49
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 5, i32 %51)
br label %55
55: ; preds = %53, %49
%56 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 6
%57 = load i32, i32* %56
%58 = icmp eq i32 %57, 0
br i1 %58, label %61, label %59
59: ; preds = %55
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 6, i32 %57)
br label %61
61: ; preds = %59, %55
%62 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 7
%63 = load i32, i32* %62
%64 = icmp eq i32 %63, 0
br i1 %64, label %67, label %65
65: ; preds = %61
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 7, i32 %63)
br label %67
67: ; preds = %65, %61
%68 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 8
%69 = load i32, i32* %68
%70 = icmp eq i32 %69, 0
br i1 %70, label %73, label %71
71: ; preds = %67
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 8, i32 %69)
br label %73
73: ; preds = %71, %67
%74 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 9
%75 = load i32, i32* %74
%76 = icmp eq i32 %75, 0
br i1 %76, label %79, label %77
77: ; preds = %73
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i32 9, i32 %75)
br label %79
79: ; preds = %77, %73
ret void
}