#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*/ freopen(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
size_t ternary_search(int *, int);
int main() {
  freopen("tests.txt", "r", stdin);
  int num_tests;
  scanf("%d", &num_tests);
  for (int t = 0; t < num_tests; t++) {
    int n;
    scanf("%d", &n);
    int array[n];
    for (int i = 0; i < n; i++) {
      scanf("%d", &array[i]);
    }
    printf("Test# %d : %d \n", t + 1, array[ternary_search(array, n)]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
lea    0xea1(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1040 <freopen@plt>
lea    0xe9a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1244 <main+0x104>
lea    0xe77(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1201 <main+0xc1>
mov    -0x30(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe1e(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cc <main+0x8c>
mov    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%esi
call   1060 <ternary_search@plt>
mov    -0x34(%rbp),%esi
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
mov    (%rax,%rcx,4),%edx
lea    0xde5(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1182 <main+0x42>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e90(%rip),%rax
mov    (%rax),%edx
lea    0xe9f(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1040 <freopen@plt>
lea    0xe98(%rip),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0x30(%rbp)
jle    1225 <main+0xe5>
xor    %r14d,%r14d
lea    0xe7b(%rip),%rbx
jmp    11c8 <main+0x88>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14d
mov    %r15,%rdi
call   1060 <ternary_search@plt>
mov    (%r15,%rax,4),%edx
lea    0xe58(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
mov    %r12,%rsp
cmp    -0x30(%rbp),%r14d
jge    1225 <main+0xe5>
mov    %rbx,%rdi
lea    -0x2c(%rbp),%rsi
call   1050 <scanf@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    -0x2c(%rbp),%esi
test   %esi,%esi
jle    11a0 <main+0x60>
mov    %r12,-0x38(%rbp)
mov    %r15,%r13
xor    %r12d,%r12d
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
add    $0x1,%r12
movslq -0x2c(%rbp),%rsi
add    $0x4,%r13
cmp    %rsi,%r12
jl     1200 <main+0xc0>
mov    -0x38(%rbp),%r12
jmp    11a0 <main+0x60>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"tests.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [16 x i8] c"Test# %d : %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @stdin
%4 = tail call i32 @freopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = bitcast i32* %1 to i8*
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = bitcast i32* %2 to i8*
br label %12
11: ; preds = %21, %0
ret i32 0
12: ; preds = %9, %21
%13 = phi i32 [ 0, %9 ], [ %23, %21 ]
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%15 = load i32, i32* %2
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
%18 = alloca i32, i64 %16
%19 = load i32, i32* %2
%20 = icmp sgt i32 %19, 0
br i1 %20, label %30, label %21
21: ; preds = %30, %12
%22 = phi i32 [ %19, %12 ], [ %35, %30 ]
%23 = add nuw nsw i32 %13, 1
%24 = call i64 @ternary_search(i32* %18, i32 %22)
%25 = getelementptr inbounds i32, i32* %18, i64 %24
%26 = load i32, i32* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %26)
%28 = load i32, i32* %1
%29 = icmp slt i32 %23, %28
br i1 %29, label %12, label %11
30: ; preds = %12, %30
%31 = phi i64 [ %34, %30 ], [ 0, %12 ]
%32 = getelementptr inbounds i32, i32* %18, i64 %31
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %32)
%34 = add nuw nsw i64 %31, 1
%35 = load i32, i32* %2
%36 = sext i32 %35 to i64
%37 = icmp slt i64 %34, %36
br i1 %37, label %30, label %21
}