#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, int *);
int main() {
  int current, base;
  int level = 1;
  scanf("%d %d", &current, &base);
  for (; current / level >= base; level *= base)
    ;
  for (; level >= 1;) {
    printf("%d", current / level);
    current %= level;
    level /= base;
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
lea    0xec3(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
cmp    -0xc(%rbp),%eax
jl     116e <main+0x4e>
jmp    115f <main+0x3f>
mov    -0xc(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    114a <main+0x2a>
jmp    1173 <main+0x53>
cmpl   $0x1,-0x10(%rbp)
jl     11b1 <main+0x91>
mov    -0x8(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
jmp    1173 <main+0x53>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rdi
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
call   1050 <scanf@plt>
mov    (%rsp),%ecx
mov    0x4(%rsp),%esi
mov    $0x1,%ebx
cmp    %esi,%ecx
jl     1170 <main+0x40>
mov    $0x1,%ebx
nopl   (%rax)
imul   %esi,%ebx
mov    %ecx,%eax
cltd
idiv   %ebx
cmp    %esi,%eax
jge    1160 <main+0x30>
test   %ebx,%ebx
jle    11a9 <main+0x79>
lea    0xe8c(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %ecx,%eax
cltd
idiv   %ebx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%eax
cltd
idiv   %ebx
mov    %edx,%ecx
mov    %edx,(%rsp)
mov    %ebx,%eax
cltd
idivl  0x4(%rsp)
mov    %eax,%ebx
test   %eax,%eax
jg     1180 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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