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

```asm
<berlekamp>:
  endbr64
  push   %r15
  pxor   %xmm0,%xmm0
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0xe8,%rsp
  mov    %rsi,0x30(%rsp)
  mov    %rdx,0x48(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0xd8(%rsp)
  xor    %eax,%eax
  lea    0x1(%rdi),%eax
  movaps %xmm0,0x50(%rsp)
  mov    %eax,%r12d
  movaps %xmm0,0x90(%rsp)
  shl    $0x3,%r12d
  movl   $0x1,0x50(%rsp)
  movl   $0x1,0x94(%rsp)
  movaps %xmm0,0xa0(%rsp)
  movaps %xmm0,0xb0(%rsp)
  movaps %xmm0,0xc0(%rsp)
  movaps %xmm0,0x60(%rsp)
  movaps %xmm0,0x70(%rsp)
  movaps %xmm0,0x80(%rsp)
  je     L108
  shl    $0x2,%eax
  movl   $0x0,0x18(%rsp)
  mov    $0x1,%ebp
  mov    %eax,0x44(%rsp)
  lea    0x90(%rsp),%rax
  mov    %rax,0x20(%rsp)
  lea    0x94(%rsp),%rax
  movq   $0x0,0x10(%rsp)
  movl   $0x0,0x2c(%rsp)
  mov    %rax,0x38(%rsp)
  mov    %r12d,0x40(%rsp)
  xor    %r12d,%r12d
  nopw   0x0(%rax,%rax,1)
L157:
  mov    0x18(%rsp),%esi
  lea    D12(%rip),%rdi
  xor    %eax,%eax
  xor    %r14d,%r14d
  xor    %ebx,%ebx
  call   <pr_debug@plt>
  mov    0x30(%rsp),%rax
  mov    0x10(%rsp),%rdx
  mov    %ebp,%edi
  lea    (%rax,%rdx,4),%r15
  mov    %r15,%r13
  jmp    L79
  nopl   0x0(%rax)
L169:
  mov    0x50(%rsp,%r14,4),%edi
  mov    %r15d,%ebx
L79:
  mov    0x0(%r13),%esi
  sub    $0x4,%r13
  call   <mpy_mod_gf@plt>
  mov    %r14d,%esi
  mov    %r12d,%edx
  lea    D33(%rip),%rdi
  mov    %eax,%r15d
  mov    %eax,%ecx
  mov    %eax,%ebp
  add    $0x1,%r14
  xor    %eax,%eax
  xor    %ebx,%r15d
  call   <pr_debug@plt>
  cmp    %r14d,%r12d
  jae    L169
  mov    %r15d,0x1c(%rsp)
  add    %r15d,%r15d
  addl   $0x1,0x18(%rsp)
  cmp    %ebx,%ebp
  je     L163
  xor    %r14d,%r14d
  mov    $0xffffffff,%ebp
  xor    %ebx,%ebx
  mov    $0x1,%ecx
  mov    %r14d,%eax
  mov    %ebx,%r13d
  mov    %ebp,%r14d
  mov    %ecx,%ebx
  movl   $0x2000,0xc(%rsp)
  mov    %eax,%ebp
  movl   $0x201b,0x28(%rsp)
  jmp    L134
  nop
L136:
  mov    0x28(%rsp),%eax
  mov    0xc(%rsp),%ecx
  xor    %r15d,%eax
  mov    %ecx,%edx
  add    %eax,%eax
  xor    %r13d,%edx
  and    $0x3fff,%eax
  cmp    $0x1,%esi
  jne    L144
  mov    %edx,0xc(%rsp)
  neg    %r14d
  mov    %ecx,%r13d
  mov    %r15d,0x28(%rsp)
  mov    %eax,%r15d
L190:
  add    $0x1,%ebp
  shr    %r13d
  sub    $0x1,%r14d
  cmp    $0x19,%ebp
  je     L80
L134:
  mov    %r12d,%edx
  mov    %ebp,%esi
  lea    D10(%rip),%rdi
  xor    %eax,%eax
  call   <pr_debug@plt>
  mov    %r15d,%eax
  xor    %edx,%edx
  shr    $0xd,%eax
  and    $0x1,%eax
  test   %r14d,%r14d
  mov    %eax,%esi
  sete   %dl
  and    %ebx,%esi
  xor    %esi,%edx
  mov    %ebx,%esi
  xor    %edx,%ebx
  test   %eax,%eax
  jne    L136
  add    %r15d,%r15d
  add    $0x1,%ebp
  shr    %r13d
  sub    $0x1,%r14d
  and    $0x3fff,%r15d
  cmp    $0x19,%ebp
  jne    L134
L80:
  lea    (%r12,%r12,1),%eax
  xor    %r15d,%r15d
  lea    0x50(%rsp),%r14
  mov    %eax,0x28(%rsp)
  mov    %r13d,%eax
  mov    %r15,%rbx
  mov    0x20(%rsp),%r13
  mov    %eax,%r15d
  jmp    L66
  nopl   0x0(%rax)
L69:
  mov    %r9d,(%r14,%rbx,4)
  cmp    %ebx,%eax
  je     L163
  mov    %r15d,%esi
  mov    %r9d,%edi
  call   <mpy_mod_gf@plt>
  mov    %r12d,%edx
  mov    %ebx,%esi
  lea    D28(%rip),%rdi
  mov    %eax,0x0(%r13,%rbx,4)
  mov    %eax,%ecx
  xor    %eax,%eax
  call   <pr_debug@plt>
L49:
  add    $0x1,%rbx
  lea    -0x1(%rbx),%eax
  cmp    0x10(%rsp),%eax
  jg     L163
L66:
  mov    0x0(%r13,%rbx,4),%esi
  mov    0x1c(%rsp),%edi
  call   <mpy_mod_gf@plt>
  lea    D73(%rip),%rdi
  mov    %r12d,%edx
  mov    %ebx,%esi
  mov    %eax,0xc(%rsp)
  mov    %eax,%ecx
  xor    %eax,%eax
  call   <pr_debug@plt>
  mov    (%r14,%rbx,4),%edi
  mov    0xc(%rsp),%r9d
  mov    0x18(%rsp),%eax
  xor    %edi,%r9d
  cmp    %eax,0x28(%rsp)
  jae    L69
  mov    %r15d,%esi
  mov    %r9d,0xc(%rsp)
  call   <mpy_mod_gf@plt>
  mov    %r12d,%edx
  mov    %ebx,%esi
  lea    D28(%rip),%rdi
  mov    %eax,0x0(%r13,%rbx,4)
  mov    %eax,%ecx
  xor    %eax,%eax
  call   <pr_debug@plt>
  mov    0xc(%rsp),%r9d
  mov    %r9d,(%r14,%rbx,4)
  cmp    %ebx,0x18(%rsp)
  jne    L49
  mov    0x2c(%rsp),%eax
  add    $0x1,%eax
  sub    %r12d,%eax
  mov    %eax,%r12d
L163:
  mov    0x20(%rsp),%rsi
  mov    0x38(%rsp),%rdi
  mov    $0x3c,%edx
  call   <memmove@plt>
  mov    0x18(%rsp),%eax
  movl   $0x0,0x90(%rsp)
  cmp    %eax,0x40(%rsp)
  je     L108
  cmp    0x44(%rsp),%r12d
  ja     L108
  addq   $0x1,0x10(%rsp)
  mov    0x50(%rsp),%ebp
  mov    %eax,0x2c(%rsp)
  jmp    L157
  nopl   0x0(%rax)
L144:
  mov    %edx,0xc(%rsp)
  mov    %eax,%r15d
  jmp    L190
L108:
  mov    0x48(%rsp),%rbx
  movdqu 0x54(%rsp),%xmm1
  lea    D69(%rip),%rdi
  xor    %eax,%eax
  movdqu 0x64(%rsp),%xmm2
  lea    D66(%rip),%rbp
  movups %xmm1,(%rbx)
  lea    0x20(%rbx),%r13
  movups %xmm2,0x10(%rbx)
  call   <pr_debug@plt>
  nopl   (%rax)
L152:
  mov    (%rbx),%esi
  mov    %rbp,%rdi
  xor    %eax,%eax
  add    $0x4,%rbx
  call   <pr_debug@plt>
  cmp    %rbx,%r13
  jne    L152
  mov    0xd8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L9
  add    $0xe8,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L9:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: label: D12
type_infered: string
name: extract_symbolic_data
arguments: label: D33
type_infered: string
name: extract_symbolic_data
arguments: label: D10
type_infered: string
name: extract_symbolic_data
arguments: label: D28
type_infered: string
name: extract_symbolic_data
arguments: label: D73
type_infered: string
name: extract_symbolic_data
arguments: label: D69
type_infered: string
name: extract_symbolic_data
arguments: label: D66
type_infered: string

tool: D12: 
Iteration.............%d


tool: D33: %02d. s=0 LL=%x poly %x


tool: D10: %02d. s=1 LL=%x poly NULL


tool: D28: %02d. s=3 LL=%x poly %x


tool: D73: %02d. s=2 LL=%x poly %x


tool: D69: 
 Err poly:

tool: D66: 0x%x 

assistant: ```c
unsigned int berlekamp(unsigned int select_4_8, unsigned int synd[], unsigned int err[]) {
  int loop, iteration;
  unsigned int LL = 0;
  unsigned int d = 0;
  unsigned int invd = 0;
  unsigned int gammas[16] = {0};
  unsigned int D[16] = {0};
  unsigned int next_gamma = 0;
  int e = 0;
  unsigned int sign = 0;
  unsigned int u = 0;
  unsigned int v = 0;
  unsigned int C1 = 0, C2 = 0;
  unsigned int ss = 0;
  unsigned int tmp_v = 0, tmp_s = 0;
  unsigned int tmp_poly;
  for (loop = 0; loop < 16; loop++)
    gammas[loop] = 0;
  gammas[0] = 1;
  D[1] = 1;
  iteration = 0;
  LL = 0;
  while ((iteration < ((select_4_8 + 1) * 2 * 4)) && (LL <= ((select_4_8 + 1) * 4))) {
    pr_debug("\nIteration.............%d\n", iteration);
    d = 0;
    for (loop = 0; loop <= LL; loop++) {
      tmp_poly = mpy_mod_gf(gammas[loop], synd[iteration - loop]);
      d ^= tmp_poly;
      pr_debug("%02d. s=0 LL=%x poly %x\n", loop, LL, tmp_poly);
    }
    v = d << 1;
    e = -1;
    sign = 1;
    ss = 0x2000;
    invd = 0;
    u = 0x201B;
    for (loop = 0; (d != 0) && (loop <= (2 * 12)); loop++) {
      pr_debug("%02d. s=1 LL=%x poly NULL\n", loop, LL);
      C1 = (v >> 13) & 1;
      C2 = C1 & sign;
      sign ^= C2 ^ (e == 0);
      tmp_v = v;
      tmp_s = ss;
      if (C1 == 1) {
        v ^= u;
        ss ^= invd;
      }
      v = (v << 1) & 0x3FFF;
      if (C2 == 1) {
        u = tmp_v;
        invd = tmp_s;
        e = -e;
      }
      invd >>= 1;
      e--;
    }
    for (loop = 0; (d != 0) && (loop <= (iteration + 1)); loop++) {
      tmp_poly = mpy_mod_gf(d, D[loop]);
      pr_debug("%02d. s=2 LL=%x poly %x\n", loop, LL, tmp_poly);
      next_gamma = gammas[loop] ^ tmp_poly;
      if ((2 * LL) < (iteration + 1)) {
      } else {
        gammas[loop] = next_gamma;
        if (loop == (iteration + 1)) {
          break;
        }
      }
      D[loop] = mpy_mod_gf(gammas[loop], invd);
      pr_debug("%02d. s=3 LL=%x poly %x\n", loop, LL, D[loop]);
      gammas[loop] = next_gamma;
      if (loop == (iteration + 1)) {
        LL = iteration - LL + 1;
        break;
      }
    }
    for (loop = 0; loop < 15; loop++)
      D[15 - loop] = D[14 - loop];
    D[0] = 0;
    iteration++;
  }
  for (loop = 0; loop < 8; loop++)
    err[loop] = gammas[loop + 1];
  pr_debug("\n Err poly:");
  for (loop = 0; loop < 8; loop++)
    pr_debug("0x%x ", err[loop]);
  return LL;
}
```