void chtoa(int value, char *str) {
  char *pStr = str;
  printf("%s : %d\n", __func__, value);
  switch (value) {
  case 1:
    *pStr = '1';
    break;
  case 2:
    *pStr = '2';
    break;
  case 3:
    *pStr = '3';
    break;
  case 4:
    *pStr = '4';
    break;
  case 5:
    *pStr = '5';
    break;
  case 6:
    *pStr = '6';
    break;
  case 7:
    *pStr = '7';
    break;
  case 8:
    *pStr = '8';
    break;
  case 9:
    *pStr = '9';
    break;
  case 0:
    *pStr = '0';
    break;
  default:
    printf("Wrong attribute value: %d\n", value);
  }
}


x86 assembly (clang, -O0):
<chtoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edx
lea    0xef7(%rip),%rdi
lea    0xef9(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x9,%rax
ja     11dc <chtoa+0xcc>
mov    -0x20(%rbp),%rax
lea    0xea5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rax
movb   $0x31,(%rax)
jmp    11ed <chtoa+0xdd>
mov    -0x18(%rbp),%rax
movb   $0x32,(%rax)
jmp    11ed <chtoa+0xdd>
mov    -0x18(%rbp),%rax
movb   $0x33,(%rax)
jmp    11ed <chtoa+0xdd>
mov    -0x18(%rbp),%rax
movb   $0x34,(%rax)
jmp    11ed <chtoa+0xdd>
mov    -0x18(%rbp),%rax
movb   $0x35,(%rax)
jmp    11ed <chtoa+0xdd>
mov    -0x18(%rbp),%rax
movb   $0x36,(%rax)
jmp    11ed <chtoa+0xdd>
mov    -0x18(%rbp),%rax
movb   $0x37,(%rax)
jmp    11ed <chtoa+0xdd>
mov    -0x18(%rbp),%rax
movb   $0x38,(%rax)
jmp    11ed <chtoa+0xdd>
mov    -0x18(%rbp),%rax
movb   $0x39,(%rax)
jmp    11ed <chtoa+0xdd>
mov    -0x18(%rbp),%rax
movb   $0x30,(%rax)
jmp    11ed <chtoa+0xdd>
mov    -0x4(%rbp),%esi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chtoa>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xf09(%rip),%rdi
lea    0xf0b(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x9,%ebp
ja     114b <chtoa+0x3b>
mov    %ebp,%eax
lea    0xec3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x30,(%rbx)
jmp    118c <chtoa+0x7c>
lea    0xee5(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>
movb   $0x31,(%rbx)
jmp    118c <chtoa+0x7c>
movb   $0x32,(%rbx)
jmp    118c <chtoa+0x7c>
movb   $0x33,(%rbx)
jmp    118c <chtoa+0x7c>
movb   $0x34,(%rbx)
jmp    118c <chtoa+0x7c>
movb   $0x35,(%rbx)
jmp    118c <chtoa+0x7c>
movb   $0x36,(%rbx)
jmp    118c <chtoa+0x7c>
movb   $0x37,(%rbx)
jmp    118c <chtoa+0x7c>
movb   $0x39,(%rbx)
jmp    118c <chtoa+0x7c>
movb   $0x38,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%s : %d\0A\00"
@__func__.chtoa = [6 x i8] c"chtoa\00"
@.str.1 = [27 x i8] c"Wrong attribute value: %d\0A\00"
define void @chtoa(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
store i8* %6, i8** %5
%7 = load i32, i32* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.chtoa, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %3
switch i32 %9, label %30 [
i32 1, label %10
i32 2, label %12
i32 3, label %14
i32 4, label %16
i32 5, label %18
i32 6, label %20
i32 7, label %22
i32 8, label %24
i32 9, label %26
i32 0, label %28
]
10: ; preds = %2
%11 = load i8*, i8** %5
store i8 49, i8* %11
br label %33
12: ; preds = %2
%13 = load i8*, i8** %5
store i8 50, i8* %13
br label %33
14: ; preds = %2
%15 = load i8*, i8** %5
store i8 51, i8* %15
br label %33
16: ; preds = %2
%17 = load i8*, i8** %5
store i8 52, i8* %17
br label %33
18: ; preds = %2
%19 = load i8*, i8** %5
store i8 53, i8* %19
br label %33
20: ; preds = %2
%21 = load i8*, i8** %5
store i8 54, i8* %21
br label %33
22: ; preds = %2
%23 = load i8*, i8** %5
store i8 55, i8* %23
br label %33
24: ; preds = %2
%25 = load i8*, i8** %5
store i8 56, i8* %25
br label %33
26: ; preds = %2
%27 = load i8*, i8** %5
store i8 57, i8* %27
br label %33
28: ; preds = %2
%29 = load i8*, i8** %5
store i8 48, i8* %29
br label %33
30: ; preds = %2
%31 = load i32, i32* %3
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %28, %26, %24, %22, %20, %18, %16, %14, %12, %10
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s : %d\0A\00"
@__func__.chtoa = [6 x i8] c"chtoa\00"
@.str.1 = [27 x i8] c"Wrong attribute value: %d\0A\00"
define void @chtoa(i32 %0, i8* nocapture writeonly %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.chtoa, i64 0, i64 0), i32 %0)
switch i32 %0, label %14 [
i32 1, label %4
i32 2, label %5
i32 3, label %6
i32 4, label %7
i32 5, label %8
i32 6, label %9
i32 7, label %10
i32 8, label %11
i32 9, label %12
i32 0, label %13
]
4: ; preds = %2
store i8 49, i8* %1
br label %16
5: ; preds = %2
store i8 50, i8* %1
br label %16
6: ; preds = %2
store i8 51, i8* %1
br label %16
7: ; preds = %2
store i8 52, i8* %1
br label %16
8: ; preds = %2
store i8 53, i8* %1
br label %16
9: ; preds = %2
store i8 54, i8* %1
br label %16
10: ; preds = %2
store i8 55, i8* %1
br label %16
11: ; preds = %2
store i8 56, i8* %1
br label %16
12: ; preds = %2
store i8 57, i8* %1
br label %16
13: ; preds = %2
store i8 48, i8* %1
br label %16
14: ; preds = %2
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %16
16: ; preds = %14, %13, %12, %11, %10, %9, %8, %7, %6, %5, %4
ret void
}