user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<memd>:
  endbr64
  push   %r15
  lea    D14(%rip),%rdi
  lea    D9(%rip),%r15
  push   %r14
  push   %r13
  xor    %r13d,%r13d
  push   %r12
  push   %rbp
  push   %rbx
  xor    %ebx,%ebx
  sub    $0x128,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x118(%rsp)
  xor    %eax,%eax
  lea    0x10(%rsp),%rbp
  call   <puts0@plt>
  lea    0x12(%rsp),%rax
  movb   $0x4d,0x7(%rsp)
  mov    %rax,0x8(%rsp)
  nopl   0x0(%rax)
L181:
  mov    %ebx,%edi
  call   <puthex@plt>
  mov    $0x3a,%edi
  call   <putch@plt>
  mov    %r13d,%edi
  call   <puthex@plt>
  mov    $0x20,%edi
  call   <putch@plt>
  cmpb   $0x41,0x7(%rsp)
  je     L286
  cmpb   $0x4d,0x7(%rsp)
  je     L191
  cmpb   $0x48,0x7(%rsp)
  je     L285
L25:
  mov    %r15,%rdi
  call   <puts0@plt>
  mov    $0x3a,%edi
  call   <putch@plt>
  mov    $0x100,%esi
  mov    %rbp,%rdi
  call   <getsn@plt>
  movzbl 0x10(%rsp),%esi
  xor    %eax,%eax
  mov    %esi,%edx
  test   %sil,%sil
  jne    L6
  jmp    L153
  nopl   0x0(%rax,%rax,1)
L57:
  add    $0x1,%rax
  movzbl 0x0(%rbp,%rax,1),%edx
  test   %dl,%dl
  je     L79
L6:
  movslq %eax,%rcx
  cmp    $0xd,%dl
  jne    L57
  movb   $0x0,0x10(%rsp,%rcx,1)
  movzbl 0x10(%rsp),%eax
  cmp    $0x2f,%al
  je     L182
  test   %al,%al
  jne    L181
L153:
  add    $0x10,%r13d
  jmp    L181
  nopl   0x0(%rax)
L79:
  cmp    $0x2f,%sil
  jne    L181
L182:
  movsbl 0x11(%rsp),%edi
  call   <toupper@plt>
  cmp    $0x51,%al
  je     L184
  lea    -0x3f(%rax),%edx
  cmp    $0x1b,%dl
  ja     L275
  lea    D13(%rip),%rcx
  movzbl %dl,%edx
  movslq (%rcx,%rdx,4),%rdx
  add    %rcx,%rdx
  notrack jmp *%rdx
L275:
  lea    D32(%rip),%rdi
  call   <puts0@plt>
  nopl   0x0(%rax)
L188:
  mov    %r15,%rdi
  call   <puts0@plt>
  jmp    L181
  mov    %al,0x7(%rsp)
  jmp    L188
  lea    D43(%rip),%rdi
  call   <puts0@plt>
  jmp    L188
  mov    0x8(%rsp),%rdi
  call   <htoi@plt>
  mov    %r13d,%edx
  mov    %ebx,%esi
  mov    %eax,%edi
  call   <poke@plt>
  jmp    L188
  xor    %eax,%eax
  call   <memmap@plt>
  jmp    L188
  mov    0x8(%rsp),%rdi
  call   <htoi@plt>
  mov    %eax,%ebx
  jmp    L188
  mov    0x8(%rsp),%rdi
  call   <htoi@plt>
  mov    %eax,%r13d
  jmp    L188
  nop
L286:
  lea    0x10(%r13),%r12d
  mov    %r13d,%r14d
  jmp    L104
  nopl   0x0(%rax)
L33:
  movsbl %al,%edi
  call   <putch@plt>
L46:
  add    $0x1,%r14d
  cmp    %r14d,%r12d
  je     L25
L104:
  mov    %r14d,%esi
  mov    %ebx,%edi
  call   <peek3@plt>
  cmp    $0x1f,%al
  jg     L33
  mov    $0x2e,%edi
  call   <putch@plt>
  jmp    L46
  nop
L191:
  lea    0x10(%r13),%r12d
  mov    %r13d,%r14d
  nopw   0x0(%rax,%rax,1)
