#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*/ scanf(char *, int *, ...);
int /*<<< orphan*/ test_case(int, int, int *);
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    int m, r;
    scanf("%d %d", &m, &r);
    int arr[r];
    for (int i = 0; i < r; i++)
      scanf("%d", arr + i);
    test_case(m, r, arr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xecd(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11eb <main+0xcb>
lea    0xea4(%rip),%rdi
xor    %eax,%eax
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <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    11d0 <main+0xb0>
mov    -0x30(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1199 <main+0x79>
mov    -0x30(%rbp),%rdx
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <test_case@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    1141 <main+0x21>
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
lea    0xecb(%rip),%rdi
lea    -0x30(%rbp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
subl   $0x1,-0x30(%rbp)
jae    115a <main+0x3a>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xea2(%rip),%rbx
jmp    1184 <main+0x64>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    -0x34(%rbp),%edi
mov    %r14,%rdx
call   1030 <test_case@plt>
mov    %r15,%rsp
subl   $0x1,-0x30(%rbp)
jb     1149 <main+0x29>
lea    0xe75(%rip),%rdi
lea    -0x34(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %rsp,%r15
mov    -0x2c(%rbp),%eax
mov    %rsp,%r14
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x2c(%rbp),%esi
test   %esi,%esi
jle    1170 <main+0x50>
mov    %r14,%r13
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
add    $0x1,%r12
movslq -0x2c(%rbp),%rsi
add    $0x4,%r13
cmp    %rsi,%r12
jl     11d0 <main+0xb0>
jmp    1170 <main+0x50>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d %d\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 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %31, %0
%10 = load i32, i32* %2
%11 = add nsw i32 %10, -1
store i32 %11, i32* %2
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %36
13: ; preds = %9
%14 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%15 = load i32, i32* %4
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %5
%18 = alloca i32, i64 %16
store i64 %16, i64* %6
store i32 0, i32* %7
br label %19
19: ; preds = %28, %13
%20 = load i32, i32* %7
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %18, i64 %25
%27 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %26)
br label %28
28: ; preds = %23
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %19
31: ; preds = %19
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = call i32 @test_case(i32 %32, i32 %33, i32* %18)
%35 = load i8*, i8** %5
br label %9
36: ; preds = %9
ret i32 0
}

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