user: Translate the below assembly code into C programming language:

```asm
<memd>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x120,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movb   $0x4d,-0x11e(%rbp)
  movl   $0x0,-0x118(%rbp)
  movl   $0x0,-0x114(%rbp)
  lea    D37(%rip),%rax
  mov    %rax,%rdi
  call   <puts0@plt>
L359:
  mov    -0x118(%rbp),%eax
  mov    %eax,%edi
  call   <puthex@plt>
  mov    $0x3a,%edi
  call   <putch@plt>
  mov    -0x114(%rbp),%eax
  mov    %eax,%edi
  call   <puthex@plt>
  mov    $0x20,%edi
  call   <putch@plt>
  cmpb   $0x41,-0x11e(%rbp)
  jne    L232
  movl   $0x0,-0x11c(%rbp)
  jmp    L120
L158:
  mov    -0x11c(%rbp),%edx
  mov    -0x114(%rbp),%eax
  add    %eax,%edx
  mov    -0x118(%rbp),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <peek3@plt>
  mov    %al,-0x11d(%rbp)
  cmpb   $0x1f,-0x11d(%rbp)
  jle    L131
  movsbl -0x11d(%rbp),%eax
  mov    %eax,%edi
  call   <putch@plt>
  jmp    L215
L131:
  mov    $0x2e,%edi
  call   <putch@plt>
L215:
  addl   $0x1,-0x11c(%rbp)
L120:
  cmpl   $0xf,-0x11c(%rbp)
  jle    L158
  jmp    L141
L232:
  cmpb   $0x4d,-0x11e(%rbp)
  jne    L102
  movl   $0x0,-0x11c(%rbp)
  jmp    L198
L135:
  mov    -0x11c(%rbp),%edx
  mov    -0x114(%rbp),%eax
  add    %eax,%edx
  mov    -0x118(%rbp),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <peek3@plt>
  movsbl %al,%eax
  mov    %eax,%edi
  call   <puthex_b@plt>
  mov    $0x20,%edi
  call   <putch@plt>
  addl   $0x1,-0x11c(%rbp)
L198:
  cmpl   $0xf,-0x11c(%rbp)
  jle    L135
  movl   $0x0,-0x11c(%rbp)
  jmp    L168
L188:
  mov    -0x11c(%rbp),%edx
  mov    -0x114(%rbp),%eax
  add    %eax,%edx
  mov    -0x118(%rbp),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <peek3@plt>
  mov    %al,-0x11d(%rbp)
  cmpb   $0x1f,-0x11d(%rbp)
  jle    L150
  movsbl -0x11d(%rbp),%eax
  mov    %eax,%edi
  call   <putch@plt>
  jmp    L4
L150:
  mov    $0x2e,%edi
  call   <putch@plt>
L4:
  addl   $0x1,-0x11c(%rbp)
L168:
  cmpl   $0xf,-0x11c(%rbp)
  jle    L188
  jmp    L141
L102:
  cmpb   $0x48,-0x11e(%rbp)
  jne    L141
  movl   $0x0,-0x11c(%rbp)
  jmp    L206
L258:
  mov    -0x11c(%rbp),%edx
  mov    -0x114(%rbp),%eax
  add    %eax,%edx
  mov    -0x118(%rbp),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <peek3@plt>
  movsbl %al,%eax
  mov    %eax,%edi
  call   <puthex_b@plt>
  mov    $0x20,%edi
  call   <putch@plt>
  addl   $0x1,-0x11c(%rbp)
L206:
  cmpl   $0xf,-0x11c(%rbp)
  jle    L258
L141:
  lea    D10(%rip),%rax
  mov    %rax,%rdi
  call   <puts0@plt>
  mov    $0x3a,%edi
  call   <putch@plt>
  lea    -0x110(%rbp),%rax
  mov    $0x100,%esi
  mov    %rax,%rdi
  call   <getsn@plt>
  movl   $0x0,-0x11c(%rbp)
  jmp    L335
L231:
  mov    -0x11c(%rbp),%eax
  cltq
  movzbl -0x110(%rbp,%rax,1),%eax
  cmp    $0xd,%al
  jne    L163
  mov    -0x11c(%rbp),%eax
  cltq
  movb   $0x0,-0x110(%rbp,%rax,1)
  jmp    L33
L163:
  addl   $0x1,-0x11c(%rbp)
L335:
  mov    -0x11c(%rbp),%eax
  cltq
  movzbl -0x110(%rbp,%rax,1),%eax
  test   %al,%al
  jne    L231
L33:
  movzbl -0x110(%rbp),%eax
  cmp    $0x2f,%al
  jne    L378
  movzbl -0x10f(%rbp),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <toupper@plt>
  mov    %al,-0x11d(%rbp)
  cmpb   $0x51,-0x11d(%rbp)
  jne    L117
  lea    D10(%rip),%rax
  mov    %rax,%rdi
  call   <puts0@plt>
  nop
  mov    -0x8(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L0
  jmp    L311
L117:
  cmpb   $0x41,-0x11d(%rbp)
  je     L15
  cmpb   $0x48,-0x11d(%rbp)
  je     L15
  cmpb   $0x4d,-0x11d(%rbp)
  jne    L339
L15:
  movzbl -0x11d(%rbp),%eax
  mov    %al,-0x11e(%rbp)
  jmp    L41
L339:
  cmpb   $0x53,-0x11d(%rbp)
  jne    L265
  lea    -0x110(%rbp),%rax
  add    $0x2,%rax
  mov    %rax,%rdi
  call   <htoi@plt>
  mov    %eax,-0x118(%rbp)
  jmp    L41
L265:
  cmpb   $0x4f,-0x11d(%rbp)
  jne    L388
  lea    -0x110(%rbp),%rax
  add    $0x2,%rax
  mov    %rax,%rdi
  call   <htoi@plt>
  mov    %eax,-0x114(%rbp)
  jmp    L41
L388:
  cmpb   $0x4b,-0x11d(%rbp)
  jne    L385
  mov    $0x0,%eax
  call   <memmap@plt>
  jmp    L41
L385:
  cmpb   $0x5a,-0x11d(%rbp)
  jne    L173
  lea    -0x110(%rbp),%rax
  add    $0x2,%rax
  mov    %rax,%rdi
  call   <htoi@plt>
  mov    %eax,%ecx
  mov    -0x114(%rbp),%edx
  mov    -0x118(%rbp),%eax
  mov    %eax,%esi
  mov    %ecx,%edi
  call   <poke@plt>
  jmp    L41
L173:
  cmpb   $0x3f,-0x11d(%rbp)
  jne    L193
  lea    D31(%rip),%rax
  mov    %rax,%rdi
  call   <puts0@plt>
  jmp    L41
L193:
  lea    D43(%rip),%rax
  mov    %rax,%rdi
  call   <puts0@plt>
L41:
  lea    D10(%rip),%rax
  mov    %rax,%rdi
  call   <puts0@plt>
  jmp    L359
L378:
  movzbl -0x110(%rbp),%eax
  test   %al,%al
  jne    L359
  addl   $0x10,-0x114(%rbp)
  jmp    L359
L311:
  call   <__stack_chk_fail@plt>
L0:
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: label: D37
type: string
name: disassemble_data
arguments: label: D10
type: string
name: disassemble_data
arguments: label: D31
type: string
name: disassemble_data
arguments: label: D43
type: string

tool: D37: Use /? command for help


tool: D10: 


tool: D31: 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


tool: D43: Invalid command


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
      ;
  }
}
```