#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*/ print(int);
int /*<<< orphan*/ scanf(char *, int *, int *);
int main() {
  int buf[100] = {0};
  int d, r;
  int ibuf, j;
  scanf("%d %d", &d, &r);
  ibuf = 0;
  while (d != 0) {
    buf[ibuf++] = d % r;
    d /= r;
  }
  for (j = ibuf - 1; j >= 0; j--)
    print(buf[j]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x1a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x190,%edx
call   1030 <memset@plt>
lea    0xea4(%rip),%rdi
lea    -0x1a4(%rbp),%rsi
lea    -0x1a8(%rbp),%rdx
call   1050 <scanf@plt>
movl   $0x0,-0x1ac(%rbp)
cmpl   $0x0,-0x1a4(%rbp)
je     11c7 <main+0x97>
mov    -0x1a4(%rbp),%eax
cltd
idivl  -0x1a8(%rbp)
mov    -0x1ac(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1ac(%rbp)
cltq
mov    %edx,-0x1a0(%rbp,%rax,4)
mov    -0x1a8(%rbp),%ecx
mov    -0x1a4(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x1a4(%rbp)
jmp    1179 <main+0x49>
mov    -0x1ac(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1b0(%rbp)
cmpl   $0x0,-0x1b0(%rbp)
jl     120a <main+0xda>
movslq -0x1b0(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%edi
call   1040 <print@plt>
mov    -0x1b0(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1b0(%rbp)
jmp    11d6 <main+0xa6>
mov    -0x4(%rbp),%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1a0,%rsp
lea    0x10(%rsp),%rdi
mov    $0x190,%edx
xor    %esi,%esi
call   1030 <memset@plt>
lea    0xeb0(%rip),%rdi
lea    0x8(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1050 <scanf@plt>
mov    0x8(%rsp),%eax
test   %eax,%eax
je     11b6 <main+0x86>
mov    0xc(%rsp),%esi
xor    %ecx,%ecx
nopl   (%rax)
cltd
idiv   %esi
mov    %edx,0x10(%rsp,%rcx,4)
add    $0x1,%rcx
test   %eax,%eax
jne    1170 <main+0x40>
movl   $0x0,0x8(%rsp)
test   %ecx,%ecx
jle    11b6 <main+0x86>
mov    %ecx,%ebx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%eax
mov    0x10(%rsp,%rax,4),%edi
call   1040 <print@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11a0 <main+0x70>
xor    %eax,%eax
add    $0x1a0,%rsp
pop    %rbx
ret

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

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