#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 */
size_t abs(int);
int /*<<< orphan*/ reverse(char *);
int strlen(char *);
void itob(int n, char s[], int b) {
  int i, sign;
  char symbols[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  if (2 > b || b > strlen(symbols))
    return;
  sign = n;
  i = 0;
  do {
    s[i++] = symbols[abs(n % b)];
  } while (n /= b);
  if (sign < 0)
    s[i++] = '-';
  s[i] = '\0';
  reverse(s);
}


x86 assembly (clang, -O0):
<itob>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x25,%edx
call   1060 <memcpy@plt>
mov    $0x2,%eax
cmp    -0x14(%rbp),%eax
jg     1191 <itob+0x51>
mov    -0x14(%rbp),%eax
mov    %eax,-0x54(%rbp)
lea    -0x50(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
cmp    %ecx,%eax
jle    1196 <itob+0x56>
jmp    1214 <itob+0xd4>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,%edi
call   1040 <abs@plt>
mov    -0x50(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%ecx
mov    -0x4(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jne    11a3 <itob+0x63>
cmpl   $0x0,-0x1c(%rbp)
jge    11ff <itob+0xbf>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <reverse@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itob>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
movaps 0xecd(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeb1(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x5a595857565554,%rax
mov    %rax,0x1d(%rsp)
cmp    $0x2,%edx
jl     11cf <itob+0x9f>
mov    %edx,%r12d
mov    %rsi,%r15
mov    %edi,%r14d
mov    %rsp,%rdi
call   1050 <strlen@plt>
cmp    %r12d,%eax
jl     11cf <itob+0x9f>
xor    %ebp,%ebp
mov    %r14d,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebx,%eax
cltd
idiv   %r12d
mov    %edx,%edi
mov    %eax,%ebx
call   1040 <abs@plt>
movzbl (%rsp,%rax,1),%eax
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
test   %ebx,%ebx
jne    1190 <itob+0x60>
test   %r14d,%r14d
jns    11bf <itob+0x8f>
mov    %ebp,%eax
add    $0x1,%rbp
movb   $0x2d,(%r15,%rax,1)
movslq %ebp,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rdi
call   1030 <reverse@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.itob.symbols = [37 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define void @itob(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [37 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = bitcast [37 x i8]* %9 to i8*
%11 = load i32, i32* %6
%12 = icmp sgt i32 2, %11
br i1 %12, label %18, label %13
13: ; preds = %3
%14 = load i32, i32* %6
%15 = getelementptr inbounds [37 x i8], [37 x i8]* %9, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = icmp sgt i32 %14, %16
br i1 %17, label %18, label %19
18: ; preds = %13, %3
br label %54
19: ; preds = %13
%20 = load i32, i32* %4
store i32 %20, i32* %8
store i32 0, i32* %7
br label %21
21: ; preds = %33, %19
%22 = load i32, i32* %4
%23 = load i32, i32* %6
%24 = srem i32 %22, %23
%25 = call i64 @abs(i32 %24)
%26 = getelementptr inbounds [37 x i8], [37 x i8]* %9, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = load i8*, i8** %5
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 %27, i8* %32
br label %33
33: ; preds = %21
%34 = load i32, i32* %6
%35 = load i32, i32* %4
%36 = sdiv i32 %35, %34
store i32 %36, i32* %4
%37 = icmp ne i32 %36, 0
br i1 %37, label %21, label %38
38: ; preds = %33
%39 = load i32, i32* %8
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i8*, i8** %5
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
store i8 45, i8* %46
br label %47
47: ; preds = %41, %38
%48 = load i8*, i8** %5
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 0, i8* %51
%52 = load i8*, i8** %5
%53 = call i32 @reverse(i8* %52)
br label %54
54: ; preds = %47, %18
ret void
}

LLVM IR (-O2):
@__const.itob.symbols = [37 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define void @itob(i32 %0, i8* %1, i32 %2) {
%4 = alloca [37 x i8]
%5 = getelementptr inbounds [37 x i8], [37 x i8]* %4, i64 0, i64 0
%6 = icmp slt i32 %2, 2
br i1 %6, label %33, label %7
7: ; preds = %3
%8 = call i32 @strlen(i8* %5)
%9 = icmp slt i32 %8, %2
br i1 %9, label %33, label %10
10: ; preds = %7, %10
%11 = phi i64 [ %17, %10 ], [ 0, %7 ]
%12 = phi i32 [ %19, %10 ], [ %0, %7 ]
%13 = srem i32 %12, %2
%14 = call i64 @abs(i32 %13)
%15 = getelementptr inbounds [37 x i8], [37 x i8]* %4, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = add nuw i64 %11, 1
%18 = getelementptr inbounds i8, i8* %1, i64 %11
store i8 %16, i8* %18
%19 = sdiv i32 %12, %2
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %10
21: ; preds = %10
%22 = icmp slt i32 %0, 0
br i1 %22, label %23, label %27
23: ; preds = %21
%24 = add i64 %11, 2
%25 = and i64 %17, 4294967295
%26 = getelementptr inbounds i8, i8* %1, i64 %25
store i8 45, i8* %26
br label %27
27: ; preds = %23, %21
%28 = phi i64 [ %24, %23 ], [ %17, %21 ]
%29 = shl i64 %28, 32
%30 = ashr exact i64 %29, 32
%31 = getelementptr inbounds i8, i8* %1, i64 %30
store i8 0, i8* %31
%32 = call i32 @reverse(i8* %1)
br label %33
33: ; preds = %3, %7, %27
ret void
}