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

```asm
<main>:
  endbr64
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  lea    0x4(%rsp),%rdx
  mov    %rsp,%rsi
  lea    D11(%rip),%rdi
  call   <scanf@plt>
  mov    0x4(%rsp),%eax
  lea    0x1(%rax),%edi
  mov    $0x8,%esi
  call   <calloc@plt>
  mov    %rax,%rbp
  mov    0x4(%rsp),%eax
  lea    0x1(%rax),%edi
  mov    $0x8,%esi
  call   <calloc@plt>
  mov    %rax,%rbx
  mov    0x4(%rsp),%eax
  lea    0x8(,%rax,8),%edx
  mov    $0x7f,%esi
  mov    %rbp,%rdi
  call   <memset@plt>
  cmpl   $0x0,(%rsp)
  jle    L114
  mov    $0x0,%r12d
  lea    D47(%rip),%r13
  jmp    L62
L65:
  movslq 0x4(%rsp),%rax
  lea    (%rbx,%rax,8),%rdx
  mov    %rbx,%rax
  cmp    %rdx,%rbx
  jae    L35
L117:
  mov    (%rax),%rcx
  mov    0x8(%rax),%rdx
  cmp    %rdx,%rcx
  jle    L35
  mov    %rcx,0x8(%rax)
  lea    0x8(%rax),%rcx
  mov    %rdx,(%rax)
  movslq 0x4(%rsp),%rax
  lea    (%rbx,%rax,8),%rax
  cmp    %rax,%rcx
  jae    L35
  mov    %rcx,%rax
  jmp    L117
L35:
  add    $0x1,%r12d
  cmp    %r12d,(%rsp)
  jle    L114
L62:
  mov    %rbx,%rsi
  mov    %r13,%rdi
  mov    $0x0,%eax
  call   <scanf@plt>
  mov    (%rbx),%rax
  mov    %rax,0x0(%rbp)
  movslq 0x4(%rsp),%rax
  lea    0x0(%rbp,%rax,8),%rdx
  mov    %rbp,%rax
  cmp    %rdx,%rbp
  jae    L65
L59:
  mov    (%rax),%rcx
  mov    0x8(%rax),%rdx
  cmp    %rdx,%rcx
  jge    L65
  mov    %rcx,0x8(%rax)
  lea    0x8(%rax),%rcx
  mov    %rdx,(%rax)
  movslq 0x4(%rsp),%rax
  lea    0x0(%rbp,%rax,8),%rax
  cmp    %rax,%rcx
  jae    L65
  mov    %rcx,%rax
  jmp    L59
L114:
  mov    0x8(%rbx),%r12
  sub    0x8(%rbp),%r12
  mov    %r12,%rdi
  call   <isprime@plt>
  test   %rax,%rax
  lea    D1(%rip),%rsi
  lea    D3(%rip),%rax
  cmove  %rax,%rsi
  mov    %r12,%rdx
  lea    D4(%rip),%rdi
  call   <printf@plt>
  mov    %rbp,%rdi
  call   <free@plt>
  mov    %rbx,%rdi
  call   <free@plt>
  mov    0x8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L108
  mov    $0x0,%eax
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L108:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: data_label: D11
type_infered: string
name: disassemble_data
arguments: data_label: D47
type_infered: string
name: disassemble_data
arguments: data_label: D1
type_infered: string
name: disassemble_data
arguments: data_label: D3
type_infered: string
name: disassemble_data
arguments: data_label: D4
type_infered: string

tool: D11: %d %d

tool: D47: %ld

tool: D1: YES

tool: D3: NO

tool: D4: %s
%d


assistant: ```c
int main(void) {
  int n, k;
  scanf("%d %d", &n, &k);
  long *p1, *p2, temp;
  long *min = (long *)calloc(k + 1, sizeof(long));
  long *max = (long *)calloc(k + 1, sizeof(long));
  memset(min, 0x7F, (k + 1) * sizeof(long));
  for (int i = 0; i < n; i++) {
    scanf("%ld", max);
    *(p1 = min) = *(p2 = max);
    while (p1 < min + k && p1[0] < p1[1]) {
      {
        temp = (p1)[1];
        (p1)[1] = *(p1);
        *(p1)++ = temp;
      };
    }
    while (p2 < max + k && p2[0] > p2[1]) {
      {
        temp = (p2)[1];
        (p2)[1] = *(p2);
        *(p2)++ = temp;
      };
    }
  }
  temp = max[1] - min[1];
  printf("%s\n%d\n", isprime(temp) ? "YES" : "NO", temp);
  free(min);
  free(max);
  return 0;
}
```