#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*/ printf(char *, ...);
int tolower(char);
void convertFromBase10(int num, int base) {
  int result[64];
  char base_digits[36] = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
                          '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                          'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
                          'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
  int i, j;
  i = 0;
  while (num != 0) {
    result[i] = num % base;
    num = num / base;
    i++;
  }
  for (j = i - 1; j >= 0; j--) {
    printf("%c", tolower(base_digits[result[j]]));
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<convertFromBase10>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x140(%rbp),%rdi
lea    0xeb1(%rip),%rsi
mov    $0x24,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x144(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11a0 <convertFromBase10+0x70>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
movslq -0x144(%rbp),%rax
mov    %edx,-0x110(%rbp,%rax,4)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x4(%rbp)
mov    -0x144(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x144(%rbp)
jmp    1163 <convertFromBase10+0x33>
mov    -0x144(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x148(%rbp)
cmpl   $0x0,-0x148(%rbp)
jl     11fc <convertFromBase10+0xcc>
movslq -0x148(%rbp),%rax
movslq -0x110(%rbp,%rax,4),%rax
ff
movsbl -0x140(%rbp,%rax,1),%edi
ff
call   1050 <tolower@plt>
mov    %eax,%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x148(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x148(%rbp)
jmp    11af <convertFromBase10+0x7f>
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertFromBase10>:
push   %r14
push   %rbx
sub    $0x108,%rsp
test   %edi,%edi
je     1182 <convertFromBase10+0x62>
mov    %edi,%eax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cltd
idiv   %esi
mov    %edx,(%rsp,%rcx,4)
add    $0x1,%rcx
test   %eax,%eax
jne    1140 <convertFromBase10+0x20>
test   %ecx,%ecx
jle    1182 <convertFromBase10+0x62>
mov    %ecx,%ebx
add    $0x1,%rbx
lea    0xea1(%rip),%r14
nop
lea    -0x2(%rbx),%eax
movslq (%rsp,%rax,4),%rax
movsbl (%rax,%r14,1),%edi
call   1040 <tolower@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1160 <convertFromBase10+0x40>
mov    $0xa,%edi
add    $0x108,%rsp
pop    %rbx
pop    %r14
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@__const.convertFromBase10.base_digits = [36 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
@.str = [3 x i8] c"%c\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @convertFromBase10(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [64 x i32]
%6 = alloca [36 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = bitcast [36 x i8]* %6 to i8*
store i32 0, i32* %7
br label %10
10: ; preds = %13, %2
%11 = load i32, i32* %3
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = load i32, i32* %3
%15 = load i32, i32* %4
%16 = srem i32 %14, %15
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [64 x i32], [64 x i32]* %5, i64 0, i64 %18
store i32 %16, i32* %19
%20 = load i32, i32* %3
%21 = load i32, i32* %4
%22 = sdiv i32 %20, %21
store i32 %22, i32* %3
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
br label %10
25: ; preds = %10
%26 = load i32, i32* %7
%27 = sub nsw i32 %26, 1
store i32 %27, i32* %8
br label %28
28: ; preds = %41, %25
%29 = load i32, i32* %8
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %44
31: ; preds = %28
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [64 x i32], [64 x i32]* %5, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [36 x i8], [36 x i8]* %6, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = call i32 @tolower(i8 signext %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %31
%42 = load i32, i32* %8
%43 = add nsw i32 %42, -1
store i32 %43, i32* %8
br label %28
44: ; preds = %28
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@__const.convertFromBase10.base_digits = [36 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
define void @convertFromBase10(i32 %0, i32 %1) {
%3 = alloca [64 x i32]
%4 = bitcast [64 x i32]* %3 to i8*
%5 = icmp eq i32 %0, 0
br i1 %5, label %31, label %11
6: ; preds = %11
%7 = trunc i64 %17 to i32
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %31
9: ; preds = %6
%10 = and i64 %17, 4294967295
br label %19
11: ; preds = %2, %11
%12 = phi i64 [ %17, %11 ], [ 0, %2 ]
%13 = phi i32 [ %16, %11 ], [ %0, %2 ]
%14 = srem i32 %13, %1
%15 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %12
store i32 %14, i32* %15
%16 = sdiv i32 %13, %1
%17 = add nuw i64 %12, 1
%18 = icmp eq i32 %16, 0
br i1 %18, label %6, label %11
19: ; preds = %9, %19
%20 = phi i64 [ %10, %9 ], [ %21, %19 ]
%21 = add nsw i64 %20, -1
%22 = and i64 %21, 4294967295
%23 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [36 x i8], [36 x i8]* @__const.convertFromBase10.base_digits, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = tail call i32 @tolower(i8 signext %27)
%29 = tail call i32 @putchar(i32 %28)
%30 = icmp ugt i64 %20, 1
br i1 %30, label %19, label %31
31: ; preds = %19, %2, %6
%32 = tail call i32 @putchar(i32 10)
ret void
}