#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);
int /*<<< orphan*/ scanf(char *, int *);
int sqrt(int);
int main() {
  int t;
  int i, j, k;
  int p, n;
  int c, rank[9];
  int sum = 0;
  int calc, arr[9];
  scanf("%d", &t);
  while (t--) {
    for (i = 0; i < 9; i++)
      rank[i] = 0;
    sum = 0;
    scanf("%d", &p);
    scanf("%d", &c);
    for (i = 0; i < c; i++) {
      scanf("%d", &n);
      rank[n]++;
    }
    int low = 0, high = 10000000;
    int mid = (low + high) / 2;
    int prev_sum = 0, prev_mid = mid;
    int count = 0;
    while (1) {
      sum = 0;
      for (i = 1; i <= 8; i++) {
        int x = mid / i;
        calc = (-1 + sqrt(1 + 8 * x)) / 2;
        sum += calc * rank[i];
        arr[i] = rank[i] > 0 ? calc : 0;
      }
      if (sum == p)
        break;
      else if (sum < p)
        low = mid + 1;
      else
        high = mid - 1;
      if (prev_sum == sum)
        count++;
      else
        count = 0;
      if (count >= 100) {
        sum = 0;
        mid = low;
        for (i = 1; i <= 8; i++) {
          int x = mid / i;
          calc = (-1 + sqrt(1 + 8 * x)) / 2;
          sum += calc * rank[i];
          arr[i] = rank[i] > 0 ? calc : 0;
        }
        break;
      }
      mid = (low + high) / 2;
      prev_sum = sum;
    }
    int max = 0;
    for (i = 1; i <= 8; i++) {
      int each = ((arr[i] * (arr[i] + 1)) / 2) * i;
      if (each > max)
        max = each;
    }
    printf("%d\n", max);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x54(%rbp)
lea    0xeb0(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     14d2 <main+0x3a2>
movl   $0x0,-0xc(%rbp)
cmpl   $0x9,-0xc(%rbp)
jge    1198 <main+0x68>
movslq -0xc(%rbp),%rax
movl   $0x0,-0x50(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1174 <main+0x44>
movl   $0x0,-0x54(%rbp)
lea    0xe5a(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe4a(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    11ff <main+0xcf>
lea    0xe27(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <scanf@plt>
movslq -0x1c(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x50(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c6 <main+0x96>
movl   $0x0,-0x84(%rbp)
movl   $0x989680,-0x88(%rbp)
mov    -0x84(%rbp),%eax
add    -0x88(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8c(%rbp)
movl   $0x0,-0x90(%rbp)
mov    -0x8c(%rbp),%eax
mov    %eax,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jg     12ee <main+0x1be>
mov    -0x8c(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x9c(%rbp)
mov    -0x9c(%rbp),%edi
shl    $0x3,%edi
add    $0x1,%edi
call   1050 <sqrt@plt>
add    $0xffffffff,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
movslq -0xc(%rbp),%rcx
imul   -0x50(%rbp,%rcx,4),%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
movslq -0xc(%rbp),%rax
cmpl   $0x0,-0x50(%rbp,%rax,4)
jle    12c5 <main+0x195>
mov    -0x58(%rbp),%eax
mov    %eax,-0xac(%rbp)
jmp    12d2 <main+0x1a2>
xor    %eax,%eax
mov    %eax,-0xac(%rbp)
jmp    12d2 <main+0x1a2>
mov    -0xac(%rbp),%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x80(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    125b <main+0x12b>
mov    -0x54(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    12ff <main+0x1cf>
jmp    1447 <main+0x317>
mov    -0x54(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    131f <main+0x1ef>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    132e <main+0x1fe>
mov    -0x8c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1333 <main+0x203>
mov    -0x90(%rbp),%eax
cmp    -0x54(%rbp),%eax
jne    1356 <main+0x226>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    1360 <main+0x230>
movl   $0x0,-0x98(%rbp)
cmpl   $0x64,-0x98(%rbp)
jl     141f <main+0x2ef>
movl   $0x0,-0x54(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0x8c(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jg     141a <main+0x2ea>
mov    -0x8c(%rbp),%eax
cltd
idivl  -0xc(%rbp)
mov    %eax,-0xa0(%rbp)
mov    -0xa0(%rbp),%edi
shl    $0x3,%edi
add    $0x1,%edi
call   1050 <sqrt@plt>
add    $0xffffffff,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
movslq -0xc(%rbp),%rcx
imul   -0x50(%rbp,%rcx,4),%eax
add    -0x54(%rbp),%eax
mov    %eax,-0x54(%rbp)
movslq -0xc(%rbp),%rax
cmpl   $0x0,-0x50(%rbp,%rax,4)
jle    13f1 <main+0x2c1>
mov    -0x58(%rbp),%eax
mov    %eax,-0xb0(%rbp)
jmp    13fe <main+0x2ce>
xor    %eax,%eax
mov    %eax,-0xb0(%rbp)
jmp    13fe <main+0x2ce>
mov    -0xb0(%rbp),%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x80(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1387 <main+0x257>
jmp    1447 <main+0x317>
mov    -0x84(%rbp),%eax
add    -0x88(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8c(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x90(%rbp)
jmp    124d <main+0x11d>
movl   $0x0,-0xa4(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jg     14bb <main+0x38b>
movslq -0xc(%rbp),%rax
mov    -0x80(%rbp,%rax,4),%eax
movslq -0xc(%rbp),%rcx
mov    -0x80(%rbp,%rcx,4),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
imul   -0xc(%rbp),%eax
mov    %eax,-0xa8(%rbp)
mov    -0xa8(%rbp),%eax
cmp    -0xa4(%rbp),%eax
jle    14a8 <main+0x378>
mov    -0xa8(%rbp),%eax
mov    %eax,-0xa4(%rbp)
jmp    14ad <main+0x37d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1458 <main+0x328>
mov    -0xa4(%rbp),%esi
lea    0xb3b(%rip),%rdi
call   1030 <printf@plt>
jmp    1159 <main+0x29>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
lea    0xed8(%rip),%rdi
lea    0x28(%rsp),%rsi
call   1040 <scanf@plt>
subl   $0x1,0x28(%rsp)
jae    116d <main+0x3d>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xeac(%rip),%r14
lea    0x24(%rsp),%rbp
jmp    1308 <main+0x1d8>
xchg   %ax,%ax
pshufd $0x1b,0x40(%rsp),%xmm1
movd   0x10(%rsp),%xmm0
movd   0x4(%rsp),%xmm4
punpckldq %xmm0,%xmm4
movd   0x8(%rsp),%xmm5
movd   0xc(%rsp),%xmm0
punpckldq %xmm5,%xmm0
punpcklqdq %xmm4,%xmm0
pxor   %xmm4,%xmm4
pcmpgtd %xmm4,%xmm0
pcmpgtd %xmm4,%xmm1
pand   %xmm3,%xmm0
pand   %xmm2,%xmm1
lea    0xe5a(%rip),%r14
pshufd $0xee,%xmm0,%xmm2
movd   %xmm2,%eax
lea    0x1(%rax),%ecx
imul   %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
mov    $0x0,%eax
cmovs  %eax,%edx
pshufd $0x55,%xmm0,%xmm2
movd   %xmm2,%eax
lea    0x1(%rax),%ecx
imul   %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
add    %ecx,%eax
and    $0xfffffffe,%eax
cmp    %edx,%eax
cmovle %edx,%eax
movdqa %xmm1,%xmm2
movsd  %xmm0,%xmm2
movdqa %xmm1,%xmm3
shufps $0x24,%xmm2,%xmm3
psubd  %xmm6,%xmm3
movdqa %xmm1,%xmm2
shufps $0x5,%xmm0,%xmm2
pshufd $0xf5,%xmm3,%xmm4
pmuludq %xmm2,%xmm4
pshufd $0xe8,%xmm4,%xmm2
pmuludq %xmm1,%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm2,%xmm3
movdqa %xmm3,%xmm2
psrld  $0x1f,%xmm2
paddd  %xmm3,%xmm2
psrad  $0x1,%xmm2
pshufd $0xf5,%xmm2,%xmm3
pmuludq 0xda6(%rip),%xmm2
pshufd $0xe8,%xmm2,%xmm2
pmuludq 0xda9(%rip),%xmm3
pshufd $0xe8,%xmm3,%xmm3
punpckldq %xmm3,%xmm2
pshufd $0xff,%xmm1,%xmm1
movd   %xmm1,%ecx
lea    0x1(%rcx),%edx
imul   %ecx,%edx
mov    %edx,%ecx
shr    $0x1f,%ecx
add    %edx,%ecx
add    %ecx,%ecx
and    $0xfffffffc,%ecx
pshufd $0xee,%xmm2,%xmm1
movdqa %xmm2,%xmm3
pcmpgtd %xmm1,%xmm3
pand   %xmm3,%xmm2
pandn  %xmm1,%xmm3
por    %xmm2,%xmm3
pshufd $0x55,%xmm3,%xmm1
movdqa %xmm3,%xmm2
pcmpgtd %xmm1,%xmm2
pand   %xmm2,%xmm3
pandn  %xmm1,%xmm2
por    %xmm3,%xmm2
movd   %xmm2,%edx
cmp    %ecx,%edx
cmovg  %edx,%ecx
cmp    %eax,%ecx
cmovle %eax,%ecx
pshufd $0xff,%xmm0,%xmm0
movd   %xmm0,%eax
lea    0x1(%rax),%edx
imul   %eax,%edx
mov    %edx,%esi
shr    $0x1f,%esi
add    %edx,%esi
shl    $0x2,%esi
and    $0xfffffff8,%esi
cmp    %ecx,%esi
cmovle %ecx,%esi
lea    0xd30(%rip),%rdi
call   1030 <printf@plt>
subl   $0x1,0x28(%rsp)
lea    0x24(%rsp),%rbp
jb     1159 <main+0x29>
pxor   %xmm0,%xmm0
movdqa %xmm0,0x80(%rsp)
movdqa %xmm0,0x70(%rsp)
movl   $0x0,0x90(%rsp)
mov    %r14,%rdi
lea    0x2c(%rsp),%rsi
call   1040 <scanf@plt>
mov    %r14,%rdi
lea    0x20(%rsp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0x20(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
jle    13a6 <main+0x276>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbp,%rsi
call   1040 <scanf@plt>
movslq 0x24(%rsp),%rax
addl   $0x1,0x70(%rsp,%rax,4)
add    $0x1,%ebx
cmp    0x20(%rsp),%ebx
jl     1370 <main+0x240>
mov    0x74(%rsp),%eax
mov    %eax,0x4(%rsp)
mov    0x78(%rsp),%eax
mov    %eax,0x8(%rsp)
mov    0x7c(%rsp),%eax
mov    %eax,0xc(%rsp)
movaps 0x80(%rsp),%xmm0
movaps %xmm0,0x40(%rsp)
movl   $0x0,0x1c(%rsp)
mov    $0x4c4b40,%r15d
mov    $0x989680,%eax
mov    %rax,0x30(%rsp)
mov    0x90(%rsp),%eax
mov    %eax,0x10(%rsp)
xor    %eax,%eax
mov    %rax,0x38(%rsp)
movl   $0x0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x1(,%r15,8),%edi
call   1050 <sqrt@plt>
mov    %eax,0x60(%rsp)
mov    %r15d,%eax
shr    $0x1f,%eax
add    %r15d,%eax
and    $0xfffffffe,%eax
lea    0x1(,%rax,4),%edi
call   1050 <sqrt@plt>
mov    %eax,0x50(%rsp)
movslq %r15d,%rbx
imul   $0x55555556,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    0x1(,%rax,8),%edi
call   1050 <sqrt@plt>
mov    %eax,0x18(%rsp)
lea    0x3(%rbx),%eax
lea    0x7(%rbx),%r13d
test   %ebx,%ebx
cmovns %r15d,%eax
cmovns %r15d,%r13d
and    $0xfffffffc,%eax
lea    (%rax,%rax,1),%edi
add    $0x1,%edi
call   1050 <sqrt@plt>
mov    %eax,0x14(%rsp)
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x21,%rcx
shr    $0x3f,%rax
add    %ecx,%eax
lea    0x1(,%rax,8),%edi
call   1050 <sqrt@plt>
mov    %eax,%r12d
imul   $0x2aaaaaab,%rbx,%rax
mov    %rax,%rcx
shr    $0x20,%rcx
shr    $0x3f,%rax
add    %ecx,%eax
lea    0x1(,%rax,8),%edi
call   1050 <sqrt@plt>
mov    %eax,%ebp
imul   $0xffffffff92492493,%rbx,%rax
shr    $0x20,%rax
add    %r15d,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
shr    $0x2,%eax
add    %ecx,%eax
lea    0x1(,%rax,8),%edi
call   1050 <sqrt@plt>
mov    %eax,%r14d
and    $0xfffffff8,%r13d
or     $0x1,%r13d
mov    %r13d,%edi
call   1050 <sqrt@plt>
movd   0x14(%rsp),%xmm0
movd   %r12d,%xmm1
punpckldq %xmm0,%xmm1
movd   %r14d,%xmm0
movd   %ebp,%xmm2
punpckldq %xmm2,%xmm0
punpcklqdq %xmm1,%xmm0
movd   0x50(%rsp),%xmm1
movd   0x18(%rsp),%xmm4
punpckldq %xmm1,%xmm4
movd   %eax,%xmm1
movd   0x60(%rsp),%xmm2
punpckldq %xmm1,%xmm2
punpcklqdq %xmm2,%xmm4
pcmpeqd %xmm6,%xmm6
paddd  %xmm6,%xmm4
paddd  %xmm6,%xmm0
movdqa %xmm0,%xmm2
psrld  $0x1f,%xmm2
paddd  %xmm0,%xmm2
psrad  $0x1,%xmm2
movdqa %xmm4,%xmm3
psrld  $0x1f,%xmm3
paddd  %xmm4,%xmm3
psrad  $0x1,%xmm3
pshufd $0xee,%xmm3,%xmm0
movd   %xmm0,%eax
imul   0x4(%rsp),%eax
pshufd $0x55,%xmm3,%xmm0
movd   %xmm0,%ecx
imul   0x8(%rsp),%ecx
movd   %xmm3,%edx
imul   0xc(%rsp),%edx
pshufd $0x1b,%xmm2,%xmm0
pshufd $0x4e,%xmm2,%xmm1
movdqa 0x40(%rsp),%xmm5
pshufd $0xf5,%xmm5,%xmm4
pmuludq %xmm1,%xmm4
pshufd $0xe8,%xmm4,%xmm1
pmuludq %xmm5,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm1,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%esi
add    %edx,%esi
add    %ecx,%esi
add    %eax,%esi
pshufd $0xff,%xmm3,%xmm0
movd   %xmm0,%eax
imul   0x10(%rsp),%eax
add    %esi,%eax
mov    0x2c(%rsp),%ecx
cmp    %ecx,%eax
je     1180 <main+0x50>
jl     15f0 <main+0x4c0>
add    $0xffffffff,%r15d
mov    %r15,0x30(%rsp)
mov    0x38(%rsp),%r15
jmp    15f4 <main+0x4c4>
nop
add    $0x1,%r15d
mov    (%rsp),%ecx
cmp    %eax,0x1c(%rsp)
je     1610 <main+0x4e0>
xor    %ecx,%ecx
cmp    $0x64,%ecx
jl     1618 <main+0x4e8>
jmp    1640 <main+0x510>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ecx
cmp    $0x64,%ecx
jge    1640 <main+0x510>
mov    %ecx,(%rsp)
mov    %r15,0x38(%rsp)
mov    0x30(%rsp),%rcx
add    %r15d,%ecx
mov    %ecx,%r15d
shr    $0x1f,%r15d
add    %ecx,%r15d
sar    %r15d
mov    %eax,0x1c(%rsp)
jmp    13f0 <main+0x2c0>
xchg   %ax,%ax
pshufd $0x1b,0x40(%rsp),%xmm2
movd   0x10(%rsp),%xmm0
movd   0x4(%rsp),%xmm1
punpckldq %xmm0,%xmm1
movd   0x8(%rsp),%xmm0
movd   0xc(%rsp),%xmm3
punpckldq %xmm0,%xmm3
punpcklqdq %xmm1,%xmm3
pxor   %xmm0,%xmm0
pcmpgtd %xmm0,%xmm3
movdqa %xmm3,0x50(%rsp)
pcmpgtd %xmm0,%xmm2
movdqa %xmm2,0x60(%rsp)
lea    0x1(,%r15,8),%edi
call   1050 <sqrt@plt>
mov    %eax,0x18(%rsp)
mov    %r15d,%eax
shr    $0x1f,%eax
add    %r15d,%eax
and    $0xfffffffe,%eax
lea    0x1(,%rax,4),%edi
call   1050 <sqrt@plt>
mov    %eax,0x14(%rsp)
movslq %r15d,%rbp
imul   $0x55555556,%rbp,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x20,%rax
add    %ecx,%eax
lea    0x1(,%rax,8),%edi
call   1050 <sqrt@plt>
mov    %eax,(%rsp)
lea    0x3(%rbp),%eax
lea    0x7(%rbp),%r14d
test   %ebp,%ebp
cmovns %r15d,%eax
cmovns %r15d,%r14d
and    $0xfffffffc,%eax
lea    (%rax,%rax,1),%edi
add    $0x1,%edi
call   1050 <sqrt@plt>
mov    %eax,%r12d
imul   $0x66666667,%rbp,%rax
mov    %rax,%rcx
shr    $0x21,%rcx
shr    $0x3f,%rax
add    %ecx,%eax
lea    0x1(,%rax,8),%edi
call   1050 <sqrt@plt>
mov    %eax,%r13d
imul   $0x2aaaaaab,%rbp,%rax
mov    %rax,%rcx
shr    $0x20,%rcx
shr    $0x3f,%rax
add    %ecx,%eax
lea    0x1(,%rax,8),%edi
call   1050 <sqrt@plt>
mov    %eax,%ebx
imul   $0xffffffff92492493,%rbp,%rax
shr    $0x20,%rax
add    %r15d,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
shr    $0x2,%eax
add    %ecx,%eax
lea    0x1(,%rax,8),%edi
call   1050 <sqrt@plt>
mov    %eax,%r15d
and    $0xfffffff8,%r14d
or     $0x1,%r14d
mov    %r14d,%edi
call   1050 <sqrt@plt>
movd   0x14(%rsp),%xmm0
movd   (%rsp),%xmm1
punpckldq %xmm0,%xmm1
movd   %eax,%xmm0
movd   0x18(%rsp),%xmm2
punpckldq %xmm0,%xmm2
punpcklqdq %xmm2,%xmm1
movd   %r12d,%xmm0
movd   %r13d,%xmm2
punpckldq %xmm0,%xmm2
movd   %r15d,%xmm3
movd   %ebx,%xmm0
punpckldq %xmm0,%xmm3
punpcklqdq %xmm2,%xmm3
pcmpeqd %xmm6,%xmm6
paddd  %xmm6,%xmm3
paddd  %xmm6,%xmm1
movdqa %xmm1,%xmm0
psrld  $0x1f,%xmm0
paddd  %xmm1,%xmm0
psrad  $0x1,%xmm0
pand   0x50(%rsp),%xmm0
movdqa %xmm3,%xmm1
psrld  $0x1f,%xmm1
paddd  %xmm3,%xmm1
psrad  $0x1,%xmm1
pand   0x60(%rsp),%xmm1
jmp    11bf <main+0x8f>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [9 x i32]
%10 = alloca i32
%11 = alloca i32
%12 = alloca [9 x i32]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %10
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %24
24: ; preds = %200, %0
%25 = load i32, i32* %2
%26 = add nsw i32 %25, -1
store i32 %26, i32* %2
%27 = icmp ne i32 %25, 0
br i1 %27, label %28, label %203
28: ; preds = %24
store i32 0, i32* %3
br label %29
29: ; preds = %36, %28
%30 = load i32, i32* %3
%31 = icmp slt i32 %30, 9
br i1 %31, label %32, label %39
32: ; preds = %29
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [9 x i32], [9 x i32]* %9, i64 0, i64 %34
store i32 0, i32* %35
br label %36
36: ; preds = %32
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %29
39: ; preds = %29
store i32 0, i32* %10
%40 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%41 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
store i32 0, i32* %3
br label %42
42: ; preds = %53, %39
%43 = load i32, i32* %3
%44 = load i32, i32* %8
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %56
46: ; preds = %42
%47 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [9 x i32], [9 x i32]* %9, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = add nsw i32 %51, 1
store i32 %52, i32* %50
br label %53
53: ; preds = %46
%54 = load i32, i32* %3
%55 = add nsw i32 %54, 1
store i32 %55, i32* %3
br label %42
56: ; preds = %42
store i32 0, i32* %13
store i32 10000000, i32* %14
%57 = load i32, i32* %13
%58 = load i32, i32* %14
%59 = add nsw i32 %57, %58
%60 = sdiv i32 %59, 2
store i32 %60, i32* %15
store i32 0, i32* %16
%61 = load i32, i32* %15
store i32 %61, i32* %17
store i32 0, i32* %18
br label %62
62: ; preds = %56, %167
store i32 0, i32* %10
store i32 1, i32* %3
br label %63
63: ; preds = %97, %62
%64 = load i32, i32* %3
%65 = icmp sle i32 %64, 8
br i1 %65, label %66, label %100
66: ; preds = %63
%67 = load i32, i32* %15
%68 = load i32, i32* %3
%69 = sdiv i32 %67, %68
store i32 %69, i32* %19
%70 = load i32, i32* %19
%71 = mul nsw i32 8, %70
%72 = add nsw i32 1, %71
%73 = call i32 @sqrt(i32 %72)
%74 = add nsw i32 -1, %73
%75 = sdiv i32 %74, 2
store i32 %75, i32* %11
%76 = load i32, i32* %11
%77 = load i32, i32* %3
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [9 x i32], [9 x i32]* %9, i64 0, i64 %78
%80 = load i32, i32* %79
%81 = mul nsw i32 %76, %80
%82 = load i32, i32* %10
%83 = add nsw i32 %82, %81
store i32 %83, i32* %10
%84 = load i32, i32* %3
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [9 x i32], [9 x i32]* %9, i64 0, i64 %85
%87 = load i32, i32* %86
%88 = icmp sgt i32 %87, 0
br i1 %88, label %89, label %91
89: ; preds = %66
%90 = load i32, i32* %11
br label %92
91: ; preds = %66
br label %92
92: ; preds = %91, %89
%93 = phi i32 [ %90, %89 ], [ 0, %91 ]
%94 = load i32, i32* %3
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [9 x i32], [9 x i32]* %12, i64 0, i64 %95
store i32 %93, i32* %96
br label %97
97: ; preds = %92
%98 = load i32, i32* %3
%99 = add nsw i32 %98, 1
store i32 %99, i32* %3
br label %63
100: ; preds = %63
%101 = load i32, i32* %10
%102 = load i32, i32* %6
%103 = icmp eq i32 %101, %102
br i1 %103, label %104, label %105
104: ; preds = %100
br label %173
105: ; preds = %100
%106 = load i32, i32* %10
%107 = load i32, i32* %6
%108 = icmp slt i32 %106, %107
br i1 %108, label %109, label %112
109: ; preds = %105
%110 = load i32, i32* %15
%111 = add nsw i32 %110, 1
store i32 %111, i32* %13
br label %115
112: ; preds = %105
%113 = load i32, i32* %15
%114 = sub nsw i32 %113, 1
store i32 %114, i32* %14
br label %115
115: ; preds = %112, %109
br label %116
116: ; preds = %115
%117 = load i32, i32* %16
%118 = load i32, i32* %10
%119 = icmp eq i32 %117, %118
br i1 %119, label %120, label %123
120: ; preds = %116
%121 = load i32, i32* %18
%122 = add nsw i32 %121, 1
store i32 %122, i32* %18
br label %124
123: ; preds = %116
store i32 0, i32* %18
br label %124
124: ; preds = %123, %120
%125 = load i32, i32* %18
%126 = icmp sge i32 %125, 100
br i1 %126, label %127, label %167
127: ; preds = %124
store i32 0, i32* %10
%128 = load i32, i32* %13
store i32 %128, i32* %15
store i32 1, i32* %3
br label %129
129: ; preds = %163, %127
%130 = load i32, i32* %3
%131 = icmp sle i32 %130, 8
br i1 %131, label %132, label %166
132: ; preds = %129
%133 = load i32, i32* %15
%134 = load i32, i32* %3
%135 = sdiv i32 %133, %134
store i32 %135, i32* %20
%136 = load i32, i32* %20
%137 = mul nsw i32 8, %136
%138 = add nsw i32 1, %137
%139 = call i32 @sqrt(i32 %138)
%140 = add nsw i32 -1, %139
%141 = sdiv i32 %140, 2
store i32 %141, i32* %11
%142 = load i32, i32* %11
%143 = load i32, i32* %3
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds [9 x i32], [9 x i32]* %9, i64 0, i64 %144
%146 = load i32, i32* %145
%147 = mul nsw i32 %142, %146
%148 = load i32, i32* %10
%149 = add nsw i32 %148, %147
store i32 %149, i32* %10
%150 = load i32, i32* %3
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds [9 x i32], [9 x i32]* %9, i64 0, i64 %151
%153 = load i32, i32* %152
%154 = icmp sgt i32 %153, 0
br i1 %154, label %155, label %157
155: ; preds = %132
%156 = load i32, i32* %11
br label %158
157: ; preds = %132
br label %158
158: ; preds = %157, %155
%159 = phi i32 [ %156, %155 ], [ 0, %157 ]
%160 = load i32, i32* %3
%161 = sext i32 %160 to i64
%162 = getelementptr inbounds [9 x i32], [9 x i32]* %12, i64 0, i64 %161
store i32 %159, i32* %162
br label %163
163: ; preds = %158
%164 = load i32, i32* %3
%165 = add nsw i32 %164, 1
store i32 %165, i32* %3
br label %129
166: ; preds = %129
br label %173
167: ; preds = %124
%168 = load i32, i32* %13
%169 = load i32, i32* %14
%170 = add nsw i32 %168, %169
%171 = sdiv i32 %170, 2
store i32 %171, i32* %15
%172 = load i32, i32* %10
store i32 %172, i32* %16
br label %62
173: ; preds = %166, %104
store i32 0, i32* %21
store i32 1, i32* %3
br label %174
174: ; preds = %197, %173
%175 = load i32, i32* %3
%176 = icmp sle i32 %175, 8
br i1 %176, label %177, label %200
177: ; preds = %174
%178 = load i32, i32* %3
%179 = sext i32 %178 to i64
%180 = getelementptr inbounds [9 x i32], [9 x i32]* %12, i64 0, i64 %179
%181 = load i32, i32* %180
%182 = load i32, i32* %3
%183 = sext i32 %182 to i64
%184 = getelementptr inbounds [9 x i32], [9 x i32]* %12, i64 0, i64 %183
%185 = load i32, i32* %184
%186 = add nsw i32 %185, 1
%187 = mul nsw i32 %181, %186
%188 = sdiv i32 %187, 2
%189 = load i32, i32* %3
%190 = mul nsw i32 %188, %189
store i32 %190, i32* %22
%191 = load i32, i32* %22
%192 = load i32, i32* %21
%193 = icmp sgt i32 %191, %192
br i1 %193, label %194, label %196
194: ; preds = %177
%195 = load i32, i32* %22
store i32 %195, i32* %21
br label %196
196: ; preds = %194, %177
br label %197
197: ; preds = %196
%198 = load i32, i32* %3
%199 = add nsw i32 %198, 1
store i32 %199, i32* %3
br label %174
200: ; preds = %174
%201 = load i32, i32* %21
%202 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %201)
br label %24
203: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [9 x i32]
%6 = bitcast [9 x i32]* %5 to i8*
%7 = bitcast i32* %1 to i8*
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = add nsw i32 %12, -1
store i32 %13, i32* %1
%14 = icmp eq i32 %12, 0
br i1 %14, label %223, label %15
15: ; preds = %0
%16 = getelementptr inbounds [9 x i32], [9 x i32]* %5, i64 0, i64 1
%17 = getelementptr inbounds [9 x i32], [9 x i32]* %5, i64 0, i64 2
%18 = getelementptr inbounds [9 x i32], [9 x i32]* %5, i64 0, i64 3
%19 = getelementptr inbounds [9 x i32], [9 x i32]* %5, i64 0, i64 4
%20 = getelementptr inbounds [9 x i32], [9 x i32]* %5, i64 0, i64 8
%21 = bitcast i32* %19 to <4 x i32>*
br label %22
22: ; preds = %15, %182
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 0
br i1 %26, label %37, label %31
27: ; preds = %37
%28 = load i32, i32* %16
%29 = load i32, i32* %17
%30 = load i32, i32* %18
br label %31
31: ; preds = %27, %22
%32 = phi i32 [ %30, %27 ], [ 0, %22 ]
%33 = phi i32 [ %29, %27 ], [ 0, %22 ]
%34 = phi i32 [ %28, %27 ], [ 0, %22 ]
%35 = load <4 x i32>, <4 x i32>* %21
%36 = load i32, i32* %20
br label %48
37: ; preds = %22, %37
%38 = phi i32 [ %45, %37 ], [ 0, %22 ]
%39 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%40 = load i32, i32* %3
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [9 x i32], [9 x i32]* %5, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = add nsw i32 %43, 1
store i32 %44, i32* %42
%45 = add nuw nsw i32 %38, 1
%46 = load i32, i32* %4
%47 = icmp slt i32 %45, %46
br i1 %47, label %37, label %27
48: ; preds = %31, %171
%49 = phi i32 [ %116, %171 ], [ 10000000, %31 ]
%50 = phi i32 [ %173, %171 ], [ 5000000, %31 ]
%51 = phi i32 [ %109, %171 ], [ 0, %31 ]
%52 = phi i32 [ %117, %171 ], [ 0, %31 ]
%53 = phi i32 [ %120, %171 ], [ 0, %31 ]
%54 = shl nsw i32 %50, 3
%55 = or i32 %54, 1
%56 = call i32 @sqrt(i32 %55)
%57 = sdiv i32 %50, 2
%58 = shl nsw i32 %57, 3
%59 = or i32 %58, 1
%60 = call i32 @sqrt(i32 %59)
%61 = sdiv i32 %50, 3
%62 = shl nsw i32 %61, 3
%63 = or i32 %62, 1
%64 = call i32 @sqrt(i32 %63)
%65 = sdiv i32 %50, 4
%66 = shl nsw i32 %65, 3
%67 = or i32 %66, 1
%68 = call i32 @sqrt(i32 %67)
%69 = sdiv i32 %50, 5
%70 = shl nsw i32 %69, 3
%71 = or i32 %70, 1
%72 = call i32 @sqrt(i32 %71)
%73 = sdiv i32 %50, 6
%74 = shl nsw i32 %73, 3
%75 = or i32 %74, 1
%76 = call i32 @sqrt(i32 %75)
%77 = sdiv i32 %50, 7
%78 = shl nsw i32 %77, 3
%79 = or i32 %78, 1
%80 = call i32 @sqrt(i32 %79)
%81 = sdiv i32 %50, 8
%82 = shl nsw i32 %81, 3
%83 = or i32 %82, 1
%84 = call i32 @sqrt(i32 %83)
%85 = insertelement <8 x i32> poison, i32 %80, i64 0
%86 = insertelement <8 x i32> %85, i32 %76, i64 1
%87 = insertelement <8 x i32> %86, i32 %72, i64 2
%88 = insertelement <8 x i32> %87, i32 %68, i64 3
%89 = insertelement <8 x i32> %88, i32 %64, i64 4
%90 = insertelement <8 x i32> %89, i32 %60, i64 5
%91 = insertelement <8 x i32> %90, i32 %56, i64 6
%92 = insertelement <8 x i32> %91, i32 %84, i64 7
%93 = add nsw <8 x i32> %92, <i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1>
%94 = sdiv <8 x i32> %93, <i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2>
%95 = extractelement <8 x i32> %94, i64 6
%96 = mul nsw i32 %95, %34
%97 = extractelement <8 x i32> %94, i64 5
%98 = mul nsw i32 %97, %33
%99 = extractelement <8 x i32> %94, i64 4
%100 = mul nsw i32 %99, %32
%101 = shufflevector <8 x i32> %94, <8 x i32> undef, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
%102 = mul nsw <4 x i32> %101, %35
%103 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %102)
%104 = add nsw i32 %103, %100
%105 = add nsw i32 %104, %98
%106 = add nsw i32 %105, %96
%107 = extractelement <8 x i32> %94, i64 7
%108 = mul nsw i32 %107, %36
%109 = add nsw i32 %108, %106
%110 = load i32, i32* %2
%111 = icmp eq i32 %109, %110
br i1 %111, label %174, label %112
112: ; preds = %48
%113 = icmp slt i32 %109, %110
%114 = add nsw i32 %50, 1
%115 = add nsw i32 %50, -1
%116 = select i1 %113, i32 %49, i32 %115
%117 = select i1 %113, i32 %114, i32 %52
%118 = icmp eq i32 %51, %109
%119 = add nsw i32 %53, 1
%120 = select i1 %118, i32 %119, i32 0
%121 = icmp sgt i32 %120, 99
br i1 %121, label %122, label %171
122: ; preds = %112
%123 = shufflevector <4 x i32> %35, <4 x i32> poison, <8 x i32> <i32 3, i32 2, i32 1, i32 0, i32 undef, i32 undef, i32 undef, i32 undef>
%124 = insertelement <8 x i32> %123, i32 %32, i64 4
%125 = insertelement <8 x i32> %124, i32 %33, i64 5
%126 = insertelement <8 x i32> %125, i32 %34, i64 6
%127 = insertelement <8 x i32> %126, i32 %36, i64 7
%128 = icmp sgt <8 x i32> %127, zeroinitializer
%129 = shl nsw i32 %117, 3
%130 = or i32 %129, 1
%131 = call i32 @sqrt(i32 %130)
%132 = sdiv i32 %117, 2
%133 = shl nsw i32 %132, 3
%134 = or i32 %133, 1
%135 = call i32 @sqrt(i32 %134)
%136 = sdiv i32 %117, 3
%137 = shl nsw i32 %136, 3
%138 = or i32 %137, 1
%139 = call i32 @sqrt(i32 %138)
%140 = sdiv i32 %117, 4
%141 = shl nsw i32 %140, 3
%142 = or i32 %141, 1
%143 = call i32 @sqrt(i32 %142)
%144 = sdiv i32 %117, 5
%145 = shl nsw i32 %144, 3
%146 = or i32 %145, 1
%147 = call i32 @sqrt(i32 %146)
%148 = sdiv i32 %117, 6
%149 = shl nsw i32 %148, 3
%150 = or i32 %149, 1
%151 = call i32 @sqrt(i32 %150)
%152 = sdiv i32 %117, 7
%153 = shl nsw i32 %152, 3
%154 = or i32 %153, 1
%155 = call i32 @sqrt(i32 %154)
%156 = sdiv i32 %117, 8
%157 = shl nsw i32 %156, 3
%158 = or i32 %157, 1
%159 = call i32 @sqrt(i32 %158)
%160 = insertelement <8 x i32> poison, i32 %155, i64 0
%161 = insertelement <8 x i32> %160, i32 %151, i64 1
%162 = insertelement <8 x i32> %161, i32 %147, i64 2
%163 = insertelement <8 x i32> %162, i32 %143, i64 3
%164 = insertelement <8 x i32> %163, i32 %139, i64 4
%165 = insertelement <8 x i32> %164, i32 %135, i64 5
%166 = insertelement <8 x i32> %165, i32 %131, i64 6
%167 = insertelement <8 x i32> %166, i32 %159, i64 7
%168 = add nsw <8 x i32> %167, <i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1>
%169 = sdiv <8 x i32> %168, <i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2, i32 2>
%170 = select <8 x i1> %128, <8 x i32> %169, <8 x i32> zeroinitializer
br label %182
171: ; preds = %112
%172 = add nsw i32 %117, %116
%173 = sdiv i32 %172, 2
br label %48
174: ; preds = %48
%175 = shufflevector <4 x i32> %35, <4 x i32> poison, <8 x i32> <i32 3, i32 2, i32 1, i32 0, i32 undef, i32 undef, i32 undef, i32 undef>
%176 = insertelement <8 x i32> %175, i32 %32, i64 4
%177 = insertelement <8 x i32> %176, i32 %33, i64 5
%178 = insertelement <8 x i32> %177, i32 %34, i64 6
%179 = insertelement <8 x i32> %178, i32 %36, i64 7
%180 = icmp sgt <8 x i32> %179, zeroinitializer
%181 = select <8 x i1> %180, <8 x i32> %94, <8 x i32> zeroinitializer
br label %182
182: ; preds = %174, %122
%183 = phi <8 x i32> [ %181, %174 ], [ %170, %122 ]
%184 = extractelement <8 x i32> %183, i64 6
%185 = add nsw i32 %184, 1
%186 = mul nsw i32 %185, %184
%187 = sdiv i32 %186, 2
%188 = icmp sgt i32 %187, 0
%189 = select i1 %188, i32 %187, i32 0
%190 = extractelement <8 x i32> %183, i64 5
%191 = add nsw i32 %190, 1
%192 = mul nsw i32 %191, %190
%193 = sdiv i32 %192, 2
%194 = shl nsw i32 %193, 1
%195 = icmp sgt i32 %194, %189
%196 = select i1 %195, i32 %194, i32 %189
%197 = shufflevector <8 x i32> %183, <8 x i32> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 4>
%198 = add nsw <4 x i32> %197, <i32 1, i32 1, i32 1, i32 1>
%199 = mul nsw <4 x i32> %198, %197
%200 = sdiv <4 x i32> %199, <i32 2, i32 2, i32 2, i32 2>
%201 = mul nsw <4 x i32> %200, <i32 7, i32 6, i32 5, i32 3>
%202 = extractelement <8 x i32> %183, i64 3
%203 = add nsw i32 %202, 1
%204 = mul nsw i32 %203, %202
%205 = sdiv i32 %204, 2
%206 = shl nsw i32 %205, 2
%207 = call i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %201)
%208 = icmp sgt i32 %207, %206
%209 = select i1 %208, i32 %207, i32 %206
%210 = icmp sgt i32 %209, %196
%211 = select i1 %210, i32 %209, i32 %196
%212 = extractelement <8 x i32> %183, i64 7
%213 = add nsw i32 %212, 1
%214 = mul nsw i32 %213, %212
%215 = sdiv i32 %214, 2
%216 = shl nsw i32 %215, 3
%217 = icmp sgt i32 %216, %211
%218 = select i1 %217, i32 %216, i32 %211
%219 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %218)
%220 = load i32, i32* %1
%221 = add nsw i32 %220, -1
store i32 %221, i32* %1
%222 = icmp eq i32 %220, 0
br i1 %222, label %223, label %22
223: ; preds = %182, %0
ret i32 0
}