#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);
int main() {
  int number = 12345;
  const int TENTHOUSAND = 10000;
  const int THOUSAND = 1000;
  const int HUNDRED = 100;
  const int TEN = 10;
  const int ONE = 1;
  int tenThousands = 0;
  int thousands = 0;
  int hundreds = 0;
  int tens = 0;
  int ones = 0;
  int remaining = number;
  while (remaining >= TENTHOUSAND) {
    remaining = remaining - TENTHOUSAND;
    tenThousands++;
  }
  while (remaining >= THOUSAND) {
    remaining = remaining - THOUSAND;
    thousands++;
  }
  while (remaining >= HUNDRED) {
    remaining = remaining - HUNDRED;
    hundreds++;
  }
  while (remaining >= TEN) {
    remaining = remaining - TEN;
    tens++;
  }
  while (remaining > 0) {
    remaining = remaining - ONE;
    ones++;
  }
  printf("Ten-thousands: %i \n", tenThousands);
  printf("Thousands: %i \n", thousands);
  printf("Hundreds: %i \n", hundreds);
  printf("Tens: %i \n", tens);
  printf("Ones: %i \n", ones);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3039,-0x8(%rbp)
movl   $0x2710,-0xc(%rbp)
movl   $0x3e8,-0x10(%rbp)
movl   $0x64,-0x14(%rbp)
movl   $0xa,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x2710,-0x34(%rbp)
jl     1198 <main+0x88>
mov    -0x34(%rbp),%eax
sub    $0x2710,%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1172 <main+0x62>
jmp    119d <main+0x8d>
cmpl   $0x3e8,-0x34(%rbp)
jl     11c3 <main+0xb3>
mov    -0x34(%rbp),%eax
sub    $0x3e8,%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119d <main+0x8d>
jmp    11c8 <main+0xb8>
cmpl   $0x64,-0x34(%rbp)
jl     11e9 <main+0xd9>
mov    -0x34(%rbp),%eax
sub    $0x64,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c8 <main+0xb8>
jmp    11ee <main+0xde>
cmpl   $0xa,-0x34(%rbp)
jl     120f <main+0xff>
mov    -0x34(%rbp),%eax
sub    $0xa,%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ee <main+0xde>
jmp    1214 <main+0x104>
cmpl   $0x0,-0x34(%rbp)
jle    1235 <main+0x125>
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1214 <main+0x104>
mov    -0x20(%rbp),%esi
lea    0xdc1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%esi
lea    0xdc6(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xdc7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%esi
lea    0xdc7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%esi
lea    0xdc3(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee8(%rip),%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
lea    0xeeb(%rip),%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
lea    0xeea(%rip),%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
lea    0xee8(%rip),%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
lea    0xee2(%rip),%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Ten-thousands: %i \0A\00"
@.str.1 = [16 x i8] c"Thousands: %i \0A\00"
@.str.2 = [15 x i8] c"Hundreds: %i \0A\00"
@.str.3 = [11 x i8] c"Tens: %i \0A\00"
@.str.4 = [11 x i8] c"Ones: %i \0A\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
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %1
store i32 12345, i32* %2
store i32 10000, i32* %3
store i32 1000, i32* %4
store i32 100, i32* %5
store i32 10, i32* %6
store i32 1, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%14 = load i32, i32* %2
store i32 %14, i32* %13
br label %15
15: ; preds = %18, %0
%16 = load i32, i32* %13
%17 = icmp sge i32 %16, 10000
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i32, i32* %13
%20 = sub nsw i32 %19, 10000
store i32 %20, i32* %13
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
br label %15
23: ; preds = %15
br label %24
24: ; preds = %27, %23
%25 = load i32, i32* %13
%26 = icmp sge i32 %25, 1000
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i32, i32* %13
%29 = sub nsw i32 %28, 1000
store i32 %29, i32* %13
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
store i32 %31, i32* %9
br label %24
32: ; preds = %24
br label %33
33: ; preds = %36, %32
%34 = load i32, i32* %13
%35 = icmp sge i32 %34, 100
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load i32, i32* %13
%38 = sub nsw i32 %37, 100
store i32 %38, i32* %13
%39 = load i32, i32* %10
%40 = add nsw i32 %39, 1
store i32 %40, i32* %10
br label %33
41: ; preds = %33
br label %42
42: ; preds = %45, %41
%43 = load i32, i32* %13
%44 = icmp sge i32 %43, 10
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = load i32, i32* %13
%47 = sub nsw i32 %46, 10
store i32 %47, i32* %13
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 1
store i32 %49, i32* %11
br label %42
50: ; preds = %42
br label %51
51: ; preds = %54, %50
%52 = load i32, i32* %13
%53 = icmp sgt i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %51
%55 = load i32, i32* %13
%56 = sub nsw i32 %55, 1
store i32 %56, i32* %13
%57 = load i32, i32* %12
%58 = add nsw i32 %57, 1
store i32 %58, i32* %12
br label %51
59: ; preds = %51
%60 = load i32, i32* %8
%61 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %9
%63 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %62)
%64 = load i32, i32* %10
%65 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %64)
%66 = load i32, i32* %11
%67 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %66)
%68 = load i32, i32* %12
%69 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 %68)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"Ten-thousands: %i \0A\00"
@.str.1 = [16 x i8] c"Thousands: %i \0A\00"
@.str.2 = [15 x i8] c"Hundreds: %i \0A\00"
@.str.3 = [11 x i8] c"Tens: %i \0A\00"
@.str.4 = [11 x i8] c"Ones: %i \0A\00"
define i32 @main() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 1)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 2)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 3)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 4)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i32 5)
ret i32 0
}