#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*/ abort();
int /*<<< orphan*/ sprintf(char *, char *, int);
char *itoa(int val, char *s, int radix) {
  switch (radix) {
  case 8:
    sprintf(s, "%o", val);
    return s;
  case 10:
    sprintf(s, "%d", val);
    return s;
  case 16:
    sprintf(s, "%x", val);
    return s;
  default:
    abort();
  }
}


x86 assembly (clang, -O0):
<itoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x8,%eax
je     1168 <itoa+0x48>
jmp    1146 <itoa+0x26>
mov    -0x20(%rbp),%eax
sub    $0xa,%eax
je     1188 <itoa+0x68>
jmp    1157 <itoa+0x37>
mov    -0x20(%rbp),%eax
sub    $0x10,%eax
je     11a8 <itoa+0x88>
jmp    11c8 <itoa+0xa8>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe8a(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cf <itoa+0xaf>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe6d(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cf <itoa+0xaf>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe50(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11cf <itoa+0xaf>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%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     113e <itoa+0x1e>
cmp    $0x10,%edx
je     1147 <itoa+0x27>
cmp    $0xa,%edx
jne    115d <itoa+0x3d>
lea    0xec7(%rip),%rsi
jmp    114e <itoa+0x2e>
lea    0xebb(%rip),%rsi
jmp    114e <itoa+0x2e>
lea    0xeb8(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret
xor    %eax,%eax
call   1030 <abort@plt>

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
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
switch i32 %8, label %24 [
i32 8, label %9
i32 10, label %14
i32 16, label %19
]
9: ; preds = %3
%10 = load i8*, i8** %6
%11 = load i32, i32* %5
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8*, i8** %6
store i8* %13, i8** %4
br label %26
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = load i32, i32* %5
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i8*, i8** %6
store i8* %18, i8** %4
br label %26
19: ; preds = %3
%20 = load i8*, i8** %6
%21 = load i32, i32* %5
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i8*, i8** %6
store i8* %23, i8** %4
br label %26
24: ; preds = %3
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %19, %14, %9
%27 = load i8*, i8** %4
ret i8* %27
}

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* returned writeonly %1, i32 %2) {
switch i32 %2, label %6 [
i32 8, label %8
i32 10, label %4
i32 16, label %5
]
4: ; preds = %3
br label %8
5: ; preds = %3
br label %8
6: ; preds = %3
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %3, %5, %4
%9 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %5 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %3 ]
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) %9, i32 %0)
ret i8* %1
}