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

```asm
<BLZ_Code>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %rdi,%r12
  mov    %esi,0x2c(%rsp)
  mov    %rdx,0x48(%rsp)
  mov    %ecx,0x38(%rsp)
  lea    0xe(%rsi),%eax
  mov    %esi,%ebx
  add    $0x7,%ebx
  cmovns %ebx,%eax
  sar    $0x3,%eax
  mov    %esi,%ebx
  lea    0xb(%rsi,%rax,1),%edi
  mov    $0x1,%esi
  call   <Memory@plt>
  mov    %rax,%r14
  mov    %rax,0x30(%rsp)
  mov    %rax,0x10(%rsp)
  mov    %ebx,%esi
  mov    %r12,%rdi
  call   <BLZ_Invert@plt>
  mov    %ebx,%eax
  movslq %ebx,%rsi
  mov    %rsi,0x40(%rsp)
  lea    (%r12,%rsi,1),%rbx
  cmp    %rbx,%r12
  jae    L352
  mov    %eax,%esi
  mov    %eax,%r15d
  mov    %r12,%rax
  mov    %r14,%r9
  mov    $0x0,%r10d
  mov    $0x0,%edi
  movslq %esi,%rsi
  mov    %rsi,0x20(%rsp)
  mov    %r12,0x8(%rsp)
  mov    %edi,%r12d
  jmp    L439
L316:
  cmp    %esi,%ecx
  jbe    L167
  cmp    $0x12,%ecx
  je     L125
  mov    %edi,%ebp
  mov    %ecx,%esi
L167:
  add    $0x1,%edi
  cmp    %edi,%r11d
  jb     L711
L496:
  test   %edi,%edi
  je     L167
  cmp    %rax,%rbx
  je     L167
  mov    %rax,%rdx
  mov    $0x0,%ecx
  mov    %edi,%r8d
  neg    %r8
L158:
  movzbl (%rdx,%r8,1),%r14d
  cmp    %r14b,(%rdx)
  jne    L316
  add    $0x1,%ecx
  cmp    $0x12,%ecx
  je     L30
  add    $0x1,%rdx
  cmp    %edi,%ecx
  jae    L316
  cmp    %rdx,%rbx
  jne    L158
  jmp    L316
L711:
  cmpl   $0x0,0x38(%rsp)
  je     L385
  cmp    $0x2,%esi
  ja     L338
L385:
  movzbl 0x0(%r13),%edi
  lea    (%rdi,%rdi,1),%edx
  mov    %dl,0x0(%r13)
  cmp    $0x2,%esi
  ja     L454
L299:
  movzbl (%rax),%edx
  mov    %dl,(%r9)
  add    $0x1,%r9
  add    $0x1,%rax
  jmp    L576
L456:
  mov    %edi,%ebp
  mov    $0x12,%esi
L338:
  mov    %esi,%r8d
  add    %rax,%r8
  cmp    %rbx,%r8
  jb     L579
L654:
  movzbl 0x0(%r13),%edi
  lea    (%rdi,%rdi,1),%edx
  jmp    L454
L579:
  mov    %r8,%rax
  sub    0x8(%rsp),%rax
  mov    $0x1002,%edx
  cmp    %rdx,%rax
  cmovg  %rdx,%rax
  mov    %eax,%r14d
  mov    $0x2,%r11d
  mov    $0x3,%ecx
  cmp    $0x2,%eax
  ja     L165
  jmp    L429
L724:
  mov    0x18(%rsp),%esi
  cmp    %r11d,%edx
  jbe    L160
  cmp    $0x12,%edx
  je     L198
  mov    %edx,%r11d
L160:
  add    $0x1,%ecx
  cmp    %ecx,%r14d
  jb     L429
L165:
  test   %ecx,%ecx
  je     L335
  mov    %r8,%rax
  mov    $0x0,%edx
  mov    %ecx,%edi
  neg    %rdi
  mov    %esi,0x18(%rsp)
L319:
  movzbl (%rax,%rdi,1),%esi
  cmp    %sil,(%rax)
  jne    L724
  add    $0x1,%edx
  cmp    $0x12,%edx
  je     L8
  add    $0x1,%rax
  cmp    %ecx,%edx
  jae    L724
  cmp    %rax,%rbx
  jne    L319
  jmp    L724
L198:
  mov    %edx,%r11d
  jmp    L429
L282:
  mov    0x18(%rsp),%rax
  cmp    %r14d,%ecx
  jbe    L260
  cmp    $0x12,%ecx
  je     L556
  mov    %ecx,%r14d
L260:
  add    $0x1,%edi
  cmp    %edi,%esi
  jb     L518
L553:
  test   %edi,%edi
  je     L260
  cmp    %rax,%rbx
  je     L260
  mov    %rax,%rdx
  mov    $0x0,%ecx
  mov    %edi,%r8d
  neg    %r8
  mov    %rax,0x18(%rsp)
L37:
  movzbl (%rdx,%r8,1),%eax
  cmp    %al,(%rdx)
  jne    L282
  add    $0x1,%ecx
  cmp    $0x12,%ecx
  je     L734
  add    $0x1,%rdx
  cmp    %edi,%ecx
  jae    L282
  cmp    %rdx,%rbx
  jne    L37
  jmp    L282
L518:
  mov    0x3c(%rsp),%esi
  sub    $0x1,%rax
  cmp    $0x2,%r11d
  mov    $0x1,%edi
  cmovbe %edi,%r11d
L166:
  cmp    $0x2,%r14d
  mov    $0x1,%edi
  cmovbe %edi,%r14d
L5:
  add    %esi,%r11d
  add    $0x1,%r14d
  cmp    %r14d,%r11d
  ja     L654
  shlb   0x0(%r13)
  jmp    L299
L281:
  mov    %r12d,0x18(%rsp)
  mov    0x8(%rsp),%r12
  cmp    $0x1,%r10b
  jbe    L721
  movzbl 0x0(%r13),%eax
L603:
  shr    %r10b
  add    %eax,%eax
  cmp    $0x1,%r10b
  ja     L603
  mov    %al,0x0(%r13)
L721:
  mov    0x30(%rsp),%r13
  sub    %r13,%r9
  mov    %r9,%rbp
  mov    %r9d,%r14d
  mov    0x2c(%rsp),%esi
  mov    %r12,%rdi
  call   <BLZ_Invert@plt>
  mov    %ebp,%esi
  mov    %r13,%rdi
  call   <BLZ_Invert@plt>
  cmpl   $0x0,0x18(%rsp)
  je     L408
  mov    0x18(%rsp),%eax
  lea    (%rax,%r15,1),%r13d
  mov    0x2c(%rsp),%eax
  lea    0x4(%rax),%edx
  lea    0x3(%r13),%eax
  and    $0xfffffffc,%eax
  add    $0x8,%eax
  cmp    %eax,%edx
  jae    L359
  cmp    %rbx,%r12
  jae    L441
L408:
  mov    0x40(%rsp),%rcx
  mov    0x30(%rsp),%rsi
  add    %rsi,%rcx
  mov    %rsi,%rax
  sub    %rsi,%r12
L442:
  movzbl (%rax,%r12,1),%edx
  mov    %dl,(%rax)
  add    $0x1,%rax
  cmp    %rax,%rcx
  jne    L442
  mov    0x30(%rsp),%rax
  add    0x40(%rsp),%rax
  testb  $0x3,0x2c(%rsp)
  je     L80
L709:
  movb   $0x0,(%rax)
  add    $0x1,%rax
  mov    %rax,%rdx
  sub    0x10(%rsp),%rdx
  test   $0x3,%dl
  jne    L709
L80:
  movl   $0x0,(%rax)
  add    $0x4,%rax
L668:
  sub    0x10(%rsp),%rax
  mov    0x48(%rsp),%rsi
  mov    %eax,(%rsi)
  mov    0x10(%rsp),%rax
  add    $0x58,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L441:
  mov    0x30(%rsp),%rax
  jmp    L80
L359:
  lea    0xb(%r13),%edi
  mov    $0x1,%esi
  call   <Memory@plt>
  mov    %rax,%rbx
  test   %r15d,%r15d
  je     L645
  mov    %r15d,%edx
  add    %rax,%rdx
  sub    %rax,%r12
L154:
  movzbl (%r12,%rax,1),%ecx
  mov    %cl,(%rax)
  add    $0x1,%rax
  cmp    %rdx,%rax
  jne    L154
L645:
  mov    %ebp,%r9d
  sub    0x18(%rsp),%r9d
  mov    %r13d,%eax
  sub    %r14d,%eax
L616:
  mov    %r9d,%edx
  mov    0x10(%rsp),%rsi
  movzbl (%rsi,%rdx,1),%ecx
  lea    (%rax,%r9,1),%edx
  mov    %cl,(%rbx,%rdx,1)
  add    $0x1,%r9d
  cmp    %r9d,%r14d
  jne    L616
  mov    0x30(%rsp),%rdi
  call   <free@plt>
  mov    %r15d,%eax
  mov    0x18(%rsp),%edx
  add    %rdx,%rax
  lea    (%rbx,%rax,1),%rdx
  mov    0x2c(%rsp),%ecx
  sub    %r13d,%ecx
  test   $0x3,%al
  je     L59
  mov    %rdx,%rax
  mov    $0x8,%esi
  sub    %edx,%esi
L568:
  movb   $0xff,(%rax)
  add    $0x1,%rax
  lea    (%rsi,%rax,1),%edx
  mov    %rax,%rdi
  sub    %rbx,%rdi
  test   $0x3,%dil
  jne    L568
L45:
  mov    0x18(%rsp),%esi
  add    %edx,%esi
  mov    %esi,(%rax)
  mov    %dl,0x3(%rax)
  sub    %edx,%ecx
  mov    %ecx,0x4(%rax)
  add    $0x8,%rax
  mov    %rbx,0x10(%rsp)
  jmp    L668
L59:
  mov    %rdx,%rax
  mov    $0x8,%edx
  jmp    L45
L556:
  mov    0x3c(%rsp),%esi
  jmp    L20
L352:
  mov    0x2c(%rsp),%esi
  mov    %r12,%rdi
  call   <BLZ_Invert@plt>
  mov    $0x0,%esi
  mov    0x30(%rsp),%rbx
  mov    %rbx,%rdi
  call   <BLZ_Invert@plt>
  mov    %rbx,%rax
  jmp    L80
L339:
  sub    $0x1,%rax
  mov    $0x2,%r14d
  cmp    $0x2,%r11d
  ja     L166
  mov    $0x1,%r11d
  mov    $0x1,%r14d
  jmp    L5
L734:
  mov    0x18(%rsp),%rax
  cmp    $0x11,%r14d
  ja     L260
  mov    0x3c(%rsp),%esi
L20:
  sub    $0x1,%rax
  mov    $0x12,%r14d
  cmp    $0x2,%r11d
  ja     L5
  mov    $0x1,%r11d
  jmp    L5
L335:
  add    $0x1,%ecx
  jmp    L165
L8:
  mov    0x18(%rsp),%esi
  cmp    $0x11,%r11d
  ja     L160
  mov    %edx,%r11d
L429:
  lea    -0x1(%rsi),%edx
  mov    %r8,%rax
  sub    %rdx,%rax
  mov    %rax,%rdx
  sub    0x8(%rsp),%rdx
  mov    $0x1002,%ecx
  cmp    %rcx,%rdx
  cmovg  %rcx,%rdx
  mov    $0x2,%r14d
  mov    $0x3,%edi
  cmp    $0x2,%edx
  jbe    L339
  mov    %esi,0x3c(%rsp)
  mov    %edx,%esi
  jmp    L553
L30:
  cmp    $0x11,%esi
  ja     L167
L125:
  cmpl   $0x0,0x38(%rsp)
  jne    L456
  movzbl 0x0(%r13),%esi
  lea    (%rsi,%rsi,1),%edx
  mov    %edi,%ebp
  mov    $0x12,%esi
L454:
  mov    %esi,%ecx
  add    %rcx,%rax
  or     $0x1,%edx
  mov    %dl,0x0(%r13)
  lea    -0x3(%rsi),%edx
  shl    $0x4,%edx
  lea    -0x3(%rbp),%ecx
  shr    $0x8,%ecx
  or     %ecx,%edx
  mov    %dl,(%r9)
  lea    -0x3(%rbp),%edx
  mov    %dl,0x1(%r9)
  add    $0x2,%r9
L576:
  mov    %r9,%rsi
  sub    0x10(%rsp),%rsi
  mov    %rax,%rcx
  sub    0x8(%rsp),%rcx
  mov    0x20(%rsp),%rdi
  lea    (%rdi,%rsi,1),%rdx
  sub    %rcx,%rdx
  lea    (%r12,%r15,1),%edi
  cmp    %rdi,%rdx
  jge    L757
  mov    %esi,%r12d
  mov    0x2c(%rsp),%r15d
  sub    %ecx,%r15d
L757:
  cmp    %rbx,%rax
  jae    L281
L439:
  shr    %r10b
  jne    L487
  movb   $0x0,(%r9)
  mov    %r9,%r13
  lea    0x1(%r9),%r9
  mov    $0xffffff80,%r10d
L487:
  mov    %rax,%rdx
  sub    0x8(%rsp),%rdx
  mov    $0x1002,%ecx
  cmp    %rcx,%rdx
  cmovg  %rcx,%rdx
  mov    %edx,%r11d
  mov    $0x2,%esi
  mov    $0x3,%edi
  cmp    $0x2,%edx
  ja     L496
  shlb   0x0(%r13)
  jmp    L299
```

