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

```asm
<diskd0>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x318,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x308(%rsp)
  xor    %eax,%eax
  lea    D117(%rip),%rdi
  call   <puts0@plt>
  mov    %rsp,%r12
  mov    $0x100,%esi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <getsn@plt>
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <htoi@plt>
  mov    %eax,%ebx
  lea    D121(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  mov    $0x100,%esi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <getsn@plt>
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <htoi@plt>
  mov    %eax,%ebp
  lea    D68(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  mov    $0x100,%esi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <getsn@plt>
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <htoi@plt>
  mov    %eax,%r13d
  lea    D27(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  mov    $0x100,%esi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <getsn@plt>
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <htoi@plt>
  mov    %eax,%r14d
  lea    D64(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  mov    %ebx,%edi
  mov    $0x0,%eax
  call   <puthex@plt>
  lea    D96(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  mov    %ebp,%edi
  mov    $0x0,%eax
  call   <puthex@plt>
  lea    D77(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  mov    %r13d,%edi
  mov    $0x0,%eax
  call   <puthex@plt>
  lea    D92(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  mov    %r14d,%edi
  mov    $0x0,%eax
  call   <puthex@plt>
  lea    0x100(%rsp),%r12
  lea    0x300(%rsp),%rdx
  mov    %r12,%rax
L97:
  movb   $0x0,(%rax)
  add    $0x1,%rax
  cmp    %rdx,%rax
  jne    L97
  lea    0x100(%rsp),%r8
  mov    %r14d,%ecx
  mov    %r13d,%edx
  mov    %ebp,%esi
  mov    %ebx,%edi
  mov    $0x0,%eax
  call   <readsec0@plt>
  mov    %eax,%ebx
  lea    D16(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  mov    %ebx,%edi
  mov    $0x0,%eax
  call   <puthex@plt>
  cmp    $0x1,%ebx
  je     L41
L96:
  lea    D107(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  add    $0x10,%r12
  mov    $0x0,%r13d
  lea    D107(%rip),%r14
  lea    D90(%rip),%r15
  jmp    L100
L41:
  lea    D12(%rip),%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  jmp    L96
L108:
  mov    %r15,%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  mov    $0x0,%eax
  call   <getch@plt>
  mov    $0xd,%edi
  mov    $0x0,%eax
  call   <putch@plt>
  jmp    L31
L36:
  movzbl %dil,%edi
  mov    $0x0,%eax
  call   <putch@plt>
L87:
  add    $0x1,%rbx
  cmp    %r12,%rbx
  je     L88
L12:
  movsbl (%rbx),%edi
  test   $0xe0,%dil
  jne    L36
  mov    $0x2e,%edi
  mov    $0x0,%eax
  call   <putch@plt>
  jmp    L87
L88:
  mov    %r14,%rdi
  mov    $0x0,%eax
  call   <puts0@plt>
  add    $0x1,%r13d
  cmp    $0x20,%r13d
  je     L103
  cmp    $0xf,%r13d
  je     L108
L31:
  add    $0x10,%r12
L100:
  lea    -0x10(%r12),%rbx
  mov    %rbx,%rbp
L115:
  movsbl 0x0(%rbp),%edi
  mov    $0x0,%eax
  call   <puthex_b@plt>
  mov    $0x20,%edi
  mov    $0x0,%eax
  call   <putch@plt>
  add    $0x1,%rbp
  cmp    %r12,%rbp
  jne    L115
  jmp    L12
L103:
  mov    0x308(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L58
  add    $0x318,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L58:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D117
data_type: string
name: unpack_data
arguments: tag: D121
data_type: string
name: unpack_data
arguments: tag: D68
data_type: string
name: unpack_data
arguments: tag: D27
data_type: string
name: unpack_data
arguments: tag: D64
data_type: string
name: unpack_data
arguments: tag: D96
data_type: string
name: unpack_data
arguments: tag: D77
data_type: string
name: unpack_data
arguments: tag: D92
data_type: string
name: unpack_data
arguments: tag: D16
data_type: string
name: unpack_data
arguments: tag: D107
data_type: string
name: unpack_data
arguments: tag: D90
data_type: string
name: unpack_data
arguments: tag: D12
data_type: string

tool: D117: drive? 

tool: D121: 
sec? (1-...) 

tool: D68: 
head? 

tool: D27: 
trk (cyl)? 

tool: D64: 
drive = 

tool: D96:  sec = 

tool: D77:  head = 

tool: D92:  trk = 

tool: D16:  err code = 

tool: D107: 


tool: D90:  press any key 

tool: D12:  OK

assistant: ```c
void diskd0(void) {
  char Buffer[512];
  char str[256];
  int drive, sec, head, trk, i, ii, c, line;
  puts0("drive? ");
  getsn(str, 256);
  drive = htoi(str);
  puts0("\r\nsec? (1-...) ");
  getsn(str, 256);
  sec = htoi(str);
  puts0("\r\nhead? ");
  getsn(str, 256);
  head = htoi(str);
  puts0("\r\ntrk (cyl)? ");
  getsn(str, 256);
  trk = htoi(str);
  puts0("\r\ndrive = ");
  puthex(drive);
  puts0(" sec = ");
  puthex(sec);
  puts0(" head = ");
  puthex(head);
  puts0(" trk = ");
  puthex(trk);
  for (i = 0; i < 512; i++)
    Buffer[i] = 0;
  i = readsec0(drive, sec, head, trk, Buffer);
  puts0(" err code = ");
  puthex(i);
  if (i == 1)
    puts0(" OK");
  puts0("\r\n");
  ii = 0;
  for (line = 0; line < 32; line++) {
    if (line == 15) {
      puts0(" press any key ");
      getch();
      putch('\r');
    }
    for (i = 0; i < 16; i++) {
      c = Buffer[ii++];
      puthex_b(c);
      putch(' ');
    }
    ii = ii - 16;
    for (i = 0; i < 16; i++) {
      c = (Buffer[ii++]) & 0xFFU;
      if (c < ' ')
        putch('.');
      else
        putch(c);
    }
    puts0("\r\n");
  }
}
```