#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*/ reverse(char *);
void uitoa(unsigned int i, char *s, char c) {
  const char *u = "0123456789";
  const char *o = "01234567";
  const char *x = "0123456789abcdef";
  const char *X = "0123456789ABCDEF";
  int b;
  char *str = s;
  const char *p;
  switch (c) {
  case 'u':
    b = 10, p = u;
    break;
  case 'o':
    b = 8, p = o;
    break;
  case 'x':
    b = 16, p = x;
    break;
  case 'X':
    b = 16, p = X;
    break;
  default:
    b = 10, p = u;
    break;
  }
  do {
    *s++ = *(p + i % b);
  } while (i /= b);
  *s = '\0';
  reverse(str);
}


x86 assembly (clang, -O0):
<uitoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
lea    0xf59(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xf59(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xf57(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xf5d(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
movsbl -0x11(%rbp),%eax
add    $0xffffffa8,%eax
mov    %eax,%ecx
mov    %rcx,-0x58(%rbp)
sub    $0x20,%eax
ja     11d2 <uitoa+0xc2>
mov    -0x58(%rbp),%rax
lea    0xe87(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xa,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    11e1 <uitoa+0xd1>
movl   $0x8,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    11e1 <uitoa+0xd1>
movl   $0x10,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    11e1 <uitoa+0xd1>
movl   $0x10,-0x3c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    11e1 <uitoa+0xd1>
movl   $0xa,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    11e6 <uitoa+0xd6>
mov    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x3c(%rbp)
mov    -0x60(%rbp),%rax
mov    %edx,%ecx
mov    (%rax,%rcx,1),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x3c(%rbp),%ecx
mov    -0x4(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jne    11e6 <uitoa+0xd6>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x48(%rbp),%rdi
call   1030 <reverse@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uitoa>:
mov    %rsi,%r8
cmp    $0x58,%edx
je     1130 <uitoa+0x20>
cmp    $0x78,%edx
je     1139 <uitoa+0x29>
cmp    $0x6f,%edx
jne    1147 <uitoa+0x37>
lea    0xee2(%rip),%r9
mov    $0x8,%esi
jmp    1153 <uitoa+0x43>
lea    0xeee(%rip),%r9
jmp    1140 <uitoa+0x30>
lea    0xed4(%rip),%r9
mov    $0x10,%esi
jmp    1153 <uitoa+0x43>
lea    0xeb2(%rip),%r9
mov    $0xa,%esi
mov    %r8,%rcx
cs nopw 0x0(%rax,%rax,1)
mov    %edi,%eax
xor    %edx,%edx
div    %esi
movzbl (%r9,%rdx,1),%edx
mov    %dl,(%rcx)
add    $0x1,%rcx
cmp    %edi,%esi
mov    %eax,%edi
jbe    1160 <uitoa+0x50>
movb   $0x0,(%rcx)
mov    %r8,%rdi
jmp    1030 <reverse@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"0123456789\00"
@.str.1 = [9 x i8] c"01234567\00"
@.str.2 = [17 x i8] c"0123456789abcdef\00"
@.str.3 = [17 x i8] c"0123456789ABCDEF\00"
define void @uitoa(i32 %0, i8* %1, i8 signext %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8 %2, i8* %6
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8** %9
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8** %10
%14 = load i8*, i8** %5
store i8* %14, i8** %12
%15 = load i8, i8* %6
%16 = sext i8 %15 to i32
switch i32 %16, label %25 [
i32 117, label %17
i32 111, label %19
i32 120, label %21
i32 88, label %23
]
17: ; preds = %3
store i32 10, i32* %11
%18 = load i8*, i8** %7
store i8* %18, i8** %13
br label %27
19: ; preds = %3
store i32 8, i32* %11
%20 = load i8*, i8** %8
store i8* %20, i8** %13
br label %27
21: ; preds = %3
store i32 16, i32* %11
%22 = load i8*, i8** %9
store i8* %22, i8** %13
br label %27
23: ; preds = %3
store i32 16, i32* %11
%24 = load i8*, i8** %10
store i8* %24, i8** %13
br label %27
25: ; preds = %3
store i32 10, i32* %11
%26 = load i8*, i8** %7
store i8* %26, i8** %13
br label %27
27: ; preds = %25, %23, %21, %19, %17
br label %28
28: ; preds = %38, %27
%29 = load i8*, i8** %13
%30 = load i32, i32* %4
%31 = load i32, i32* %11
%32 = urem i32 %30, %31
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %29, i64 %33
%35 = load i8, i8* %34
%36 = load i8*, i8** %5
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %5
store i8 %35, i8* %36
br label %38
38: ; preds = %28
%39 = load i32, i32* %11
%40 = load i32, i32* %4
%41 = udiv i32 %40, %39
store i32 %41, i32* %4
%42 = icmp ne i32 %41, 0
br i1 %42, label %28, label %43
43: ; preds = %38
%44 = load i8*, i8** %5
store i8 0, i8* %44
%45 = load i8*, i8** %12
%46 = call i32 @reverse(i8* %45)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
@.str.1 = [9 x i8] c"01234567\00"
@.str.2 = [17 x i8] c"0123456789abcdef\00"
@.str.3 = [17 x i8] c"0123456789ABCDEF\00"
define void @uitoa(i32 %0, i8* %1, i8 signext %2) {
%4 = sext i8 %2 to i32
switch i32 %4, label %8 [
i32 88, label %7
i32 111, label %5
i32 120, label %6
]
5: ; preds = %3
br label %8
6: ; preds = %3
br label %8
7: ; preds = %3
br label %8
8: ; preds = %3, %7, %6, %5
%9 = phi i32 [ 16, %7 ], [ 16, %6 ], [ 8, %5 ], [ 10, %3 ]
%10 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), %7 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), %6 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %5 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %3 ]
br label %11
11: ; preds = %11, %8
%12 = phi i8* [ %1, %8 ], [ %18, %11 ]
%13 = phi i32 [ %0, %8 ], [ %19, %11 ]
%14 = urem i32 %13, %9
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %10, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %17, i8* %12
%19 = udiv i32 %13, %9
%20 = icmp ugt i32 %9, %13
br i1 %20, label %21, label %11
21: ; preds = %11
store i8 0, i8* %18
%22 = tail call i32 @reverse(i8* %1)
ret void
}