int uint128_print(unsigned __int128 n) {
  if (n == 0)
    return printf("0");
  char str[40] = {0};
  char *s = str + sizeof(str) - 1;
  while (n != 0) {
    if (s == str)
      return -1;
    *--s = "0123456789"[n % 10];
    n /= 10;
  }
  return printf("%s", s);
}


x86 assembly (clang, -O0):
<uint128_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
or     %rcx,%rax
jne    116f <uint128_print+0x4f>
jmp    1159 <uint128_print+0x39>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %eax,-0x4(%rbp)
jmp    1235 <uint128_print+0x115>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    -0x60(%rbp),%rax
add    $0x28,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x68(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%rcx
or     %rcx,%rax
je     1220 <uint128_print+0x100>
jmp    11a5 <uint128_print+0x85>
mov    -0x68(%rbp),%rax
lea    -0x60(%rbp),%rcx
cmp    %rcx,%rax
jne    11c2 <uint128_print+0xa2>
movl   $0xffffffff,-0x4(%rbp)
jmp    1235 <uint128_print+0x115>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,-0x70(%rbp)
mov    $0xa,%edx
mov    %rdx,-0x78(%rbp)
call   1350 <__umodti3>
mov    -0x78(%rbp),%rdx
mov    -0x70(%rbp),%rcx
lea    0xe13(%rip),%rsi
mov    (%rax,%rsi,1),%sil
mov    -0x68(%rbp),%rax
mov    %rax,%rdi
add    $0xffffffffffffffff,%rdi
mov    %rdi,-0x68(%rbp)
mov    %sil,-0x1(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1250 <__udivti3>
mov    %rdx,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
jmp    118f <uint128_print+0x6f>
mov    -0x68(%rbp),%rsi
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)

x86 assembly (clang, -O2):
<uint128_print>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rax
or     %rsi,%rax
je     11e7 <uint128_print+0xd7>
mov    %rsi,%rbx
mov    %rdi,%r15
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movq   $0x0,0x20(%rsp)
mov    $0xffffffffffffffda,%r12
lea    0x27(%rsp),%r14
lea    0xeab(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1230 <__udivti3>
mov    %rdx,%rsi
lea    (%rax,%rax,1),%rcx
lea    (%rcx,%rcx,4),%rcx
mov    %r15,%rdx
sub    %rcx,%rdx
movzbl 0x0(%r13,%rdx,1),%ecx
mov    %cl,-0x1(%r14)
cmp    $0xa,%r15
mov    %rbx,%rcx
sbb    $0x0,%rcx
jb     1202 <uint128_print+0xf2>
test   %r12,%r12
je     1219 <uint128_print+0x109>
mov    $0xa,%edx
mov    %rax,%rdi
xor    %ecx,%ecx
call   1330 <__umodti3>
movzbl (%rax,%r13,1),%eax
mov    %al,-0x2(%r14)
add    $0xfffffffffffffffe,%r14
mov    $0x64,%edx
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %ecx,%ecx
call   1230 <__udivti3>
add    $0x2,%r12
cmp    $0x64,%r15
sbb    $0x0,%rbx
mov    %rax,%r15
mov    %rdx,%rbx
jae    1160 <uint128_print+0x50>
jmp    1206 <uint128_print+0xf6>
lea    0xe12(%rip),%rdi
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <printf@plt>
add    $0xffffffffffffffff,%r14
lea    0xe00(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    121e <uint128_print+0x10e>
mov    $0xffffffff,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
nopl   0x0(%rax)

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [11 x i8] c"0123456789\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @uint128_print(i64 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i128
%5 = alloca i128
%6 = alloca [40 x i8]
%7 = alloca i8*
%8 = bitcast i128* %4 to { i64, i64 }*
%9 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %8, i32 0, i32 0
store i64 %0, i64* %9
%10 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %8, i32 0, i32 1
store i64 %1, i64* %10
%11 = load i128, i128* %4
store i128 %11, i128* %5
%12 = load i128, i128* %5
%13 = icmp eq i128 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %3
br label %42
16: ; preds = %2
%17 = bitcast [40 x i8]* %6 to i8*
%18 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%19 = getelementptr inbounds i8, i8* %18, i64 40
%20 = getelementptr inbounds i8, i8* %19, i64 -1
store i8* %20, i8** %7
br label %21
21: ; preds = %29, %16
%22 = load i128, i128* %5
%23 = icmp ne i128 %22, 0
br i1 %23, label %24, label %39
24: ; preds = %21
%25 = load i8*, i8** %7
%26 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%27 = icmp eq i8* %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 -1, i32* %3
br label %42
29: ; preds = %24
%30 = load i128, i128* %5
%31 = urem i128 %30, 10
%32 = trunc i128 %31 to i64
%33 = getelementptr inbounds [11 x i8], [11 x i8]* @.str.1, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i32 -1
store i8* %36, i8** %7
store i8 %34, i8* %36
%37 = load i128, i128* %5
%38 = udiv i128 %37, 10
store i128 %38, i128* %5
br label %21
39: ; preds = %21
%40 = load i8*, i8** %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %40)
store i32 %41, i32* %3
br label %42
42: ; preds = %39, %28, %14
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@.str.1 = [11 x i8] c"0123456789\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @uint128_print(i64 %0, i64 %1) {
%3 = alloca [40 x i8]
%4 = zext i64 %1 to i128
%5 = shl nuw i128 %4, 64
%6 = zext i64 %0 to i128
%7 = or i128 %5, %6
%8 = icmp eq i128 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %41
11: ; preds = %2
%12 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 39
br label %14
14: ; preds = %28, %11
%15 = phi i8* [ %13, %11 ], [ %33, %28 ]
%16 = phi i128 [ %7, %11 ], [ %34, %28 ]
%17 = freeze i128 %16
%18 = udiv i128 %17, 10
%19 = mul i128 %18, 10
%20 = sub i128 %17, %19
%21 = trunc i128 %20 to i64
%22 = getelementptr inbounds [11 x i8], [11 x i8]* @.str.1, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %15, i64 -1
store i8 %23, i8* %24
%25 = icmp ult i128 %16, 10
br i1 %25, label %36, label %26
26: ; preds = %14
%27 = icmp eq i8* %24, %12
br i1 %27, label %39, label %28
28: ; preds = %26
%29 = urem i128 %18, 10
%30 = trunc i128 %29 to i64
%31 = getelementptr inbounds [11 x i8], [11 x i8]* @.str.1, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = getelementptr inbounds i8, i8* %15, i64 -2
store i8 %32, i8* %33
%34 = udiv i128 %16, 100
%35 = icmp ult i128 %16, 100
br i1 %35, label %36, label %14
36: ; preds = %28, %14
%37 = phi i8* [ %24, %14 ], [ %33, %28 ]
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %26, %36
%40 = phi i32 [ %38, %36 ], [ -1, %26 ]
br label %41
41: ; preds = %39, %9
%42 = phi i32 [ %10, %9 ], [ %40, %39 ]
ret i32 %42
}