void writetwodig(sp, i) struct slot *sp;
{
  if (i >= 100)
    writeint(sp, i);
  else {
    writech(sp, i / 10 + '0');
    writech(sp, i % 10 + '0');
  }
}


x86 assembly (clang, -O0):
<writetwodig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jl     114c <writetwodig+0x2c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x0,%al
call   1030 <writeint@plt>
jmp    1182 <writetwodig+0x62>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
add    $0x30,%esi
mov    $0x0,%al
call   1040 <writech@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
add    $0x30,%esi
mov    $0x0,%al
call   1040 <writech@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writetwodig>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
cmp    $0x64,%esi
jl     114b <writetwodig+0x2b>
mov    %r14,%rdi
mov    %r15d,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <writeint@plt>
movslq %r15d,%rax
imul   $0x66666667,%rax,%rbx
mov    %rbx,%r12
shr    $0x3f,%r12
sar    $0x22,%rbx
lea    (%rbx,%r12,1),%esi
add    $0x30,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <writech@plt>
add    %r12d,%ebx
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%eax
neg    %eax
lea    (%r15,%rax,1),%esi
add    $0x30,%esi
mov    %r14,%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <writech@plt>

LLVM IR (-O0):
%struct.slot = type opaque
define void @writetwodig(%struct.slot* %0, i32 %1) {
%3 = alloca %struct.slot*
%4 = alloca i32
store %struct.slot* %0, %struct.slot** %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
%6 = icmp sge i32 %5, 100
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load %struct.slot*, %struct.slot** %3
%9 = load i32, i32* %4
%10 = call i32 (%struct.slot*, i32, ...) bitcast (i32 (...)* @writeint to i32 (%struct.slot*, i32, ...)*)(%struct.slot* %8, i32 %9)
br label %22
11: ; preds = %2
%12 = load %struct.slot*, %struct.slot** %3
%13 = load i32, i32* %4
%14 = sdiv i32 %13, 10
%15 = add nsw i32 %14, 48
%16 = call i32 (%struct.slot*, i32, ...) bitcast (i32 (...)* @writech to i32 (%struct.slot*, i32, ...)*)(%struct.slot* %12, i32 %15)
%17 = load %struct.slot*, %struct.slot** %3
%18 = load i32, i32* %4
%19 = srem i32 %18, 10
%20 = add nsw i32 %19, 48
%21 = call i32 (%struct.slot*, i32, ...) bitcast (i32 (...)* @writech to i32 (%struct.slot*, i32, ...)*)(%struct.slot* %17, i32 %20)
br label %22
22: ; preds = %11, %7
ret void
}

LLVM IR (-O2):
%struct.slot = type opaque
define void @writetwodig(%struct.slot* %0, i32 %1) {
%3 = icmp sgt i32 %1, 99
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (%struct.slot*, i32, ...) bitcast (i32 (...)* @writeint to i32 (%struct.slot*, i32, ...)*)(%struct.slot* %0, i32 %1)
br label %13
6: ; preds = %2
%7 = sdiv i32 %1, 10
%8 = add nsw i32 %7, 48
%9 = tail call i32 (%struct.slot*, i32, ...) bitcast (i32 (...)* @writech to i32 (%struct.slot*, i32, ...)*)(%struct.slot* %0, i32 %8)
%10 = srem i32 %1, 10
%11 = add nsw i32 %10, 48
%12 = tail call i32 (%struct.slot*, i32, ...) bitcast (i32 (...)* @writech to i32 (%struct.slot*, i32, ...)*)(%struct.slot* %0, i32 %11)
br label %13
13: ; preds = %6, %4
ret void
}