#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 */
typedef scalar_t__ int32_t;

/* Variables and functions */
int josephus(scalar_t__, scalar_t__);
int /*<<< orphan*/ printf(char *, scalar_t__, int);
int /*<<< orphan*/ scanf(char *, scalar_t__ *, ...);
int main() {
  int32_t n, k, q, c = 0;
  scanf("%d", &q);
  while (++c <= q) {
    scanf("%d %d", &n, &k);
    printf("Case %d: %d\n", c, josephus(n, k));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xeb5(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
cmp    -0x20(%rbp),%rax
jg     11b1 <main+0x81>
lea    0xe8a(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <josephus@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
jmp    1159 <main+0x29>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
lea    0xebf(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmpq   $0x0,0x8(%rsp)
jle    11b7 <main+0x87>
lea    0xea1(%rip),%r14
lea    0x18(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xe96(%rip),%r13
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x18(%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1030 <josephus@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
cmp    0x8(%rsp),%rbx
jl     1180 <main+0x50>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [13 x i8] c"Case %d: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %5
%6 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64* %4)
br label %7
7: ; preds = %12, %0
%8 = load i64, i64* %5
%9 = add nsw i64 %8, 1
store i64 %9, i64* %5
%10 = load i64, i64* %4
%11 = icmp sle i64 %9, %10
br i1 %11, label %12, label %19
12: ; preds = %7
%13 = call i32 (i8*, i64*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64* %2, i64* %3)
%14 = load i64, i64* %5
%15 = load i64, i64* %2
%16 = load i64, i64* %3
%17 = call i32 @josephus(i64 %15, i64 %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %14, i32 %17)
br label %7
19: ; preds = %7
ret i32 0
}

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