user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<valid_port>:
  endbr64
  push   %rbx
  sub    $0x20,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  test   %rdi,%rdi
  je     L30
  mov    %rdi,%rbx
  movb   $0x0,0x7(%rsp)
  call   <strlen@plt>
  cmp    $0x8,%eax
  je     L39
  cmp    $0x9,%eax
  je     L212
  mov    $0x0,%eax
L30:
  mov    0x18(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L118
  add    $0x20,%rsp
  pop    %rbx
  ret
L39:
  lea    0xc(%rsp),%rcx
  lea    0x8(%rsp),%rdx
  sub    $0x8,%rsp
  lea    0xf(%rsp),%rax
  push   %rax
  lea    0x24(%rsp),%r9
  lea    0x20(%rsp),%r8
  lea    D2(%rip),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <sscanf@plt>
  mov    %eax,%edx
  add    $0x10,%rsp
  mov    $0x0,%eax
  cmp    $0x4,%edx
  jne    L30
  cmpl   $0x2,0x8(%rsp)
  jne    L30
  mov    0xc(%rsp),%edx
  cmp    $0x27,%edx
  ja     L30
  movabs $0x8208200000,%rax
  bt     %rdx,%rax
  jae    L18
  mov    0x10(%rsp),%eax
  lea    -0x1(%rax),%edx
  mov    $0x0,%eax
  cmp    $0x8,%edx
  ja     L30
  cmpl   $0x0,0x14(%rsp)
  setne  %al
  movzbl %al,%eax
  jmp    L30
L212:
  movzbl (%rbx),%eax
  cmp    $0x41,%al
  je     L201
  cmp    $0x42,%al
  je     L21
  cmp    $0x30,%al
  jne    L261
  mov    $0x0,%eax
  cmpb   $0x32,0x1(%rbx)
  jne    L30
  lea    0x10(%rsp),%rcx
  lea    0xc(%rsp),%rdx
  lea    0x2(%rbx),%rdi
  sub    $0x8,%rsp
  lea    0xf(%rsp),%rax
  push   %rax
  lea    0x24(%rsp),%r9
  lea    0x18(%rsp),%r8
  lea    D29(%rip),%rsi
  mov    $0x0,%eax
  call   <sscanf@plt>
  mov    %eax,%edx
  add    $0x10,%rsp
  mov    $0x0,%eax
  cmp    $0x4,%edx
  jne    L30
  mov    0xc(%rsp),%eax
  lea    -0x1(%rax),%edx
  mov    $0x0,%eax
  cmp    $0x31,%edx
  ja     L30
  mov    0x10(%rsp),%eax
  lea    -0x1(%rax),%edx
  mov    $0x0,%eax
  cmp    $0x13,%edx
  ja     L30
  mov    0x14(%rsp),%eax
  sub    $0x1,%eax
  cmp    $0x1f,%eax
  setbe  %al
  movzbl %al,%eax
  jmp    L30
L201:
  mov    $0x0,%eax
  cmpb   $0x42,0x1(%rbx)
  jne    L30
  jmp    L129
L21:
  movzbl 0x1(%rbx),%eax
  lea    -0x41(%rax),%edx
  mov    $0x0,%eax
  cmp    $0x19,%dl
  ja     L30
L129:
  lea    0x10(%rsp),%rcx
  lea    0xc(%rsp),%rdx
  lea    0x2(%rbx),%rdi
  sub    $0x8,%rsp
  lea    0xf(%rsp),%rax
  push   %rax
  lea    0x24(%rsp),%r9
  lea    0x18(%rsp),%r8
  lea    D29(%rip),%rsi
  mov    $0x0,%eax
  call   <sscanf@plt>
  mov    %eax,%edx
  add    $0x10,%rsp
  mov    $0x0,%eax
  cmp    $0x4,%edx
  jne    L30
  mov    0xc(%rsp),%eax
  lea    -0x1(%rax),%edx
  mov    $0x0,%eax
  cmp    $0x2,%edx
  ja     L30
  mov    0x10(%rsp),%eax
  lea    -0x1(%rax),%edx
  mov    $0x0,%eax
  cmp    $0x13,%edx
  ja     L30
  mov    0x14(%rsp),%eax
  sub    $0x1,%eax
  cmp    $0x1f,%eax
  setbe  %al
  movzbl %al,%eax
  jmp    L30
L18:
  mov    $0x0,%eax
  jmp    L30
L261:
  mov    $0x0,%eax
  jmp    L30
L118:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: label: D2
type_infered: string
name: read_data
arguments: label: D29
type_infered: string

tool: D2: %2u%2u%2u%2u%c

tool: D29: %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;
}
```