#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 */
scalar_t__ l(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int c;
  int counter = 0;
  scanf("%d", &c);
  while (c--) {
    counter++;
    int a;
    int t = 0;
    scanf("%d", &a);
    if (a < 3) {
      printf("0\n");
    } else {
      while (a > 0) {
        t++;
        a -= l(t);
        if (a < 0) {
          t--;
        }
      }
      printf("Case %d: %d\n", counter, t);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1205 <main+0xd5>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xe7f(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x3,-0x10(%rbp)
jge    11a7 <main+0x77>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1200 <main+0xd0>
jmp    11ac <main+0x7c>
cmpl   $0x0,-0x10(%rbp)
jle    11ec <main+0xbc>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <l@plt>
mov    %rax,%rcx
movslq -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11e7 <main+0xb7>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11ac <main+0x7c>
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1156 <main+0x26>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
subl   $0x1,0x4(%rsp)
jae    1174 <main+0x34>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe85(%rip),%r14
mov    %rsp,%r13
lea    0xe7e(%rip),%r12
xor    %ebp,%ebp
jmp    11a5 <main+0x65>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
subl   $0x1,0x4(%rsp)
jb     1163 <main+0x23>
add    $0x1,%ebp
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <scanf@plt>
cmpl   $0x3,(%rsp)
jge    11d0 <main+0x90>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
subl   $0x1,0x4(%rsp)
jae    11a5 <main+0x65>
jmp    1163 <main+0x23>
xchg   %ax,%ax
xor    %ebx,%ebx
jmp    11e2 <main+0xa2>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
jle    1190 <main+0x50>
lea    0x1(%rbx),%r15d
mov    %r15d,%edi
call   1040 <l@plt>
mov    (%rsp),%ecx
sub    %eax,%ecx
mov    %ecx,(%rsp)
test   %ecx,%ecx
js     11e0 <main+0xa0>
mov    %r15d,%ebx
jmp    11e0 <main+0xa0>

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.2 = [13 x i8] c"Case %d: %d\0A\00"
@str = [2 x i8] c"0\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = add nsw i32 %5, -1
store i32 %6, i32* %1
%7 = icmp eq i32 %5, 0
br i1 %7, label %34, label %8
8: ; preds = %0
%9 = bitcast i32* %2 to i8*
br label %10
10: ; preds = %8, %30
%11 = phi i32 [ 0, %8 ], [ %12, %30 ]
%12 = add nuw nsw i32 %11, 1
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%14 = load i32, i32* %2
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
br label %30
18: ; preds = %10, %18
%19 = phi i32 [ %26, %18 ], [ 0, %10 ]
%20 = add nsw i32 %19, 1
%21 = call i64 @l(i32 %20)
%22 = load i32, i32* %2
%23 = trunc i64 %21 to i32
%24 = sub i32 %22, %23
store i32 %24, i32* %2
%25 = icmp slt i32 %24, 0
%26 = select i1 %25, i32 %19, i32 %20
%27 = icmp sgt i32 %24, 0
br i1 %27, label %18, label %28
28: ; preds = %18
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %12, i32 %26)
br label %30
30: ; preds = %28, %16
%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 %10
34: ; preds = %30, %0
ret i32 0
}