#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 *, long *);
int main(void) {
  int digit_seen[10] = {0};
  int digit, i;
  long n;
  printf("Enter a number: ");
  scanf("%ld", &n);
  while (n > 0) {
    digit = n % 10;
    ++digit_seen[digit];
    n /= 10;
  }
  printf("Digit:\t\t");
  for (i = 0; i < 10; i++)
    printf("%3d", i);
  printf("\nOccurrences: \t");
  for (i = 0; i < 10; i++) {
    printf("%3d", digit_seen[i]);
  }
  printf("\n");
  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    0xead(%rip),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <scanf@plt>
cmpq   $0x0,-0x40(%rbp)
jle    11b1 <main+0x81>
mov    -0x40(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x30(%rbp,%rax,4)
mov    -0x40(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x40(%rbp)
jmp    116d <main+0x3d>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x38(%rbp)
cmpl   $0xa,-0x38(%rbp)
jge    11ef <main+0xbf>
mov    -0x38(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11c6 <main+0x96>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x38(%rbp)
cmpl   $0xa,-0x38(%rbp)
jge    1232 <main+0x102>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1204 <main+0xd4>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x40(%rsp)
lea    0xea5(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
lea    0x18(%rsp),%rsi
call   1050 <scanf@plt>
mov    0x18(%rsp),%rdx
mov    $0x0,%ecx
mov    $0x0,%esi
mov    $0x0,%eax
mov    $0x0,%edi
mov    $0x0,%ebp
mov    $0x0,%r15d
mov    $0x0,%r12d
mov    $0x0,%r13d
test   %rdx,%rdx
jle    1212 <main+0xe2>
movabs $0xcccccccccccccccd,%rsi
cc cc cc
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rdx,%rcx
mov    %rdx,%rax
mul    %rsi
shr    $0x3,%rdx
lea    (%rdx,%rdx,1),%rax
lea    (%rax,%rax,4),%rax
mov    %rcx,%rdi
sub    %rax,%rdi
addl   $0x1,0x20(%rsp,%rdi,4)
cmp    $0x9,%rcx
ja     11c0 <main+0x90>
mov    %rdx,0x18(%rsp)
mov    0x20(%rsp),%r13d
mov    0x24(%rsp),%r12d
mov    0x28(%rsp),%r15d
mov    0x2c(%rsp),%ebp
mov    0x30(%rsp),%edi
mov    0x34(%rsp),%eax
mov    0x38(%rsp),%esi
mov    0x3c(%rsp),%ecx
mov    0x40(%rsp),%ebx
mov    %edi,0x8(%rsp)
mov    %eax,0xc(%rsp)
mov    %esi,0x10(%rsp)
mov    %ecx,0x14(%rsp)
lea    0xdec(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xde7(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd51(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    0x8(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    0xc(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    0x10(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    0x14(%rsp),%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x44(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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