#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 */
char *calloc(int, int);
int /*<<< orphan*/ char_from_value(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ stradd(char **, int /*<<< orphan*/, int *);
int /*<<< orphan*/ strrvrt(char *);
void from_dec_to_base(unsigned long int number, char *to, int base) {
  int remaining, memlen;
  free(to);
  to = calloc(1, sizeof(char));
  memlen = 1;
  do {
    remaining = number % base;
    stradd(&to, char_from_value(remaining), &memlen);
  } while (number = (number / base));
  strrvrt(to);
}


x86 assembly (clang, -O0):
<from_dec_to_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    %edx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <char_from_value@plt>
mov    %eax,%esi
lea    -0x10(%rbp),%rdi
lea    -0x1c(%rbp),%rdx
call   1050 <stradd@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1183 <from_dec_to_base+0x33>
mov    -0x10(%rbp),%rdi
call   1070 <strrvrt@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<from_dec_to_base>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,0x10(%rsp)
movl   $0x1,0xc(%rsp)
movslq %r14d,%r13
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
jmp    11c8 <from_dec_to_base+0x78>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rax
xor    %edx,%edx
div    %r13
mov    %rdx,%rdi
mov    %rax,%rbp
call   1060 <char_from_value@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    %r12,%rdx
call   1050 <stradd@plt>
cmp    %r13,%rbx
mov    %rbp,%rbx
jb     11e1 <from_dec_to_base+0x91>
mov    %rbx,%rax
or     %r13,%rax
shr    $0x20,%rax
jne    11a0 <from_dec_to_base+0x50>
mov    %ebx,%eax
xor    %edx,%edx
div    %r14d
mov    %edx,%edi
mov    %eax,%ebp
jmp    11ae <from_dec_to_base+0x5e>
mov    0x10(%rsp),%rdi
call   1070 <strrvrt@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @from_dec_to_base(i64 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i64 %0, i64* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %5
%10 = call i32 @free(i8* %9)
%11 = call i8* @calloc(i32 1, i32 1)
store i8* %11, i8** %5
store i32 1, i32* %8
br label %12
12: ; preds = %21, %3
%13 = load i64, i64* %4
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = urem i64 %13, %15
%17 = trunc i64 %16 to i32
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = call i32 @char_from_value(i32 %18)
%20 = call i32 @stradd(i8** %5, i32 %19, i32* %8)
br label %21
21: ; preds = %12
%22 = load i64, i64* %4
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = udiv i64 %22, %24
store i64 %25, i64* %4
%26 = icmp ne i64 %25, 0
br i1 %26, label %12, label %27
27: ; preds = %21
%28 = load i8*, i8** %5
%29 = call i32 @strrvrt(i8* %28)
ret void
}

LLVM IR (-O2):
define void @from_dec_to_base(i64 %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = tail call i32 @free(i8* %1)
%8 = tail call dereferenceable_or_null(1) i8* @calloc(i32 1, i32 1)
store i8* %8, i8** %4
store i32 1, i32* %5
%9 = sext i32 %2 to i64
br label %10
10: ; preds = %10, %3
%11 = phi i64 [ %0, %3 ], [ %16, %10 ]
%12 = urem i64 %11, %9
%13 = trunc i64 %12 to i32
%14 = call i32 @char_from_value(i32 %13)
%15 = call i32 @stradd(i8** %4, i32 %14, i32* %5)
%16 = udiv i64 %11, %9
%17 = icmp ult i64 %11, %9
br i1 %17, label %18, label %10
18: ; preds = %10
%19 = load i8*, i8** %4
%20 = call i32 @strrvrt(i8* %19)
ret void
}