#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__ convertDecimalToBase(int, char *, int);
int convertToDecimal(char *, int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ scanf(char *, ...);
int main(void) {
  char representation[1000 + 1], result[7 + 1];
  int fromBase, toBase, decimal;
  while (scanf("%s", representation) > 0) {
    scanf("%d %d", &fromBase, &toBase);
    decimal = convertToDecimal(representation, fromBase);
    if (decimal < 0 || convertDecimalToBase(decimal, result, toBase) < 0)
      printf("%7s\n", "ERROR");
    else
      printf("%7s\n", result);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x3f0(%rbp),%rsi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
cmp    $0x0,%rax
jle    1204 <main+0xc4>
lea    0xe8b(%rip),%rdi
lea    -0x3fc(%rbp),%rsi
lea    -0x400(%rbp),%rdx
mov    $0x0,%al
call   1060 <scanf@plt>
lea    -0x3f0(%rbp),%rdi
mov    -0x3fc(%rbp),%esi
call   1050 <convertToDecimal@plt>
mov    %eax,-0x404(%rbp)
cmpl   $0x0,-0x404(%rbp)
jl     11d4 <main+0x94>
mov    -0x404(%rbp),%edi
lea    -0x3f8(%rbp),%rsi
mov    -0x400(%rbp),%edx
call   1040 <convertDecimalToBase@plt>
cmp    $0x0,%rax
jge    11ec <main+0xac>
lea    0xe2e(%rip),%rdi
lea    0xe2c(%rip),%rsi
call   1030 <printf@plt>
jmp    11ff <main+0xbf>
lea    -0x3f8(%rbp),%rsi
lea    0xe0f(%rip),%rdi
call   1030 <printf@plt>
jmp    1152 <main+0x12>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
lea    0xea8(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
test   %rax,%rax
jle    11ef <main+0xaf>
lea    0x4(%rsp),%r15
mov    %rsp,%r12
lea    0x10(%rsp),%rbx
lea    0xe88(%rip),%r13
lea    0xe78(%rip),%rbp
lea    0x8(%rsp),%r14
jmp    11b1 <main+0x71>
nop
mov    %r13,%rdi
lea    0xe74(%rip),%rsi
call   1030 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
test   %rax,%rax
jle    11ef <main+0xaf>
lea    0xe4b(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1050 <convertToDecimal@plt>
test   %eax,%eax
js     1190 <main+0x50>
mov    (%rsp),%edx
mov    %eax,%edi
mov    %r14,%rsi
call   1040 <convertDecimalToBase@plt>
test   %rax,%rax
js     1190 <main+0x50>
mov    %r13,%rdi
mov    %r14,%rsi
jmp    119a <main+0x5a>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [5 x i8] c"%7s\0A\00"
@.str.3 = [6 x i8] c"ERROR\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1001 x i8]
%3 = alloca [8 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
br label %7
7: ; preds = %29, %0
%8 = getelementptr inbounds [1001 x i8], [1001 x i8]* %2, i64 0, i64 0
%9 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %7
%12 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5)
%13 = getelementptr inbounds [1001 x i8], [1001 x i8]* %2, i64 0, i64 0
%14 = load i32, i32* %4
%15 = call i32 @convertToDecimal(i8* %13, i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %11
%19 = load i32, i32* %6
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%21 = load i32, i32* %5
%22 = call i64 @convertDecimalToBase(i32 %19, i8* %20, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %18, %11
%25 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %29
26: ; preds = %18
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%28 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %26, %24
br label %7
30: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [5 x i8] c"%7s\0A\00"
@.str.3 = [6 x i8] c"ERROR\00"
define i32 @main() {
%1 = alloca [1001 x i8]
%2 = alloca [8 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [1001 x i8], [1001 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %0, %24
%12 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%13 = load i32, i32* %3
%14 = call i32 @convertToDecimal(i8* %5, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %11
%17 = load i32, i32* %4
%18 = call i64 @convertDecimalToBase(i32 %14, i8* %6, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16, %11
%21 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %24
22: ; preds = %16
%23 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %6)
br label %24
24: ; preds = %22, %20
%25 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%26 = icmp sgt i64 %25, 0
br i1 %26, label %11, label %27
27: ; preds = %24, %0
ret i32 0
}