#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 *);
int main() {
  int num, digit[10] = {}, i;
  printf("Enter an integer :: ");
  scanf("%d", &num);
  if (num <= 0)
    return -1;
  while (num > 0) {
    i = num % 10;
    digit[i]++;
    num /= 10;
  }
  printf("digit\thow many?");
  for (i = 0; i < 10; i++)
    if (digit[i] != 0)
      printf("\n%d\t%d", i, digit[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec5(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jg     1183 <main+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    1223 <main+0xf3>
jmp    1188 <main+0x58>
cmpl   $0x0,-0x8(%rbp)
jle    11c2 <main+0x92>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x34(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1188 <main+0x58>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    121c <main+0xec>
movslq -0x34(%rbp),%rax
cmpl   $0x0,-0x30(%rbp,%rax,4)
je     1209 <main+0xd9>
mov    -0x34(%rbp),%esi
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%edx
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120e <main+0xde>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d7 <main+0xa7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x30(%rsp)
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xed9(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    12b1 <main+0x191>
mov    $0xcccccccd,%ecx
nopl   0x0(%rax,%rax,1)
mov    %eax,%edx
mov    %eax,%eax
imul   %rcx,%rax
shr    $0x23,%rax
lea    (%rax,%rax,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %edx,%edi
sub    %esi,%edi
addl   $0x1,0x10(%rsp,%rdi,4)
cmp    $0x9,%edx
ja     1170 <main+0x50>
mov    %eax,0xc(%rsp)
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%edx
test   %edx,%edx
je     11ba <main+0x9a>
lea    0xe74(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x14(%rsp),%edx
test   %edx,%edx
je     11d5 <main+0xb5>
lea    0xe5c(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x18(%rsp),%edx
test   %edx,%edx
je     11f0 <main+0xd0>
lea    0xe41(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x1c(%rsp),%edx
test   %edx,%edx
je     120b <main+0xeb>
lea    0xe26(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x20(%rsp),%edx
test   %edx,%edx
je     1226 <main+0x106>
lea    0xe0b(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x24(%rsp),%edx
test   %edx,%edx
je     1241 <main+0x121>
lea    0xdf0(%rip),%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x28(%rsp),%edx
test   %edx,%edx
je     125c <main+0x13c>
lea    0xdd5(%rip),%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2c(%rsp),%edx
test   %edx,%edx
je     1277 <main+0x157>
lea    0xdba(%rip),%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x30(%rsp),%edx
test   %edx,%edx
je     1292 <main+0x172>
lea    0xd9f(%rip),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x34(%rsp),%edx
test   %edx,%edx
je     12b8 <main+0x198>
lea    0xd84(%rip),%rdi
xor    %ebx,%ebx
mov    $0x9,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    12ba <main+0x19a>
mov    $0xffffffff,%ebx
jmp    12ba <main+0x19a>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [21 x i8] c"Enter an integer :: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [16 x i8] c"digit\09how many?\00"
@.str.3 = [7 x i8] c"\0A%d\09%d\00"
define i32 @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 ([21 x i8], [21 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 slt i32 %7, 1
br i1 %8, label %79, label %9
9: ; preds = %0, %9
%10 = phi i32 [ %16, %9 ], [ %7, %0 ]
%11 = urem i32 %10, 10
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
store i32 %15, i32* %13
%16 = udiv i32 %10, 10
%17 = icmp ult i32 %10, 10
br i1 %17, label %18, label %9
18: ; preds = %9
store i32 %16, i32* %1
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 %21)
br label %25
25: ; preds = %18, %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 ([7 x i8], [7 x i8]* @.str.3, 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 ([7 x i8], [7 x i8]* @.str.3, 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 ([7 x i8], [7 x i8]* @.str.3, 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 ([7 x i8], [7 x i8]* @.str.3, 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 ([7 x i8], [7 x i8]* @.str.3, 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 ([7 x i8], [7 x i8]* @.str.3, 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 ([7 x i8], [7 x i8]* @.str.3, 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 ([7 x i8], [7 x i8]* @.str.3, 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 ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 9, i32 %75)
br label %79
79: ; preds = %73, %77, %0
%80 = phi i32 [ -1, %0 ], [ 0, %77 ], [ 0, %73 ]
ret i32 %80
}