#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ write_text(char *, char *);
void format_byte(uint8_t byte, char *buf) {
  buf[3] = '\0';
  write_text(buf, "   ");
  buf = &buf[2];
  do {
    *(buf--) = (byte % 10) + '0';
    byte /= 10;
  } while (byte);
}


x86 assembly (clang, -O0):
<format_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x10(%rbp),%rdi
lea    0xece(%rip),%rsi
call   1030 <write_text@plt>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    %dl,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1143 <format_byte+0x33>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_byte>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
movb   $0x0,0x3(%rsi)
lea    0xedc(%rip),%rsi
mov    %r14,%rdi
call   1030 <write_text@plt>
add    $0x2,%r14
movslq %ebx,%rax
imul   $0x66666667,%rax,%rbx
mov    %rbx,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rbx
add    %ecx,%ebx
lea    (%rbx,%rbx,1),%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%edx
sub    %ecx,%edx
add    $0x30,%dl
mov    %dl,(%r14)
add    $0xffffffffffffffff,%r14
add    $0x9,%eax
cmp    $0x12,%eax
ja     1130 <format_byte+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c" \00"
define void @format_byte(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = getelementptr inbounds i8, i8* %5, i64 3
store i8 0, i8* %6
%7 = load i8*, i8** %4
%8 = call i32 @write_text(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %4
%10 = getelementptr inbounds i8, i8* %9, i64 2
store i8* %10, i8** %4
br label %11
11: ; preds = %20, %2
%12 = load i32, i32* %3
%13 = srem i32 %12, 10
%14 = add nsw i32 %13, 48
%15 = trunc i32 %14 to i8
%16 = load i8*, i8** %4
%17 = getelementptr inbounds i8, i8* %16, i32 -1
store i8* %17, i8** %4
store i8 %15, i8* %16
%18 = load i32, i32* %3
%19 = sdiv i32 %18, 10
store i32 %19, i32* %3
br label %20
20: ; preds = %11
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, 0
br i1 %22, label %11, label %23
23: ; preds = %20
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c" \00"
define void @format_byte(i32 %0, i8* %1) {
%3 = getelementptr inbounds i8, i8* %1, i64 3
store i8 0, i8* %3
%4 = tail call i32 @write_text(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds i8, i8* %1, i64 2
br label %6
6: ; preds = %6, %2
%7 = phi i32 [ %0, %2 ], [ %13, %6 ]
%8 = phi i8* [ %5, %2 ], [ %12, %6 ]
%9 = srem i32 %7, 10
%10 = trunc i32 %9 to i8
%11 = add nsw i8 %10, 48
%12 = getelementptr inbounds i8, i8* %8, i64 -1
store i8 %11, i8* %8
%13 = sdiv i32 %7, 10
%14 = add i32 %7, 9
%15 = icmp ult i32 %14, 19
br i1 %15, label %16, label %6
16: ; preds = %6
ret void
}