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

```asm
<pmesh_get_invariant_index>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  mov    %edi,%r15d
  push   %r14
  push   %r13
  push   %r12
  mov    %edx,%r12d
  push   %rbx
  mov    %rsi,%rbx
  sub    $0x68,%rsp
  mov    %edi,-0x70(%rbp)
  mov    %ecx,-0x44(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  call   <absmax@plt>
  mov    %eax,%r8d
  test   %eax,%eax
  je     L283
  test   %r15d,%r15d
  jle    L223
  movslq %r15d,%rsi
  xor    %eax,%eax
  nopl   0x0(%rax)
L354:
  bt     %eax,%r12d
  jae    L332
  mov    (%rbx,%rax,4),%edx
  test   %edx,%edx
  js     L287
L332:
  add    $0x1,%rax
  cmp    %rsi,%rax
  jne    L354
  lea    0xf(,%rsi,4),%rax
  mov    %rsp,%rcx
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rcx
  and    $0xfffffffffffffff0,%rdx
  cmp    %rcx,%rsp
  je     L107
L173:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L173
L107:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  je     L18
  orq    $0x0,-0x8(%rsp,%rdx,1)
L18:
  mov    %rsp,%rdi
  xor    %edx,%edx
  xor    %r9d,%r9d
  xor    %r13d,%r13d
  mov    %rdi,-0x90(%rbp)
  xor    %r10d,%r10d
  xor    %r14d,%r14d
  mov    $0x1,%r11d
  jmp    L369
  nopl   0x0(%rax,%rax,1)
L194:
  movslq %r9d,%rcx
  mov    %eax,(%rdi,%rcx,4)
  mov    %edx,%ecx
  mov    %r12d,%eax
  add    $0x1,%rdx
  sar    %cl,%eax
  mov    %r9d,%ecx
  add    $0x1,%r9d
  and    $0x1,%eax
  shl    %cl,%eax
  or     %eax,%r13d
  cmp    %rsi,%rdx
  je     L318
L369:
  mov    (%rbx,%rdx,4),%eax
  mov    %eax,%ecx
  neg    %ecx
  cmovs  %eax,%ecx
  cmp    %r8d,%ecx
  jne    L194
  mov    %edx,%ecx
  mov    %r11d,%r15d
  shr    $0x1f,%eax
  add    $0x1,%rdx
  shl    %cl,%r15d
  shl    %cl,%eax
  or     %r15d,%r14d
  or     %eax,%r10d
  cmp    %rsi,%rdx
  jne    L369
L318:
  movzbl -0x70(%rbp),%ecx
  mov    $0x1,%eax
  mov    %rsp,%rsi
  mov    %r14d,-0x6c(%rbp)
  mov    %r13d,-0x84(%rbp)
  shl    %cl,%eax
  movslq %eax,%rcx
  mov    %eax,-0x7c(%rbp)
  lea    0xf(,%rcx,4),%rax
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rsi
  and    $0xfffffffffffffff0,%rdx
  cmp    %rsi,%rsp
  je     L70
L278:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rsi,%rsp
  jne    L278
L70:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  je     L47
  orq    $0x0,-0x8(%rsp,%rdx,1)
L47:
  mov    %rsp,%r11
  lea    0x0(,%rcx,4),%edx
  xor    %esi,%esi
  mov    %r8d,-0x48(%rbp)
  mov    %r11,%rdi
  mov    %r9d,-0x68(%rbp)
  mov    %r10d,-0x60(%rbp)
  mov    %rcx,-0x58(%rbp)
  mov    %r11,-0x50(%rbp)
  call   <memset@plt>
  mov    -0x7c(%rbp),%eax
  mov    -0x50(%rbp),%r11
  mov    -0x58(%rbp),%rcx
  mov    -0x60(%rbp),%r10d
  test   %eax,%eax
  mov    -0x68(%rbp),%r9d
  mov    -0x48(%rbp),%r8d
  jle    L287
L308:
  lea    (%r8,%r8,1),%eax
  mov    %r8d,-0x78(%rbp)
  xor    %r14d,%r14d
  xor    %r15d,%r15d
  mov    %eax,-0x74(%rbp)
  mov    -0x44(%rbp),%eax
  mov    %r9d,-0x80(%rbp)
  not    %eax
  mov    %eax,%r9d
L206:
  xor    %ebx,%ebx
  jmp    L158
  nopl   0x0(%rax)
L389:
  add    $0x1,%rbx
  cmp    %rbx,%rcx
  je     L109
L158:
  mov    %ebx,%esi
  mov    %r12d,%eax
  mov    %ebx,%edi
  not    %esi
  or     %esi,%eax
  test   %r14d,%eax
  jne    L389
  cmp    %r10d,%r14d
  jne    L126
  cmp    %ebx,-0x6c(%rbp)
  je     L129
L126:
  mov    (%r11,%rbx,4),%r13d
  test   %r13d,%r13d
  je     L88
L170:
  add    %r13d,%r15d
  test   %r9d,%r9d
  jns    L389
  cmp    -0x44(%rbp),%r15d
  jl     L389
L287:
  mov    $0xffffffff,%r8d
L283:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L344
  lea    -0x28(%rbp),%rsp
  mov    %r8d,%eax
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
  nopl   (%rax)
L88:
  mov    %r9d,-0x48(%rbp)
  mov    %rcx,-0x68(%rbp)
  mov    %r11,-0x60(%rbp)
  mov    %r10d,-0x58(%rbp)
  mov    %esi,-0x50(%rbp)
  call   <get_nbits@plt>
  mov    -0x50(%rbp),%edi
  mov    %eax,%r13d
  and    %r12d,%edi
  call   <get_nbits@plt>
  mov    -0x70(%rbp),%esi
  mov    %eax,-0x50(%rbp)
  sub    %r13d,%esi
  sub    %eax,%esi
  mov    -0x74(%rbp),%eax
  lea    -0x1(%rax),%edi
  call   <ipow@plt>
  mov    -0x50(%rbp),%esi
  mov    -0x78(%rbp),%edi
  mov    %eax,%r13d
  call   <ipow@plt>
  mov    -0x60(%rbp),%r11
  mov    -0x48(%rbp),%r9d
  imul   %eax,%r13d
  mov    -0x68(%rbp),%rcx
  mov    -0x58(%rbp),%r10d
  mov    %r13d,(%r11,%rbx,4)
  jmp    L170
  nopw   0x0(%rax,%rax,1)
L109:
  add    $0x1,%r14d
  cmp    -0x7c(%rbp),%r14d
  jne    L206
  jmp    L287
  nopl   0x0(%rax,%rax,1)
L129:
  mov    -0x44(%rbp),%ebx
  mov    -0x80(%rbp),%r9d
  test   %ebx,%ebx
  js     L137
  mov    %ebx,%ecx
  mov    -0x84(%rbp),%edx
  mov    -0x90(%rbp),%rsi
  mov    %r9d,%edi
  sub    %r15d,%ecx
  call   <pmesh_get_invariant_index>
  cmp    $0xffffffff,%eax
  je     L287
  lea    (%rax,%r15,1),%r8d
  cmp    %r8d,%ebx
  jg     L283
  jmp    L287
  nopl   0x0(%rax,%rax,1)
L137:
  mov    -0x84(%rbp),%edx
  mov    -0x90(%rbp),%rsi
  mov    $0xffffffff,%ecx
  mov    %r9d,%edi
  call   <pmesh_get_invariant_index>
  cmp    $0xffffffff,%eax
  je     L287
  lea    (%r15,%rax,1),%r8d
  jmp    L283
L223:
  movslq -0x70(%rbp),%rax
  mov    %rsp,%rcx
  lea    0xf(,%rax,4),%rax
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rcx
  and    $0xfffffffffffffff0,%rdx
  cmp    %rcx,%rsp
  je     L260
L341:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L341
L260:
  mov    %rdx,%rax
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  je     L370
  orq    $0x0,-0x8(%rsp,%rax,1)
L370:
  mov    %rsp,%rax
  mov    %rsp,-0x90(%rbp)
  cmp    %rax,%rsp
  je     L221
L315:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rax,%rsp
  jne    L315
L221:
  mov    %r8d,-0x58(%rbp)
  sub    $0x10,%rsp
  orq    $0x0,0x8(%rsp)
  mov    $0x4,%edx
  xor    %esi,%esi
  mov    %rsp,%r11
  mov    %r11,%rdi
  mov    %r11,-0x50(%rbp)
  call   <memset@plt>
  mov    -0x50(%rbp),%r11
  mov    -0x58(%rbp),%r8d
  xor    %r9d,%r9d
  movl   $0x0,-0x6c(%rbp)
  xor    %r10d,%r10d
  mov    $0x1,%ecx
  movl   $0x0,-0x84(%rbp)
  movl   $0x1,-0x7c(%rbp)
  jmp    L308
L344:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
ptrdiff_t pmesh_get_invariant_index(int ndim, const ptrdiff_t x[], const uint32_t cmask, ptrdiff_t max_length) {
  int d;
  ptrdiff_t shell = absmax(ndim, x);
  if (shell == 0)
    return 0;
  ptrdiff_t side = shell * 2 + 1;
  ptrdiff_t ind = 0;
  uint32_t icapset = 0;
  uint32_t icapset_x = 0;
  uint32_t icap_x = 0;
  for (d = 0; d < ndim; d++) {
    if ((cmask & (1 << d)) && x[d] < 0) {
      return -1;
    }
  }
  ptrdiff_t x1[ndim];
  uint32_t cmask1 = 0;
  int ndim1;
  for (ndim1 = 0, d = 0; d < ndim; d++) {
    if (abs(x[d]) == shell) {
      icapset_x |= (1 << d);
      icap_x |= (x[d] < 0) * (1 << d);
    } else {
      x1[ndim1] = x[d];
      cmask1 |= (1 << ndim1) * ((cmask >> d) & 1);
      ndim1++;
    }
  }
  int ncapsets = 1 << ndim;
  int ncapsmax = 1 << ndim;
  int icap;
  ptrdiff_t size[ncapsets];
  memset(size, 0, sizeof(size[0]) * ncapsets);
  for (icap = 0; icap < ncapsmax; icap++) {
    for (icapset = 0; icapset < ncapsets; icapset++) {
      if (icap & ~icapset)
        continue;
      if (icap & cmask)
        continue;
      if (icap == icap_x && icapset == icapset_x) {
        ptrdiff_t max_length1 = -1;
        if (max_length >= 0) {
          max_length1 = max_length - ind;
        }
        ptrdiff_t subind = pmesh_get_invariant_index(ndim1, x1, cmask1, max_length1);
        if (subind == -1) {
          return -1;
        }
        ind += subind;
        if (max_length >= 0 && ind >= max_length) {
          return -1;
        }
        return ind;
      }
      if (size[icapset] == 0) {
        int n = get_nbits(icapset);
        int nhalf = get_nbits(cmask & ~icapset);
        size[icapset] = ipow(side - 2, ndim - n - nhalf) * ipow(shell, nhalf);
      }
      ind += size[icapset];
      if (max_length >= 0 && ind >= max_length) {
        return -1;
      }
    }
  }
  return -1;
}
```