user: Please show me the C implementation that matches the assembly code listed below:

```asm
<main>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  lea    0x10(%rsp),%rsi
  lea    D8(%rip),%rdi
  call   <scanf@plt>
  mov    0x10(%rsp),%rax
  lea    -0x1(%rax),%rdx
  mov    %rdx,0x10(%rsp)
  test   %rax,%rax
  je     L146
  lea    0x8(%rsp),%r15
  lea    D8(%rip),%r13
  jmp    L117
L231:
  add    $0x1,%rdx
  add    $0x8,%rax
  cmp    %rdx,0x8(%rsp)
  jle    L47
L94:
  mov    (%rdi),%rcx
  mov    (%rax),%rsi
  cmp    %rsi,%rcx
  jle    L231
  mov    %rsi,(%rdi)
  mov    %rcx,(%rax)
  jmp    L231
L47:
  add    $0x1,%r8
  mov    0x8(%rsp),%rax
  add    $0x8,%rbx
  cmp    %r8,%rax
  jle    L42
L131:
  mov    %rbx,%rdi
  mov    %rbx,%rax
  mov    %r8,%rdx
  cmp    %r8,0x8(%rsp)
  jg     L94
  jmp    L47
L42:
  mov    %rax,%rcx
  test   $0x1,%al
  je     L15
L208:
  cmp    $0x1,%rax
  jne    L229
  mov    (%r14),%rsi
L164:
  lea    D0(%rip),%rdi
  call   <printf@plt>
  mov    0x10(%rsp),%rax
  lea    -0x1(%rax),%rdx
  mov    %rdx,0x10(%rsp)
  test   %rax,%rax
  je     L146
L117:
  mov    %r15,%rsi
  mov    %r13,%rdi
  call   <scanf@plt>
  mov    0x8(%rsp),%rax
  lea    0x0(,%rax,8),%rdi
  call   <malloc@plt>
  mov    %rax,%r14
  mov    0x8(%rsp),%rax
  test   %rax,%rax
  jle    L177
  mov    %r14,%rbx
  mov    %r14,%r12
  mov    $0x0,%ebp
L257:
  mov    %r12,%rsi
  mov    %r13,%rdi
  call   <scanf@plt>
  add    $0x1,%rbp
  mov    0x8(%rsp),%rax
  add    $0x8,%r12
  cmp    %rbp,%rax
  jg     L257
  test   %rax,%rax
  jle    L42
  mov    $0x0,%r8d
  jmp    L131
L15:
  cmp    $0x1,%rax
  jle    L6
  lea    0x8(%r14),%rdx
  lea    -0x10(,%rax,8),%rcx
  and    $0xfffffffffffffff0,%rcx
  lea    0x18(%r14,%rcx,1),%rsi
  mov    $0x0,%ecx
L160:
  add    (%rdx),%rcx
  add    $0x10,%rdx
  cmp    %rsi,%rdx
  jne    L160
L89:
  mov    %rax,%rdx
  shr    $0x3f,%rdx
  add    %rdx,%rax
  sar    %rax
  sub    $0x1,%rax
  mov    %rax,%rdx
  imul   (%r14),%rdx
  add    %rcx,%rdx
  imul   0x8(%r14),%rax
  lea    (%rdx,%rax,2),%rsi
  jmp    L164
L6:
  mov    $0x0,%ecx
  jmp    L89
L229:
  mov    0x8(%r14),%rdi
  cmp    $0x4,%rax
  jle    L84
  lea    0x20(%r14),%rdx
  lea    -0x28(,%rcx,8),%rcx
  and    $0xfffffffffffffff0,%rcx
  lea    0x30(%r14,%rcx,1),%rsi
  mov    %rdi,%rcx
L25:
  add    (%rdx),%rcx
  add    $0x10,%rdx
  cmp    %rsi,%rdx
  jne    L25
L10:
  lea    -0x1(%rax),%rdx
  mov    %rdx,%rax
  shr    $0x3f,%rax
  add    %rdx,%rax
  sar    %rax
  mov    %rax,%rdx
  imul   (%r14),%rdx
  add    %rcx,%rdx
  add    0x10(%r14),%rdx
  sub    $0x1,%rax
  imul   %rdi,%rax
  lea    (%rdx,%rax,2),%rsi
  jmp    L164
L84:
  mov    %rdi,%rcx
  jmp    L10
L146:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L235
  mov    $0x0,%eax
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L177:
  mov    %rax,%rcx
  test   $0x1,%al
  jne    L208
  mov    $0x0,%ecx
  jmp    L89
L235:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: data_tag: D8
datatype: string
name: disassemble_data
arguments: data_tag: D0
datatype: string

tool: D8: %lld

tool: D0: %lld


assistant: ```c
int main() {
  long long int i, n, j, k, l, *a, T, sum = 0;
  scanf("%lld", &T);
  while (T--) {
    scanf("%lld", &n);
    a = (long long int *)malloc(n * sizeof(long long int));
    for (i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
    }
    for (i = 0; i < n; i++) {
      for (j = i; j < n; j++) {
        if (a[i] > a[j]) {
          l = a[i];
          a[i] = a[j];
          a[j] = l;
        }
      }
    }
    sum = 0;
    if (n % 2 == 0) {
      for (i = 1; i < n; i = i + 2) {
        sum = sum + a[i];
      }
      sum = sum + a[0] * (n / 2 - 1) + a[1] * 2 * (n / 2 - 1);
    } else if ((n % 2 != 0) && (n != 1)) {
      sum = a[1];
      for (i = 4; i < n; i = i + 2) {
        sum = sum + a[i];
      }
      sum = sum + a[0] * ((n - 1) / 2) + a[2] + a[1] * 2 * ((n - 1) / 2 - 1);
    } else {
      sum = a[0];
    }
    printf("%lld\n", sum);
  }
  return 0;
}
```