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

```asm
<check_str_2>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x38,%rsp
  mov    %rcx,-0x58(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  test   %rdi,%rdi
  je     L342
  mov    %rdi,%r12
  mov    %rsi,%r14
  mov    %rdx,%rbx
  mov    %r8d,%r13d
  test   %rdx,%rdx
  je     L12
  movb   $0x0,(%rdx)
L12:
  test   %r13d,%r13d
  jne    L129
  mov    $0x100,%edi
  call   <alloca@plt>
  mov    %rax,%r15
  mov    $0x100,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  movzbl (%r12),%eax
  test   %al,%al
  je     L95
  mov    $0xffffffff,%edx
  jmp    L240
L83:
  add    $0x1,%r12
  movzbl (%r12),%eax
  test   %al,%al
  je     L216
L240:
  movzbl %al,%eax
  cmpb   $0x0,(%r14,%rax,1)
  jne    L83
  movb   $0x1,(%r15,%rax,1)
  mov    %edx,%r13d
  jmp    L83
L216:
  test   %r13d,%r13d
  jns    L89
  test   %rbx,%rbx
  je     L89
  mov    $0x0,%eax
  jmp    L85
L246:
  add    $0x1,%rax
  cmp    $0x100,%rax
  je     L43
L85:
  cmpb   $0x0,(%r15,%rax,1)
  je     L246
  mov    %al,(%rbx)
  lea    0x1(%rbx),%rbx
  jmp    L246
L43:
  movb   $0x0,(%rbx)
  mov    %r13d,-0x4c(%rbp)
L290:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L137
  mov    -0x4c(%rbp),%eax
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L129:
  mov    $0x10000,%edi
  call   <alloca@plt>
  mov    %rax,-0x48(%rbp)
  mov    $0x10000,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  mov    %r12,%rdi
  call   <strlen@plt>
  lea    0x4(,%rax,4),%edi
  call   <alloca@plt>
  mov    %rax,%r13
  mov    %r12,%rsi
  mov    %rax,%rdi
  call   <utf8_to_ucs4_str@plt>
  mov    0x0(%r13),%r12d
  test   %r12d,%r12d
  je     L116
  mov    $0xffffffff,%r15d
  movl   $0x0,-0x4c(%rbp)
  mov    $0xffffffff,%edx
  mov    $0x3f,%ecx
  jmp    L150
L91:
  movslq %r12d,%rax
  cmpb   $0x0,(%r14,%rax,1)
  jne    L11
  cmp    $0x1f,%r12d
  cmovle %ecx,%r12d
  jmp    L38
L295:
  mov    $0x3f,%r12d
L38:
  movslq %r12d,%rax
  mov    -0x48(%rbp),%rdi
  movb   $0x1,(%rdi,%rax,1)
  cmp    %r12d,%r15d
  cmovl  %r12d,%r15d
  mov    %edx,-0x4c(%rbp)
L11:
  add    $0x4,%r13
  mov    0x0(%r13),%r12d
  test   %r12d,%r12d
  je     L233
L150:
  test   %r12d,%r12d
  js     L295
  cmp    $0x7f,%r12d
  jle    L91
  cmpb   $0x0,0xff(%r14)
  jne    L11
  cmp    $0x10000,%r12d
  cmovge %ecx,%r12d
  jmp    L38
L233:
  cmpl   $0x0,-0x4c(%rbp)
  jns    L290
  test   %rbx,%rbx
  je     L290
  cmp    $0x1f,%r15d
  jle    L284
L301:
  lea    0x4(,%r15,4),%edi
  call   <alloca@plt>
  test   %r15d,%r15d
  js     L365
  lea    0x1(%r15),%ecx
  mov    $0x0,%edx
  jmp    L218
L284:
  lea    D4(%rip),%rcx
  lea    D1(%rip),%rdx
  mov    $0x34f,%esi
  lea    D10(%rip),%rdi
  call   <swerr@plt>
  jmp    L301
L261:
  add    $0x1,%rdx
  cmp    %rdx,%rcx
  je     L365
L218:
  mov    -0x48(%rbp),%rsi
  cmpb   $0x0,(%rsi,%rdx,1)
  je     L261
  movslq %r12d,%rsi
  mov    %edx,(%rax,%rsi,4)
  lea    0x1(%r12),%r12d
  jmp    L261
L365:
  movslq %r12d,%r12
  movl   $0x0,(%rax,%r12,4)
  mov    %rax,%rdx
  mov    -0x58(%rbp),%rsi
  mov    %rbx,%rdi
  call   <ucs4_to_utf8_str@plt>
  jmp    L290
L342:
  movl   $0x0,-0x4c(%rbp)
  jmp    L290
L95:
  mov    %r13d,-0x4c(%rbp)
  jmp    L290
L89:
  mov    %r13d,-0x4c(%rbp)
  jmp    L290
L116:
  mov    %r12d,-0x4c(%rbp)
  jmp    L290
L137:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: label: D4
type: string
name: unpack_data
arguments: label: D1
type: string
name: unpack_data
arguments: label: D10
type: string

tool: D4: maxinv >= ' '

tool: D1: assertion failed: %s

tool: D10: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/stden/ejudge/refs/heads/master/misctext.c

assistant: ```c
int check_str_2(const unsigned char *str, const unsigned char *map, unsigned char *invchars, size_t invsize, int utf8_flag) {
  unsigned char *invset;
  unsigned char *p = invchars;
  int retval = 0, i, slen, *wstr, maxinv = -1, invc, *ibuf, j;
  if (!str)
    return 0;
  if (p)
    *p = 0;
  if (!utf8_flag) {
    invset = (unsigned char *)alloca(256);
    memset(invset, 0, 256);
    for (; *str; str++)
      if (!map[*str]) {
        invset[*str] = 1;
        retval = -1;
      }
    if (retval >= 0 || !p)
      return retval;
    for (i = 0; i < 256; i++)
      if (invset[i])
        *p++ = i;
    *p = 0;
  } else {
    invset = (unsigned char *)alloca(65536);
    memset(invset, 0, 65536);
    slen = strlen(str);
    wstr = (int *)alloca((slen + 1) * sizeof(wstr[0]));
    utf8_to_ucs4_str(wstr, str);
    for (; *wstr; wstr++) {
      invc = -1;
      if (*wstr < 0) {
        invc = '?';
      } else if (*wstr >= 128) {
        if (!map[255]) {
          if (*wstr >= 65536)
            invc = '?';
          else
            invc = *wstr;
        }
      } else if (!map[*wstr]) {
        if (*wstr < 32)
          invc = '?';
        else
          invc = *wstr;
      }
      if (invc > 0) {
        invset[invc] = 1;
        retval = -1;
        if (invc > maxinv)
          maxinv = invc;
      }
    }
    if (retval >= 0 || !p)
      return retval;
    do {
      if (!(maxinv >= ' '))
        swerr("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/stden/ejudge/refs/heads/master/misctext.c", 847, "assertion failed: %s", "maxinv >= ' '");
    } while (0);
    ibuf = (int *)alloca((maxinv + 1) * sizeof(ibuf[0]));
    for (i = 0, j = 0; i <= maxinv; i++)
      if (invset[i])
        ibuf[j++] = i;
    ibuf[j++] = 0;
    ucs4_to_utf8_str(invchars, invsize, ibuf);
  }
  return retval;
}
```