#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*/ fb_write_text(char const *);
void fb_write_dec(unsigned int digit) {
  unsigned int divider = 1000000000;
  unsigned int digits_done = 0;
  while (digits_done < 10) {
    if (digit >= divider) {
      unsigned int next_digit = digit / divider;
      unsigned char modulo = next_digit % 10;
      char char_digit = 48 + modulo;
      char buf[2];
      buf[0] = char_digit;
      buf[2] = '\0';
      fb_write_text((const char *)&buf);
    }
    divider = divider / 10;
    digits_done++;
  }
}


x86 assembly (clang, -O0):
<fb_write_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x3b9aca00,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jae    1195 <fb_write_dec+0x85>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jb     1178 <fb_write_dec+0x68>
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %dl,%al
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
add    $0x30,%eax
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x14(%rbp)
movb   $0x0,-0x12(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <fb_write_text@plt>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1129 <fb_write_dec+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fb_write_dec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r15d
mov    $0x3b9aca00,%ebx
mov    $0xa,%ebp
mov    $0xcccccccd,%r12d
lea    0xe(%rsp),%r14
jmp    114f <fb_write_dec+0x3f>
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%ebx
imul   %r12,%rbx
shr    $0x23,%rbx
add    $0xffffffff,%ebp
je     1182 <fb_write_dec+0x72>
cmp    %r15d,%ebx
ja     1140 <fb_write_dec+0x30>
mov    %r15d,%eax
xor    %edx,%edx
div    %ebx
mov    %rax,%rcx
imul   %r12,%rcx
shr    $0x23,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
or     $0x30,%al
mov    %al,0xe(%rsp)
movb   $0x0,0x10(%rsp)
mov    %r14,%rdi
call   1030 <fb_write_text@plt>
jmp    1140 <fb_write_dec+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fb_write_dec(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8
%8 = alloca [2 x i8]
store i32 %0, i32* %2
store i32 1000000000, i32* %3
store i32 0, i32* %4
br label %9
9: ; preds = %32, %1
%10 = load i32, i32* %4
%11 = icmp ult i32 %10, 10
br i1 %11, label %12, label %37
12: ; preds = %9
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = icmp uge i32 %13, %14
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = load i32, i32* %2
%18 = load i32, i32* %3
%19 = udiv i32 %17, %18
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = urem i32 %20, 10
%22 = trunc i32 %21 to i8
store i8 %22, i8* %6
%23 = load i8, i8* %6
%24 = zext i8 %23 to i32
%25 = add nsw i32 48, %24
%26 = trunc i32 %25 to i8
store i8 %26, i8* %7
%27 = load i8, i8* %7
%28 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
store i8 %27, i8* %28
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 2
store i8 0, i8* %29
%30 = bitcast [2 x i8]* %8 to i8*
%31 = call i32 @fb_write_text(i8* %30)
br label %32
32: ; preds = %16, %12
%33 = load i32, i32* %3
%34 = udiv i32 %33, 10
store i32 %34, i32* %3
%35 = load i32, i32* %4
%36 = add i32 %35, 1
store i32 %36, i32* %4
br label %9
37: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @fb_write_dec(i32 %0) {
%2 = alloca [2 x i8]
%3 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 2
br label %5
5: ; preds = %1, %15
%6 = phi i32 [ 1000000000, %1 ], [ %16, %15 ]
%7 = phi i32 [ 0, %1 ], [ %17, %15 ]
%8 = icmp ugt i32 %6, %0
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = udiv i32 %0, %6
%11 = urem i32 %10, 10
%12 = trunc i32 %11 to i8
%13 = or i8 %12, 48
store i8 %13, i8* %3
store i8 0, i8* %4
%14 = call i32 @fb_write_text(i8* %3)
br label %15
15: ; preds = %9, %5
%16 = udiv i32 %6, 10
%17 = add nuw nsw i32 %7, 1
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %5
19: ; preds = %15
ret void
}