#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*/ getChar(char);
int /*<<< orphan*/ reverse(char *);
void convert(char *rslt, unsigned long n, unsigned char base) {
  char *saveRslt = rslt;
  while (n > 0) {
    *rslt++ = getChar((char)(n % base));
    n /= base;
  }
  *rslt = '\0';
  reverse(saveRslt);
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jbe    118a <convert+0x6a>
mov    -0x10(%rbp),%rax
movzbl -0x11(%rbp),%ecx
xor    %edx,%edx
div    %rcx
mov    %dl,%al
movsbl %al,%edi
call   1040 <getChar@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
movzbl -0x11(%rbp),%eax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
jmp    113d <convert+0x1d>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <reverse@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
mov    %rdi,%rbx
test   %rsi,%rsi
je     1177 <convert+0x57>
mov    %rsi,%r12
movzbl %dl,%r13d
mov    %r14,%rbx
jmp    1161 <convert+0x41>
mov    %r12,%rax
xor    %edx,%edx
div    %r13
mov    %rax,%r15
movsbl %dl,%edi
call   1040 <getChar@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
cmp    %r13,%r12
mov    %r15,%r12
jb     1177 <convert+0x57>
mov    %r12,%rax
shr    $0x20,%rax
jne    1140 <convert+0x20>
mov    %r12d,%eax
xor    %edx,%edx
div    %r13d
mov    %eax,%r15d
jmp    114b <convert+0x2b>
movb   $0x0,(%rbx)
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <reverse@plt>

LLVM IR (-O0):
define void @convert(i8* %0, i64 %1, i8 zeroext %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8 %2, i8* %6
%8 = load i8*, i8** %4
store i8* %8, i8** %7
br label %9
9: ; preds = %12, %3
%10 = load i64, i64* %5
%11 = icmp ugt i64 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %9
%13 = load i64, i64* %5
%14 = load i8, i8* %6
%15 = zext i8 %14 to i64
%16 = urem i64 %13, %15
%17 = trunc i64 %16 to i8
%18 = call i32 @getChar(i8 signext %17)
%19 = trunc i32 %18 to i8
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
store i8 %19, i8* %20
%22 = load i8, i8* %6
%23 = zext i8 %22 to i64
%24 = load i64, i64* %5
%25 = udiv i64 %24, %23
store i64 %25, i64* %5
br label %9
26: ; preds = %9
%27 = load i8*, i8** %4
store i8 0, i8* %27
%28 = load i8*, i8** %7
%29 = call i32 @reverse(i8* %28)
ret void
}

LLVM IR (-O2):
define void @convert(i8* %0, i64 %1, i8 zeroext %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %17, label %5
5: ; preds = %3
%6 = zext i8 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i8* [ %0, %5 ], [ %14, %7 ]
%9 = phi i64 [ %1, %5 ], [ %15, %7 ]
%10 = urem i64 %9, %6
%11 = trunc i64 %10 to i8
%12 = tail call i32 @getChar(i8 signext %11)
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %13, i8* %8
%15 = udiv i64 %9, %6
%16 = icmp ult i64 %9, %6
br i1 %16, label %17, label %7
17: ; preds = %7, %3
%18 = phi i8* [ %0, %3 ], [ %14, %7 ]
store i8 0, i8* %18
%19 = tail call i32 @reverse(i8* %0)
ret void
}