user: Please show me the C implementation that matches the assembly code listed below:

```asm
<kernel_main>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x20,%rsp
  mov    $0x0,%eax
  call   <uart_init@plt>
  lea    D2(%rip),%rax
  mov    %rax,%rdi
  call   <uart_puts@plt>
L42:
  mov    $0x0,%eax
  call   <uart_get@plt>
  mov    %al,-0x19(%rbp)
  cmpb   $0x2,-0x19(%rbp)
  je     L99
  jmp    L42
L99:
  nop
  movl   $0x0,-0x18(%rbp)
  movl   $0x0,-0x14(%rbp)
  movl   $0x1c,-0x10(%rbp)
  movl   $0x4000,-0xc(%rbp)
  movl   $0x0,-0x8(%rbp)
L108:
  mov    $0x0,%eax
  call   <uart_get@plt>
  mov    %al,-0x1a(%rbp)
  cmpb   $0x3,-0x1a(%rbp)
  je     L125
  cmpb   $0x23,-0x1a(%rbp)
  jne    L65
  movl   $0x1,-0x18(%rbp)
L65:
  cmpl   $0x0,-0x18(%rbp)
  je     L37
  cmpb   $0x10,-0x1a(%rbp)
  jne    L147
  movl   $0x0,-0x18(%rbp)
  jmp    L147
L37:
  cmpb   $0x2f,-0x1a(%rbp)
  jle    L90
  cmpb   $0x39,-0x1a(%rbp)
  jg     L23
  movzbl -0x1a(%rbp),%eax
  sub    $0x30,%eax
  mov    %al,-0x1a(%rbp)
  jmp    L105
L23:
  movzbl -0x1a(%rbp),%eax
  sub    $0x57,%eax
  mov    %al,-0x1a(%rbp)
L105:
  movsbl -0x1a(%rbp),%edx
  mov    -0x10(%rbp),%eax
  mov    %eax,%ecx
  shl    %cl,%edx
  mov    %edx,%eax
  add    %eax,-0x14(%rbp)
  cmpl   $0x0,-0x10(%rbp)
  jne    L164
  movl   $0x1c,-0x10(%rbp)
  mov    -0x14(%rbp),%eax
  mov    %eax,%edi
  call   <uart_puthex@plt>
  mov    -0x14(%rbp),%edx
  mov    -0xc(%rbp),%eax
  mov    %edx,%esi
  mov    %eax,%edi
  call   <put_mem@plt>
  mov    -0xc(%rbp),%eax
  add    $0x4,%eax
  mov    %eax,-0xc(%rbp)
  movl   $0x0,-0x14(%rbp)
  addl   $0x1,-0x8(%rbp)
  jmp    L108
L164:
  subl   $0x4,-0x10(%rbp)
  jmp    L108
L147:
  nop
  jmp    L108
L90:
  nop
  jmp    L108
L125:
  nop
  movl   $0x0,-0x4(%rbp)
  jmp    L109
L35:
  mov    -0x4(%rbp),%eax
  add    $0x1000,%eax
  shl    $0x2,%eax
  mov    %eax,%edi
  call   <get_mem@plt>
  mov    %eax,%edi
  call   <uart_puthex@plt>
  addl   $0x1,-0x4(%rbp)
L109:
  mov    -0x4(%rbp),%eax
  cmp    -0x8(%rbp),%eax
  jl     L35
L130:
  mov    $0x0,%eax
  call   <dummy@plt>
  jmp    L130
```

tool_calls: name: disassemble_data
arguments: tag: D2
datatype: string

tool: D2: debugc


assistant: ```c
int kernel_main() {
  uart_init();
  uart_puts("debugc\r\n");
  while (true) {
    const char c = uart_get();
    if (c == 0x02) {
      break;
    }
  }
  bool comment_mode = false;
  uint32_t temp_num = 0x00000000;
  uint8_t num_shift = 28;
  uint32_t mem_pos = 0x4000;
  uint32_t vals_read = 0;
  while (true) {
    char c = uart_get();
    if (c == 0x03) {
      break;
    }
    if (c == 0x23) {
      comment_mode = true;
    }
    if (comment_mode) {
      if (c == 0x10) {
        comment_mode = false;
      }
      continue;
    }
    if (c < 0x30) {
      continue;
    }
    if (c <= 0x39) {
      c -= 0x30;
    } else {
      c -= 0x57;
    }
    temp_num += (((uint32_t)c) << num_shift);
    if (num_shift == 0) {
      num_shift = 28;
      uart_puthex(temp_num);
      put_mem(mem_pos, temp_num);
      mem_pos += sizeof(uint32_t);
      temp_num = 0x00000000;
      ++vals_read;
    } else {
      num_shift -= 4;
    }
  }
  for (int i = 0; i < vals_read; ++i) {
    uart_puthex(get_mem(0x4000 + (i * 4)));
  }
  while (true) {
    dummy();
  }
}
```