#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);
int scanf(char *, int *, int *);
int main() {
  int e, c, total, temp, mod, num;
  while (scanf("%d %d", &e, &c) == 2) {
    total = e;
    mod = 0;
    num = 0;
    while (total > mod) {
      temp = total / c;
      mod = total % c;
      num += temp;
      total = temp + mod;
    }
    printf("%d\n", e + num);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
cmp    $0x2,%eax
jne    11ae <main+0x8e>
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    1197 <main+0x77>
mov    -0x10(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1160 <main+0x40>
mov    -0x8(%rbp),%esi
add    -0x1c(%rbp),%esi
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xed1(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <scanf@plt>
cmp    $0x2,%eax
jne    119f <main+0x7f>
lea    0xebe(%rip),%r14
lea    0xeb1(%rip),%r15
lea    0x4(%rsp),%r12
mov    %rsp,%rbx
jmp    117d <main+0x5d>
nopl   0x0(%rax)
add    %ecx,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <scanf@plt>
cmp    $0x2,%eax
jne    119f <main+0x7f>
mov    0x4(%rsp),%ecx
xor    %esi,%esi
test   %ecx,%ecx
jle    1160 <main+0x40>
mov    (%rsp),%edi
mov    %ecx,%edx
nopl   0x0(%rax)
mov    %edx,%eax
cltd
idiv   %edi
add    %eax,%esi
add    %eax,%edx
test   %eax,%eax
jg     1190 <main+0x70>
jmp    1160 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [4 x i8] c"%d\0A\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 = icmp eq i32 %5, 2
br i1 %6, label %7, label %26
7: ; preds = %0, %20
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %7
%11 = load i32, i32* %2
br label %12
12: ; preds = %10, %12
%13 = phi i32 [ 0, %10 ], [ %17, %12 ]
%14 = phi i32 [ %8, %10 ], [ %18, %12 ]
%15 = sdiv i32 %14, %11
%16 = srem i32 %14, %11
%17 = add nsw i32 %15, %13
%18 = add nsw i32 %16, %15
%19 = icmp sgt i32 %15, 0
br i1 %19, label %12, label %20
20: ; preds = %12, %7
%21 = phi i32 [ 0, %7 ], [ %17, %12 ]
%22 = add nsw i32 %21, %8
%23 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%25 = icmp eq i32 %24, 2
br i1 %25, label %7, label %26
26: ; preds = %20, %0
ret i32 0
}