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

```asm
<bi_bi2str>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  mov    %esi,%ebp
  mov    %rdx,%rsi
  push   %rbx
  mov    %rdi,%rbx
  sub    $0x3f8,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x3e8(%rsp)
  xor    %eax,%eax
  cmp    $0xa,%ecx
  je     L83
  cmp    $0x10,%ecx
  jne    L68
  sub    $0x1,%ebp
  js     L30
  movslq %ebp,%rax
  mov    %ebp,%ebp
  xor    %esi,%esi
  xor    %r12d,%r12d
  shl    $0x3,%rax
  lea    -0x8(%rdx,%rax,1),%r8
  lea    (%rdx,%rax,1),%rdi
  lea    0x0(,%rbp,8),%rax
  sub    %rax,%r8
  nopl   (%rax)
L80:
  mov    $0x1c,%ecx
  nopl   (%rax)
L84:
  mov    (%rdi),%rax
  mov    %esi,%edx
  xor    $0x1,%edx
  shr    %cl,%rax
  and    $0xf,%eax
  setne  %sil
  test   %sil,%dl
  jne    L29
  xor    %esi,%esi
  test   %dl,%dl
  jne    L75
L29:
  lea    0x30(%rax),%esi
  lea    0x57(%rax),%edx
  cmp    $0x9,%rax
  mov    %esi,%eax
  mov    $0x1,%esi
  cmova  %edx,%eax
  movslq %r12d,%rdx
  add    $0x1,%r12d
  mov    %al,(%rbx,%rdx,1)
L75:
  sub    $0x4,%ecx
  cmp    $0xfffffffc,%ecx
  jne    L84
  sub    $0x8,%rdi
  cmp    %r8,%rdi
  jne    L80
  movslq %r12d,%r15
  add    %rbx,%r15
  jmp    L54
  nopl   0x0(%rax)
L68:
  mov    %ecx,%esi
  lea    D1(%rip),%rdi
  xor    %r12d,%r12d
  mov    %rbx,%r15
  call   <printf@plt>
  mov    $0xffffffff,%edi
  call   <exit@plt>
L54:
  movb   $0x0,(%r15)
  mov    0x3e8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L103
  add    $0x3f8,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  xchg   %ax,%ax
L83:
  test   %ebp,%ebp
  jle    L30
  mov    %rsp,%r13
  movslq %ebp,%rdx
  mov    %rbx,%r14
  xor    %r12d,%r12d
  shl    $0x3,%rdx
  mov    %r13,%rdi
  call   <memcpy@plt>
  nopl   0x0(%rax)
L6:
  lea    -0x1(%rbp),%eax
  mov    %r14,%r15
  cltq
  cmpq   $0x0,(%rsp,%rax,8)
  je     L54
  mov    %ebp,%edi
  mov    $0xa,%edx
  mov    %r13,%rsi
  add    $0x1,%r12d
  call   <bi_mod1@plt>
  mov    %ebp,%edi
  mov    $0xa,%edx
  mov    %r13,%rsi
  add    $0x30,%eax
  mov    %al,(%r14)
  lea    0x1(%r15),%r14
  call   <bi_div1@plt>
  mov    %eax,%ebp
  test   %eax,%eax
  jg     L6
  movslq %r12d,%r15
  add    %rbx,%r15
  jmp    L54
L30:
  mov    %rbx,%r15
  xor    %r12d,%r12d
  jmp    L54
L103:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: label: D1
type_infered: string

tool: D1: Error: invalid system: %d, quit


assistant: ```c
int bi_bi2str(char *str, int a_len, unsigned long *a_data, const unsigned int system) {
  unsigned long data[125];
  int i;
  char ch;
  if (system == 10) {
    for (i = 0; i < a_len; i++)
      data[i] = a_data[i];
    i = 0;
    while (a_len > 0 && data[a_len - 1] > 0) {
      ch = (char)bi_mod1(a_len, data, system) + 48;
      str[i] = ch;
      a_len = bi_div1(a_len, data, system);
      i++;
    }
  } else if (system == 16) {
    int j, k;
    int start = 0;
    unsigned long d;
    i = 0;
    for (k = a_len - 1; k >= 0; k--) {
      for (j = 7; j >= 0; j--) {
        d = (a_data[k] >> (j * 4)) & 0xf;
        if (!start && d != 0)
          start = 1;
        if (!start)
          continue;
        if (d < 10)
          ch = d + 48;
        else
          ch = d - 10 + 97;
        str[i] = ch;
        i++;
      }
    }
  } else {
    printf("Error: invalid system: %d, quit\n", system);
    exit(-1);
  }
  str[i] = 0;
  return i;
}
```