user: 请将以下的汇编代码转换成C语言代码：

```asm
<utf8_to_value>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %rdi,-0x18(%rbp)
  mov    %esi,-0x1c(%rbp)
  mov    %rdx,-0x28(%rbp)
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  js     L139
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%edx
  mov    -0x28(%rbp),%rax
  mov    %edx,(%rax)
  mov    $0x1,%eax
  jmp    L188
L139:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0xbf,%al
  ja     L124
  mov    $0xffffffff,%eax
  jmp    L188
L124:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0xfc,%eax
  cmp    $0xfc,%eax
  jne    L159
  cmpl   $0x5,-0x1c(%rbp)
  jg     L238
  mov    $0xffffffff,%eax
  jmp    L188
L238:
  movl   $0x6,-0xc(%rbp)
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0x1,%eax
  mov    %eax,-0x8(%rbp)
  jmp    L202
L159:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0xf8,%eax
  cmp    $0xf8,%eax
  jne    L115
  cmpl   $0x4,-0x1c(%rbp)
  jg     L194
  mov    $0xffffffff,%eax
  jmp    L188
L194:
  movl   $0x5,-0xc(%rbp)
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0x3,%eax
  mov    %eax,-0x8(%rbp)
  jmp    L202
L115:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0xf0,%eax
  cmp    $0xf0,%eax
  jne    L165
  cmpl   $0x3,-0x1c(%rbp)
  jg     L74
  mov    $0xffffffff,%eax
  jmp    L188
L74:
  movl   $0x4,-0xc(%rbp)
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0x7,%eax
  mov    %eax,-0x8(%rbp)
  jmp    L202
L165:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0xe0,%eax
  cmp    $0xe0,%eax
  jne    L78
  cmpl   $0x2,-0x1c(%rbp)
  jg     L246
  mov    $0xffffffff,%eax
  jmp    L188
L246:
  movl   $0x3,-0xc(%rbp)
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0xf,%eax
  mov    %eax,-0x8(%rbp)
  jmp    L202
L78:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0xc0,%eax
  cmp    $0xc0,%eax
  jne    L202
  cmpl   $0x1,-0x1c(%rbp)
  jg     L157
  mov    $0xffffffff,%eax
  jmp    L188
L157:
  movl   $0x2,-0xc(%rbp)
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0x1f,%eax
  mov    %eax,-0x8(%rbp)
L202:
  movl   $0x1,-0x4(%rbp)
  jmp    L2
L212:
  mov    -0x4(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0xc0,%eax
  cmp    $0x80,%eax
  je     L118
  mov    $0xffffffff,%eax
  jmp    L188
L118:
  mov    -0x8(%rbp),%eax
  shl    $0x6,%eax
  mov    %eax,%ecx
  mov    -0x4(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0x3f,%eax
  or     %ecx,%eax
  mov    %eax,-0x8(%rbp)
  addl   $0x1,-0x4(%rbp)
L2:
  mov    -0x4(%rbp),%eax
  cmp    -0xc(%rbp),%eax
  jl     L212
  mov    -0x28(%rbp),%rax
  mov    -0x8(%rbp),%edx
  mov    %edx,(%rax)
  mov    -0xc(%rbp),%eax
L188:
  pop    %rbp
  ret
```

assistant: ```c
int utf8_to_value(unsigned char *str, int len, int *val) {
  int bytelen;
  int v;
  int i;
  if (str[0] < 0x80) {
    *val = str[0];
    return 1;
  }
  if (str[0] < 0xC0) {
    return -1;
  }
  if ((str[0] & 0xFC) == 0xFC) {
    if (len < 6) {
      return -1;
    }
    bytelen = 6;
    v = (str[0] & 1);
  } else if ((str[0] & 0xF8) == 0xF8) {
    if (len < 5) {
      return -1;
    }
    bytelen = 5;
    v = (str[0] & 3);
  } else if ((str[0] & 0xF0) == 0xF0) {
    if (len < 4) {
      return -1;
    }
    bytelen = 4;
    v = (str[0] & 7);
  } else if ((str[0] & 0xE0) == 0xE0) {
    if (len < 3) {
      return -1;
    }
    bytelen = 3;
    v = (str[0] & 0xF);
  } else if ((str[0] & 0xC0) == 0xC0) {
    if (len < 2) {
      return -1;
    }
    bytelen = 2;
    v = (str[0] & 0x1F);
  }
  for (i = 1; i < bytelen; i++) {
    if ((str[i] & 0xC0) != 0x80) {
      return -1;
    }
    v = (v << 6) | (str[i] & 0x3F);
  }
  *val = v;
  return bytelen;
}
```