#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, int);
char *itoa(int val, char *str, int radix) {
  switch (radix) {
  case 8:
    sprintf(str, "%o", val);
    break;
  case 10:
    sprintf(str, "%u", val);
    break;
  case 16:
    sprintf(str, "%x", val);
    break;
  default:
    sprintf(str, "bad radix: %d", radix);
    break;
  }
  return (str);
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x8,%eax
je     1158 <itoa+0x48>
jmp    1136 <itoa+0x26>
mov    -0x18(%rbp),%eax
sub    $0xa,%eax
je     1170 <itoa+0x60>
jmp    1147 <itoa+0x37>
mov    -0x18(%rbp),%eax
sub    $0x10,%eax
je     1188 <itoa+0x78>
jmp    11a0 <itoa+0x90>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe9a(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11b3 <itoa+0xa3>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe85(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11b3 <itoa+0xa3>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe70(%rip),%rsi
call   1030 <sprintf@plt>
jmp    11b3 <itoa+0xa3>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe5b(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %rbx
mov    %rsi,%rbx
mov    %edi,%eax
cmp    $0x10,%edx
je     112e <itoa+0x1e>
cmp    $0xa,%edx
je     1137 <itoa+0x27>
cmp    $0x8,%edx
jne    1145 <itoa+0x35>
lea    0xed4(%rip),%rsi
jmp    113e <itoa+0x2e>
lea    0xed1(%rip),%rsi
jmp    113e <itoa+0x2e>
lea    0xec5(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
jmp    114f <itoa+0x3f>
lea    0xebd(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%o\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [14 x i8] c"bad radix: %d\00"
define i8* @itoa(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
switch i32 %7, label %20 [
i32 8, label %8
i32 10, label %12
i32 16, label %16
]
8: ; preds = %3
%9 = load i8*, i8** %5
%10 = load i32, i32* %4
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
br label %24
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i32, i32* %4
%15 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %24
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = load i32, i32* %4
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %18)
br label %24
20: ; preds = %3
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %20, %16, %12, %8
%25 = load i8*, i8** %5
ret i8* %25
}

LLVM IR (-O2):
@.str = [3 x i8] c"%o\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [14 x i8] c"bad radix: %d\00"
define i8* @itoa(i32 %0, i8* returned writeonly %1, i32 %2) {
switch i32 %2, label %10 [
i32 8, label %4
i32 10, label %6
i32 16, label %8
]
4: ; preds = %3
%5 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %12
6: ; preds = %3
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %12
8: ; preds = %3
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %12
10: ; preds = %3
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %2)
br label %12
12: ; preds = %10, %8, %6, %4
ret i8* %1
}