#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[16] = {'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("%d", &numberToConvert);
  printf("Base? ");
  scanf("%d", &base);
  do {
    convertedNumber[index] = numberToConvert % base;
    ++index;
    numberToConvert = numberToConvert / base;
  } while (numberToConvert != 0);
  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    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9f(%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
movslq -0x134(%rbp),%rax
mov    %ecx,-0x120(%rbp,%rax,4)
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
mov    -0x128(%rbp),%rax
movslq -0x130(%rbp),%rcx
cqto
idiv   %rcx
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    1198 <main+0x78>
lea    0xe3a(%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     125e <main+0x13e>
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    0xe04(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x134(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x134(%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    %r15d,%r15d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed3(%rip),%r14
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xec0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
movslq 0x4(%rsp),%rcx
mov    0x8(%rsp),%rax
jmp    11a3 <main+0x73>
xchg   %ax,%ax
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    0xe6e(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffffffffffff,%r15
mov    %r15d,%eax
lea    (%rsp,%rax,4),%r14
add    $0x10,%r14
lea    0xe1c(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
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>
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 = [3 x i8] c"%d\00"
@.str.2 = [7 x i8] c"Base? \00"
@.str.3 = [20 x i8] c"Converted number = \00"
@.str.4 = [3 x i8] c"%c\00"
@.str.5 = [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 ([3 x i8], [3 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.1, i64 0, i64 0), i32* %6)
br label %13
13: ; preds = %28, %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 = 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* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
%24 = load i64, i64* %4
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = sdiv i64 %24, %26
store i64 %27, i64* %4
br label %28
28: ; preds = %13
%29 = load i64, i64* %4
%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.3, i64 0, i64 0))
%33 = load i32, i32* %7
%34 = add nsw i32 %33, -1
store i32 %34, i32* %7
br label %35
35: ; preds = %49, %31
%36 = load i32, i32* %7
%37 = icmp sge i32 %36, 0
br i1 %37, label %38, label %52
38: ; preds = %35
%39 = load i32, i32* %7
%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* %5
%43 = load i32, i32* %5
%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.4, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %38
%50 = load i32, i32* %7
%51 = add nsw i32 %50, -1
store i32 %51, i32* %7
br label %35
52: ; preds = %35
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, 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 = [3 x i8] c"%d\00"
@.str.2 = [7 x i8] c"Base? \00"
@.str.3 = [20 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 ([3 x i8], [3 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.1, 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 [ %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* %2
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, 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
}