#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 *, unsigned int);
void PrintUnsignedNumber(unsigned int number) {
  unsigned int num, denom, quot, rem;
  if (number < 1000) {
    printf("%u", number);
    return;
  }
  denom = 1;
  num = number;
  while (num >= 1000) {
    num /= 1000;
    denom *= 1000;
  }
  printf("%u,", num);
  num = (number - num * denom);
  denom /= 1000;
  while (denom > 1) {
    quot = (num / denom);
    rem = (num - quot * denom);
    printf("%03u,", quot);
    num = rem;
    denom /= 1000;
  }
  printf("%03u", num);
}


x86 assembly (clang, -O0):
<PrintUnsignedNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x3e8,-0x4(%rbp)
jae    113c <PrintUnsignedNumber+0x2c>
mov    -0x4(%rbp),%esi
lea    0xece(%rip),%rdi
call   1030 <printf@plt>
jmp    11fd <PrintUnsignedNumber+0xed>
movl   $0x1,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jb     1174 <PrintUnsignedNumber+0x64>
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x8(%rbp)
imul   $0x3e8,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1149 <PrintUnsignedNumber+0x39>
mov    -0x8(%rbp),%esi
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
imul   -0xc(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jbe    11ee <PrintUnsignedNumber+0xde>
mov    -0x8(%rbp),%eax
xor    %edx,%edx
divl   -0xc(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
imul   -0xc(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0xc(%rbp)
jmp    11a1 <PrintUnsignedNumber+0x91>
mov    -0x8(%rbp),%esi
lea    0xe15(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrintUnsignedNumber>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
cmp    $0x3e8,%edi
jae    112e <PrintUnsignedNumber+0x1e>
lea    0xed7(%rip),%rdi
jmp    11b2 <PrintUnsignedNumber+0xa2>
mov    $0x1,%ebp
mov    %r15d,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%eax
mov    %ebx,%ecx
imul   $0x10624dd3,%rcx,%rbx
shr    $0x26,%rbx
imul   $0x3e8,%ebp,%ebp
cmp    $0xf423f,%eax
ja     1140 <PrintUnsignedNumber+0x30>
lea    0xea0(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
imul   %ebp,%ebx
sub    %ebx,%r15d
cmp    $0x7d0,%ebp
jb     11ab <PrintUnsignedNumber+0x9b>
lea    0xe88(%rip),%r14
nop
mov    %ebp,%eax
imul   $0x10624dd3,%rax,%rbx
shr    $0x26,%rbx
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
mov    %edx,%r15d
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
cmp    $0x1e847f,%ebp
mov    %ebx,%ebp
ja     1180 <PrintUnsignedNumber+0x70>
lea    0xe5b(%rip),%rdi
mov    %r15d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@.str.1 = [4 x i8] c"%u,\00"
@.str.2 = [6 x i8] c"%03u,\00"
@.str.3 = [5 x i8] c"%03u\00"
define void @PrintUnsignedNumber(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = icmp ult i32 %7, 1000
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* %2
%11 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %52
12: ; preds = %1
store i32 1, i32* %4
%13 = load i32, i32* %2
store i32 %13, i32* %3
br label %14
14: ; preds = %17, %12
%15 = load i32, i32* %3
%16 = icmp uge i32 %15, 1000
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i32, i32* %3
%19 = udiv i32 %18, 1000
store i32 %19, i32* %3
%20 = load i32, i32* %4
%21 = mul i32 %20, 1000
store i32 %21, i32* %4
br label %14
22: ; preds = %14
%23 = load i32, i32* %3
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %2
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = mul i32 %26, %27
%29 = sub i32 %25, %28
store i32 %29, i32* %3
%30 = load i32, i32* %4
%31 = udiv i32 %30, 1000
store i32 %31, i32* %4
br label %32
32: ; preds = %35, %22
%33 = load i32, i32* %4
%34 = icmp ugt i32 %33, 1
br i1 %34, label %35, label %49
35: ; preds = %32
%36 = load i32, i32* %3
%37 = load i32, i32* %4
%38 = udiv i32 %36, %37
store i32 %38, i32* %5
%39 = load i32, i32* %3
%40 = load i32, i32* %5
%41 = load i32, i32* %4
%42 = mul i32 %40, %41
%43 = sub i32 %39, %42
store i32 %43, i32* %6
%44 = load i32, i32* %5
%45 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %6
store i32 %46, i32* %3
%47 = load i32, i32* %4
%48 = udiv i32 %47, 1000
store i32 %48, i32* %4
br label %32
49: ; preds = %32
%50 = load i32, i32* %3
%51 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %49, %9
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%u\00"
@.str.1 = [4 x i8] c"%u,\00"
@.str.2 = [6 x i8] c"%03u,\00"
@.str.3 = [5 x i8] c"%03u\00"
define void @PrintUnsignedNumber(i32 %0) {
%2 = icmp ult i32 %0, 1000
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %28
5: ; preds = %1, %5
%6 = phi i32 [ %8, %5 ], [ %0, %1 ]
%7 = phi i32 [ %9, %5 ], [ 1, %1 ]
%8 = udiv i32 %6, 1000
%9 = mul i32 %7, 1000
%10 = icmp ugt i32 %6, 999999
br i1 %10, label %5, label %11
11: ; preds = %5
%12 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%13 = mul i32 %8, %9
%14 = sub i32 %0, %13
%15 = icmp ugt i32 %9, 1999
br i1 %15, label %16, label %25
16: ; preds = %11, %16
%17 = phi i32 [ %19, %16 ], [ %9, %11 ]
%18 = phi i32 [ %22, %16 ], [ %14, %11 ]
%19 = udiv i32 %17, 1000
%20 = udiv i32 %18, %19
%21 = mul i32 %20, %19
%22 = urem i32 %18, %19
%23 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%24 = icmp ugt i32 %17, 1999999
br i1 %24, label %16, label %25
25: ; preds = %16, %11
%26 = phi i32 [ %14, %11 ], [ %22, %16 ]
%27 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %25, %3
ret void
}