void wrint(n) int n;
{
  int i, j, t;
  for (i = 4; i > 0; i--) {
    t = 1;
    for (j = 0; j < i; j++)
      t *= 10;
    if (n > t - 1)
      writec((n / t) % 10 + '0');
  }
  writec(n % 10 + '0');
}


x86 assembly (clang, -O0):
<wrint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    119a <wrint+0x8a>
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    115b <wrint+0x4b>
imul   $0xa,-0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113a <wrint+0x2a>
mov    -0x4(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    1187 <wrint+0x77>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
add    $0x30,%edi
mov    $0x0,%al
call   1030 <writec@plt>
jmp    118c <wrint+0x7c>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1122 <wrint+0x12>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
add    $0x30,%edi
mov    $0x0,%al
call   1030 <writec@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wrint>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    %edi,%ebx
cmp    $0x2710,%edi
jge    113f <wrint+0x2f>
cmp    $0x3e8,%r14d
jge    116a <wrint+0x5a>
cmp    $0x64,%r14d
jge    1193 <wrint+0x83>
cmp    $0xa,%r14d
jge    11bc <wrint+0xac>
jmp    11e7 <wrint+0xd7>
mov    $0xd1b71759,%edi
imul   %rbx,%rdi
shr    $0x2d,%rdi
mov    $0xcccccccd,%eax
imul   %rdi,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
or     $0x30,%edi
xor    %eax,%eax
call   1030 <writec@plt>
imul   $0x10624dd3,%rbx,%rdi
shr    $0x26,%rdi
mov    $0xcccccccd,%eax
imul   %rdi,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
or     $0x30,%edi
xor    %eax,%eax
call   1030 <writec@plt>
imul   $0x51eb851f,%rbx,%rdi
shr    $0x25,%rdi
mov    $0xcccccccd,%eax
imul   %rdi,%rax
shr    $0x23,%rax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edi
or     $0x30,%edi
xor    %eax,%eax
call   1030 <writec@plt>
mov    $0xcccccccd,%eax
imul   %rax,%rbx
shr    $0x23,%rbx
mov    %rbx,%rcx
imul   %rax,%rcx
shr    $0x23,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%eax
sub    %eax,%ebx
or     $0x30,%ebx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <writec@plt>
movslq %r14d,%rax
imul   $0x66666667,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
neg    %eax
lea    (%r14,%rax,1),%edi
add    $0x30,%edi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <writec@plt>

LLVM IR (-O0):
define void @wrint(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 4, i32* %3
br label %6
6: ; preds = %33, %1
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %36
9: ; preds = %6
store i32 1, i32* %5
store i32 0, i32* %4
br label %10
10: ; preds = %17, %9
%11 = load i32, i32* %4
%12 = load i32, i32* %3
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i32, i32* %5
%16 = mul nsw i32 %15, 10
store i32 %16, i32* %5
br label %17
17: ; preds = %14
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
store i32 %19, i32* %4
br label %10
20: ; preds = %10
%21 = load i32, i32* %2
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 1
%24 = icmp sgt i32 %21, %23
br i1 %24, label %25, label %32
25: ; preds = %20
%26 = load i32, i32* %2
%27 = load i32, i32* %5
%28 = sdiv i32 %26, %27
%29 = srem i32 %28, 10
%30 = add nsw i32 %29, 48
%31 = call i32 (i32, ...) bitcast (i32 (...)* @writec to i32 (i32, ...)*)(i32 %30)
br label %32
32: ; preds = %25, %20
br label %33
33: ; preds = %32
%34 = load i32, i32* %3
%35 = add nsw i32 %34, -1
store i32 %35, i32* %3
br label %6
36: ; preds = %6
%37 = load i32, i32* %2
%38 = srem i32 %37, 10
%39 = add nsw i32 %38, 48
%40 = call i32 (i32, ...) bitcast (i32 (...)* @writec to i32 (i32, ...)*)(i32 %39)
ret void
}

LLVM IR (-O2):
define void @wrint(i32 %0) {
%2 = icmp slt i32 %0, 10000
br i1 %2, label %8, label %3
3: ; preds = %1
%4 = udiv i32 %0, 10000
%5 = urem i32 %4, 10
%6 = or i32 %5, 48
%7 = tail call i32 (i32, ...) bitcast (i32 (...)* @writec to i32 (i32, ...)*)(i32 %6)
br label %10
8: ; preds = %1
%9 = icmp slt i32 %0, 1000
br i1 %9, label %15, label %10
10: ; preds = %8, %3
%11 = udiv i32 %0, 1000
%12 = urem i32 %11, 10
%13 = or i32 %12, 48
%14 = tail call i32 (i32, ...) bitcast (i32 (...)* @writec to i32 (i32, ...)*)(i32 %13)
br label %17
15: ; preds = %8
%16 = icmp slt i32 %0, 100
br i1 %16, label %22, label %17
17: ; preds = %15, %10
%18 = udiv i32 %0, 100
%19 = urem i32 %18, 10
%20 = or i32 %19, 48
%21 = tail call i32 (i32, ...) bitcast (i32 (...)* @writec to i32 (i32, ...)*)(i32 %20)
br label %24
22: ; preds = %15
%23 = icmp slt i32 %0, 10
br i1 %23, label %29, label %24
24: ; preds = %17, %22
%25 = udiv i32 %0, 10
%26 = urem i32 %25, 10
%27 = or i32 %26, 48
%28 = tail call i32 (i32, ...) bitcast (i32 (...)* @writec to i32 (i32, ...)*)(i32 %27)
br label %29
29: ; preds = %24, %22
%30 = srem i32 %0, 10
%31 = add nsw i32 %30, 48
%32 = tail call i32 (i32, ...) bitcast (i32 (...)* @writec to i32 (i32, ...)*)(i32 %31)
ret void
}