#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 */
long atoi(char *);
int /*<<< orphan*/ convert_from_dec_to_anybase(long, int);
long convert_to_decimal(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  char num_to_convert[30];
  int base_system;
  int target_system;
  long int decimal_no;
  printf("\nEnter the Number to Convert: ");
  scanf("%s", num_to_convert);
  printf("\nEnter the Current Number System (2 for Bin, 10 for Dec, 8 for Oct, "
         "16 for Hex): ");
  scanf("%d", &base_system);
  printf("\nEnter the Target System (2 for Bin, 10 for Dec, 8 for Oct, 16 for "
         "Hex): ");
  scanf("%d", &target_system);
  if (base_system == 10) {
    decimal_no = atoi(num_to_convert);
    convert_from_dec_to_anybase(decimal_no, target_system);
  } else {
    if (target_system == 10) {
      decimal_no = convert_to_decimal(num_to_convert, base_system);
      printf("\nDecimal Number = %ld\n", decimal_no);
    } else {
      decimal_no = convert_to_decimal(num_to_convert, base_system);
      convert_from_dec_to_anybase(decimal_no, target_system);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xee0(%rip),%rdi
lea    -0x34(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xec0(%rip),%rdi
lea    -0x38(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
cmpl   $0xa,-0x34(%rbp)
jne    11e7 <main+0x97>
lea    -0x30(%rbp),%rdi
call   1070 <atoi@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   1040 <convert_from_dec_to_anybase@plt>
jmp    1239 <main+0xe9>
cmpl   $0xa,-0x38(%rbp)
jne    1218 <main+0xc8>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1030 <convert_to_decimal@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rsi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1234 <main+0xe4>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1030 <convert_to_decimal@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   1040 <convert_from_dec_to_anybase@plt>
jmp    1239 <main+0xe9>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xee9(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xed6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0xc(%rsp),%esi
cmp    $0xa,%esi
jne    11cc <main+0x7c>
lea    0x10(%rsp),%rdi
call   1070 <atoi@plt>
jmp    11f2 <main+0xa2>
mov    0x8(%rsp),%ebx
lea    0x10(%rsp),%rdi
call   1030 <convert_to_decimal@plt>
cmp    $0xa,%ebx
jne    11f2 <main+0xa2>
lea    0xedb(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11fe <main+0xae>
mov    0x8(%rsp),%esi
mov    %rax,%rdi
call   1040 <convert_from_dec_to_anybase@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"\0AEnter the Number to Convert: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [82 x i8] c"\0AEnter the Current Number System (2 for Bin, 10 for Dec, 8 for Oct, 16 for Hex): \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [74 x i8] c"\0AEnter the Target System (2 for Bin, 10 for Dec, 8 for Oct, 16 for Hex): \00"
@.str.5 = [23 x i8] c"\0ADecimal Number = %ld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([82 x i8], [82 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 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, 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* %4)
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 10
br i1 %14, label %15, label %21
15: ; preds = %0
%16 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%17 = call i64 @atoi(i8* %16)
store i64 %17, i64* %5
%18 = load i64, i64* %5
%19 = load i32, i32* %4
%20 = call i32 @convert_from_dec_to_anybase(i64 %18, i32 %19)
br label %38
21: ; preds = %0
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%26 = load i32, i32* %3
%27 = call i64 @convert_to_decimal(i8* %25, i32 %26)
store i64 %27, i64* %5
%28 = load i64, i64* %5
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 %28)
br label %37
30: ; preds = %21
%31 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%32 = load i32, i32* %3
%33 = call i64 @convert_to_decimal(i8* %31, i32 %32)
store i64 %33, i64* %5
%34 = load i64, i64* %5
%35 = load i32, i32* %4
%36 = call i32 @convert_from_dec_to_anybase(i64 %34, i32 %35)
br label %37
37: ; preds = %30, %24
br label %38
38: ; preds = %37, %15
ret i32 0
}

LLVM IR (-O2):
@.str = [31 x i8] c"\0AEnter the Number to Convert: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [82 x i8] c"\0AEnter the Current Number System (2 for Bin, 10 for Dec, 8 for Oct, 16 for Hex): \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [74 x i8] c"\0AEnter the Target System (2 for Bin, 10 for Dec, 8 for Oct, 16 for Hex): \00"
@.str.5 = [23 x i8] c"\0ADecimal Number = %ld\0A\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 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), i8* %4)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([82 x i8], [82 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 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([74 x i8], [74 x i8]* @.str.4, 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* %3)
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 10
br i1 %14, label %15, label %19
15: ; preds = %0
%16 = call i64 @atoi(i8* %4)
%17 = load i32, i32* %3
%18 = call i32 @convert_from_dec_to_anybase(i64 %16, i32 %17)
br label %28
19: ; preds = %0
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 10
%22 = call i64 @convert_to_decimal(i8* %4, i32 %13)
br i1 %21, label %23, label %25
23: ; preds = %19
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 %22)
br label %28
25: ; preds = %19
%26 = load i32, i32* %3
%27 = call i32 @convert_from_dec_to_anybase(i64 %22, i32 %26)
br label %28
28: ; preds = %23, %25, %15
ret i32 0
}