#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 */
scalar_t__ EOF;
long long convertBase10(char *, int);
int /*<<< orphan*/ convertToBase(long long, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, char *, int, ...);
scalar_t__ scanf(char *, int *, int *, char *);
int main() {
  int input_base, output_base;
  char input[10];
  while (scanf("%d %d %s", &input_base, &output_base, input) != EOF) {
    long long int base10Input = convertBase10(input, input_base);
    if (base10Input != -1) {
      char output[1024];
      memset(output, '\0', 1024);
      convertToBase(base10Input, output, output_base);
      printf("%s base %i = %s base %i\n", input, input_base, output,
             output_base);
    } else {
      printf("%s is an illegal base %i number\n", input, input_base);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x16(%rbp),%rcx
lea    0xe93(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1070 <scanf@plt>
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
je     120a <main+0xba>
lea    -0x16(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <convertBase10@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
je     11f0 <main+0xa0>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1060 <convertToBase@plt>
lea    -0x16(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    -0x420(%rbp),%rcx
mov    -0xc(%rbp),%r8d
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1205 <main+0xb5>
lea    -0x16(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1162 <main+0x12>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
lea    0xe98(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x16(%rsp),%rcx
call   1070 <scanf@plt>
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
jne    119c <main+0x4c>
xor    %eax,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x16(%rsp),%rbx
lea    0xe58(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0x20(%rsp),%rbp
jmp    11f2 <main+0xa2>
nopl   0x0(%rax)
mov    0xc(%rsp),%edx
lea    0xe57(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1070 <scanf@plt>
mov    0x2dfb(%rip),%rcx
cmp    (%rcx),%rax
je     1188 <main+0x38>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1050 <convertBase10@plt>
cmp    $0xffffffffffffffff,%rax
je     11c0 <main+0x70>
mov    %rax,%r14
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1040 <memset@plt>
mov    0x10(%rsp),%edx
mov    %r14,%rdi
mov    %rbp,%rsi
call   1060 <convertToBase@plt>
mov    0xc(%rsp),%edx
mov    0x10(%rsp),%r8d
lea    0xdd4(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rcx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11d5 <main+0x85>

LLVM IR (-O0):
@.str = [9 x i8] c"%d %d %s\00"
@EOF = global i64 0
@.str.1 = [25 x i8] c"%s base %i = %s base %i\0A\00"
@.str.2 = [33 x i8] c"%s is an illegal base %i number\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = alloca i64
%6 = alloca [1024 x i8]
store i32 0, i32* %1
br label %7
7: ; preds = %34, %0
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%9 = call i64 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i8* %8)
%10 = load i64, i64* @EOF
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %35
12: ; preds = %7
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%14 = load i32, i32* %2
%15 = call i64 @convertBase10(i8* %13, i32 %14)
store i64 %15, i64* %5
%16 = load i64, i64* %5
%17 = icmp ne i64 %16, -1
br i1 %17, label %18, label %30
18: ; preds = %12
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i8 signext 0, i32 1024)
%21 = load i64, i64* %5
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = load i32, i32* %3
%24 = call i32 @convertToBase(i64 %21, i8* %22, i32 %23)
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%26 = load i32, i32* %2
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%28 = load i32, i32* %3
%29 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %25, i32 %26, i8* %27, i32 %28)
br label %34
30: ; preds = %12
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%32 = load i32, i32* %2
%33 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %31, i32 %32)
br label %34
34: ; preds = %30, %18
br label %7
35: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d %d %s\00"
@EOF = global i64 0
@.str.1 = [25 x i8] c"%s base %i = %s base %i\0A\00"
@.str.2 = [33 x i8] c"%s is an illegal base %i number\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = alloca [1024 x i8]
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%8 = call i64 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i8* %7)
%9 = load i64, i64* @EOF
%10 = icmp eq i64 %8, %9
br i1 %10, label %31, label %11
11: ; preds = %0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
br label %13
13: ; preds = %11, %27
%14 = load i32, i32* %1
%15 = call i64 @convertBase10(i8* %7, i32 %14)
%16 = icmp eq i64 %15, -1
br i1 %16, label %24, label %17
17: ; preds = %13
%18 = call i32 @memset(i8* %12, i8 signext 0, i32 1024)
%19 = load i32, i32* %2
%20 = call i32 @convertToBase(i64 %15, i8* %12, i32 %19)
%21 = load i32, i32* %1
%22 = load i32, i32* %2
%23 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %7, i32 %21, i8* %12, i32 %22)
br label %27
24: ; preds = %13
%25 = load i32, i32* %1
%26 = call i32 (i8*, i8*, i32, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %7, i32 %25)
br label %27
27: ; preds = %24, %17
%28 = call i64 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2, i8* %7)
%29 = load i64, i64* @EOF
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %13
31: ; preds = %27, %0
ret i32 0
}