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

```asm
<main>:
  endbr64
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  lea    0xc(%rsp),%rsi
  lea    D35(%rip),%rdi
  call   <scanf@plt>
  mov    0xc(%rsp),%eax
  lea    0x0(,%rax,4),%edi
  call   <malloc@plt>
  mov    %rax,%r12
  cmpl   $0x0,0xc(%rsp)
  je     L145
  mov    %rax,%rbp
  mov    $0x0,%ebx
  lea    D35(%rip),%r13
L62:
  mov    %rbp,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <scanf@plt>
  add    $0x1,%rbx
  add    $0x4,%rbp
  movslq 0xc(%rsp),%rax
  cmp    %rbx,%rax
  ja     L62
L145:
  lea    0x14(%rsp),%rdx
  lea    0x10(%rsp),%rsi
  lea    D27(%rip),%rdi
  mov    $0x0,%eax
  call   <scanf@plt>
  mov    0xc(%rsp),%eax
  lea    -0x1(%rax),%edx
  mov    $0x0,%esi
  mov    %r12,%rdi
  call   <quick_sort@plt>
  mov    (%r12),%eax
  mov    0x10(%rsp),%edi
  cmp    %edi,%eax
  jl     L266
  mov    %eax,%r9d
  sub    %edi,%r9d
  mov    %edi,%r11d
L8:
  movslq 0xc(%rsp),%rbx
  cmp    $0x1,%rbx
  jbe    L95
  mov    0x14(%rsp),%esi
  lea    0x4(%r12),%rdx
  lea    (%r12,%rbx,4),%r10
  jmp    L337
L266:
  mov    $0x0,%r11d
  mov    $0xffffffff,%r9d
  jmp    L8
L298:
  cmp    %eax,%esi
  jge    L344
  lea    (%rax,%rcx,1),%ebp
  mov    %ebp,%r8d
  shr    $0x1f,%r8d
  add    %ebp,%r8d
  sar    %r8d
  cmp    %r8d,%esi
  jl     L324
  cmp    %r8d,%edi
  jle    L136
L324:
  cmp    %r8d,%esi
  jge    L74
  mov    %esi,%r8d
  sub    %ecx,%r8d
  cmp    %r9d,%r8d
  jle    L93
  mov    %esi,%r11d
  mov    %r8d,%r9d
  jmp    L93
L136:
  mov    %r8d,%ebp
  sub    %ecx,%ebp
  cmp    %r9d,%ebp
  jle    L93
  mov    %r8d,%r11d
  mov    %ebp,%r9d
  jmp    L93
L74:
  mov    %eax,%ecx
  sub    %edi,%ecx
  cmp    %r9d,%ecx
  jle    L93
  mov    %edi,%r11d
  mov    %ecx,%r9d
  jmp    L93
L123:
  lea    (%rax,%rcx,1),%ebp
  mov    %ebp,%r8d
  shr    $0x1f,%r8d
  add    %ebp,%r8d
  sar    %r8d
  cmp    %r8d,%esi
  jl     L6
  mov    %r8d,%ebp
  sub    %ecx,%ebp
  cmp    %r9d,%ebp
  jle    L93
  mov    %r8d,%r11d
  mov    %ebp,%r9d
  jmp    L93
L6:
  mov    %esi,%r8d
  sub    %ecx,%r8d
  cmp    %r9d,%r8d
  jle    L93
  mov    %esi,%r11d
  mov    %r8d,%r9d
  jmp    L93
L296:
  mov    %eax,%ecx
  sub    %edi,%ecx
  cmp    %r9d,%ecx
  jle    L93
  mov    %edi,%r11d
  mov    %ecx,%r9d
  jmp    L93
L95:
  mov    -0x4(%r12,%rbx,4),%edx
  mov    0x14(%rsp),%eax
  cmp    %eax,%edx
  jg     L142
  mov    %eax,%ecx
  sub    %edx,%ecx
  cmp    %r9d,%ecx
  cmovg  %eax,%r11d
L142:
  mov    %r11d,%esi
  lea    D23(%rip),%rdi
  call   <printf@plt>
  mov    %r12,%rdi
  call   <free@plt>
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L335
  mov    $0x0,%eax
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L344:
  cmp    %eax,%edi
  jg     L93
  lea    (%rax,%rcx,1),%ebp
  mov    %ebp,%r8d
  shr    $0x1f,%r8d
  add    %ebp,%r8d
  sar    %r8d
  cmp    %r8d,%edi
  jg     L296
  mov    %r8d,%ebp
  sub    %ecx,%ebp
  cmp    %r9d,%ebp
  jle    L93
  mov    %r8d,%r11d
  mov    %ebp,%r9d
  jmp    L93
L210:
  cmp    %ecx,%esi
  jge    L123
L93:
  add    $0x4,%rdx
  cmp    %rdx,%r10
  je     L95
L337:
  mov    %eax,%ecx
  mov    (%rdx),%eax
  cmp    %ecx,%edi
  jg     L298
  cmp    %eax,%esi
  jl     L210
  lea    (%rax,%rcx,1),%ebp
  mov    %ebp,%r8d
  shr    $0x1f,%r8d
  add    %ebp,%r8d
  sar    %r8d
  mov    %r8d,%ebp
  sub    %ecx,%ebp
  cmp    %r9d,%ebp
  jle    L93
  mov    %r8d,%r11d
  mov    %ebp,%r9d
  jmp    L93
L335:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: label: D35
type: string
name: extract_symbolic_data
arguments: label: D27
type: string
name: extract_symbolic_data
arguments: label: D23
type: string

tool: D35: %d

tool: D27: %d %d

tool: D23: %d


assistant: ```c
int main() {
  int n;
  scanf("%d", &n);
  int *a = malloc(sizeof(int) * n);
  for (size_t i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  int p, q;
  scanf("%d %d", &p, &q);
  quick_sort(a, 0, n - 1);
  int max = -1;
  int ans = 0;
  if (a[0] >= p) {
    max = a[0] - p;
    ans = p;
  }
  int left = a[0];
  int right = 0;
  for (size_t i = 1; i < n; i++) {
    right = a[i];
    if (p <= left && q >= right) {
      int mid = (left + right) / 2;
      if ((mid - left) > max) {
        max = mid - left;
        ans = mid;
      }
    } else if (left < p && right > q) {
      int mid = (left + right) / 2;
      if (mid >= p && mid <= q) {
        if ((mid - left) > max) {
          max = mid - left;
          ans = mid;
        }
      } else if (mid > q) {
        if ((q - left) > max) {
          max = q - left;
          ans = q;
        }
      } else {
        if ((right - p) > max) {
          max = right - p;
          ans = p;
        }
      }
    } else if (right > q && left <= q) {
      int mid = (left + right) / 2;
      if (mid <= q) {
        if ((mid - left) > max) {
          max = mid - left;
          ans = mid;
        }
      } else {
        if ((q - left) > max) {
          max = q - left;
          ans = q;
        }
      }
    } else if (left < p && p <= right) {
      int mid = (left + right) / 2;
      if (mid >= p) {
        if ((mid - left) > max) {
          max = mid - left;
          ans = mid;
        }
      } else {
        if ((right - p) > max) {
          max = right - p;
          ans = p;
        }
      }
    }
    left = a[i];
  }
  if (q >= a[n - 1]) {
    if ((q - a[n - 1]) > max) {
      max = q - a[n - 1];
      ans = q;
    }
  }
  printf("%d\n", ans);
  free(a);
  return 0;
}
```