void setdec8(char *s, int i) {
  int j;
  for (j = 7; j >= 0; j--) {
    s[j] = '0' + i % 10;
    i /= 10;
  }
  s[8] = 0;
  return;
}


x86 assembly (clang, -O0):
<setdec8>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x7,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1151 <setdec8+0x51>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1112 <setdec8+0x12>
mov    -0x8(%rbp),%rax
movb   $0x0,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<setdec8>:
push   %r15
push   %r14
push   %r12
push   %rbx
movslq %esi,%r11
imul   $0x66666667,%r11,%r9
mov    %r9,%rax
shr    $0x3f,%rax
sar    $0x22,%r9
add    %eax,%r9d
lea    (%r9,%r9,1),%eax
lea    (%rax,%rax,4),%r8d
imul   $0x51eb851f,%r11,%r10
imul   $0x10624dd3,%r11,%r14
imul   $0x68db8bad,%r11,%r15
imul   $0x14f8b589,%r11,%r12
imul   $0x431bde83,%r11,%rcx
imul   $0x6b5fca6b,%r11,%rbx
mov    %r11d,%edx
sub    %r8d,%edx
add    $0x30,%dl
mov    %dl,0x7(%rdi)
movslq %r9d,%rdx
imul   $0x66666667,%rdx,%rax
mov    %rax,%rsi
shr    $0x3f,%rsi
shr    $0x22,%rax
add    %esi,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%edx
add    $0x30,%dl
mov    %dl,0x6(%rdi)
mov    %r10,%rax
shr    $0x3f,%rax
sar    $0x25,%r10
add    %eax,%r10d
movslq %r10d,%rax
imul   $0x66666667,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x22,%rdx
add    %esi,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%eax
add    $0x30,%al
mov    %al,0x5(%rdi)
mov    %r14,%rax
shr    $0x3f,%rax
sar    $0x26,%r14
add    %eax,%r14d
movslq %r14d,%rax
imul   $0x66666667,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x22,%rdx
add    %esi,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%eax
add    $0x30,%al
mov    %al,0x4(%rdi)
mov    %r15,%rax
shr    $0x3f,%rax
sar    $0x2c,%r15
add    %eax,%r15d
movslq %r15d,%rax
imul   $0x66666667,%rax,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
shr    $0x22,%rdx
add    %esi,%edx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
sub    %edx,%eax
add    $0x30,%al
mov    %al,0x3(%rdi)
mov    %r12,%rax
shr    $0x3f,%rax
sar    $0x2d,%r12
add    %eax,%r12d
movswl %r12w,%eax
imul   $0x6667,%eax,%eax
mov    %eax,%edx
shr    $0x1f,%edx
shr    $0x12,%eax
add    %edx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%r12d
add    $0x30,%r12b
mov    %r12b,0x2(%rdi)
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x32,%rcx
add    %eax,%ecx
imul   $0x6667,%ecx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
shr    $0x12,%eax
add    %edx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ecx
add    $0x30,%cl
mov    %cl,0x1(%rdi)
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x36,%rbx
add    %eax,%ebx
imul   $0x6667,%ebx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
shr    $0x12,%eax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
add    $0x30,%bl
mov    %bl,(%rdi)
movb   $0x0,0x8(%rdi)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @setdec8(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 7, i32* %5
br label %6
6: ; preds = %20, %2
%7 = load i32, i32* %5
%8 = icmp sge i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %6
%10 = load i32, i32* %4
%11 = srem i32 %10, 10
%12 = add nsw i32 48, %11
%13 = trunc i32 %12 to i8
%14 = load i8*, i8** %3
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
store i8 %13, i8* %17
%18 = load i32, i32* %4
%19 = sdiv i32 %18, 10
store i32 %19, i32* %4
br label %20
20: ; preds = %9
%21 = load i32, i32* %5
%22 = add nsw i32 %21, -1
store i32 %22, i32* %5
br label %6
23: ; preds = %6
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 8
store i8 0, i8* %25
ret void
}

LLVM IR (-O2):
define void @setdec8(i8* nocapture writeonly %0, i32 %1) {
%3 = srem i32 %1, 10
%4 = trunc i32 %3 to i8
%5 = add nsw i8 %4, 48
%6 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %5, i8* %6
%7 = sdiv i32 %1, 10
%8 = srem i32 %7, 10
%9 = trunc i32 %8 to i8
%10 = add nsw i8 %9, 48
%11 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %10, i8* %11
%12 = sdiv i32 %1, 100
%13 = srem i32 %12, 10
%14 = trunc i32 %13 to i8
%15 = add nsw i8 %14, 48
%16 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %15, i8* %16
%17 = sdiv i32 %1, 1000
%18 = srem i32 %17, 10
%19 = trunc i32 %18 to i8
%20 = add nsw i8 %19, 48
%21 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %20, i8* %21
%22 = sdiv i32 %1, 10000
%23 = srem i32 %22, 10
%24 = trunc i32 %23 to i8
%25 = add nsw i8 %24, 48
%26 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %25, i8* %26
%27 = sdiv i32 %1, 100000
%28 = trunc i32 %27 to i16
%29 = srem i16 %28, 10
%30 = trunc i16 %29 to i8
%31 = add nsw i8 %30, 48
%32 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %31, i8* %32
%33 = sdiv i32 %1, 1000000
%34 = trunc i32 %33 to i16
%35 = srem i16 %34, 10
%36 = trunc i16 %35 to i8
%37 = add nsw i8 %36, 48
%38 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %37, i8* %38
%39 = sdiv i32 %1, 10000000
%40 = trunc i32 %39 to i16
%41 = srem i16 %40, 10
%42 = trunc i16 %41 to i8
%43 = add nsw i8 %42, 48
store i8 %43, i8* %0
%44 = getelementptr inbounds i8, i8* %0, i64 8
store i8 0, i8* %44
ret void
}