#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 /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  const char digitos[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
                            '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
  int numeroConvertido[64], siguienteDigito, base, indice = 0;
  long int numeroAConvertir;
  printf("Numero a convertir: ");
  scanf("%ld", &numeroAConvertir);
  printf("Base: ");
  scanf("%i", &base);
  do {
    numeroConvertido[indice] = numeroAConvertir % base;
    indice++;
    numeroAConvertir /= base;
  } while (numeroAConvertir != 0);
  printf("Numero Convertido: ");
  for (indice--; indice >= 0; indice--) {
    siguienteDigito = numeroConvertido[indice];
    printf("%c", digitos[siguienteDigito]);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x12c(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebe(%rip),%rdi
lea    -0x138(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea6(%rip),%rdi
lea    -0x128(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x138(%rbp),%rax
movslq -0x128(%rbp),%rcx
cqto
idiv   %rcx
mov    %edx,%ecx
movslq -0x12c(%rbp),%rax
mov    %ecx,-0x120(%rbp,%rax,4)
mov    -0x12c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x12c(%rbp)
movslq -0x128(%rbp),%rcx
mov    -0x138(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
jne    1198 <main+0x78>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x12c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x12c(%rbp)
cmpl   $0x0,-0x12c(%rbp)
jl     125e <main+0x13e>
movslq -0x12c(%rbp),%rax
mov    -0x120(%rbp,%rax,4),%eax
mov    %eax,-0x124(%rbp)
movslq -0x124(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%esi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x12c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x12c(%rbp)
jmp    120f <main+0xef>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
lea    0xecb(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xecf(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
movslq 0x4(%rsp),%rcx
mov    0x8(%rsp),%rax
jmp    11a3 <main+0x73>
nop
cqto
idiv   %rcx
mov    %edx,0x10(%rsp,%r14,4)
add    $0x1,%r14
test   %rax,%rax
je     11b5 <main+0x85>
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
jne    1190 <main+0x60>
xor    %edx,%edx
div    %ecx
jmp    1195 <main+0x65>
movq   $0x0,0x8(%rsp)
lea    0xe6e(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%r14
mov    %r14d,%eax
lea    (%rsp,%rax,4),%r15
add    $0x10,%r15
lea    0xe1c(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq (%r15,%rbx,4),%rax
movsbl (%rax,%r12,1),%edi
call   1030 <putchar@plt>
lea    -0x1(%rbx),%rax
add    %r14d,%ebx
test   %ebx,%ebx
mov    %rax,%rbx
jg     11f0 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.digitos = [16 x i8] c"0123456789ABCDEF"
@.str = [21 x i8] c"Numero a convertir: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [7 x i8] c"Base: \00"
@.str.3 = [3 x i8] c"%i\00"
@.str.4 = [20 x i8] c"Numero Convertido: \00"
@.str.5 = [3 x i8] c"%c\00"
@.str.6 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca [64 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %1
%8 = bitcast [16 x i8]* %2 to i8*
store i32 0, i32* %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %7)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
br label %13
13: ; preds = %28, %0
%14 = load i64, i64* %7
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = srem i64 %14, %16
%18 = trunc i64 %17 to i32
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %20
store i32 %18, i32* %21
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = load i64, i64* %7
%27 = sdiv i64 %26, %25
store i64 %27, i64* %7
br label %28
28: ; preds = %13
%29 = load i64, i64* %7
%30 = icmp ne i64 %29, 0
br i1 %30, label %13, label %31
31: ; preds = %28
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%33 = load i32, i32* %6
%34 = add nsw i32 %33, -1
store i32 %34, i32* %6
br label %35
35: ; preds = %49, %31
%36 = load i32, i32* %6
%37 = icmp sge i32 %36, 0
br i1 %37, label %38, label %52
38: ; preds = %35
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %40
%42 = load i32, i32* %41
store i32 %42, i32* %4
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %38
%50 = load i32, i32* %6
%51 = add nsw i32 %50, -1
store i32 %51, i32* %6
br label %35
52: ; preds = %35
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.digitos = [16 x i8] c"0123456789ABCDEF"
@.str = [21 x i8] c"Numero a convertir: \00"
@.str.1 = [4 x i8] c"%ld\00"
@.str.2 = [7 x i8] c"Base: \00"
@.str.3 = [3 x i8] c"%i\00"
@.str.4 = [20 x i8] c"Numero Convertido: \00"
define i32 @main() {
%1 = alloca [64 x i32]
%2 = alloca i32
%3 = alloca i64
%4 = bitcast [64 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = load i64, i64* %3
br label %14
14: ; preds = %14, %0
%15 = phi i64 [ %20, %14 ], [ 0, %0 ]
%16 = phi i64 [ %21, %14 ], [ %13, %0 ]
%17 = srem i64 %16, %12
%18 = trunc i64 %17 to i32
%19 = getelementptr inbounds [64 x i32], [64 x i32]* %1, i64 0, i64 %15
store i32 %18, i32* %19
%20 = add nuw i64 %15, 1
%21 = sdiv i64 %16, %12
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %14
23: ; preds = %14
store i64 0, i64* %3
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%25 = and i64 %15, 4294967295
br label %26
26: ; preds = %23, %26
%27 = phi i64 [ %25, %23 ], [ %35, %26 ]
%28 = getelementptr inbounds [64 x i32], [64 x i32]* %1, i64 0, i64 %27
%29 = load i32, i32* %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [16 x i8], [16 x i8]* @__const.main.digitos, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = call i32 @putchar(i32 %33)
%35 = add nsw i64 %27, -1
%36 = trunc i64 %27 to i32
%37 = icmp sgt i32 %36, 0
br i1 %37, label %26, label %38
38: ; preds = %26
%39 = call i32 @putchar(i32 10)
ret i32 0
}