void int_to_str(char *buf, int i) {
  do {
    int mod = i % 10;
    switch (mod) {
    case 0:
      buf = "0";
      break;
    case 1:
      buf = "1";
      break;
    case 2:
      buf = "2";
      break;
    case 3:
      buf = "3";
      break;
    case 4:
      buf = "4";
      break;
    case 5:
      buf = "5";
      break;
    case 6:
      buf = "6";
      break;
    case 7:
      buf = "7";
      break;
    case 8:
      buf = "8";
      break;
    case 9:
      buf = "9";
      break;
    }
    buf++;
    i = i / 10;
  } while (i != 0);
  buf = '\0';
}


x86 assembly (clang, -O0):
<int_to_str>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rcx
mov    %ecx,%eax
imul   $0x66666667,%rcx,%rdx
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rdx
add    %ecx,%edx
add    %edx,%edx
mov    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x9,%rax
ja     11f1 <int_to_str+0xf1>
mov    -0x18(%rbp),%rax
lea    0xeb3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xecb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f1 <int_to_str+0xf1>
lea    0xebd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f1 <int_to_str+0xf1>
lea    0xeaf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f1 <int_to_str+0xf1>
lea    0xea1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f1 <int_to_str+0xf1>
lea    0xe93(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f1 <int_to_str+0xf1>
lea    0xe85(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f1 <int_to_str+0xf1>
lea    0xe77(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f1 <int_to_str+0xf1>
lea    0xe69(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f1 <int_to_str+0xf1>
lea    0xe5b(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f1 <int_to_str+0xf1>
lea    0xe4d(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    110b <int_to_str+0xb>
movq   $0x0,-0x8(%rbp)
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_to_str>:
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [2 x i8] c"1\00"
@.str.2 = [2 x i8] c"2\00"
@.str.3 = [2 x i8] c"3\00"
@.str.4 = [2 x i8] c"4\00"
@.str.5 = [2 x i8] c"5\00"
@.str.6 = [2 x i8] c"6\00"
@.str.7 = [2 x i8] c"7\00"
@.str.8 = [2 x i8] c"8\00"
@.str.9 = [2 x i8] c"9\00"
define void @int_to_str(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
br label %6
6: ; preds = %25, %2
%7 = load i32, i32* %4
%8 = srem i32 %7, 10
store i32 %8, i32* %5
%9 = load i32, i32* %5
switch i32 %9, label %20 [
i32 0, label %10
i32 1, label %11
i32 2, label %12
i32 3, label %13
i32 4, label %14
i32 5, label %15
i32 6, label %16
i32 7, label %17
i32 8, label %18
i32 9, label %19
]
10: ; preds = %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3
br label %20
11: ; preds = %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %20
12: ; preds = %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %20
13: ; preds = %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %20
14: ; preds = %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8** %3
br label %20
15: ; preds = %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8** %3
br label %20
16: ; preds = %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8** %3
br label %20
17: ; preds = %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i8** %3
br label %20
18: ; preds = %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8** %3
br label %20
19: ; preds = %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i8** %3
br label %20
20: ; preds = %6, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
%23 = load i32, i32* %4
%24 = sdiv i32 %23, 10
store i32 %24, i32* %4
br label %25
25: ; preds = %20
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 0
br i1 %27, label %6, label %28
28: ; preds = %25
store i8* null, i8** %3
ret void
}

LLVM IR (-O2):
define void @int_to_str(i8* nocapture %0, i32 %1) {
ret void
}