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

```asm
<read_int>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %rdx,-0x48(%rbp)
  cmpq   $0x0,-0x38(%rbp)
  setne  %al
  movzbl %al,%eax
  mov    %eax,%edi
  call   <assert@plt>
  cmpq   $0x0,-0x48(%rbp)
  setne  %al
  movzbl %al,%eax
  mov    %eax,%edi
  call   <assert@plt>
  movq   $0x0,-0x18(%rbp)
  movq   $0x0,-0x10(%rbp)
  movl   $0x0,-0x20(%rbp)
  movb   $0x1,-0x22(%rbp)
  movq   $0x0,-0x8(%rbp)
  jmp    L141
L166:
  mov    -0x38(%rbp),%rdx
  mov    -0x8(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  mov    %al,-0x21(%rbp)
  cmpb   $0x0,-0x22(%rbp)
  je     L10
  movsbl -0x21(%rbp),%eax
  mov    %eax,%edi
  call   <isdigit@plt>
  test   %rax,%rax
  jne    L10
  mov    $0x1,%eax
  jmp    L157
L10:
  mov    $0x0,%eax
L157:
  mov    %al,-0x22(%rbp)
  cmpb   $0x0,-0x22(%rbp)
  je     L151
  cmpb   $0x20,-0x21(%rbp)
  jne    L156
  addq   $0x1,-0x18(%rbp)
  jmp    L145
L156:
  mov    $0x0,%eax
  jmp    L5
L151:
  movsbl -0x21(%rbp),%eax
  mov    %eax,%edi
  call   <isdigit@plt>
  test   %rax,%rax
  je     L126
  movsbl -0x21(%rbp),%eax
  sub    $0x30,%eax
  mov    %eax,-0x1c(%rbp)
  cmpl   $0x9,-0x1c(%rbp)
  setle  %al
  movzbl %al,%eax
  mov    %eax,%edi
  call   <assert@plt>
  mov    -0x1c(%rbp),%eax
  not    %eax
  shr    $0x1f,%eax
  movzbl %al,%eax
  mov    %eax,%edi
  call   <assert@plt>
  mov    D24(%rip),%rax
  mov    (%rax),%eax
  movslq %eax,%rdx
  imul   $0x66666667,%rdx,%rdx
  shr    $0x20,%rdx
  sar    $0x2,%edx
  sar    $0x1f,%eax
  mov    %eax,%ecx
  mov    %edx,%eax
  sub    %ecx,%eax
  cmp    %eax,-0x20(%rbp)
  jg     L117
  mov    -0x20(%rbp),%edx
  mov    %edx,%eax
  shl    $0x2,%eax
  add    %edx,%eax
  add    %eax,%eax
  mov    %eax,-0x20(%rbp)
  jmp    L102
L117:
  mov    D24(%rip),%rax
  mov    (%rax),%eax
  mov    %eax,-0x20(%rbp)
L102:
  mov    D24(%rip),%rax
  mov    (%rax),%eax
  sub    -0x1c(%rbp),%eax
  cmp    %eax,-0x20(%rbp)
  jge    L127
  mov    -0x1c(%rbp),%eax
  add    %eax,-0x20(%rbp)
  jmp    L25
L127:
  mov    D24(%rip),%rax
  mov    (%rax),%eax
  mov    %eax,-0x20(%rbp)
L25:
  addq   $0x1,-0x18(%rbp)
  addq   $0x1,-0x10(%rbp)
L145:
  addq   $0x1,-0x8(%rbp)
L141:
  mov    -0x8(%rbp),%rax
  cmp    -0x40(%rbp),%rax
  jb     L166
  jmp    L138
L126:
  nop
L138:
  cmpq   $0x0,-0x10(%rbp)
  je     L158
  mov    -0x48(%rbp),%rax
  mov    -0x20(%rbp),%edx
  mov    %edx,(%rax)
  mov    -0x18(%rbp),%rax
  jmp    L5
L158:
  mov    $0x0,%eax
L5:
  leave
  ret
```

assistant: ```c
size_t read_int(const char *text, size_t lim, int *result) {
  assert(text != NULL);
  assert(result != NULL);
  size_t chars_read = 0;
  size_t digits_read = 0;
  int tmp_res = 0;
  char no_digit_yet = 1;
  for (size_t i = 0; i < lim; ++i) {
    char c = text[i];
    no_digit_yet = no_digit_yet && !isdigit(c);
    if (no_digit_yet) {
      if (c == ' ') {
        ++chars_read;
        continue;
      } else {
        return 0;
      }
    } else {
      if (isdigit(c)) {
        int digit = c - '0';
        assert(digit < 10);
        assert(digit >= 0);
        if (tmp_res <= INT_MAX / 10) {
          tmp_res *= 10;
        } else {
          tmp_res = INT_MAX;
        }
        if (tmp_res < INT_MAX - digit) {
          tmp_res += digit;
        } else {
          tmp_res = INT_MAX;
        }
        ++chars_read;
        ++digits_read;
      } else {
        break;
      }
    }
  }
  if (digits_read > 0) {
    *result = tmp_res;
    return chars_read;
  } else {
    return 0;
  }
}
```