void _prtl10(long num, char *str) {
  int i;
  char temp[11];
  temp[0] = '\0';
  for (i = 1; i <= 10; i++) {
    temp[i] = num % 10 + '0';
    num /= 10;
  }
  for (i = 10; temp[i] == '0'; i--)
    ;
  if (i == 0)
    i++;
  while (i >= 0)
    *str++ = temp[i--];
}


x86 assembly (clang, -O0):
<_prtl10>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x1f(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jg     115d <_prtl10+0x5d>
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
add    $0x30,%rdx
mov    %dl,%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x1f(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1117 <_prtl10+0x17>
movl   $0xa,-0x14(%rbp)
movslq -0x14(%rbp),%rax
movsbl -0x1f(%rbp,%rax,1),%eax
cmp    $0x30,%eax
jne    1189 <_prtl10+0x89>
jmp    117b <_prtl10+0x7b>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1164 <_prtl10+0x64>
cmpl   $0x0,-0x14(%rbp)
jne    119c <_prtl10+0x9c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a1 <_prtl10+0xa1>
cmpl   $0x0,-0x14(%rbp)
jl     11d2 <_prtl10+0xd2>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cltq
mov    -0x1f(%rbp,%rax,1),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    11a1 <_prtl10+0xa1>
pop    %rbp
ret

x86 assembly (clang, -O2):
<_prtl10>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r8
movb   $0x0,-0x1b(%rsp)
movabs $0x6666666666666667,%rcx
66 66 66
mov    %rdi,%rax
imul   %rcx
mov    %rcx,%rbx
mov    %rdx,%r10
shr    $0x3f,%r10
sar    $0x2,%rdx
add    %rdx,%r10
lea    (%r10,%r10,1),%edi
mov    %r10,%rax
imul   %rcx
mov    %rdx,%rcx
lea    (%rdi,%rdi,4),%edi
movabs $0xa3d70a3d70a3d70b,%rdx
0a d7 a3
mov    %r8,%rax
imul   %rdx
mov    %rdx,%r15
add    %r8,%r15
mov    %r8d,%eax
sub    %edi,%eax
add    $0x30,%al
mov    %al,-0x1a(%rsp)
mov    %rcx,%rax
shr    $0x3f,%rax
shr    $0x2,%ecx
add    %eax,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%eax
sub    %eax,%r10d
mov    %r15,%rax
shr    $0x3f,%rax
sar    $0x6,%r15
add    %rax,%r15
mov    %r15,%rax
imul   %rbx
mov    %rdx,-0x8(%rsp)
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mov    %r8,%rax
imul   %rcx
mov    %rdx,%r12
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x7,%r12
add    %rax,%r12
mov    %r12,%rax
imul   %rbx
mov    %rdx,%r11
movabs $0x346dc5d63886594b,%rcx
c5 6d 34
mov    %r8,%rax
imul   %rcx
mov    %rdx,%r13
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xb,%r13
add    %rax,%r13
mov    %r13,%rax
imul   %rbx
mov    %rdx,%r14
movabs $0x29f16b11c6d1e109,%rcx
6b f1 29
mov    %r8,%rax
imul   %rcx
mov    %rdx,%rdi
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xe,%rdi
add    %rax,%rdi
mov    %rdi,%rax
imul   %rbx
mov    %rbx,%rcx
mov    %rdx,%r9
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %r8,%rax
imul   %rdx
mov    %rdx,%rbx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rbx
add    %rax,%rbx
mov    %rbx,%rax
imul   %rcx
mov    %rdx,%rbp
movabs $0xd6bf94d5e57a42bd,%rdx
94 bf d6
mov    %r8,%rcx
mov    %r8,-0x10(%rsp)
mov    %r8,%rax
imul   %rdx
mov    %rdx,%r8
add    %rcx,%r8
add    $0x30,%r10b
mov    %r10b,-0x19(%rsp)
mov    -0x8(%rsp),%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
shr    $0x2,%ecx
add    %eax,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%eax
sub    %eax,%r15d
add    $0x30,%r15b
mov    %r15b,-0x18(%rsp)
mov    %r11,%rax
shr    $0x3f,%rax
shr    $0x2,%r11d
add    %eax,%r11d
add    %r11d,%r11d
lea    (%r11,%r11,4),%eax
sub    %eax,%r12d
add    $0x30,%r12b
mov    %r12b,-0x17(%rsp)
mov    %r14,%rax
shr    $0x3f,%rax
shr    $0x2,%r14d
add    %eax,%r14d
add    %r14d,%r14d
lea    (%r14,%r14,4),%eax
sub    %eax,%r13d
add    $0x30,%r13b
mov    %r13b,-0x16(%rsp)
mov    %r9,%rax
shr    $0x3f,%rax
shr    $0x2,%r9d
add    %eax,%r9d
add    %r9d,%r9d
lea    (%r9,%r9,4),%eax
sub    %eax,%edi
add    $0x30,%dil
mov    %dil,-0x15(%rsp)
mov    %rbp,%rax
shr    $0x3f,%rax
shr    $0x2,%ebp
add    %eax,%ebp
add    %ebp,%ebp
lea    0x0(%rbp,%rbp,4),%eax
sub    %eax,%ebx
add    $0x30,%bl
mov    %bl,-0x14(%rsp)
mov    %r8,%rax
shr    $0x3f,%rax
sar    $0x17,%r8
add    %rax,%r8
mov    %r8,%rax
movabs $0x6666666666666667,%rbp
66 66 66
imul   %rbp
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x2,%edx
add    %eax,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%r8d
add    $0x30,%r8b
movabs $0x55e63b88c230e77f,%rcx
3b e6 55
mov    -0x10(%rsp),%rbx
mov    %rbx,%rax
imul   %rcx
mov    %rdx,%rdi
mov    %r8b,-0x13(%rsp)
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x19,%rdi
add    %rax,%rdi
mov    %rdi,%rax
imul   %rbp
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x2,%edx
add    %eax,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%edi
add    $0x30,%dil
movabs $0x112e0be826d694b3,%rcx
0b 2e 11
mov    %rbx,%rax
imul   %rcx
mov    %rdx,%rcx
mov    %dil,-0x12(%rsp)
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1a,%rcx
add    %rax,%rcx
mov    %rcx,%rax
imul   %rbp
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x2,%edx
add    %eax,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%eax
sub    %eax,%ecx
lea    0x30(%rcx),%eax
mov    %al,-0x11(%rsp)
mov    $0xa,%eax
test   %cl,%cl
jne    13ee <_prtl10+0x2ee>
mov    $0xa,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    -0x1(%rcx),%rax
cmpb   $0x30,-0x1c(%rsp,%rcx,1)
mov    %rax,%rcx
je     13e0 <_prtl10+0x2e0>
test   %eax,%eax
mov    $0x1,%ecx
cmovne %eax,%ecx
test   %ecx,%ecx
js     1562 <_prtl10+0x462>
mov    %ecx,%eax
cmp    $0x7,%ecx
jae    140f <_prtl10+0x30f>
mov    %rsi,%rbp
jmp    1550 <_prtl10+0x450>
lea    0x1(%rax),%r8
movabs $0x1ffffffe0,%r9
cmp    $0x1f,%ecx
jae    1429 <_prtl10+0x329>
xor    %edi,%edi
jmp    14e1 <_prtl10+0x3e1>
mov    %r8,%rdi
and    %r9,%rdi
lea    0x10(%rsi),%rbp
mov    %r8,%rcx
and    $0xffffffffffffffe0,%rcx
neg    %rcx
lea    -0x1b(%rsp),%rdx
lea    (%rax,%rdx,1),%rbx
add    $0xfffffffffffffff1,%rbx
xor    %edx,%edx
pxor   %xmm0,%xmm0
movdqu -0x10(%rbx,%rdx,1),%xmm1
movdqu (%rbx,%rdx,1),%xmm2
movdqa %xmm2,%xmm3
punpcklbw %xmm0,%xmm3
pshufd $0x4e,%xmm3,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm3
punpckhbw %xmm0,%xmm2
pshufd $0x4e,%xmm2,%xmm2
pshuflw $0x1b,%xmm2,%xmm2
pshufhw $0x1b,%xmm2,%xmm2
packuswb %xmm3,%xmm2
movdqa %xmm1,%xmm3
punpcklbw %xmm0,%xmm3
pshufd $0x4e,%xmm3,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm3
punpckhbw %xmm0,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
packuswb %xmm3,%xmm1
movdqu %xmm2,-0x10(%rbp)
movdqu %xmm1,0x0(%rbp)
add    $0x20,%rbp
add    $0xffffffffffffffe0,%rdx
cmp    %rdx,%rcx
jne    1450 <_prtl10+0x350>
cmp    %rdi,%r8
je     1562 <_prtl10+0x462>
test   $0x18,%r8b
je     156d <_prtl10+0x46d>
add    $0x18,%r9
and    %r8,%r9
lea    (%rsi,%r9,1),%rbp
add    %rdi,%rsi
mov    %r8,%rcx
and    $0xfffffffffffffff8,%rcx
neg    %rcx
neg    %rdi
lea    -0x1b(%rsp),%rdx
add    %rax,%rdx
add    $0xfffffffffffffff9,%rdx
sub    %r9,%rax
pxor   %xmm0,%xmm0
nop
movq   (%rdx,%rdi,1),%xmm1
punpcklbw %xmm0,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
packuswb %xmm1,%xmm1
movq   %xmm1,(%rsi)
add    $0x8,%rsi
add    $0xfffffffffffffff8,%rdi
cmp    %rdi,%rcx
jne    1510 <_prtl10+0x410>
cmp    %r9,%r8
je     1562 <_prtl10+0x462>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl -0x1b(%rsp,%rax,1),%ecx
mov    %cl,0x0(%rbp)
add    $0x1,%rbp
add    $0xffffffffffffffff,%rax
jb     1550 <_prtl10+0x450>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    %rdi,%rsi
sub    %rdi,%rax
jmp    1407 <_prtl10+0x307>

LLVM IR (-O0):
define void @_prtl10(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [11 x i8]
store i64 %0, i64* %3
store i8* %1, i8** %4
%7 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 0
store i8 0, i8* %7
store i32 1, i32* %5
br label %8
8: ; preds = %21, %2
%9 = load i32, i32* %5
%10 = icmp sle i32 %9, 10
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = load i64, i64* %3
%13 = srem i64 %12, 10
%14 = add nsw i64 %13, 48
%15 = trunc i64 %14 to i8
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 %17
store i8 %15, i8* %18
%19 = load i64, i64* %3
%20 = sdiv i64 %19, 10
store i64 %20, i64* %3
br label %21
21: ; preds = %11
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %8
24: ; preds = %8
store i32 10, i32* %5
br label %25
25: ; preds = %33, %24
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 48
br i1 %31, label %32, label %36
32: ; preds = %25
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add nsw i32 %34, -1
store i32 %35, i32* %5
br label %25
36: ; preds = %25
%37 = load i32, i32* %5
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %5
%41 = add nsw i32 %40, 1
store i32 %41, i32* %5
br label %42
42: ; preds = %39, %36
br label %43
43: ; preds = %46, %42
%44 = load i32, i32* %5
%45 = icmp sge i32 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %43
%47 = load i32, i32* %5
%48 = add nsw i32 %47, -1
store i32 %48, i32* %5
%49 = sext i32 %47 to i64
%50 = getelementptr inbounds [11 x i8], [11 x i8]* %6, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = load i8*, i8** %4
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %4
store i8 %51, i8* %52
br label %43
54: ; preds = %43
ret void
}

LLVM IR (-O2):
define void @_prtl10(i64 %0, i8* nocapture writeonly %1) {
%3 = alloca [11 x i8]
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
store i8 0, i8* %4
%5 = srem i64 %0, 10
%6 = trunc i64 %5 to i8
%7 = add nsw i8 %6, 48
%8 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 1
store i8 %7, i8* %8
%9 = sdiv i64 %0, 10
%10 = srem i64 %9, 10
%11 = trunc i64 %10 to i8
%12 = add nsw i8 %11, 48
%13 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 2
store i8 %12, i8* %13
%14 = sdiv i64 %0, 100
%15 = srem i64 %14, 10
%16 = trunc i64 %15 to i8
%17 = add nsw i8 %16, 48
%18 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 3
store i8 %17, i8* %18
%19 = sdiv i64 %0, 1000
%20 = srem i64 %19, 10
%21 = trunc i64 %20 to i8
%22 = add nsw i8 %21, 48
%23 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 4
store i8 %22, i8* %23
%24 = sdiv i64 %0, 10000
%25 = srem i64 %24, 10
%26 = trunc i64 %25 to i8
%27 = add nsw i8 %26, 48
%28 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 5
store i8 %27, i8* %28
%29 = sdiv i64 %0, 100000
%30 = srem i64 %29, 10
%31 = trunc i64 %30 to i8
%32 = add nsw i8 %31, 48
%33 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 6
store i8 %32, i8* %33
%34 = sdiv i64 %0, 1000000
%35 = srem i64 %34, 10
%36 = trunc i64 %35 to i8
%37 = add nsw i8 %36, 48
%38 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 7
store i8 %37, i8* %38
%39 = sdiv i64 %0, 10000000
%40 = srem i64 %39, 10
%41 = trunc i64 %40 to i8
%42 = add nsw i8 %41, 48
%43 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 8
store i8 %42, i8* %43
%44 = sdiv i64 %0, 100000000
%45 = srem i64 %44, 10
%46 = trunc i64 %45 to i8
%47 = add nsw i8 %46, 48
%48 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 9
store i8 %47, i8* %48
%49 = sdiv i64 %0, 1000000000
%50 = srem i64 %49, 10
%51 = trunc i64 %50 to i8
%52 = add nsw i8 %51, 48
%53 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 10
store i8 %52, i8* %53
%54 = icmp eq i8 %51, 0
br i1 %54, label %55, label %61
55: ; preds = %2, %55
%56 = phi i64 [ %60, %55 ], [ 9, %2 ]
%57 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 %56
%58 = load i8, i8* %57
%59 = icmp eq i8 %58, 48
%60 = add i64 %56, -1
br i1 %59, label %55, label %61
61: ; preds = %55, %2
%62 = phi i64 [ 10, %2 ], [ %56, %55 ]
%63 = trunc i64 %62 to i32
%64 = icmp eq i32 %63, 0
%65 = select i1 %64, i32 1, i32 %63
%66 = icmp sgt i32 %65, -1
br i1 %66, label %67, label %131
67: ; preds = %61
%68 = zext i32 %65 to i64
%69 = add nuw nsw i64 %68, 1
%70 = icmp ult i32 %65, 7
br i1 %70, label %120, label %71
71: ; preds = %67
%72 = icmp ult i32 %65, 31
br i1 %72, label %100, label %73
73: ; preds = %71
%74 = and i64 %69, 8589934560
br label %75
75: ; preds = %75, %73
%76 = phi i64 [ 0, %73 ], [ %91, %75 ]
%77 = sub i64 %68, %76
%78 = getelementptr i8, i8* %1, i64 %76
%79 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 %77
%80 = getelementptr inbounds i8, i8* %79, i64 -15
%81 = bitcast i8* %80 to <16 x i8>*
%82 = load <16 x i8>, <16 x i8>* %81
%83 = shufflevector <16 x i8> %82, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%84 = getelementptr inbounds i8, i8* %79, i64 -31
%85 = bitcast i8* %84 to <16 x i8>*
%86 = load <16 x i8>, <16 x i8>* %85
%87 = shufflevector <16 x i8> %86, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%88 = bitcast i8* %78 to <16 x i8>*
store <16 x i8> %83, <16 x i8>* %88
%89 = getelementptr i8, i8* %78, i64 16
%90 = bitcast i8* %89 to <16 x i8>*
store <16 x i8> %87, <16 x i8>* %90
%91 = add nuw i64 %76, 32
%92 = icmp eq i64 %91, %74
br i1 %92, label %93, label %75
93: ; preds = %75
%94 = icmp eq i64 %69, %74
br i1 %94, label %131, label %95
95: ; preds = %93
%96 = getelementptr i8, i8* %1, i64 %74
%97 = sub nsw i64 %68, %74
%98 = and i64 %69, 24
%99 = icmp eq i64 %98, 0
br i1 %99, label %120, label %100
100: ; preds = %71, %95
%101 = phi i64 [ %74, %95 ], [ 0, %71 ]
%102 = add nuw nsw i64 %68, 1
%103 = and i64 %102, 8589934584
%104 = sub nsw i64 %68, %103
%105 = getelementptr i8, i8* %1, i64 %103
br label %106
106: ; preds = %106, %100
%107 = phi i64 [ %101, %100 ], [ %116, %106 ]
%108 = sub i64 %68, %107
%109 = getelementptr i8, i8* %1, i64 %107
%110 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 %108
%111 = getelementptr inbounds i8, i8* %110, i64 -7
%112 = bitcast i8* %111 to <8 x i8>*
%113 = load <8 x i8>, <8 x i8>* %112
%114 = shufflevector <8 x i8> %113, <8 x i8> poison, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%115 = bitcast i8* %109 to <8 x i8>*
store <8 x i8> %114, <8 x i8>* %115
%116 = add nuw i64 %107, 8
%117 = icmp eq i64 %116, %103
br i1 %117, label %118, label %106
118: ; preds = %106
%119 = icmp eq i64 %102, %103
br i1 %119, label %131, label %120
120: ; preds = %67, %95, %118
%121 = phi i64 [ %68, %67 ], [ %97, %95 ], [ %104, %118 ]
%122 = phi i8* [ %1, %67 ], [ %96, %95 ], [ %105, %118 ]
br label %123
123: ; preds = %120, %123
%124 = phi i64 [ %126, %123 ], [ %121, %120 ]
%125 = phi i8* [ %129, %123 ], [ %122, %120 ]
%126 = add nsw i64 %124, -1
%127 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 %124
%128 = load i8, i8* %127
%129 = getelementptr inbounds i8, i8* %125, i64 1
store i8 %128, i8* %125
%130 = icmp eq i64 %124, 0
br i1 %130, label %131, label %123
131: ; preds = %123, %93, %118, %61
ret void
}