#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 *, ...);
void main() {
  char b[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
                '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
  int c[64], d, i, base;
  long n;
  printf("Input a number:\n");
  scanf("%ld", &n);
  printf("Input new base(2-16):\n");
  scanf("%d", &base);
  i = 0;
  do {
    c[i] = n % base;
    i++;
    n /= base;
  } while (n != 0);
  printf("Transmite new base:\n");
  for (--i; i >= 0; --i) {
    d = c[i];
    printf("%c", b[d]);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    0xece(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xecb(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecb(%rip),%rdi
lea    -0x128(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec3(%rip),%rdi
lea    -0x11c(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movl   $0x0,-0x118(%rbp)
mov    -0x128(%rbp),%rax
movslq -0x11c(%rbp),%rcx
cqto
idiv   %rcx
mov    %edx,%ecx
movslq -0x118(%rbp),%rax
mov    %ecx,-0x110(%rbp,%rax,4)
mov    -0x118(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x118(%rbp)
movslq -0x11c(%rbp),%rcx
mov    -0x128(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    1191 <main+0x71>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x118(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x118(%rbp)
cmpl   $0x0,-0x118(%rbp)
jl     1257 <main+0x137>
movslq -0x118(%rbp),%rax
mov    -0x110(%rbp,%rax,4),%eax
mov    %eax,-0x114(%rbp)
movslq -0x114(%rbp),%rax
movsbl -0x10(%rbp,%rax,1),%esi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x118(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x118(%rbp)
jmp    1208 <main+0xe8>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
lea    0xed2(%rip),%rdi
call   1040 <puts@plt>
lea    0xebf(%rip),%rdi
xor    %r15d,%r15d
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xec0(%rip),%rdi
call   1040 <puts@plt>
lea    0xea1(%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>
nopl   0x0(%rax,%rax,1)
cqto
idiv   %rcx
mov    %edx,0x10(%rsp,%r15,4)
add    $0x1,%r15
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    0xe78(%rip),%rdi
call   1040 <puts@plt>
add    $0xffffffffffffffff,%r15
mov    %r15d,%eax
lea    (%rsp,%rax,4),%r14
add    $0x10,%r14
xor    %ebx,%ebx
lea    0xe1e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq (%r14,%rbx,4),%rax
movsbl (%rax,%r12,1),%edi
call   1030 <putchar@plt>
lea    -0x1(%rbx),%rax
add    %r15d,%ebx
test   %ebx,%ebx
mov    %rax,%rbx
jg     11f0 <main+0xc0>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@__const.main.b = [16 x i8] c"0123456789ABCDEF"
@.str.1 = [4 x i8] c"%ld\00"
@.str.3 = [3 x i8] c"%d\00"
@str = [16 x i8] c"Input a number:\00"
@str.7 = [22 x i8] c"Input new base(2-16):\00"
@str.8 = [20 x i8] c"Transmite new base:\00"
define void @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 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, 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.b, 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 void
}