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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea6(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     12c8 <main+0x188>
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    $0xa,%edi
call   1030 <power@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x24(%rbp)
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    -0x24(%rbp),%ecx
imul   -0x28(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
mov    $0xa,%edi
call   1030 <power@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%esi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%eax
imul   -0x30(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x30(%rbp),%ecx
shl    $0x1,%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    1259 <main+0x119>
mov    -0x30(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%esi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1295 <main+0x155>
mov    -0x2c(%rbp),%eax
mov    -0x30(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    1290 <main+0x150>
mov    -0x2c(%rbp),%eax
sub    -0x30(%rbp),%eax
add    $0x1,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x2c(%rbp),%esi
sub    -0x30(%rbp),%esi
add    $0x1,%esi
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1295 <main+0x155>
mov    -0x20(%rbp),%esi
sub    -0x1c(%rbp),%esi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1189 <main+0x49>
mov    -0x20(%rbp),%esi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    $0x1,%ebx
xor    %r12d,%r12d
jmp    11c4 <main+0x84>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    %ebp,%r12d
lea    0xecc(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%esi
sub    %r14d,%esi
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
test   %r15d,%r15d
je     1278 <main+0x138>
mov    %r12d,%r14d
lea    -0x1(%rbx),%r12d
mov    $0xa,%edi
mov    %ebx,%esi
call   1030 <power@plt>
mov    %eax,%ebp
lea    0xe34(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%eax
cltd
idiv   %ebp
mov    %eax,%r15d
lea    0xe2b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x4(%rsp),%r13d
imul   %r15d,%ebp
sub    %ebp,%r13d
lea    0xe1f(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
mov    %r12d,%esi
call   1030 <power@plt>
mov    %eax,%ebp
lea    0xe0f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%r12d
imul   %r15d,%r12d
add    %r14d,%r12d
lea    0x0(%rbp,%rbp,1),%eax
cmp    %eax,%r13d
jge    1180 <main+0x40>
sub    %ebp,%r13d
jl     1193 <main+0x53>
mov    %r13d,%esi
add    $0x1,%esi
add    %r13d,%r12d
add    $0x1,%r12d
lea    0xdea(%rip),%rdi
jmp    118c <main+0x4c>
lea    0xe06(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x8,%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 = [17 x i8] c"The base is: %d\0A\00"
@.str.3 = [16 x i8] c"The fra is: %d\0A\00"
@.str.4 = [16 x i8] c"The mod is: %d\0A\00"
@.str.5 = [17 x i8] c"The quan is: %d\0A\00"
@.str.6 = [7 x i8] c"A: %d\0A\00"
@.str.7 = [7 x i8] c"B: %d\0A\00"
@.str.8 = [17 x i8] c"The diff 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"
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
store i32 0, i32* %7
store i32 0, i32* %9
store i32 1, i32* %11
br label %16
16: ; preds = %76, %2
%17 = load i32, i32* %11
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %85
19: ; preds = %16
%20 = load i32, i32* %7
%21 = add nsw i32 %20, 1
%22 = call i32 @power(i32 10, i32 %21)
store i32 %22, i32* %10
%23 = load i32, i32* %10
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %6
%26 = load i32, i32* %10
%27 = sdiv i32 %25, %26
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %6
%31 = load i32, i32* %10
%32 = load i32, i32* %11
%33 = mul nsw i32 %31, %32
%34 = sub nsw i32 %30, %33
store i32 %34, i32* %12
%35 = load i32, i32* %12
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %35)
%37 = load i32, i32* %7
%38 = call i32 @power(i32 10, i32 %37)
store i32 %38, i32* %13
%39 = load i32, i32* %13
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %9
store i32 %41, i32* %8
%42 = load i32, i32* %11
%43 = load i32, i32* %13
%44 = mul nsw i32 %42, %43
%45 = load i32, i32* %9
%46 = add nsw i32 %45, %44
store i32 %46, i32* %9
%47 = load i32, i32* %12
%48 = load i32, i32* %13
%49 = mul nsw i32 2, %48
%50 = sub nsw i32 %49, 1
%51 = icmp sgt i32 %47, %50
br i1 %51, label %52, label %58
52: ; preds = %19
%53 = load i32, i32* %13
%54 = load i32, i32* %9
%55 = add nsw i32 %54, %53
store i32 %55, i32* %9
%56 = load i32, i32* %13
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %56)
br label %76
58: ; preds = %19
%59 = load i32, i32* %12
%60 = load i32, i32* %13
%61 = sub nsw i32 %60, 1
%62 = icmp sgt i32 %59, %61
br i1 %62, label %63, label %75
63: ; preds = %58
%64 = load i32, i32* %12
%65 = load i32, i32* %13
%66 = sub nsw i32 %64, %65
%67 = add nsw i32 %66, 1
%68 = load i32, i32* %9
%69 = add nsw i32 %68, %67
store i32 %69, i32* %9
%70 = load i32, i32* %12
%71 = load i32, i32* %13
%72 = sub nsw i32 %70, %71
%73 = add nsw i32 %72, 1
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %63, %58
br label %76
76: ; preds = %75, %52
%77 = load i32, i32* %9
%78 = load i32, i32* %8
%79 = sub nsw i32 %77, %78
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %79)
%81 = load i32, i32* %9
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %81)
%83 = load i32, i32* %7
%84 = add nsw i32 %83, 1
store i32 %84, i32* %7
br label %16
85: ; preds = %16
%86 = load i32, i32* %9
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %86)
%88 = call i32 (...) @getchar()
%89 = 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 = [17 x i8] c"The base is: %d\0A\00"
@.str.3 = [16 x i8] c"The fra is: %d\0A\00"
@.str.4 = [16 x i8] c"The mod is: %d\0A\00"
@.str.5 = [17 x i8] c"The quan is: %d\0A\00"
@.str.6 = [7 x i8] c"A: %d\0A\00"
@.str.7 = [7 x i8] c"B: %d\0A\00"
@.str.8 = [17 x i8] c"The diff 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"
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 = %2, %36
%8 = phi i32 [ 0, %2 ], [ %10, %36 ]
%9 = phi i32 [ 0, %2 ], [ %37, %36 ]
%10 = add nuw nsw i32 %8, 1
%11 = call i32 @power(i32 10, i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %3
%14 = sdiv i32 %13, %11
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %3
%17 = mul nsw i32 %14, %11
%18 = sub nsw i32 %16, %17
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = call i32 @power(i32 10, i32 %8)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %20)
%22 = mul nsw i32 %20, %14
%23 = add nsw i32 %22, %9
%24 = shl nsw i32 %20, 1
%25 = icmp slt i32 %18, %24
br i1 %25, label %29, label %26
26: ; preds = %7
%27 = add nsw i32 %23, %20
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %20)
br label %36
29: ; preds = %7
%30 = icmp slt i32 %18, %20
br i1 %30, label %36, label %31
31: ; preds = %29
%32 = sub nsw i32 %18, %20
%33 = add nsw i32 %32, 1
%34 = add nsw i32 %23, %33
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %33)
br label %36
36: ; preds = %29, %31, %26
%37 = phi i32 [ %27, %26 ], [ %34, %31 ], [ %23, %29 ]
%38 = sub nsw i32 %37, %9
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0), i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %37)
%41 = icmp eq i32 %14, 0
br i1 %41, label %42, label %7
42: ; preds = %36
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %37)
%44 = call i32 (...) @getchar()
%45 = call i32 (...) @getchar()
ret i32 0
}