#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 /*<<< orphan*/ scanf(char *, ...);
int solve(unsigned int, unsigned int, unsigned int);
int main(int argc, char **argv) {
  int num_tests, test = 0, ret = 1;
  int round;
  unsigned int a, b, k;
  scanf("%d", &num_tests);
  if (num_tests < 1 || num_tests > 100) {
    printf("Illegal number of tests (1 <= T <= 100)\n");
    goto out;
  }
  while (test++ < num_tests) {
    scanf("%d %d %d", &a, &b, &k);
    if (a < 1 || a > 1000) {
      printf("1 <= a <= 1000\n");
      continue;
    }
    if (b < 1 || b > 1000) {
      printf("1 <= b <= 1000\n");
      continue;
    }
    if (k < 1 || k > 1000) {
      printf("1 <= k <= 1000\n");
      continue;
    }
    round = solve(a, b, k);
    printf("Case #%d: ", test);
    if (round < 0)
      printf("ERROR\n");
    else
      printf("%d\n", round);
  }
  ret = 0;
out:
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    0xed4(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x1,-0x14(%rbp)
jl     117a <main+0x4a>
cmpl   $0x64,-0x14(%rbp)
jle    118d <main+0x5d>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    129a <main+0x16a>
jmp    1192 <main+0x62>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cmp    -0x14(%rbp),%eax
jge    1293 <main+0x163>
lea    0xe7c(%rip),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
mov    $0x0,%al
call   1050 <scanf@plt>
cmpl   $0x1,-0x24(%rbp)
jb     11d7 <main+0xa7>
cmpl   $0x3e8,-0x24(%rbp)
jbe    11ea <main+0xba>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1192 <main+0x62>
cmpl   $0x1,-0x28(%rbp)
jb     1201 <main+0xd1>
cmpl   $0x3e8,-0x28(%rbp)
jbe    1214 <main+0xe4>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1192 <main+0x62>
cmpl   $0x1,-0x2c(%rbp)
jb     122b <main+0xfb>
cmpl   $0x3e8,-0x2c(%rbp)
jbe    123e <main+0x10e>
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1192 <main+0x62>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1030 <solve@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
jge    127d <main+0x14d>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    128e <main+0x15e>
mov    -0x20(%rbp),%esi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1192 <main+0x62>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb1(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xffffff9b,%eax
cmp    $0xffffff9c,%eax
jae    1183 <main+0x43>
lea    0xed7(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    127d <main+0x13d>
lea    0xe76(%rip),%r15
lea    0x8(%rsp),%rbx
lea    0x14(%rsp),%r12
lea    0x10(%rsp),%r14
lea    0xe9c(%rip),%r13
xor    %ebp,%ebp
jmp    11c2 <main+0x82>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
call   1040 <puts@plt>
cmp    0xc(%rsp),%ebp
jge    127b <main+0x13b>
add    $0x1,%ebp
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x8(%rsp),%edi
lea    -0x3e9(%rdi),%eax
cmp    $0xfffffc17,%eax
jbe    11b0 <main+0x70>
mov    0x14(%rsp),%esi
lea    -0x3e9(%rsi),%eax
cmp    $0xfffffc17,%eax
ja     1210 <main+0xd0>
lea    0xe2c(%rip),%rdi
jmp    11b3 <main+0x73>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp),%edx
lea    -0x3e9(%rdx),%eax
cmp    $0xfffffc17,%eax
ja     122a <main+0xea>
lea    0xdf6(%rip),%rdi
jmp    11b3 <main+0x73>
mov    %r13,%rbx
call   1030 <solve@plt>
mov    %eax,%r13d
lea    0xdcd(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r13d,%r13d
js     125d <main+0x11d>
lea    0xdc3(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1269 <main+0x129>
lea    0xdb4(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%r13
lea    0x8(%rsp),%rbx
cmp    0xc(%rsp),%ebp
jl     11c2 <main+0x82>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [41 x i8] c"Illegal number of tests (1 <= T <= 100)\0A\00"
@.str.2 = [9 x i8] c"%d %d %d\00"
@.str.3 = [16 x i8] c"1 <= a <= 1000\0A\00"
@.str.4 = [16 x i8] c"1 <= b <= 1000\0A\00"
@.str.5 = [16 x i8] c"1 <= k <= 1000\0A\00"
@.str.6 = [11 x i8] c"Case #%d: \00"
@.str.7 = [7 x i8] c"ERROR\0A\00"
@.str.8 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 1, i32* %8
%13 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 1
br i1 %15, label %19, label %16
16: ; preds = %2
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, 100
br i1 %18, label %19, label %21
19: ; preds = %16, %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %68
21: ; preds = %16
br label %22
22: ; preds = %66, %50, %42, %34, %21
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
%25 = load i32, i32* %6
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %67
27: ; preds = %22
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %10, i32* %11, i32* %12)
%29 = load i32, i32* %10
%30 = icmp ult i32 %29, 1
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = load i32, i32* %10
%33 = icmp ugt i32 %32, 1000
br i1 %33, label %34, label %36
34: ; preds = %31, %27
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %22
36: ; preds = %31
%37 = load i32, i32* %11
%38 = icmp ult i32 %37, 1
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = load i32, i32* %11
%41 = icmp ugt i32 %40, 1000
br i1 %41, label %42, label %44
42: ; preds = %39, %36
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %22
44: ; preds = %39
%45 = load i32, i32* %12
%46 = icmp ult i32 %45, 1
br i1 %46, label %50, label %47
47: ; preds = %44
%48 = load i32, i32* %12
%49 = icmp ugt i32 %48, 1000
br i1 %49, label %50, label %52
50: ; preds = %47, %44
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %22
52: ; preds = %47
%53 = load i32, i32* %10
%54 = load i32, i32* %11
%55 = load i32, i32* %12
%56 = call i32 @solve(i32 %53, i32 %54, i32 %55)
store i32 %56, i32* %9
%57 = load i32, i32* %7
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %9
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %52
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %66
63: ; preds = %52
%64 = load i32, i32* %9
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %64)
br label %66
66: ; preds = %63, %61
br label %22
67: ; preds = %22
store i32 0, i32* %8
br label %68
68: ; preds = %67, %19
%69 = load i32, i32* %8
ret i32 %69
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.2 = [9 x i8] c"%d %d %d\00"
@.str.6 = [11 x i8] c"Case #%d: \00"
@.str.8 = [4 x i8] c"%d\0A\00"
@str = [6 x i8] c"ERROR\00"
@str.9 = [15 x i8] c"1 <= k <= 1000\00"
@str.10 = [15 x i8] c"1 <= b <= 1000\00"
@str.11 = [15 x i8] c"1 <= a <= 1000\00"
@str.12 = [40 x i8] c"Illegal number of tests (1 <= T <= 100)\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
%13 = add i32 %12, -101
%14 = icmp ult i32 %13, -100
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.12, i64 0, i64 0))
br label %49
17: ; preds = %2, %25
%18 = phi i32 [ %26, %25 ], [ 1, %2 ]
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %4, i32* %5, i32* %6)
%20 = load i32, i32* %4
%21 = add i32 %20, -1001
%22 = icmp ult i32 %21, -1000
br i1 %22, label %23, label %29
23: ; preds = %17
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.11, i64 0, i64 0))
br label %25
25: ; preds = %45, %47, %23, %33, %39
%26 = add nuw nsw i32 %18, 1
%27 = load i32, i32* %3
%28 = icmp slt i32 %18, %27
br i1 %28, label %17, label %49
29: ; preds = %17
%30 = load i32, i32* %5
%31 = add i32 %30, -1001
%32 = icmp ult i32 %31, -1000
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.10, i64 0, i64 0))
br label %25
35: ; preds = %29
%36 = load i32, i32* %6
%37 = add i32 %36, -1001
%38 = icmp ult i32 %37, -1000
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.9, i64 0, i64 0))
br label %25
41: ; preds = %35
%42 = call i32 @solve(i32 %20, i32 %30, i32 %36)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %18)
%44 = icmp slt i32 %42, 0
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %25
47: ; preds = %41
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %42)
br label %25
49: ; preds = %25, %15
%50 = phi i32 [ 1, %15 ], [ 0, %25 ]
ret i32 %50
}