#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 fmod(int, int);
int /*<<< orphan*/ getchar();
int power(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int num;
  int frac = 1;
  int digit = 1;
  printf("Enter a number: ");
  scanf("%d", &num);
  while (1) {
    frac = num / power(10, digit);
    if (frac == 0)
      break;
    digit += 1;
  }
  printf("the digit is: %d\n\n", digit);
  int j;
  int n1 = 0;
  for (j = 0; j < digit; j++) {
    int base = power(10, j + 1);
    printf("The base is: %d\n", base);
    int fra = num / base;
    printf("The fra is: %d\n", fra);
    int mod = fmod(num, base);
    printf("The mod is: %d\n", mod);
    int quan = power(10, j);
    printf("The quan is: %d\n", quan);
    n1 += fra * quan;
    if (mod > 2 * quan - 1) {
      n1 += quan;
      printf("A\n");
    }
    if (2 * quan > mod > quan - 1) {
      n1 += mod - quan + 1;
      printf("B\n");
    }
    printf("The n1 is: %d\n\n", n1);
  }
  printf("The number of ones is: %d\n", n1);
  getchar();
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe88(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%esi
mov    $0xa,%edi
call   1030 <power@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11bf <main+0x6f>
jmp    11cd <main+0x7d>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1192 <main+0x42>
mov    -0x1c(%rbp),%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    130a <main+0x1ba>
mov    -0x20(%rbp),%esi
add    $0x1,%esi
mov    $0xa,%edi
call   1030 <power@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x28(%rbp)
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1050 <fmod@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%esi
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%esi
mov    $0xa,%edi
call   1030 <power@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
imul   -0x34(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x34(%rbp),%ecx
shl    $0x1,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    12af <main+0x15f>
mov    -0x34(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
shl    $0x1,%eax
cmp    -0x30(%rbp),%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    12eb <main+0x19b>
mov    -0x30(%rbp),%eax
sub    -0x34(%rbp),%eax
add    $0x1,%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11ec <main+0x9c>
mov    -0x24(%rbp),%esi
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    $0x0,%al
call   1060 <getchar@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    $0x18,%rsp
lea    0xe8b(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe8b(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
add    $0x1,%r14d
mov    0xc(%rsp),%ebp
mov    $0xa,%edi
mov    %r14d,%esi
call   1030 <power@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
test   %eax,%eax
jne    1190 <main+0x30>
lea    0xe5d(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    11ee <main+0x8e>
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp),%ebx
lea    0xe8e(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    %ebx,%r14d
je     12bd <main+0x15d>
mov    %r15d,0x14(%rsp)
mov    %ebx,%r13d
lea    0x1(%r13),%esi
mov    $0xa,%edi
mov    %esi,0x10(%rsp)
call   1030 <power@plt>
mov    %eax,%ebp
lea    0xe16(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%eax
cltd
idiv   %ebp
mov    %eax,%r15d
lea    0xe0d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
mov    %ebp,%esi
call   1060 <fmod@plt>
mov    %eax,%r12d
lea    0xdff(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
mov    %r13d,%esi
call   1030 <power@plt>
mov    %eax,%ebp
lea    0xdf0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
imul   %ebp,%r15d
add    0x14(%rsp),%r15d
lea    0x0(%rbp,%rbp,1),%ebx
cmp    %ebx,%r12d
jl     1292 <main+0x132>
add    %ebp,%r15d
lea    0xe09(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
cmp    %ebx,%r12d
setl   %al
cmp    %eax,%ebp
jg     11d0 <main+0x70>
sub    %ebp,%r12d
add    %r12d,%r15d
add    $0x1,%r15d
lea    0xde1(%rip),%rdi
call   1040 <puts@plt>
jmp    11d0 <main+0x70>
lea    0xdb5(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
add    $0x18,%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 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"the digit is: %d\0A\0A\00"
@.str.3 = [17 x i8] c"The base is: %d\0A\00"
@.str.4 = [16 x i8] c"The fra is: %d\0A\00"
@.str.5 = [16 x i8] c"The mod is: %d\0A\00"
@.str.6 = [17 x i8] c"The quan is: %d\0A\00"
@.str.7 = [3 x i8] c"A\0A\00"
@.str.8 = [3 x i8] c"B\0A\00"
@.str.9 = [16 x i8] c"The n1 is: %d\0A\0A\00"
@.str.10 = [27 x i8] c"The number of ones is: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
store i32 1, i32* %8
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
br label %17
17: ; preds = %2, %25
%18 = load i32, i32* %6
%19 = load i32, i32* %8
%20 = call i32 @power(i32 10, i32 %19)
%21 = sdiv i32 %18, %20
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %17
br label %28
25: ; preds = %17
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
br label %17
28: ; preds = %24
%29 = load i32, i32* %8
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %29)
store i32 0, i32* %10
store i32 0, i32* %9
br label %31
31: ; preds = %90, %28
%32 = load i32, i32* %9
%33 = load i32, i32* %8
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %93
35: ; preds = %31
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
%38 = call i32 @power(i32 10, i32 %37)
store i32 %38, i32* %11
%39 = load i32, i32* %11
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %6
%42 = load i32, i32* %11
%43 = sdiv i32 %41, %42
store i32 %43, i32* %12
%44 = load i32, i32* %12
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %6
%47 = load i32, i32* %11
%48 = call i32 @fmod(i32 %46, i32 %47)
store i32 %48, i32* %13
%49 = load i32, i32* %13
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %9
%52 = call i32 @power(i32 10, i32 %51)
store i32 %52, i32* %14
%53 = load i32, i32* %14
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %53)
%55 = load i32, i32* %12
%56 = load i32, i32* %14
%57 = mul nsw i32 %55, %56
%58 = load i32, i32* %10
%59 = add nsw i32 %58, %57
store i32 %59, i32* %10
%60 = load i32, i32* %13
%61 = load i32, i32* %14
%62 = mul nsw i32 2, %61
%63 = sub nsw i32 %62, 1
%64 = icmp sgt i32 %60, %63
br i1 %64, label %65, label %70
65: ; preds = %35
%66 = load i32, i32* %14
%67 = load i32, i32* %10
%68 = add nsw i32 %67, %66
store i32 %68, i32* %10
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %70
70: ; preds = %65, %35
%71 = load i32, i32* %14
%72 = mul nsw i32 2, %71
%73 = load i32, i32* %13
%74 = icmp sgt i32 %72, %73
%75 = zext i1 %74 to i32
%76 = load i32, i32* %14
%77 = sub nsw i32 %76, 1
%78 = icmp sgt i32 %75, %77
br i1 %78, label %79, label %87
79: ; preds = %70
%80 = load i32, i32* %13
%81 = load i32, i32* %14
%82 = sub nsw i32 %80, %81
%83 = add nsw i32 %82, 1
%84 = load i32, i32* %10
%85 = add nsw i32 %84, %83
store i32 %85, i32* %10
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
br label %87
87: ; preds = %79, %70
%88 = load i32, i32* %10
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %88)
br label %90
90: ; preds = %87
%91 = load i32, i32* %9
%92 = add nsw i32 %91, 1
store i32 %92, i32* %9
br label %31
93: ; preds = %31
%94 = load i32, i32* %10
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %94)
%96 = call i32 (...) @getchar()
%97 = call i32 (...) @getchar()
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"Enter a number: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [19 x i8] c"the digit is: %d\0A\0A\00"
@.str.3 = [17 x i8] c"The base is: %d\0A\00"
@.str.4 = [16 x i8] c"The fra is: %d\0A\00"
@.str.5 = [16 x i8] c"The mod is: %d\0A\00"
@.str.6 = [17 x i8] c"The quan is: %d\0A\00"
@.str.9 = [16 x i8] c"The n1 is: %d\0A\0A\00"
@.str.10 = [27 x i8] c"The number of ones is: %d\0A\00"
@str = [2 x i8] c"B\00"
@str.11 = [2 x i8] c"A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 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* %3)
br label %7
7: ; preds = %7, %2
%8 = phi i32 [ 1, %2 ], [ %13, %7 ]
%9 = load i32, i32* %3
%10 = call i32 @power(i32 10, i32 %8)
%11 = sdiv i32 %9, %10
%12 = icmp eq i32 %11, 0
%13 = add nuw nsw i32 %8, 1
br i1 %12, label %14, label %7
14: ; preds = %7
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %8)
br label %16
16: ; preds = %14, %46
%17 = phi i32 [ 0, %14 ], [ %19, %46 ]
%18 = phi i32 [ 0, %14 ], [ %47, %46 ]
%19 = add nuw nsw i32 %17, 1
%20 = call i32 @power(i32 10, i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %3
%23 = sdiv i32 %22, %20
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %3
%26 = call i32 @fmod(i32 %25, i32 %20)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = call i32 @power(i32 10, i32 %17)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 %28)
%30 = mul nsw i32 %28, %23
%31 = add nsw i32 %30, %18
%32 = shl nsw i32 %28, 1
%33 = icmp slt i32 %26, %32
br i1 %33, label %37, label %34
34: ; preds = %16
%35 = add nsw i32 %31, %28
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.11, i64 0, i64 0))
br label %37
37: ; preds = %34, %16
%38 = phi i32 [ %35, %34 ], [ %31, %16 ]
%39 = zext i1 %33 to i32
%40 = icmp sgt i32 %28, %39
br i1 %40, label %46, label %41
41: ; preds = %37
%42 = add i32 %26, 1
%43 = sub i32 %42, %28
%44 = add i32 %43, %38
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %46
46: ; preds = %41, %37
%47 = phi i32 [ %44, %41 ], [ %38, %37 ]
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %47)
%49 = icmp eq i32 %19, %8
br i1 %49, label %50, label %16
50: ; preds = %46
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %47)
%52 = call i32 (...) @getchar()
%53 = call i32 (...) @getchar()
ret i32 0
}