#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__ EOF;
int HookLengthFormula(int, int *);
int /*<<< orphan*/ printf(char *, int, int);
scalar_t__ scanf(char *, ...);
int main(void) {
  int p[1000 + 2], n, i, T = 0;
  scanf("%*d");
  while (scanf("%d", &n) != EOF) {
    for (i = 1; i <= n; i++)
      scanf("%d", &p[i]);
    printf("Case %d: %d\n", ++T, HookLengthFormula(n, p));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfc0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xfbc(%rbp)
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xea3(%rip),%rdi
lea    -0xfb4(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    0x2e72(%rip),%rcx
cmp    (%rcx),%rax
je     1212 <main+0xe2>
movl   $0x1,-0xfb8(%rbp)
mov    -0xfb8(%rbp),%eax
cmp    -0xfb4(%rbp),%eax
jg     11d2 <main+0xa2>
movslq -0xfb8(%rbp),%rax
lea    -0xfb0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0xfb8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfb8(%rbp)
jmp    1189 <main+0x59>
mov    -0xfbc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfc0(%rbp)
mov    %eax,-0xfbc(%rbp)
mov    -0xfb4(%rbp),%edi
lea    -0xfb0(%rbp),%rsi
call   1050 <HookLengthFormula@plt>
mov    -0xfc0(%rbp),%esi
mov    %eax,%edx
lea    0xdff(%rip),%rdi
call   1030 <printf@plt>
jmp    115a <main+0x2a>
xor    %eax,%eax
add    $0xfc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xfb8,%rsp
lea    0xeb8(%rip),%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xeae(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x2e7f(%rip),%r14
cmp    (%r14),%rax
jne    1182 <main+0x52>
xor    %eax,%eax
add    $0xfb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe7b(%rip),%rbx
lea    0xc(%rsp),%r12
xor    %r13d,%r13d
jmp    11d1 <main+0xa1>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r13d
lea    0x10(%rsp),%rsi
call   1050 <HookLengthFormula@plt>
lea    0xe52(%rip),%rdi
mov    %r13d,%esi
mov    %eax,%edx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    (%r14),%rax
je     116e <main+0x3e>
mov    0xc(%rsp),%edi
test   %edi,%edi
jle    11a0 <main+0x70>
lea    0x14(%rsp),%rbp
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
movslq 0xc(%rsp),%rdi
add    $0x1,%r15
add    $0x4,%rbp
cmp    %rdi,%r15
jl     11f0 <main+0xc0>
jmp    11a0 <main+0x70>

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

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