#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 /*<<< orphan*/ scanf(char *, int *, int *, int *);
int main() {
  int a, b, c, i, sum = 0;
  scanf("%d %d %d", &a, &b, &c);
  for (i = a; i <= b; i *= c) {
    sum += i;
  }
  sum *= 2;
  sum -= i / c;
  printf("%d", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xec3(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     1178 <main+0x58>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1154 <main+0x34>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe6a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xed5(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1040 <scanf@plt>
mov    0x14(%rsp),%eax
mov    0x10(%rsp),%edx
xor    %esi,%esi
mov    0xc(%rsp),%ecx
cmp    %edx,%eax
jg     116b <main+0x4b>
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %eax,%esi
imul   %ecx,%eax
cmp    %edx,%eax
jle    1160 <main+0x40>
add    %esi,%esi
cltd
idiv   %ecx
sub    %eax,%esi
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

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

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