#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 itob(int n, char s[], int b) {
  char diglet[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int count = 0;
  do {
    s[count++] = diglet[n % b];
  } while ((n /= b) > 0);
  s[count] = 0;
  reverse(s);
  return;
}


x86 assembly (clang, -O0):
<itob>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xec3(%rip),%rsi
mov    $0x25,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x14(%rbp)
movslq %edx,%rax
mov    -0x40(%rbp,%rax,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x44(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x44(%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
jg     114e <itob+0x2e>
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <reverse@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<itob>:
mov    %edx,%ecx
mov    %edi,%eax
xor    %edi,%edi
lea    0xee3(%rip),%r8
nopl   (%rax)
cltd
idiv   %ecx
movslq %edx,%rdx
movzbl (%rdx,%r8,1),%edx
mov    %dl,(%rsi,%rdi,1)
add    $0x1,%rdi
test   %eax,%eax
jg     1120 <itob+0x10>
mov    %edi,%eax
movb   $0x0,(%rsi,%rax,1)
mov    %rsi,%rdi
jmp    1030 <reverse@plt>

LLVM IR (-O0):
@__const.itob.diglet = [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 [37 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = bitcast [37 x i8]* %7 to i8*
store i32 0, i32* %8
br label %10
10: ; preds = %22, %3
%11 = load i32, i32* %4
%12 = load i32, i32* %6
%13 = srem i32 %11, %12
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [37 x i8], [37 x i8]* %7, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = load i8*, i8** %5
%18 = load i32, i32* %8
%19 = add nsw i32 %18, 1
store i32 %19, i32* %8
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
store i8 %16, i8* %21
br label %22
22: ; preds = %10
%23 = load i32, i32* %6
%24 = load i32, i32* %4
%25 = sdiv i32 %24, %23
store i32 %25, i32* %4
%26 = icmp sgt i32 %25, 0
br i1 %26, label %10, label %27
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = load i32, i32* %8
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 0, i8* %31
%32 = load i8*, i8** %5
%33 = call i32 @reverse(i8* %32)
ret void
}

LLVM IR (-O2):
@__const.itob.diglet = [37 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
define void @itob(i32 %0, i8* %1, i32 %2) {
br label %4
4: ; preds = %4, %3
%5 = phi i64 [ %11, %4 ], [ 0, %3 ]
%6 = phi i32 [ %13, %4 ], [ %0, %3 ]
%7 = srem i32 %6, %2
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [37 x i8], [37 x i8]* @__const.itob.diglet, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = add nuw i64 %5, 1
%12 = getelementptr inbounds i8, i8* %1, i64 %5
store i8 %10, i8* %12
%13 = sdiv i32 %6, %2
%14 = icmp sgt i32 %13, 0
br i1 %14, label %4, label %15
15: ; preds = %4
%16 = and i64 %11, 4294967295
%17 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 0, i8* %17
%18 = tail call i32 @reverse(i8* %1)
ret void
}