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


x86 assembly (clang, -O0):
<ultoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jne    1144 <ultoa+0x34>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xec6(%rip),%rsi
call   1030 <sprintf@plt>
jmp    118d <ultoa+0x7d>
cmpl   $0xa,-0x14(%rbp)
jne    1166 <ultoa+0x56>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xea7(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1188 <ultoa+0x78>
cmpl   $0x10,-0x14(%rbp)
jne    1183 <ultoa+0x73>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe88(%rip),%rsi
call   1030 <sprintf@plt>
jmp    1188 <ultoa+0x78>
jmp    118d <ultoa+0x7d>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ultoa>:
push   %rbx
mov    %rsi,%rbx
mov    %edi,%eax
cmp    $0x8,%edx
je     112e <ultoa+0x1e>
cmp    $0x10,%edx
je     1137 <ultoa+0x27>
cmp    $0xa,%edx
jne    1148 <ultoa+0x38>
lea    0xed7(%rip),%rsi
jmp    113e <ultoa+0x2e>
lea    0xecb(%rip),%rsi
jmp    113e <ultoa+0x2e>
lea    0xec8(%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"%u\00"
@.str.2 = [3 x i8] c"%x\00"
define i8* @ultoa(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, 8
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i8*, i8** %5
%11 = load i32, i32* %4
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %29
13: ; preds = %3
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %20
16: ; preds = %13
%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.1, i64 0, i64 0), i32 %18)
br label %28
20: ; preds = %13
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 16
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i8*, i8** %5
%25 = load i32, i32* %4
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %23, %20
br label %28
28: ; preds = %27, %16
br label %29
29: ; preds = %28, %9
%30 = load i8*, i8** %5
ret i8* %30
}

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