#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 */
struct cb_context {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ cb_putc(struct cb_context *, unsigned int);
void cb_puti(struct cb_context *context, unsigned i) {
  if (i == 0) {
    cb_putc(context, '0');
  } else {
    if (i > 10)
      cb_puti(context, i / 10);
    cb_putc(context, '0' + (i % 10));
  }
}


x86 assembly (clang, -O0):
<cb_puti>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    114c <cb_puti+0x2c>
mov    -0x8(%rbp),%rdi
mov    $0x30,%esi
call   1040 <cb_putc@plt>
jmp    1187 <cb_puti+0x67>
cmpl   $0xa,-0xc(%rbp)
jbe    116d <cb_puti+0x4d>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%esi
call   1030 <cb_puti@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%esi
add    $0x30,%esi
call   1040 <cb_putc@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cb_puti>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
test   %esi,%esi
je     1164 <cb_puti+0x44>
mov    %esi,%ebx
mov    %esi,%r15d
cmp    $0xb,%esi
jb     114b <cb_puti+0x2b>
mov    $0xcccccccd,%esi
imul   %r15,%rsi
shr    $0x23,%rsi
mov    %r14,%rdi
call   1030 <cb_puti@plt>
mov    $0xcccccccd,%eax
imul   %r15,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
or     $0x30,%ebx
jmp    1169 <cb_puti+0x49>
mov    $0x30,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <cb_putc@plt>

LLVM IR (-O0):
%struct.cb_context = type { i32 }
define void @cb_puti(%struct.cb_context* %0, i32 %1) {
%3 = alloca %struct.cb_context*
%4 = alloca i32
store %struct.cb_context* %0, %struct.cb_context** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load %struct.cb_context*, %struct.cb_context** %3
%9 = call i32 @cb_putc(%struct.cb_context* %8, i32 48)
br label %23
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp ugt i32 %11, 10
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load %struct.cb_context*, %struct.cb_context** %3
%15 = load i32, i32* %4
%16 = udiv i32 %15, 10
br label %17
17: ; preds = %13, %10
%18 = load %struct.cb_context*, %struct.cb_context** %3
%19 = load i32, i32* %4
%20 = urem i32 %19, 10
%21 = add i32 48, %20
%22 = call i32 @cb_putc(%struct.cb_context* %18, i32 %21)
br label %23
23: ; preds = %17, %7
ret void
}

LLVM IR (-O2):
%struct.cb_context = type { i32 }
define void @cb_puti(%struct.cb_context* %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = icmp ugt i32 %1, 10
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = udiv i32 %1, 10
tail call void @cb_puti(%struct.cb_context* %0, i32 %7)
br label %8
8: ; preds = %6, %4
%9 = urem i32 %1, 10
%10 = or i32 %9, 48
br label %11
11: ; preds = %2, %8
%12 = phi i32 [ %10, %8 ], [ 48, %2 ]
%13 = tail call i32 @cb_putc(%struct.cb_context* %0, i32 %12)
ret void
}