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

```asm
<main>:
  endbr64
  push   %r15
  lea    D32(%rip),%rdi
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  lea    0x20(%rsp),%rsi
  mov    %rsi,0x18(%rsp)
  call   <scanf@plt>
  mov    0x20(%rsp),%ebx
  test   %ebx,%ebx
  je     L121
L96:
  lea    0x4(,%rbx,4),%r15d
  xor    %r14d,%r14d
  mov    %r15d,%edi
  call   <malloc@plt>
  mov    %r15d,%edi
  mov    %rax,%r13
  call   <malloc@plt>
  mov    %r15d,%edi
  mov    %r13,%rbp
  mov    %rax,0x8(%rsp)
  call   <malloc@plt>
  mov    %r15d,%edx
  mov    $0xffffffff,%esi
  mov    %rax,%rdi
  mov    %rax,%r12
  call   <memset@plt>
  movslq %ebx,%rax
  movl   $0xfffffffe,(%r12,%rax,4)
  lea    0x0(,%rax,4),%rcx
  lea    0x24(%rsp),%rax
  mov    %rax,(%rsp)
  mov    0x20(%rsp),%eax
  mov    %rcx,0x10(%rsp)
  test   %eax,%eax
  jle    L30
  xchg   %ax,%ax
L21:
  mov    (%rsp),%rsi
  lea    D32(%rip),%rdi
  add    $0x1,%r14d
  add    $0x4,%rbp
  call   <scanf@plt>
  mov    0x24(%rsp),%eax
  mov    %eax,-0x4(%rbp)
  cmp    %r14d,0x20(%rsp)
  jg     L21
L30:
  mov    0x8(%rsp),%r14
  mov    %r15d,%edx
  mov    %r13,%rsi
  mov    %r14,%rdi
  mov    %r14,%rbp
  call   <memcpy@plt>
  mov    0x10(%rsp),%rsi
  mov    %r14,%rdi
  add    %r14,%rsi
  call   <sort@plt>
  mov    %r14,%rax
  xor    %r14d,%r14d
  cmpl   $0xffffffff,(%rax)
  jne    L144
  nopw   0x0(%rax,%rax,1)
L91:
  add    $0x4,%rbp
  add    $0x1,%r14d
  cmpl   $0xffffffff,0x0(%rbp)
  je     L91
L95:
  cmp    %ebx,%r14d
  je     L29
L144:
  mov    0x0(%rbp),%edi
  cmp    $0xffffffff,%edi
  jne    L146
  add    $0x4,%rbp
  cmp    %ebx,%r14d
  jne    L144
L29:
  mov    0x18(%rsp),%rsi
  lea    D32(%rip),%rdi
  call   <scanf@plt>
  mov    %r13,%rdi
  mov    0x20(%rsp),%ebx
  call   <free@plt>
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  mov    %r12,%rdi
  call   <free@plt>
  test   %ebx,%ebx
  jne    L96
L121:
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L19
  add    $0x38,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L146:
  mov    %rbp,%r15
  nopl   0x0(%rax,%rax,1)
L26:
  mov    %ebx,%esi
  mov    %r12,%rdx
  call   <hash@plt>
  mov    (%r15),%edi
  mov    %eax,%esi
  cltq
  cmp    %edi,0x0(%r13,%rax,4)
  je     L101
L83:
  mov    0x4(%r15),%edi
  add    $0x4,%r15
  cmp    $0xffffffff,%edi
  je     L83
  jmp    L26
  nop
L101:
  mov    %r12,%rdx
  call   <ins@plt>
  lea    -0x1(%rbx),%eax
  cmp    %r14d,%eax
  je     L11
  mov    (%r15),%esi
  mov    $0x20,%edx
  lea    D29(%rip),%rdi
  call   <printf@plt>
L4:
  movl   $0xffffffff,(%r15)
  add    $0x1,%r14d
  jmp    L95
L11:
  mov    (%r15),%esi
  mov    $0xa,%edx
  lea    D29(%rip),%rdi
  call   <printf@plt>
  jmp    L4
L19:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: data_tag: D32
type_infered: string
name: read_data
arguments: data_tag: D29
type_infered: string

tool: D32: %d

tool: D29: %d%c

assistant: ```c
int main() {
  int N, n;
  scanf("%d", &N);
  n = N;
  while (n) {
    int *result, *heap, *test;
    int *heap_c;
    result = (int *)malloc((n + 1) * sizeof(int));
    heap = (int *)malloc((n + 1) * sizeof(int));
    heap_c = heap;
    test = (int *)malloc((n + 1) * sizeof(int));
    memset(test, -1, (n + 1) * sizeof(int));
    test[n] = -2;
    int temp;
    int i;
    for (i = 0; i < N; i++) {
      scanf("%d", &temp);
      *(result + i) = temp;
    }
    memcpy(heap, result, (n + 1) * sizeof(int));
    sort(heap, heap + n);
    int poped = 0;
    int *tmp, posi;
    tmp = heap;
    while (*heap == -1)
      heap++, poped++, tmp = heap;
    while (poped != n) {
      tmp = heap;
      if (*heap == -1)
        heap++, tmp = heap;
      else {
        while (result[posi = hash(*tmp, n, test)] != *tmp) {
          do {
            tmp++;
          } while (*tmp == -1);
        }
        ins(*tmp, posi, test);
        if (poped != n - 1)
          printf("%d%c", *tmp, ' ');
        else
          printf("%d%c", *tmp, '\n');
        *tmp = -1;
        poped++;
      }
    }
    scanf("%d", &N);
    n = N;
    free(result);
    free(heap_c);
    free(test);
  }
  return 0;
}
```