#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 pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf_s(char *, int *);
int /*<<< orphan*/ system(char *);
main() {
  int number, x, i, digit = 0;
  int count = 0;
  int temp;
  int k;
  printf("Enter a number: ");
  scanf_s("%d", &number);
  temp = number;
  while (temp > 0) {
    digit++;
    temp = temp / 10;
  }
  printf("Number of digits is : %d\n", digit);
  i = 0;
  k = pow(10, digit - 1);
  while (i < digit) {
    x = number / k;
    printf("%d", x);
    number = number % k;
    k = k / 10;
    i++;
  }
  printf("\n");
  printf("\n");
  system("pause");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9f(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf_s@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11a7 <main+0x67>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
jmp    1181 <main+0x41>
mov    -0x14(%rbp),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    $0xa,%edi
call   1060 <pow@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121f <main+0xdf>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %edx,-0x8(%rbp)
mov    -0x20(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11d2 <main+0x92>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdec(%rip),%rdi
call   1030 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xea0(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xea0(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf_s@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11a5 <main+0x55>
xor    %r14d,%r14d
mov    $0xcccccccd,%ecx
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14d
mov    %eax,%edx
imul   %rcx,%rdx
shr    $0x23,%rdx
cmp    $0x9,%eax
mov    %edx,%eax
ja     1190 <main+0x40>
lea    0xe68(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    -0x1(%r14),%esi
mov    $0xa,%edi
call   1070 <pow@plt>
cmp    $0x1,%r14d
jb     1219 <main+0xc9>
mov    %eax,%ebx
mov    0xc(%rsp),%edx
lea    0xe3a(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %edx,%eax
cltd
idiv   %ebx
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
cltd
idiv   %ebx
mov    %edx,0xc(%rsp)
movslq %ebx,%rax
imul   $0x66666667,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
add    $0xffffffff,%r14d
jne    11e0 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdfa(%rip),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [26 x i8] c"Number of digits is : %d\0A\00"
@.str.4 = [6 x i8] c"pause\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf_s(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %0, %7
%8 = phi i32 [ %11, %7 ], [ %5, %0 ]
%9 = phi i32 [ %10, %7 ], [ 0, %0 ]
%10 = add nuw nsw i32 %9, 1
%11 = udiv i32 %8, 10
%12 = icmp ult i32 %8, 10
br i1 %12, label %13, label %7
13: ; preds = %7, %0
%14 = phi i32 [ 0, %0 ], [ %10, %7 ]
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = add nsw i32 %14, -1
%17 = call i32 @pow(i32 10, i32 %16)
%18 = icmp eq i32 %14, 0
br i1 %18, label %32, label %19
19: ; preds = %13
%20 = load i32, i32* %1
br label %21
21: ; preds = %19, %21
%22 = phi i32 [ %28, %21 ], [ %20, %19 ]
%23 = phi i32 [ %29, %21 ], [ %17, %19 ]
%24 = phi i32 [ %30, %21 ], [ 0, %19 ]
%25 = sdiv i32 %22, %23
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %1
%28 = srem i32 %27, %23
store i32 %28, i32* %1
%29 = sdiv i32 %23, 10
%30 = add nuw i32 %24, 1
%31 = icmp eq i32 %30, %14
br i1 %31, label %32, label %21
32: ; preds = %21, %13
%33 = call i32 @putchar(i32 10)
%34 = call i32 @putchar(i32 10)
%35 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}