user: Converte this assembly snippet into its equivalent C code:

```asm
<main>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  lea    -0x48(%rbp),%rax
  mov    %rax,%rsi
  lea    D16(%rip),%rax
  mov    %rax,%rdi
  call   <scanf@plt>
  mov    -0x48(%rbp),%eax
  mov    %eax,-0x40(%rbp)
  jmp    L138
L4:
  mov    -0x40(%rbp),%eax
  add    $0x1,%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x20(%rbp)
  mov    -0x40(%rbp),%eax
  add    $0x1,%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x30(%rbp)
  mov    -0x30(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x40(%rbp),%eax
  add    $0x1,%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x10(%rbp)
  mov    -0x40(%rbp),%eax
  add    $0x1,%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edx
  mov    -0x10(%rbp),%rax
  mov    $0xffffffff,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  mov    -0x40(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movl   $0xfffffffe,(%rax)
  movl   $0x0,-0x3c(%rbp)
  jmp    L72
L77:
  lea    -0x44(%rbp),%rax
  mov    %rax,%rsi
  lea    D16(%rip),%rax
  mov    %rax,%rdi
  call   <scanf@plt>
  mov    -0x3c(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x20(%rbp),%rax
  add    %rax,%rdx
  mov    -0x44(%rbp),%eax
  mov    %eax,(%rdx)
  addl   $0x1,-0x3c(%rbp)
L72:
  mov    -0x48(%rbp),%eax
  cmp    %eax,-0x3c(%rbp)
  jl     L77
  mov    -0x40(%rbp),%eax
  add    $0x1,%eax
  cltq
  shl    $0x2,%eax
  mov    %eax,%edx
  mov    -0x20(%rbp),%rcx
  mov    -0x30(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0x40(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x30(%rbp),%rax
  add    %rax,%rdx
  mov    -0x30(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <sort@plt>
  movl   $0x0,-0x38(%rbp)
  mov    -0x30(%rbp),%rax
  mov    %rax,-0x28(%rbp)
  jmp    L98
L113:
  addq   $0x4,-0x30(%rbp)
  addl   $0x1,-0x38(%rbp)
  mov    -0x30(%rbp),%rax
  mov    %rax,-0x28(%rbp)
L98:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%eax
  cmp    $0xffffffff,%eax
  je     L113
  jmp    L126
L11:
  mov    -0x30(%rbp),%rax
  mov    %rax,-0x28(%rbp)
  mov    -0x30(%rbp),%rax
  mov    (%rax),%eax
  cmp    $0xffffffff,%eax
  jne    L26
  addq   $0x4,-0x30(%rbp)
  mov    -0x30(%rbp),%rax
  mov    %rax,-0x28(%rbp)
  jmp    L126
L51:
  addq   $0x4,-0x28(%rbp)
  mov    -0x28(%rbp),%rax
  mov    (%rax),%eax
  cmp    $0xffffffff,%eax
  je     L51
L26:
  mov    -0x28(%rbp),%rax
  mov    (%rax),%eax
  mov    -0x10(%rbp),%rdx
  mov    -0x40(%rbp),%ecx
  mov    %ecx,%esi
  mov    %eax,%edi
  call   <hash@plt>
  mov    %eax,-0x34(%rbp)
  mov    -0x34(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%edx
  mov    -0x28(%rbp),%rax
  mov    (%rax),%eax
  cmp    %eax,%edx
  jne    L51
  mov    -0x28(%rbp),%rax
  mov    (%rax),%eax
  mov    -0x10(%rbp),%rdx
  mov    -0x34(%rbp),%ecx
  mov    %ecx,%esi
  mov    %eax,%edi
  call   <ins@plt>
  mov    -0x40(%rbp),%eax
  sub    $0x1,%eax
  cmp    %eax,-0x38(%rbp)
  je     L86
  mov    -0x28(%rbp),%rax
  mov    (%rax),%eax
  mov    $0x20,%edx
  mov    %eax,%esi
  lea    D19(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
  jmp    L112
L86:
  mov    -0x28(%rbp),%rax
  mov    (%rax),%eax
  mov    $0xa,%edx
  mov    %eax,%esi
  lea    D19(%rip),%rax
  mov    %rax,%rdi
  call   <printf@plt>
L112:
  mov    -0x28(%rbp),%rax
  movl   $0xffffffff,(%rax)
  addl   $0x1,-0x38(%rbp)
L126:
  mov    -0x38(%rbp),%eax
  cmp    -0x40(%rbp),%eax
  jne    L11
  lea    -0x48(%rbp),%rax
  mov    %rax,%rsi
  lea    D16(%rip),%rax
  mov    %rax,%rdi
  call   <scanf@plt>
  mov    -0x48(%rbp),%eax
  mov    %eax,-0x40(%rbp)
  mov    -0x20(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
L138:
  cmpl   $0x0,-0x40(%rbp)
  jne    L4
  mov    $0x0,%eax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L85
  call   <__stack_chk_fail@plt>
L85:
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: tag: D16
type: string
name: disassemble_data
arguments: tag: D19
type: string

tool: D16: %d

tool: D19: %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;
}
```