assistant: ```c
char *BLZ_Code(unsigned char *raw_buffer, int raw_len, int *new_len, int best) {
  unsigned char *pak_buffer, *pak, *raw, *raw_end, *flg, *tmp;
  unsigned int pak_len, inc_len, hdr_len, enc_len, len, pos, max;
  unsigned int len_best, pos_best, len_next, pos_next, len_post, pos_post;
  unsigned int pak_tmp, raw_tmp;
  unsigned char mask;
  pak_tmp = 0;
  raw_tmp = raw_len;
  pak_len = raw_len + ((raw_len + 7) / 8) + 11;
  pak_buffer = (unsigned char *)Memory(pak_len, sizeof(char));
  BLZ_Invert(raw_buffer, raw_len);
  pak = pak_buffer;
  raw = raw_buffer;
  raw_end = raw_buffer + raw_len;
  mask = 0;
  while (raw < raw_end) {
    if (!(mask >>= 1)) {
      *(flg = pak) = 0;
      pak++;
      mask = 0x80;
    }
    {
      len_best = 2;
      max = raw - raw_buffer >= 0x1002 ? 0x1002 : raw - raw_buffer;
      for (pos = 3; pos <= max; pos++) {
        for (len = 0; len < 0x12; len++) {
          if (raw + len == raw_end)
            break;
          if (len >= pos)
            break;
          if (*(raw + len) != *(raw + len - pos))
            break;
        }
        if (len > len_best) {
          pos_best = pos;
          if ((len_best = len) == 0x12)
            break;
        }
      }
    };
    if (best) {
      if (len_best > 2) {
        if (raw + len_best < raw_end) {
          raw += len_best;
          {
            len_next = 2;
            max = raw - raw_buffer >= 0x1002 ? 0x1002 : raw - raw_buffer;
            for (pos = 3; pos <= max; pos++) {
              for (len = 0; len < 0x12; len++) {
                if (raw + len == raw_end)
                  break;
                if (len >= pos)
                  break;
                if (*(raw + len) != *(raw + len - pos))
                  break;
              }
              if (len > len_next) {
                pos_next = pos;
                if ((len_next = len) == 0x12)
                  break;
              }
            }
          };
          raw -= len_best - 1;
          {
            len_post = 2;
            max = raw - raw_buffer >= 0x1002 ? 0x1002 : raw - raw_buffer;
            for (pos = 3; pos <= max; pos++) {
              for (len = 0; len < 0x12; len++) {
                if (raw + len == raw_end)
                  break;
                if (len >= pos)
                  break;
                if (*(raw + len) != *(raw + len - pos))
                  break;
              }
              if (len > len_post) {
                pos_post = pos;
                if ((len_post = len) == 0x12)
                  break;
              }
            }
          };
          raw--;
          if (len_next <= 2)
            len_next = 1;
          if (len_post <= 2)
            len_post = 1;
          if (len_best + len_next <= 1 + len_post)
            len_best = 1;
        }
      }
    }
    *flg <<= 1;
    if (len_best > 2) {
      raw += len_best;
      *flg |= 1;
      *pak = ((len_best - (2 + 1)) << 4) | ((pos_best - 3) >> 8);
      pak++;
      *pak = (pos_best - 3) & 0xFF;
      pak++;
    } else {
      *pak = *raw;
      pak++;
      raw++;
    }
    if (pak - pak_buffer + raw_len - (raw - raw_buffer) < pak_tmp + raw_tmp) {
      pak_tmp = pak - pak_buffer;
      raw_tmp = raw_len - (raw - raw_buffer);
    }
  }
  while (mask && (mask != 1)) {
    mask >>= 1;
    *flg <<= 1;
  }
  pak_len = pak - pak_buffer;
  BLZ_Invert(raw_buffer, raw_len);
  BLZ_Invert(pak_buffer, pak_len);
  if (!pak_tmp || (raw_len + 4 < ((pak_tmp + raw_tmp + 3) & -4) + 8)) {
    pak = pak_buffer;
    raw = raw_buffer;
    raw_end = raw_buffer + raw_len;
    while (raw < raw_end) {
      *pak = *raw;
      pak++;
      raw++;
    }
    while ((pak - pak_buffer) & 3) {
      *pak = 0;
      pak++;
    }
    *(unsigned int *)pak = 0;
    pak += 4;
  } else {
    tmp = (unsigned char *)Memory(raw_tmp + pak_tmp + 11, sizeof(char));
    for (len = 0; len < raw_tmp; len++)
      tmp[len] = raw_buffer[len];
    for (len = 0; len < pak_tmp; len++)
      tmp[raw_tmp + len] = pak_buffer[len + pak_len - pak_tmp];
    pak = pak_buffer;
    pak_buffer = tmp;
    free(pak);
    pak = pak_buffer + raw_tmp + pak_tmp;
    enc_len = pak_tmp;
    hdr_len = 8;
    inc_len = raw_len - pak_tmp - raw_tmp;
    while ((pak - pak_buffer) & 3) {
      *pak = 0xFF;
      pak++;
      hdr_len++;
    }
    *(unsigned int *)pak = enc_len + hdr_len;
    pak += 3;
    *pak = hdr_len;
    pak++;
    *(unsigned int *)pak = inc_len - hdr_len;
    pak += 4;
  }
  *new_len = pak - pak_buffer;
  return (pak_buffer);
}
```