#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 atol(int /*<<< orphan*/);
int /*<<< orphan*/ strrev(char *);
int to_base(int base, char repr[], int number) {
  int remainder, length = 0, old;
  old = number;
  static char new_number[250000000];
  new_number[0] = '\0';
  while (number) {
    remainder = number % base;
    number /= base;
    new_number[length++] = repr[remainder];
    new_number[length] = '\0';
  }
  return atol(strrev(new_number));
}


x86 assembly (clang, -O0):
<to_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
movb   $0x0,0x2efa(%rip)
cmpl   $0x0,-0x14(%rbp)
je     119d <to_base+0x7d>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x4(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x4(%rbp),%ecx
mov    -0x14(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x1c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %eax,%rcx
lea    0x2eba(%rip),%rax
mov    %dl,(%rax,%rcx,1)
movslq -0x1c(%rbp),%rcx
lea    0x2eac(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
jmp    1146 <to_base+0x26>
lea    0x2e9c(%rip),%rdi
call   1040 <strrev@plt>
mov    %eax,%edi
call   1030 <atol@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_base>:
push   %rax
movb   $0x0,0x2f18(%rip)
test   %edx,%edx
je     1158 <to_base+0x38>
mov    %edx,%eax
lea    0x2f0c(%rip),%rcx
cs nopw 0x0(%rax,%rax,1)
nop
cltd
idiv   %edi
movslq %edx,%rdx
movzbl (%rsi,%rdx,1),%edx
mov    %dl,-0x1(%rcx)
movb   $0x0,(%rcx)
add    $0x1,%rcx
test   %eax,%eax
jne    1140 <to_base+0x20>
lea    0x2ee1(%rip),%rdi
call   1040 <strrev@plt>
mov    %eax,%edi
pop    %rax
jmp    1030 <atol@plt>

LLVM IR (-O0):
@to_base.new_number = internal global [250000000 x i8] zeroinitializer
define i32 @to_base(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %8
%10 = load i32, i32* %6
store i32 %10, i32* %9
store i8 0, i8* getelementptr inbounds ([250000000 x i8], [250000000 x i8]* @to_base.new_number, i64 0, i64 0)
br label %11
11: ; preds = %14, %3
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %33
14: ; preds = %11
%15 = load i32, i32* %6
%16 = load i32, i32* %4
%17 = srem i32 %15, %16
store i32 %17, i32* %7
%18 = load i32, i32* %4
%19 = load i32, i32* %6
%20 = sdiv i32 %19, %18
store i32 %20, i32* %6
%21 = load i8*, i8** %5
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = load i8, i8* %24
%26 = load i32, i32* %8
%27 = add nsw i32 %26, 1
store i32 %27, i32* %8
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds [250000000 x i8], [250000000 x i8]* @to_base.new_number, i64 0, i64 %28
store i8 %25, i8* %29
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [250000000 x i8], [250000000 x i8]* @to_base.new_number, i64 0, i64 %31
store i8 0, i8* %32
br label %11
33: ; preds = %11
%34 = call i32 @strrev(i8* getelementptr inbounds ([250000000 x i8], [250000000 x i8]* @to_base.new_number, i64 0, i64 0))
%35 = call i32 @atol(i32 %34)
ret i32 %35
}

LLVM IR (-O2):
@to_base.new_number = internal global [250000000 x i8] zeroinitializer
define i32 @to_base(i32 %0, i8* nocapture %1, i32 %2) {
store i8 0, i8* getelementptr inbounds ([250000000 x i8], [250000000 x i8]* @to_base.new_number, i64 0, i64 0)
%4 = icmp eq i32 %2, 0
br i1 %4, label %17, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %13, %5 ], [ 0, %3 ]
%7 = phi i32 [ %9, %5 ], [ %2, %3 ]
%8 = srem i32 %7, %0
%9 = sdiv i32 %7, %0
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = load i8, i8* %11
%13 = add nuw nsw i64 %6, 1
%14 = getelementptr inbounds [250000000 x i8], [250000000 x i8]* @to_base.new_number, i64 0, i64 %6
store i8 %12, i8* %14
%15 = getelementptr inbounds [250000000 x i8], [250000000 x i8]* @to_base.new_number, i64 0, i64 %13
store i8 0, i8* %15
%16 = icmp eq i32 %9, 0
br i1 %16, label %17, label %5
17: ; preds = %5, %3
%18 = tail call i32 @strrev(i8* getelementptr inbounds ([250000000 x i8], [250000000 x i8]* @to_base.new_number, i64 0, i64 0))
%19 = tail call i32 @atol(i32 %18)
ret i32 %19
}