#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 *, ...);
char *itoa(int val, char *buf, int radix) {
  if (radix == 10) {
    sprintf(buf, "%d", val);
  } else if (radix == 16) {
    sprintf(buf, "%x", val);
  } else if (radix == 8) {
    sprintf(buf, "%o", val);
  } else {
    sprintf(buf, "%s", "");
  }
  return (buf);
}


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)
cmpl   $0xa,-0x14(%rbp)
jne    1146 <itoa+0x36>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xec6(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11b1 <itoa+0xa1>
cmpl   $0x10,-0x14(%rbp)
jne    116a <itoa+0x5a>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea5(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11ac <itoa+0x9c>
cmpl   $0x8,-0x14(%rbp)
jne    118e <itoa+0x7e>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11a7 <itoa+0x97>
mov    -0x10(%rbp),%rdi
lea    0xe70(%rip),%rsi
lea    0xe62(%rip),%rdx
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11ac <itoa+0x9c>
jmp    11b1 <itoa+0xa1>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %rbx
mov    %rsi,%rbx
mov    %edi,%eax
cmp    $0x8,%edx
je     112e <itoa+0x1e>
cmp    $0x10,%edx
je     1137 <itoa+0x27>
cmp    $0xa,%edx
jne    114c <itoa+0x3c>
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
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    114f <itoa+0x3f>
movb   $0x0,(%rbx)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [3 x i8] c"%o\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [1 x i8] zeroinitializer
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
%8 = icmp eq i32 %7, 10
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i8*, i8** %5
%11 = load i32, i32* %4
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %32
13: ; preds = %3
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 16
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = load i32, i32* %4
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %31
20: ; preds = %13
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 8
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i8*, i8** %5
%25 = load i32, i32* %4
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %30
27: ; preds = %20
%28 = load i8*, i8** %5
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %27, %23
br label %31
31: ; preds = %30, %16
br label %32
32: ; preds = %31, %9
%33 = load i8*, i8** %5
ret i8* %33
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [3 x i8] c"%o\00"
define i8* @itoa(i32 %0, i8* returned writeonly %1, i32 %2) {
switch i32 %2, label %10 [
i32 10, label %4
i32 16, label %6
i32 8, label %8
]
4: ; preds = %3
%5 = tail call i32 (i8*, i8*, ...) @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 %11
6: ; preds = %3
%7 = tail call i32 (i8*, i8*, ...) @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 %11
8: ; preds = %3
%9 = tail call i32 (i8*, i8*, ...) @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 %11
10: ; preds = %3
store i8 0, i8* %1
br label %11
11: ; preds = %6, %10, %8, %4
ret i8* %1
}