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    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x748,%rsp
  lea    D32(%rip),%rbp
  lea    D21(%rip),%r15
  mov    %fs:0x28,%rax
  mov    %rax,0x2738(%rsp)
  xor    %eax,%eax
  lea    0x20(%rsp),%rbx
  lea    0x18(%rsp),%r14
  nopl   0x0(%rax,%rax,1)
L34:
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <printf@plt>
  mov    %rbx,%rsi
  mov    %r15,%rdi
  call   <scanf@plt>
  mov    $0xa,%edx
  mov    %r14,%rsi
  mov    %rbx,%rdi
  call   <strtol@plt>
  mov    %rax,%rdx
  mov    0x18(%rsp),%rax
  cmpb   $0x0,(%rax)
  jne    L34
  lea    0x0(,%rdx,8),%edi
  mov    %edx,%r13d
  mov    %rdx,0x8(%rsp)
  xor    %ebp,%ebp
  call   <malloc@plt>
  mov    %r13d,%esi
  lea    D13(%rip),%rdi
  mov    %rax,%r12
  xor    %eax,%eax
  call   <printf@plt>
  mov    0x8(%rsp),%rdx
  test   %edx,%edx
  jle    L46
  nopl   (%rax)
L21:
  mov    %rbx,%rsi
  mov    %r15,%rdi
  call   <scanf@plt>
  mov    $0xa,%edx
  mov    %r14,%rsi
  mov    %rbx,%rdi
  call   <strtol@plt>
  mov    %rax,%r8
  movslq %ebp,%rax
  mov    %r8,(%r12,%rax,8)
  mov    0x18(%rsp),%rax
  cmpb   $0x1,(%rax)
  adc    $0x0,%ebp
  cmp    %ebp,%r13d
  jg     L21
L46:
  lea    D20(%rip),%rdi
  call   <puts@plt>
  nopl   0x0(%rax)
L70:
  xor    %eax,%eax
  call   <getchar@plt>
  cmp    $0x71,%al
  je     L57
L7:
  cmp    $0x31,%al
  je     L38
  cmp    $0x32,%al
  jne    L70
  mov    %r13d,%esi
  mov    %r12,%rdi
  call   <sort2@plt>
  mov    %r13d,%esi
  mov    %r12,%rdi
  call   <wypisz@plt>
  xor    %eax,%eax
  call   <getchar@plt>
  cmp    $0x71,%al
  jne    L7
  nopl   0x0(%rax)
L57:
  mov    0x2738(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L40
  add    $0x2748,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nop
L38:
  mov    %r13d,%esi
  mov    %r12,%rdi
  call   <sort1@plt>
  mov    %r13d,%esi
  mov    %r12,%rdi
  call   <wypisz@plt>
  jmp    L70
L40:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: data_label: D32
type: string
name: retrieve_data
arguments: data_label: D21
type: string
name: retrieve_data
arguments: data_label: D13
type: string
name: retrieve_data
arguments: data_label: D20
type: string

tool: D32: Wprowadz dlugosc tablicy: 

tool: D21: %s

tool: D13: Wprowadz %i elementow:


tool: D20: 1 wypisuje liczby posortowane rosnaco przez wybieranie, 2 wypisuje liczby posortowane malejaco przez wstawianie, q konczy prace programu

assistant: ```c
int main(void) {
  int dlug;
  long int *tab;
  char s[10000], *er, c;
  do {
    printf("Wprowadz dlugosc tablicy: ");
    scanf("%s", s);
    dlug = strtol(s, &er, 10);
  } while (*er);
  tab = malloc(dlug * sizeof(long int));
  printf("Wprowadz %i elementow:\n", dlug);
  for (int i = 0; i < dlug; ++i) {
    scanf("%s", s);
    tab[i] = strtol(s, &er, 10);
    if (*er)
      --i;
  }
  printf("1 wypisuje liczby posortowane rosnaco przez wybieranie, 2 wypisuje liczby posortowane malejaco przez wstawianie, q konczy prace programu\n");
  while ((c = getchar()) != 'q') {
    if (c == '1') {
      sort1(tab, dlug);
      wypisz(tab, dlug);
    }
    if (c == '2') {
      sort2(tab, dlug);
      wypisz(tab, dlug);
    }
  }
  return 0;
}
```