#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 baseDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7',
                             '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
  int convertedNumber[64];
  long int numberToConvert;
  int nextDigit, base, index = 0;
  printf("Number to be converted: ");
  scanf("%ld", &numberToConvert);
  printf("Base? ");
  scanf("%i", &base);
  do {
    convertedNumber[index++] = numberToConvert % base;
    numberToConvert /= base;
  } while (numberToConvert);
  printf("Converted number: ");
  for (--index; index >= 0; --index) {
    nextDigit = convertedNumber[index];
    printf("%c", baseDigits[nextDigit]);
  }
  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,-0x134(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec2(%rip),%rdi
lea    -0x128(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeaa(%rip),%rdi
lea    -0x130(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x128(%rbp),%rax
movslq -0x130(%rbp),%rcx
cqto
idiv   %rcx
mov    %edx,%ecx
mov    -0x134(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x134(%rbp)
cltq
mov    %ecx,-0x120(%rbp,%rax,4)
movslq -0x130(%rbp),%rcx
mov    -0x128(%rbp),%rax
cqto
idiv   %rcx
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    1198 <main+0x78>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x134(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x134(%rbp)
cmpl   $0x0,-0x134(%rbp)
jl     125b <main+0x13b>
movslq -0x134(%rbp),%rax
mov    -0x120(%rbp,%rax,4),%eax
mov    %eax,-0x12c(%rbp)
movslq -0x12c(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%esi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x134(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x134(%rbp)
jmp    120c <main+0xec>
lea    0xdeb(%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    0xed3(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xebd(%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    0xe72(%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.baseDigits = [16 x i8] c"0123456789ABCDEF"
@.str = [25 x i8] c"Number to be converted: \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 = [19 x i8] c"Converted number: \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 i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [16 x i8]* %2 to i8*
store i32 0, i32* %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 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* %4)
%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* %6)
br label %13
13: ; preds = %27, %0
%14 = load i64, i64* %4
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = srem i64 %14, %16
%18 = trunc i64 %17 to i32
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %21
store i32 %18, i32* %22
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = load i64, i64* %4
%26 = sdiv i64 %25, %24
store i64 %26, i64* %4
br label %27
27: ; preds = %13
%28 = load i64, i64* %4
%29 = icmp ne i64 %28, 0
br i1 %29, label %13, label %30
30: ; preds = %27
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%32 = load i32, i32* %7
%33 = add nsw i32 %32, -1
store i32 %33, i32* %7
br label %34
34: ; preds = %48, %30
%35 = load i32, i32* %7
%36 = icmp sge i32 %35, 0
br i1 %36, label %37, label %51
37: ; preds = %34
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [64 x i32], [64 x i32]* %3, i64 0, i64 %39
%41 = load i32, i32* %40
store i32 %41, i32* %5
%42 = load i32, i32* %5
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [16 x i8], [16 x i8]* %2, 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* %7
%50 = add nsw i32 %49, -1
store i32 %50, i32* %7
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 i32 0
}

LLVM IR (-O2):
@__const.main.baseDigits = [16 x i8] c"0123456789ABCDEF"
@.str = [25 x i8] c"Number to be converted: \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 = [19 x i8] c"Converted number: \00"
define i32 @main() {
%1 = alloca [64 x i32]
%2 = alloca i64
%3 = alloca i32
%4 = bitcast [64 x i32]* %1 to i8*
%5 = bitcast i64* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 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* %2)
%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* %3)
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = load i64, i64* %2
br label %14
14: ; preds = %14, %0
%15 = phi i64 [ %19, %14 ], [ 0, %0 ]
%16 = phi i64 [ %21, %14 ], [ %13, %0 ]
%17 = srem i64 %16, %12
%18 = trunc i64 %17 to i32
%19 = add nuw i64 %15, 1
%20 = getelementptr inbounds [64 x i32], [64 x i32]* %1, i64 0, i64 %15
store i32 %18, i32* %20
%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* %2
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 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.baseDigits, 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
}