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

```asm
<fmtnum>:
  endbr64
  push   %r15
  mov    %rdi,%r10
  mov    %r9d,%r15d
  mov    %esi,%edi
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %ecx,%ebx
  sub    $0x38,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  test   %edx,%edx
  je     L124
  test   %r10,%r10
  js     L97
L124:
  movl   $0x0,0xc(%rsp)
L154:
  xor    %eax,%eax
  test   %edi,%edi
  jns    L67
  neg    %edi
  mov    $0x1,%eax
L67:
  test   %eax,%eax
  movslq %edi,%rdi
  lea    0xf(%rsp),%rbp
  mov    $0x1,%ecx
  lea    D10(%rip),%r9
  lea    D8(%rip),%rax
  cmove  %rax,%r9
  nop
L136:
  mov    %r10,%rax
  xor    %edx,%edx
  mov    %ecx,%r14d
  div    %rdi
  movslq %ecx,%r13
  movzbl (%r9,%rdx,1),%edx
  mov    %dl,0x0(%rbp,%rcx,1)
  mov    %r10,%rdx
  add    $0x1,%rcx
  mov    %rax,%r10
  cmp    %rdi,%rdx
  jae    L136
  movslq %r14d,%rax
  sub    %r14d,%r8d
  mov    $0x0,%r12d
  movb   $0x0,0x10(%rsp,%rax,1)
  cmovns %r8d,%r12d
  test   %ebx,%ebx
  je     L174
  mov    %r12d,%ebx
  neg    %ebx
L177:
  mov    0xc(%rsp),%eax
  test   %eax,%eax
  je     L169
  mov    $0x2d,%edi
  xor    %eax,%eax
  call   <dopr_outch@plt>
L169:
  add    %r13,%rbp
  lea    -0x1(%r14),%eax
  lea    0x10(%rsp,%r13,1),%r12
  sub    %rax,%rbp
  nopl   0x0(%rax,%rax,1)
L47:
  movsbl -0x1(%r12),%edi
  xor    %eax,%eax
  sub    $0x1,%r12
  call   <dopr_outch@plt>
  cmp    %r12,%rbp
  jne    L47
  test   %ebx,%ebx
  je     L219
  nopw   0x0(%rax,%rax,1)
L238:
  xor    %eax,%eax
  mov    $0x20,%edi
  call   <dopr_outch@plt>
  add    $0x1,%ebx
  jne    L238
L219:
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L30
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L174:
  test   %r15d,%r15d
  je     L88
  test   %r8d,%r8d
  jle    L29
  mov    0xc(%rsp),%edx
  test   %edx,%edx
  jne    L57
  nopw   0x0(%rax,%rax,1)
L27:
  xor    %eax,%eax
  mov    %r15d,%edi
  call   <dopr_outch@plt>
  sub    $0x1,%r12d
  je     L169
L13:
  xor    %eax,%eax
  mov    %r15d,%edi
  call   <dopr_outch@plt>
  sub    $0x1,%r12d
  jne    L27
  jmp    L169
  nopl   0x0(%rax)
L97:
  movl   $0x2d,0xc(%rsp)
  neg    %r10
  jmp    L154
L88:
  test   %r8d,%r8d
  jle    L29
  mov    %r12d,%ebx
L143:
  xor    %eax,%eax
  mov    $0x20,%edi
  call   <dopr_outch@plt>
  sub    $0x1,%ebx
  jne    L143
  test   %r12d,%r12d
  mov    $0x1,%eax
  mov    %r12d,%ebx
  cmovg  %r12d,%eax
  sub    %eax,%ebx
  jmp    L177
  nopw   0x0(%rax,%rax,1)
L57:
  sub    $0x1,%r12d
  xor    %eax,%eax
  mov    $0x2d,%edi
  call   <dopr_outch@plt>
  test   %r12d,%r12d
  je     L169
  xor    %eax,%eax
  mov    %r15d,%edi
  call   <dopr_outch@plt>
  sub    $0x1,%r12d
  jne    L13
  jmp    L169
L30:
  call   <__stack_chk_fail@plt>
L29:
  mov    %r12d,%ebx
  jmp    L177
```

tool_calls: name: retrieve_data
arguments: label: D10
data_type: string
name: retrieve_data
arguments: label: D8
data_type: string

tool: D10: 0123456789ABCDEF

tool: D8: 0123456789abcdef

assistant: ```c
void fmtnum(value, base, dosign, ljust, len, zpad) long value;
int base, dosign, ljust, len, zpad;
{
  int signvalue = 0;
  unsigned long uvalue;
  char convert[20];
  int place = 0;
  int padlen = 0;
  int caps = 0;
  uvalue = value;
  if (dosign) {
    if (value < 0) {
      signvalue = '-';
      uvalue = -value;
    }
  }
  if (base < 0) {
    caps = 1;
    base = -base;
  }
  do {
    convert[place++] = (caps ? "0123456789ABCDEF" : "0123456789abcdef")[uvalue % (unsigned)base];
    uvalue = (uvalue / (unsigned)base);
  } while (uvalue);
  convert[place] = 0;
  padlen = len - place;
  if (padlen < 0)
    padlen = 0;
  if (ljust)
    padlen = -padlen;
  if (zpad && padlen > 0) {
    if (signvalue) {
      dopr_outch(signvalue);
      --padlen;
      signvalue = 0;
    }
    while (padlen > 0) {
      dopr_outch(zpad);
      --padlen;
    }
  }
  while (padlen > 0) {
    dopr_outch(' ');
    --padlen;
  }
  if (signvalue)
    dopr_outch(signvalue);
  while (place > 0)
    dopr_outch(convert[--place]);
  while (padlen < 0) {
    dopr_outch(' ');
    ++padlen;
  }
}
```