#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 chocolatefeast(void) {
  int numCases;
  scanf("%d", &numCases);
  while (numCases--) {
    int money, cost, tradeCost;
    scanf("%d %d %d", &money, &cost, &tradeCost);
    int firstRoundAmt = money / cost;
    int lastRoundAmt = firstRoundAmt >= tradeCost;
    int midRoundAmt = 0;
    if (lastRoundAmt) {
      midRoundAmt = (firstRoundAmt - tradeCost) / (tradeCost - 1);
    }
    printf("%d\n", firstRoundAmt + lastRoundAmt + midRoundAmt);
  }
  return 0;
}


x86 assembly (clang, -O0):
<chocolatefeast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed7(%rip),%rdi
lea    -0x4(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     11c0 <chocolatefeast+0xa0>
lea    0xeab(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
setge  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11a6 <chocolatefeast+0x86>
mov    -0x14(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
add    -0x18(%rbp),%esi
add    -0x1c(%rbp),%esi
lea    0xe53(%rip),%rdi
call   1030 <printf@plt>
jmp    113a <chocolatefeast+0x1a>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chocolatefeast>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xed1(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,0x8(%rsp)
jae    1159 <chocolatefeast+0x39>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
lea    0xe9a(%rip),%r14
jmp    1195 <chocolatefeast+0x75>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %bl,%cl
add    %ecx,%esi
add    %ebp,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
subl   $0x1,0x8(%rsp)
jb     1148 <chocolatefeast+0x28>
xor    %ebp,%ebp
lea    0xe62(%rip),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x14(%rsp),%eax
cltd
idivl  0x10(%rsp)
mov    %eax,%esi
mov    0xc(%rsp),%edi
xor    %ecx,%ecx
sub    %edi,%eax
setge  %bl
jl     1180 <chocolatefeast+0x60>
add    $0xffffffff,%edi
cltd
idiv   %edi
mov    %eax,%ebp
jmp    1180 <chocolatefeast+0x60>

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

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