L12:
  mov    %r14d,%esi
  mov    %ebx,%edi
  add    $0x1,%r14d
  call   <peek3@plt>
  movsbl %al,%edi
  call   <puthex_b@plt>
  mov    $0x20,%edi
  call   <putch@plt>
  cmp    %r14d,%r12d
  jne    L12
  mov    %r13d,%r14d
  jmp    L307
  nopw   0x0(%rax,%rax,1)
L228:
  movsbl %al,%edi
  call   <putch@plt>
L15:
  add    $0x1,%r14d
  cmp    %r12d,%r14d
  je     L25
L307:
  mov    %r14d,%esi
  mov    %ebx,%edi
  call   <peek3@plt>
  cmp    $0x1f,%al
  jg     L228
  mov    $0x2e,%edi
  call   <putch@plt>
  jmp    L15
  nop
L285:
  lea    0x10(%r13),%r14d
  mov    %r13d,%r12d
  nopw   0x0(%rax,%rax,1)
L246:
  mov    %r12d,%esi
  mov    %ebx,%edi
  add    $0x1,%r12d
  call   <peek3@plt>
  movsbl %al,%edi
  call   <puthex_b@plt>
  mov    $0x20,%edi
  call   <putch@plt>
  cmp    %r12d,%r14d
  jne    L246
  jmp    L25
L184:
  mov    %r15,%rdi
  call   <puts0@plt>
  mov    0x118(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L196
  add    $0x128,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L196:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: data_tag: D14
type_infered: string
name: disassemble_data
arguments: data_tag: D9
type_infered: string
name: disassemble_data
arguments: data_tag: D32
type_infered: string
name: disassemble_data
arguments: data_tag: D43
type_infered: string

tool: D14: Use /? command for help


tool: D9: 


tool: D32: Invalid command


tool: D43: Commands:
/Q - Quit
/A - Ascii mode
/H - Hex mode
/M - Mix (hex & ascii) mode
/S<hex_value> - set Segment
/O<hex_value> - set Offset
/K - print memory map
Enter - next string
/Z<hex_value> - poke hex_value to memory


assistant: ```c
void memd(void) {
  char c;
  int i;
  char Option = 'M';
  unsigned int segm, off;
  char cmd[256];
  segm = 0;
  off = 0;
  puts0("Use /? command for help\r\n");
  while (1) {
    puthex(segm);
    putch(':');
    puthex(off);
    putch(' ');
    {
      if (Option == 'A') {
        for (i = 0; i < 16; i++) {
          if ((c = peek3(segm, (off + i))) >= ' ')
            putch(c);
          else
            putch('.');
        }
      } else if (Option == 'M') {
        for (i = 0; i < 16; i++) {
          puthex_b(peek3(segm, (off + i)));
          putch(' ');
        }
        for (i = 0; i < 16; i++) {
          if ((c = peek3(segm, (off + i))) >= ' ')
            putch(c);
          else
            putch('.');
        }
      } else if (Option == 'H') {
        for (i = 0; i < 16; i++) {
          puthex_b(peek3(segm, (off + i)));
          putch(' ');
        }
      }
    }
    puts0("\r\n");
    putch(':');
    getsn(cmd, 256);
    i = 0;
    while (cmd[i])
      if (cmd[i] == '\r') {
        cmd[i] = 0;
        break;
      } else
        i++;
    if (cmd[0] == '/') {
      c = toupper(cmd[1]);
      {
        if (c == 'Q') {
          puts0("\r\n");
          return;
        } else if ((c == 'A') || (c == 'H') || (c == 'M'))
          Option = c;
        else if (c == 'S')
          segm = htoi(cmd + 2);
        else if (c == 'O')
          off = htoi(cmd + 2);
        else if (c == 'K')
          memmap();
        else if (c == 'Z')
          poke(htoi(cmd + 2), segm, off);
        else if (c == '?')
          puts0("Commands:\r\n/Q - Quit\r\n/A - Ascii mode\r\n/H - Hex mode\r\n/M - Mix (hex & ascii) mode\r\n/S<hex_value> - set Segment\r\n/O<hex_value> - set Offset\r\n/K - print memory map\r\nEnter - next string\r\n/Z<hex_value> - poke hex_value to memory\r\n");
        else
          puts0("Invalid command\r\n");
      }
      puts0("\r\n");
    } else if (!cmd[0]) {
      off = (off + 16);
    } else
      ;
  }
}
```