#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 */
typedef int /*<<< orphan*/ value_out;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
unsigned long strtoul(char *, int /*<<< orphan*/, int);
int main() {
  int radix_in, radix_out;
  char *value_in = 0;
  scanf("%d", &radix_in);
  scanf("%ms", &value_in);
  scanf("%d", &radix_out);
  unsigned long value = strtoul(value_in, 0, radix_in);
  char value_out[32], *value_out_ptr = value_out + sizeof(value_out);
  *--value_out_ptr = 0;
  while (value) {
    assert(value_out_ptr != value_out);
    *--value_out_ptr =
        "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[value % radix_out];
    value /= radix_out;
  }
  if (*value_out_ptr) {
    printf("%s\n", value_out_ptr);
  } else {
    printf("0\n");
  }
  free(value_in);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe92(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe83(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe6e(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%edx
xor    %esi,%esi
call   1070 <strtoul@plt>
mov    %rax,-0x20(%rbp)
lea    -0x40(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x48(%rbp)
movb   $0x0,-0x1(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1230 <main+0xe0>
mov    -0x48(%rbp),%rax
lea    -0x40(%rbp),%rcx
cmp    %rcx,%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
xor    %edx,%edx
div    %rcx
lea    0xe02(%rip),%rax
mov    (%rax,%rdx,1),%cl
mov    -0x48(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x48(%rbp)
mov    %cl,-0x1(%rax)
movslq -0xc(%rbp),%rcx
mov    -0x20(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
jmp    11ce <main+0x7e>
mov    -0x48(%rbp),%rax
cmpb   $0x0,(%rax)
je     1254 <main+0x104>
mov    -0x48(%rbp),%rsi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1262 <main+0x112>
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
movq   $0x0,(%rsp)
lea    0xe96(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0xe83(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    (%rsp),%rdi
mov    0xc(%rsp),%edx
xor    %esi,%esi
call   1070 <strtoul@plt>
movb   $0x0,0x2f(%rsp)
test   %rax,%rax
je     1220 <main+0xd0>
mov    %rax,%r14
lea    0x2f(%rsp),%r15
mov    $0x1e,%ebx
lea    0xe41(%rip),%r12
jmp    11f1 <main+0xa1>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rax
xor    %edx,%edx
div    %rsi
movzbl (%rdx,%r12,1),%ecx
mov    %cl,-0x1(%r15)
add    $0xffffffffffffffff,%r15
add    $0xffffffffffffffff,%rbx
cmp    %rsi,%r14
mov    %rax,%r14
jb     121a <main+0xca>
xor    %edi,%edi
cmp    $0xffffffffffffffff,%rbx
setne  %dil
call   1050 <assert@plt>
movslq 0x8(%rsp),%rsi
mov    %r14,%rax
or     %rsi,%rax
shr    $0x20,%rax
jne    11d0 <main+0x80>
mov    %r14d,%eax
xor    %edx,%edx
div    %esi
jmp    11d8 <main+0x88>
cmp    $0x24,%rdx
jne    1229 <main+0xd9>
lea    0xe05(%rip),%rdi
jmp    122c <main+0xdc>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%ms\00"
@.str.2 = [37 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [3 x i8] c"0\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca [32 x i8]
%7 = alloca i8*
store i32 0, i32* %1
store i8* null, i8** %4
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %4)
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%11 = load i8*, i8** %4
%12 = load i32, i32* %2
%13 = call i64 @strtoul(i8* %11, i32 0, i32 %12)
store i64 %13, i64* %5
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds i8, i8* %14, i64 32
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = getelementptr inbounds i8, i8* %16, i32 -1
store i8* %17, i8** %7
store i8 0, i8* %17
br label %18
18: ; preds = %21, %0
%19 = load i64, i64* %5
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %39
21: ; preds = %18
%22 = load i8*, i8** %7
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%24 = icmp ne i8* %22, %23
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i64, i64* %5
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = urem i64 %27, %29
%31 = getelementptr inbounds [37 x i8], [37 x i8]* @.str.2, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i32 -1
store i8* %34, i8** %7
store i8 %32, i8* %34
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = load i64, i64* %5
%38 = udiv i64 %37, %36
store i64 %38, i64* %5
br label %18
39: ; preds = %18
%40 = load i8*, i8** %7
%41 = load i8, i8* %40
%42 = icmp ne i8 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i8*, i8** %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %44)
br label %48
46: ; preds = %39
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %46, %43
%49 = load i8*, i8** %4
%50 = call i32 @free(i8* %49)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%ms\00"
@.str.2 = [37 x i8] c"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@str = [2 x i8] c"0\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [32 x i8]
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %3)
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = load i8*, i8** %3
%12 = load i32, i32* %1
%13 = call i64 @strtoul(i8* %11, i32 0, i32 %12)
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 31
store i8 0, i8* %15
%16 = icmp eq i64 %13, 0
br i1 %16, label %35, label %17
17: ; preds = %0, %17
%18 = phi i8* [ %28, %17 ], [ %15, %0 ]
%19 = phi i64 [ %29, %17 ], [ %13, %0 ]
%20 = icmp ne i8* %18, %14
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %2
%24 = sext i32 %23 to i64
%25 = urem i64 %19, %24
%26 = getelementptr inbounds [37 x i8], [37 x i8]* @.str.2, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = getelementptr inbounds i8, i8* %18, i64 -1
store i8 %27, i8* %28
%29 = udiv i64 %19, %24
%30 = icmp ult i64 %19, %24
br i1 %30, label %31, label %17
31: ; preds = %17
%32 = icmp eq i64 %25, 36
br i1 %32, label %35, label %33
33: ; preds = %31
%34 = call i32 @puts(i8* %28)
br label %37
35: ; preds = %0, %31
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %37
37: ; preds = %35, %33
%38 = load i8*, i8** %3
%39 = call i32 @free(i8* %38)
ret i32 0
}