#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 value, char *buffer, int radix) {
  char *fmt;
  if (!buffer)
    return NULL;
  switch (radix) {
  case 8:
    fmt = "%o";
    break;
  case 10:
    fmt = "%d";
    break;
  case 16:
    fmt = "%x";
    break;
  default:
    return NULL;
  }
  sprintf(buffer, fmt, value);
  return buffer;
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    113a <itoa+0x2a>
movq   $0x0,-0x8(%rbp)
jmp    11c5 <itoa+0xb5>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x8,%eax
je     1170 <itoa+0x60>
jmp    114e <itoa+0x3e>
mov    -0x2c(%rbp),%eax
sub    $0xa,%eax
je     1180 <itoa+0x70>
jmp    115f <itoa+0x4f>
mov    -0x2c(%rbp),%eax
sub    $0x10,%eax
je     1190 <itoa+0x80>
jmp    11a0 <itoa+0x90>
lea    0xe89(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11ad <itoa+0x9d>
lea    0xe7c(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11ad <itoa+0x9d>
lea    0xe6f(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11ad <itoa+0x9d>
movq   $0x0,-0x8(%rbp)
jmp    11c5 <itoa+0xb5>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itoa>:
push   %rbx
test   %rsi,%rsi
je     1133 <itoa+0x23>
mov    %rsi,%rbx
mov    %edi,%eax
cmp    $0x8,%edx
je     1137 <itoa+0x27>
cmp    $0x10,%edx
je     1140 <itoa+0x30>
cmp    $0xa,%edx
jne    1133 <itoa+0x23>
lea    0xed2(%rip),%rsi
jmp    1147 <itoa+0x37>
xor    %ebx,%ebx
jmp    1151 <itoa+0x41>
lea    0xec2(%rip),%rsi
jmp    1147 <itoa+0x37>
lea    0xebf(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
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"%d\00"
@.str.2 = [3 x i8] c"%x\00"
define i8* @itoa(i32 %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %3
store i8* null, i8** %4
br label %24
12: ; preds = %3
%13 = load i32, i32* %7
switch i32 %13, label %17 [
i32 8, label %14
i32 10, label %15
i32 16, label %16
]
14: ; preds = %12
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %8
br label %18
15: ; preds = %12
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %18
16: ; preds = %12
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %8
br label %18
17: ; preds = %12
store i8* null, i8** %4
br label %24
18: ; preds = %16, %15, %14
%19 = load i8*, i8** %6
%20 = load i8*, i8** %8
%21 = load i32, i32* %5
%22 = call i32 @sprintf(i8* %19, i8* %20, i32 %21)
%23 = load i8*, i8** %6
store i8* %23, i8** %4
br label %24
24: ; preds = %18, %17, %11
%25 = load i8*, i8** %4
ret i8* %25
}

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