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

```asm
<lznt1_block>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  mov    %rsi,%r12
  push   %rbp
  push   %rbx
  sub    $0x8,%rsp
  cmp    %rsi,%rdx
  je     L211
  mov    %rdi,%rbp
  mov    %rdx,%rsi
  mov    %rcx,%r8
  xor    %r9d,%r9d
  xor    %edi,%edi
  mov    $0x10,%edx
  mov    $0xc,%ecx
  xor    %eax,%eax
  nopl   0x0(%rax,%rax,1)
L195:
  test   %edi,%edi
  jne    L215
  mov    0x0(%rbp,%rsi,1),%r9d
  add    $0x1,%rsi
  cmp    %rsi,%r12
  je     L66
L215:
  test   $0x1,%r9b
  je     L214
  lea    0x4(%rsi),%r13
  cmp    %r12,%r13
  ja     L201
  mov    $0x1,%r10d
  mov    0x0(%rbp,%rsi,1),%r15d
  mov    %r13,%rsi
  shl    %cl,%r10d
  sub    $0x1,%r10d
  and    %r15d,%r10d
  lea    0x3(%r10),%r11d
  movslq %r11d,%r11
  add    %r11,%rax
  test   %r8,%r8
  jne    L110
L84:
  mov    %edx,%r10d
  cmp    %r10,%rax
  jbe    L184
  nopl   0x0(%rax)
L7:
  lea    (%rdx,%rdx,1),%r10d
  sub    $0x1,%ecx
  mov    %r10,%rdx
  cmp    %rax,%r10
  jb     L7
L184:
  add    $0x1,%edi
  shr    %r9d
  and    $0x7,%edi
  cmp    %rsi,%r12
  jne    L195
L66:
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L214:
  test   %r8,%r8
  je     L64
  mov    0x0(%rbp,%rsi,1),%r10d
  add    $0x4,%r8
  mov    %r10d,-0x4(%r8)
L64:
  add    $0x1,%rsi
  add    $0x1,%rax
  jmp    L84
  nopl   0x0(%rax)
L110:
  sar    %cl,%r15d
  mov    $0xfffffffffffffffc,%rbx
  lea    -0x1(%r11),%r14
  movslq %r15d,%r15
  shl    $0x2,%r15
  sub    %r15,%rbx
  add    %r8,%rbx
  test   %r11,%r11
  je     L84
  cmp    $0x8,%r15
  jbe    L164
  cmp    $0x2,%r14
  jbe    L164
  lea    -0x4(%r11),%r15
  xor    %esi,%esi
  xor    %r10d,%r10d
  shr    $0x2,%r15
  add    $0x1,%r15
  nopl   (%rax)
L186:
  movdqu (%rbx,%rsi,1),%xmm0
  add    $0x1,%r10
  movups %xmm0,(%r8,%rsi,1)
  add    $0x10,%rsi
  cmp    %r10,%r15
  ja     L186
  lea    0x0(,%r15,4),%rsi
  shl    $0x4,%r15
  add    %r15,%rbx
  sub    %rsi,%r14
  add    %r8,%r15
  cmp    %rsi,%r11
  je     L157
  mov    (%rbx),%esi
  mov    %esi,(%r15)
  test   %r14,%r14
  je     L157
  mov    0x4(%rbx),%esi
  mov    %esi,0x4(%r15)
  cmp    $0x1,%r14
  je     L157
  mov    0x8(%rbx),%esi
  mov    %esi,0x8(%r15)
L157:
  lea    (%r8,%r11,4),%r8
  mov    %r13,%rsi
  jmp    L84
L164:
  movslq %r10d,%r10
  xor    %esi,%esi
  add    $0x3,%r10
  nopl   0x0(%rax)
L38:
  mov    (%rbx,%rsi,4),%r14d
  mov    %r14d,(%r8,%rsi,4)
  add    $0x1,%rsi
  cmp    %rsi,%r10
  jne    L38
  jmp    L157
L201:
  lea    D0(%rip),%rdi
  call   <printf@plt>
  add    $0x8,%rsp
  mov    $0xffffffff,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L211:
  xor    %eax,%eax
  jmp    L66
```

tool_calls: name: read_data
arguments: data_tag: D0
type_guessed: string

tool: D0: LZNT1 compressed value overrun at %#zx


assistant: ```c
ssize_t lznt1_block(const void *data, size_t limit, size_t offset, void *block) {
  const uint16_t *tuple;
  const uint8_t *copy_src;
  uint8_t *copy_dest = block;
  size_t copy_len;
  size_t block_out_len = 0;
  unsigned int split = 12;
  unsigned int next_threshold = 16;
  unsigned int tag_bit = 0;
  unsigned int tag = 0;
  while (offset != limit) {
    if (tag_bit == 0) {
      tag = *((uint8_t *)(data + offset));
      offset++;
      if (offset == limit)
        break;
    }
    if (tag & 1) {
      if (offset + sizeof(*tuple) > limit) {
        do {
          if (1 & 1) {
            printf("LZNT1 compressed value overrun at "
                   "%#zx\n",
                   offset);
          }
        } while (0);
        return -1;
      }
      tuple = (data + offset);
      offset += sizeof(*tuple);
      copy_len = (((*tuple) & ((1 << (split)) - 1)) + 3);
      block_out_len += copy_len;
      if (copy_dest) {
        copy_src = (copy_dest - (((*tuple) >> split) + 1));
        while (copy_len--)
          *(copy_dest++) = *(copy_src++);
      }
    } else {
      copy_src = (data + offset);
      if (copy_dest)
        *(copy_dest++) = *copy_src;
      offset++;
      block_out_len++;
    }
    while (block_out_len > next_threshold) {
      split--;
      next_threshold <<= 1;
    }
    tag >>= 1;
    tag_bit = ((tag_bit + 1) % 8);
  }
  return block_out_len;
}
```