user: Converte this assembly snippet into its equivalent C code:

```asm
<valid_domain>:
  endbr64
  movzbl (%rdi),%edx
  cmp    $0x5b,%dl
  je     L286
  mov    %edx,%eax
  and    $0xffffffdf,%eax
  sub    $0x41,%eax
  cmp    $0x19,%al
  jbe    L231
  sub    $0x30,%edx
  cmp    $0x9,%dl
  ja     L76
L231:
  lea    0x1(%rdi),%rax
  lea    0xff(%rdi),%rcx
  mov    $0x0,%edx
  mov    $0x0,%r8d
  mov    $0x1,%r9d
  mov    $0x2,%r10d
  jmp    L161
L286:
  lea    0x1(%rdi),%rdx
  mov    $0x0,%r8d
  mov    $0x0,%esi
  mov    $0x0,%r10d
  mov    $0x1,%r9d
  jmp    L29
L244:
  movzbl (%rdx),%ecx
  cmp    $0x2e,%cl
  je     L197
  lea    -0x30(%rcx),%edi
  cmp    $0x9,%dil
  ja     L270
  lea    (%rax,%rax,4),%eax
  movzbl %cl,%ecx
  lea    -0x30(%rcx,%rax,2),%eax
  cmp    $0xff,%eax
  jg     L291
L158:
  add    $0x1,%rdx
L29:
  test   %esi,%esi
  jne    L244
  movzbl (%rdx),%eax
  lea    -0x30(%rax),%ecx
  cmp    $0x9,%cl
  ja     L96
  movzbl %al,%eax
  sub    $0x30,%eax
  mov    %r9d,%esi
  jmp    L158
L197:
  add    $0x1,%r8d
  cmp    $0x3,%r8d
  jg     L206
  mov    %r10d,%esi
  jmp    L158
L270:
  cmp    $0x3,%r8d
  jne    L168
  cmp    $0x5d,%cl
  jne    L168
  lea    0x1(%rdx),%rax
  jmp    L190
L308:
  cmp    $0x1,%edx
  je     L213
  movzbl (%rax),%esi
  mov    %esi,%edx
  and    $0xffffffdf,%edx
  sub    $0x41,%edx
  cmp    $0x19,%dl
  jbe    L143
  sub    $0x30,%esi
  cmp    $0x9,%sil
  ja     L88
  mov    %r8d,%edx
  jmp    L216
L213:
  movzbl (%rax),%esi
  mov    %esi,%edx
  and    $0xffffffdf,%edx
  sub    $0x41,%edx
  cmp    $0x19,%dl
  jbe    L293
  sub    $0x30,%esi
  cmp    $0x9,%sil
  ja     L186
  mov    %r8d,%edx
  jmp    L216
L319:
  mov    %r9d,%edx
L216:
  cmp    %rcx,%rax
  je     L178
  add    $0x1,%rax
L161:
  test   %edx,%edx
  jne    L308
  movzbl (%rax),%esi
  cmp    $0x2d,%sil
  je     L319
  cmp    $0x2e,%sil
  je     L90
  mov    %esi,%edi
  and    $0xffffffdf,%edi
  sub    $0x41,%edi
  cmp    $0x19,%dil
  jbe    L216
  sub    $0x30,%esi
  cmp    $0x9,%sil
  jbe    L216
L190:
  movzbl (%rax),%eax
  neg    %al
  sbb    %eax,%eax
  ret
L90:
  mov    %r10d,%edx
  jmp    L216
L293:
  mov    %r8d,%edx
  jmp    L216
L143:
  mov    %r8d,%edx
  jmp    L216
L96:
  mov    $0xffffffff,%eax
  ret
L206:
  mov    $0xffffffff,%eax
  ret
L291:
  mov    $0xffffffff,%eax
  ret
L168:
  mov    $0xffffffff,%eax
  ret
L76:
  mov    $0xffffffff,%eax
  ret
L186:
  mov    $0xffffffff,%eax
  ret
L88:
  mov    $0xffffffff,%eax
  ret
L178:
  mov    $0xffffffff,%eax
  ret
```

assistant: ```c
int valid_domain(const unsigned char *domain) {
  const unsigned char *ptr;
  int state;
  int n;
  int ndots;
  size_t len;
  ptr = domain;
  if (*ptr == '[') {
    ptr++;
    ndots = 0;
    state = 0;
    do {
      if (state == 0) {
        if (!((*ptr >= '0') && (*ptr <= '9'))) {
          return -1;
        }
        n = *ptr - '0';
        state = 1;
      } else {
        if (*ptr == '.') {
          if (++ndots > 3) {
            return -1;
          }
          state = 0;
        } else if (((*ptr >= '0') && (*ptr <= '9'))) {
          n = (n * 10) + (*ptr - '0');
          if (n > 255) {
            return -1;
          }
        } else if (*ptr == ']') {
          break;
        } else {
          return -1;
        }
      }
      ptr++;
    } while (1);
    if (ndots != 3) {
      return -1;
    }
    ptr++;
  } else {
    if ((!(((*ptr >= 'A') && (*ptr <= 'Z')) || ((*ptr >= 'a') && (*ptr <= 'z')))) && (!((*ptr >= '0') && (*ptr <= '9')))) {
      return -1;
    }
    ptr++;
    len = 1;
    state = 0;
    do {
      if (state == 0) {
        if (*ptr == '-') {
          state = 1;
        } else if (*ptr == '.') {
          state = 2;
        } else if ((!(((*ptr >= 'A') && (*ptr <= 'Z')) || ((*ptr >= 'a') && (*ptr <= 'z')))) && (!((*ptr >= '0') && (*ptr <= '9')))) {
          break;
        }
      } else if (state == 1) {
        if ((!(((*ptr >= 'A') && (*ptr <= 'Z')) || ((*ptr >= 'a') && (*ptr <= 'z')))) && (!((*ptr >= '0') && (*ptr <= '9')))) {
          return -1;
        }
        state = 0;
      } else {
        if ((!(((*ptr >= 'A') && (*ptr <= 'Z')) || ((*ptr >= 'a') && (*ptr <= 'z')))) && (!((*ptr >= '0') && (*ptr <= '9')))) {
          return -1;
        }
        state = 0;
      }
      if (++len > 255) {
        return -1;
      }
      ptr++;
    } while (1);
  }
  if (*ptr) {
    return -1;
  }
  return 0;
}
```