#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*/ fromDecimal(int, int, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int toDecimal(char *, int);
int main() {
  char in_number[16 + 1];
  int in_base = 0;
  int out_base = 0;
  char out_number[16 + 1];
  printf("Enter a number for the base to convert from, between 2 and 16: ");
  scanf("%d", &in_base);
  printf("Enter a number for the base to be converted to, between 2 and 16: ");
  scanf("%d", &out_base);
  printf("Enter the number to be converted: ");
  scanf("%s", in_number);
  if (16 < in_base || in_base < 2) {
    printf("Inputted base is outside range: 2-16.");
    return -1;
  } else if (16 < out_base || out_base < 2) {
    printf("Outputted base is outside range: 2-16.");
    return -1;
  }
  int decimalized_number = toDecimal(in_number, in_base);
  if (decimalized_number < 0) {
    printf("\nInput number too large, overflowed\n");
    return -1;
  }
  printf("\nThe decimal representation of %s is: %d \n", in_number,
         decimalized_number);
  fromDecimal(decimalized_number, out_base, in_number);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xee2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xef3(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    $0x10,%eax
cmp    -0x24(%rbp),%eax
jl     11d5 <main+0x95>
cmpl   $0x2,-0x24(%rbp)
jge    11ef <main+0xaf>
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1284 <main+0x144>
mov    $0x10,%eax
cmp    -0x28(%rbp),%eax
jl     1207 <main+0xc7>
cmpl   $0x2,-0x28(%rbp)
jge    1221 <main+0xe1>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1284 <main+0x144>
jmp    1226 <main+0xe6>
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <toDecimal@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1259 <main+0x119>
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1284 <main+0x144>
lea    -0x20(%rbp),%rsi
mov    -0x44(%rbp),%edx
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%edi
mov    -0x28(%rbp),%esi
lea    -0x20(%rbp),%rdx
call   1060 <fromDecimal@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec3(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xeb0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xed6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeeb(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
lea    -0x11(%rsi),%eax
cmp    $0xfffffff0,%eax
ja     11df <main+0x8f>
lea    0xecf(%rip),%rdi
jmp    11f2 <main+0xa2>
mov    0x8(%rsp),%eax
add    $0xffffffef,%eax
cmp    $0xfffffff0,%eax
ja     1209 <main+0xb9>
lea    0xee0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0x10(%rsp),%rdi
call   1050 <toDecimal@plt>
test   %eax,%eax
js     1243 <main+0xf3>
mov    %eax,%ebp
lea    0xed9(%rip),%rdi
xor    %ebx,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1070 <fromDecimal@plt>
jmp    11fe <main+0xae>
lea    0xeda(%rip),%rdi
call   1030 <puts@plt>
jmp    11f9 <main+0xa9>

LLVM IR (-O0):
@.str = [64 x i8] c"Enter a number for the base to convert from, between 2 and 16: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [67 x i8] c"Enter a number for the base to be converted to, between 2 and 16: \00"
@.str.3 = [35 x i8] c"Enter the number to be converted: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [38 x i8] c"Inputted base is outside range: 2-16.\00"
@.str.6 = [39 x i8] c"Outputted base is outside range: 2-16.\00"
@.str.7 = [37 x i8] c"\0AInput number too large, overflowed\0A\00"
@.str.8 = [43 x i8] c"\0AThe decimal representation of %s is: %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [17 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca [17 x i8]
%6 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
store i32 0, i32* %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 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), i32* %3)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 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* %4)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%12 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %12)
%14 = load i32, i32* %3
%15 = icmp slt i32 16, %14
br i1 %15, label %19, label %16
16: ; preds = %0
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 2
br i1 %18, label %19, label %21
19: ; preds = %16, %0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %46
21: ; preds = %16
%22 = load i32, i32* %4
%23 = icmp slt i32 16, %22
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 2
br i1 %26, label %27, label %29
27: ; preds = %24, %21
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %46
29: ; preds = %24
br label %30
30: ; preds = %29
%31 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%32 = load i32, i32* %3
%33 = call i32 @toDecimal(i8* %31, i32 %32)
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %46
38: ; preds = %30
%39 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%40 = load i32, i32* %6
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i8* %39, i32 %40)
%42 = load i32, i32* %6
%43 = load i32, i32* %4
%44 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%45 = call i32 @fromDecimal(i32 %42, i32 %43, i8* %44)
store i32 0, i32* %1
br label %46
46: ; preds = %38, %36, %27, %19
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str = [64 x i8] c"Enter a number for the base to convert from, between 2 and 16: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [67 x i8] c"Enter a number for the base to be converted to, between 2 and 16: \00"
@.str.3 = [35 x i8] c"Enter the number to be converted: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [38 x i8] c"Inputted base is outside range: 2-16.\00"
@.str.6 = [39 x i8] c"Outputted base is outside range: 2-16.\00"
@.str.8 = [43 x i8] c"\0AThe decimal representation of %s is: %d \0A\00"
@str = [36 x i8] c"\0AInput number too large, overflowed\00"
define i32 @main() {
%1 = alloca [17 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [17 x i8], [17 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 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), i32* %2)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 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 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%13 = load i32, i32* %2
%14 = add i32 %13, -17
%15 = icmp ult i32 %14, -15
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0))
br label %33
18: ; preds = %0
%19 = load i32, i32* %3
%20 = add i32 %19, -17
%21 = icmp ult i32 %20, -15
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
br label %33
24: ; preds = %18
%25 = call i32 @toDecimal(i8* %4, i32 %13)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %33
29: ; preds = %24
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i8* %4, i32 %25)
%31 = load i32, i32* %3
%32 = call i32 @fromDecimal(i32 %25, i32 %31, i8* %4)
br label %33
33: ; preds = %27, %29, %22, %16
%34 = phi i32 [ -1, %16 ], [ -1, %22 ], [ -1, %27 ], [ 0, %29 ]
ret i32 %34
}