#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*/ free(int *);
int *malloc(int);
long maximize(int *, int);
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char const *argv[]) {
  int t;
  scanf("%d", &t);
  for (int i_t = 0; i_t < t; i_t++) {
    int n;
    scanf("%d", &n);
    int *prices = malloc(sizeof(int) * n);
    for (int i_n = 0; i_n < n; i_n++) {
      scanf("%d", &prices[i_n]);
    }
    long profit = maximize(prices, n);
    free(prices);
    printf("%ld\n", profit);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <scanf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    121f <main+0xcf>
lea    0xe70(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <scanf@plt>
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e8 <main+0x98>
mov    -0x28(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe2b(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11b3 <main+0x63>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <maximize@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rsi
lea    0xdf7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117d <main+0x2d>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    120e <main+0xbe>
xor    %r14d,%r14d
lea    0xe7f(%rip),%r13
jmp    11bf <main+0x6f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12,%rdi
mov    %ebx,%esi
call   1050 <maximize@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <free@plt>
lea    0xe57(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
add    $0x1,%r14d
cmp    0x4(%rsp),%r14d
jge    120e <main+0xbe>
mov    %r13,%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
mov    (%rsp),%ebx
lea    0x0(,%rbx,4),%edi
call   1060 <malloc@plt>
mov    %rax,%r12
test   %ebx,%ebx
jle    1190 <main+0x40>
mov    %r12,%rbp
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1070 <scanf@plt>
add    $0x1,%r15
movslq (%rsp),%rbx
add    $0x4,%rbp
cmp    %rbx,%r15
jl     11f0 <main+0xa0>
jmp    1190 <main+0x40>
xor    %eax,%eax
add    $0x8,%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 = [5 x i8] c"%ld\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 i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
store i32 0, i32* %7
br label %13
13: ; preds = %45, %2
%14 = load i32, i32* %7
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %48
17: ; preds = %13
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = mul i64 4, %20
%22 = trunc i64 %21 to i32
%23 = call i32* @malloc(i32 %22)
store i32* %23, i32** %9
store i32 0, i32* %10
br label %24
24: ; preds = %34, %17
%25 = load i32, i32* %10
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = load i32*, i32** %9
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %32)
br label %34
34: ; preds = %28
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %24
37: ; preds = %24
%38 = load i32*, i32** %9
%39 = load i32, i32* %8
%40 = call i64 @maximize(i32* %38, i32 %39)
store i64 %40, i64* %11
%41 = load i32*, i32** %9
%42 = call i32 @free(i32* %41)
%43 = load i64, i64* %11
%44 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %43)
br label %45
45: ; preds = %37
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %13
48: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%ld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = bitcast i32* %4 to i8*
br label %12
11: ; preds = %19, %2
ret i32 0
12: ; preds = %9, %19
%13 = phi i32 [ 0, %9 ], [ %24, %19 ]
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%15 = load i32, i32* %4
%16 = shl i32 %15, 2
%17 = call i32* @malloc(i32 %16)
%18 = icmp sgt i32 %15, 0
br i1 %18, label %27, label %19
19: ; preds = %27, %12
%20 = phi i32 [ %15, %12 ], [ %32, %27 ]
%21 = call i64 @maximize(i32* %17, i32 %20)
%22 = call i32 @free(i32* %17)
%23 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %21)
%24 = add nuw nsw i32 %13, 1
%25 = load i32, i32* %3
%26 = icmp slt i32 %24, %25
br i1 %26, label %12, label %11
27: ; preds = %12, %27
%28 = phi i64 [ %31, %27 ], [ 0, %12 ]
%29 = getelementptr inbounds i32, i32* %17, i64 %28
%30 = call 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* %4
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %27, label %19
}