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

```asm
<hsfc2d>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%rbx
  mov    %rdx,%r9
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  mov    (%rsi),%edi
  mov    D38(%rip),%rax
  movslq (%rax),%rdx
  mov    $0x2,%eax
  cmp    %eax,%edi
  cmovbe %edi,%eax
  mov    %eax,%eax
  imul   %rax,%rdx
  shl    $0x2,%rdx
  shr    %rdx
  mov    %edx,%r12d
  cmpl   $0x0,D15(%rip)
  jne    L42
  movb   $0x0,0x4(%rsp)
  mov    $0x1,%ecx
L65:
  lea    -0x1(%rcx),%eax
  lea    (%rcx,%rcx,1),%esi
  sub    $0x1,%esi
  test   %ecx,%ecx
  je     L65
L35:
  mov    %esi,%r8d
  sub    %eax,%r8d
  mov    %eax,%r10d
  mov    %ecx,%r14d
  or     0x4(%rsp,%r10,1),%r14b
  mov    %r14b,0x4(%rsp,%r8,1)
  sub    $0x1,%eax
  cmp    $0xffffffff,%eax
  jne    L35
  add    %ecx,%ecx
  cmp    $0x3,%ecx
  jbe    L65
  lea    D58(%rip),%rax
  movzbl 0x4(%rsp),%ecx
  movb   $0x0,(%rax,%rcx,1)
  movzbl 0x5(%rsp),%ecx
  movb   $0x1,(%rax,%rcx,1)
  movzbl 0x6(%rsp),%ecx
  movb   $0x2,(%rax,%rcx,1)
  movzbl 0x7(%rsp),%ecx
  movb   $0x3,(%rax,%rcx,1)
  movl   $0x1,D15(%rip)
L42:
  test   %edi,%edi
  je     L91
  movl   $0x0,(%r9)
  cmp    $0x1,%edi
  jbe    L91
  movl   $0x0,0x4(%r9)
L91:
  test   %edx,%edx
  je     L96
  mov    $0x1,%r11d
  mov    $0x0,%ebp
  mov    $0x1,%edi
  mov    $0x0,%r10d
  mov    D38(%rip),%r14
  lea    D58(%rip),%r13
  jmp    L142
L57:
  lea    -0x1(%rax),%eax
  or     %r15d,(%r9,%rax,4)
  jmp    L140
L19:
  mov    %r10d,%eax
  mov    %r11d,%r10d
  mov    %eax,%r11d
L132:
  add    $0x1,%edi
  cmp    %edi,%r12d
  jb     L96
L142:
  mov    (%r14),%esi
  movslq %esi,%rdx
  shl    $0x2,%esi
  mov    %esi,%r8d
  sub    %edi,%r8d
  mov    (%rbx),%eax
  mov    %r8d,%ecx
  shr    %cl,%eax
  and    $0x1,%eax
  mov    %r10d,%ecx
  shl    %cl,%eax
  mov    0x4(%rbx),%r15d
  mov    %r8d,%ecx
  shr    %cl,%r15d
  mov    %r15d,%r8d
  and    $0x1,%r8d
  mov    %r11d,%ecx
  shl    %cl,%r8d
  or     %r8d,%eax
  movzbl %bpl,%ecx
  xor    %ecx,%eax
  movzbl 0x0(%r13,%rax,1),%r8d
  movzbl %r8b,%r15d
  lea    (%rdi,%rdi,1),%eax
  mov    %eax,%eax
  lea    0x0(,%rdx,4),%rcx
  mov    $0x0,%edx
  div    %rcx
  sub    %edx,%esi
  mov    %esi,%edx
  cmp    %rdx,%rcx
  je     L57
  mov    %esi,%ecx
  shl    %cl,%r15d
  or     %r15d,(%r9,%rax,4)
L140:
  test   %r8b,%r8b
  je     L19
  cmp    $0x3,%r8b
  jne    L132
  xor    $0x3,%ebp
  mov    %r10d,%eax
  mov    %r11d,%r10d
  mov    %eax,%r11d
  jmp    L132
L96:
  mov    0x8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L89
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L89:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void hsfc2d(unsigned coord[], unsigned *nkey, unsigned key[]) {
  static int init = 0;
  static unsigned char gray_inv[2 * 2];
  const unsigned NKey = (2 < *nkey) ? 2 : (*nkey);
  const unsigned NBits = ((sizeof(unsigned) * CHAR_BIT) * NKey) / 2;
  unsigned i;
  unsigned char order[2 + 2];
  unsigned char reflect;
  if (!init) {
    unsigned char gray[2 * 2];
    register unsigned k;
    register unsigned j;
    gray[0] = 0;
    for (k = 1; k < sizeof(gray); k <<= 1) {
      for (j = 0; j < k; j++)
        gray[k + j] = k | gray[k - (j + 1)];
    }
    for (k = 0; k < sizeof(gray); k++)
      gray_inv[gray[k]] = k;
    init = 1;
  }
  for (i = 0; i < NKey; ++i)
    key[i] = 0;
  order[0] = 0;
  order[1] = 1;
  reflect = (0 << 0) | (0);
  for (i = 1; i <= NBits; i++) {
    const unsigned s = (sizeof(unsigned) * CHAR_BIT) - i;
    const unsigned c = gray_inv[reflect ^ ((((coord[0] >> s) & 01) << order[0]) | (((coord[1] >> s) & 01) << order[1]))];
    const unsigned off = 2 * i;
    const unsigned which = off / (sizeof(unsigned) * CHAR_BIT);
    const unsigned shift = (sizeof(unsigned) * CHAR_BIT) - off % (sizeof(unsigned) * CHAR_BIT);
    if (shift == (sizeof(unsigned) * CHAR_BIT)) {
      key[which - 1] |= c;
    } else {
      key[which] |= c << shift;
    }
    switch (c) {
    case 3:
      reflect ^= 03;
    case 0:
      order[2 + 0] = order[0];
      order[2 + 1] = order[1];
      order[0] = order[2 + 1];
      order[1] = order[2 + 0];
      break;
    }
  }
}
```