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

```asm
<valid_port>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  cmpq   $0x0,-0x28(%rbp)
  jne    L36
  mov    $0x0,%eax
  jmp    L37
L36:
  movb   $0x0,-0x19(%rbp)
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cmp    $0x8,%eax
  je     L321
  cmp    $0x9,%eax
  je     L343
  jmp    L283
L321:
  lea    -0xc(%rbp),%r8
  lea    -0x10(%rbp),%rdi
  lea    -0x14(%rbp),%rcx
  lea    -0x18(%rbp),%rdx
  mov    -0x28(%rbp),%rax
  sub    $0x8,%rsp
  lea    -0x19(%rbp),%rsi
  push   %rsi
  mov    %r8,%r9
  mov    %rdi,%r8
  lea    D11(%rip),%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <sscanf@plt>
  add    $0x10,%rsp
  cmp    $0x4,%eax
  je     L41
  mov    $0x0,%eax
  jmp    L37
L41:
  mov    -0x18(%rbp),%eax
  cmp    $0x2,%eax
  je     L110
  mov    $0x0,%eax
  jmp    L37
L110:
  mov    -0x14(%rbp),%eax
  cmp    $0x15,%eax
  je     L22
  mov    -0x14(%rbp),%eax
  cmp    $0x1b,%eax
  je     L22
  mov    -0x14(%rbp),%eax
  cmp    $0x21,%eax
  je     L22
  mov    -0x14(%rbp),%eax
  cmp    $0x27,%eax
  je     L22
  mov    $0x0,%eax
  jmp    L37
L22:
  mov    -0x10(%rbp),%eax
  test   %eax,%eax
  je     L374
  mov    -0x10(%rbp),%eax
  cmp    $0x9,%eax
  jbe    L359
L374:
  mov    $0x0,%eax
  jmp    L37
L359:
  mov    -0xc(%rbp),%eax
  test   %eax,%eax
  je     L251
  mov    -0x10(%rbp),%eax
  cmp    $0x20,%eax
  jbe    L449
L251:
  mov    $0x0,%eax
  jmp    L37
L449:
  mov    $0x1,%eax
  jmp    L37
L343:
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x41,%al
  jne    L93
  mov    -0x28(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x42,%al
  je     L40
L93:
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x42,%al
  jne    L5
  mov    -0x28(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x40,%al
  jle    L5
  mov    -0x28(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x5a,%al
  jg     L5
L40:
  mov    -0x28(%rbp),%rax
  lea    0x2(%rax),%rdi
  lea    -0xc(%rbp),%r8
  lea    -0x18(%rbp),%rsi
  lea    -0x10(%rbp),%rdx
  lea    -0x14(%rbp),%rax
  sub    $0x8,%rsp
  lea    -0x19(%rbp),%rcx
  push   %rcx
  mov    %r8,%r9
  mov    %rsi,%r8
  mov    %rdx,%rcx
  mov    %rax,%rdx
  lea    D21(%rip),%rax
  mov    %rax,%rsi
  mov    $0x0,%eax
  call   <sscanf@plt>
  add    $0x10,%rsp
  cmp    $0x4,%eax
  je     L345
  mov    $0x0,%eax
  jmp    L37
L345:
  mov    -0x14(%rbp),%eax
  test   %eax,%eax
  je     L159
  mov    -0x14(%rbp),%eax
  cmp    $0x3,%eax
  jbe    L412
L159:
  mov    $0x0,%eax
  jmp    L37
L412:
  mov    -0x10(%rbp),%eax
  test   %eax,%eax
  je     L268
  mov    -0x10(%rbp),%eax
  cmp    $0x14,%eax
  jbe    L236
L268:
  mov    $0x0,%eax
  jmp    L37
L236:
  mov    -0xc(%rbp),%eax
  test   %eax,%eax
  je     L364
  mov    -0xc(%rbp),%eax
  cmp    $0x20,%eax
  jbe    L527
L364:
  mov    $0x0,%eax
  jmp    L37
L527:
  mov    $0x1,%eax
  jmp    L37
L5:
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x30,%al
  jne    L229
  mov    -0x28(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x32,%al
  jne    L229
  mov    -0x28(%rbp),%rax
  lea    0x2(%rax),%rdi
  lea    -0xc(%rbp),%r8
  lea    -0x18(%rbp),%rsi
  lea    -0x10(%rbp),%rdx
  lea    -0x14(%rbp),%rax
  sub    $0x8,%rsp
  lea    -0x19(%rbp),%rcx
  push   %rcx
  mov    %r8,%r9
  mov    %rsi,%r8
  mov    %rdx,%rcx
  mov    %rax,%rdx
  lea    D21(%rip),%rax
  mov    %rax,%rsi
  mov    $0x0,%eax
  call   <sscanf@plt>
  add    $0x10,%rsp
  cmp    $0x4,%eax
  je     L416
  mov    $0x0,%eax
  jmp    L37
L416:
  mov    -0x14(%rbp),%eax
  test   %eax,%eax
  je     L387
  mov    -0x14(%rbp),%eax
  cmp    $0x32,%eax
  jbe    L370
L387:
  mov    $0x0,%eax
  jmp    L37
L370:
  mov    -0x10(%rbp),%eax
  test   %eax,%eax
  je     L517
  mov    -0x10(%rbp),%eax
  cmp    $0x14,%eax
  jbe    L113
L517:
  mov    $0x0,%eax
  jmp    L37
L113:
  mov    -0xc(%rbp),%eax
  test   %eax,%eax
  je     L101
  mov    -0xc(%rbp),%eax
  cmp    $0x20,%eax
  jbe    L399
L101:
  mov    $0x0,%eax
  jmp    L37
L399:
  mov    $0x1,%eax
  jmp    L37
L229:
  mov    $0x0,%eax
  jmp    L37
L283:
  mov    $0x0,%eax
L37:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L92
  call   <__stack_chk_fail@plt>
L92:
  leave
  ret
```

tool_calls: name: read_data
arguments: data_label: D11
type_infered: string
name: read_data
arguments: data_label: D21
type_infered: string

tool: D11: %2u%2u%2u%2u%c

tool: D21: %2u%2u%c%2u%c

assistant: ```c
int valid_port(const char *port) {
  unsigned int h, r, p, o;
  char c, t;
  if (!port)
    return 0;
  c = 0;
  switch (strlen(port)) {
  case 8:
    if (sscanf(port, "%2u%2u%2u%2u%c", &h, &r, &p, &o, &c) != 4)
      return 0;
    if (h != 2)
      return 0;
    if (!(r == 21 || r == 27 || r == 33 || r == 39))
      return 0;
    if (p < 1 || p > 9)
      return 0;
    if (o < 1 || p > 32)
      return 0;
    return 1;
  case 9:
    if ((port[0] == 'A' && port[1] == 'B') || (port[0] == 'B' && (port[1] >= 'A' && port[1] <= 'Z'))) {
      if (sscanf(port + 2, "%2u%2u%c%2u%c", &r, &p, &t, &o, &c) != 4)
        return 0;
      if (r < 1 || r > 3)
        return 0;
      if (p < 1 || p > 20)
        return 0;
      if (o < 1 || o > 32)
        return 0;
      return 1;
    } else if (port[0] == '0' && port[1] == '2') {
      if (sscanf(port + 2, "%2u%2u%c%2u%c", &r, &p, &t, &o, &c) != 4)
        return 0;
      if (r < 1 || r > 50)
        return 0;
      if (p < 1 || p > 20)
        return 0;
      if (o < 1 || o > 32)
        return 0;
      return 1;
    } else
      return 0;
  }
  return 0;
}
```