user: Please show me the C implementation that matches the assembly code listed below:

```asm
<fmtint>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  mov    %r9d,%r13d
  push   %r12
  mov    %rdx,%r12
  push   %rbp
  mov    %rsi,%rbp
  mov    %rcx,%rsi
  push   %rbx
  mov    %rdi,%rbx
  sub    $0x38,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  mov    0x70(%rsp),%r14d
  mov    0x78(%rsp),%edi
  test   %r14d,%r14d
  cmovs  %eax,%r14d
  test   $0x40,%dil
  jne    L68
  test   %rcx,%rcx
  js     L76
  test   $0x2,%dil
  je     L50
  movl   $0x2b,0x8(%rsp)
  mov    $0x1,%r11d
  jmp    L20
  nopw   0x0(%rax,%rax,1)
L68:
  movl   $0x0,0x8(%rsp)
  xor    %r11d,%r11d
L20:
  test   $0x20,%dil
  mov    %r8d,%r8d
  lea    0xf(%rsp),%r15
  mov    $0x1,%ecx
  lea    D9(%rip),%r9
  lea    D7(%rip),%rax
  cmove  %rax,%r9
  xchg   %ax,%ax
L69:
  mov    %rsi,%rax
  xor    %edx,%edx
  mov    %ecx,%r10d
  div    %r8
  movzbl (%r9,%rdx,1),%edx
  mov    %dl,(%r15,%rcx,1)
  mov    %rsi,%rdx
  mov    %rax,%rsi
  cmp    %r8,%rdx
  setae  %dl
  cmp    $0x13,%ecx
  setle  %al
  add    $0x1,%rcx
  test   %al,%dl
  jne    L69
  cmp    $0x14,%r10d
  mov    $0x13,%eax
  mov    $0x0,%edx
  cmove  %eax,%r10d
  mov    %edx,%esi
  movslq %r10d,%rax
  cmp    %r10d,%r14d
  mov    %rax,(%rsp)
  movb   $0x0,0x10(%rsp,%rax,1)
  mov    %r10d,%eax
  cmovge %r14d,%eax
  sub    %eax,%r13d
  mov    %r13d,%eax
  mov    %edi,%r13d
  sub    %r11d,%eax
  sub    %r10d,%r14d
  cmovs  %edx,%r14d
  test   %eax,%eax
  cmovns %eax,%esi
  and    $0x1,%r13d
  and    $0x10,%edi
  mov    %esi,0xc(%rsp)
  je     L28
  cmp    %esi,%r14d
  cmovl  %esi,%r14d
  xor    %r13d,%r13d
L46:
  mov    0x8(%rsp),%eax
  test   %eax,%eax
  jne    L153
L43:
  test   %r14d,%r14d
  jne    L149
L118:
  mov    (%rsp),%r14
L61:
  movsbl (%r15,%r14,1),%ecx
  mov    %r12,%rdx
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  sub    $0x1,%r14
  call   <dopr_outch@plt>
  test   %r14d,%r14d
  jne    L61
  test   %r13d,%r13d
  je     L120
  nopl   0x0(%rax)
L72:
  mov    $0x20,%ecx
  mov    %r12,%rdx
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <dopr_outch@plt>
  add    $0x1,%r13d
  jne    L72
L120:
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L109
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L149:
  mov    $0x30,%ecx
  mov    %r12,%rdx
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <dopr_outch@plt>
  sub    $0x1,%r14d
  jne    L149
  jmp    L118
  cs nopw 0x0(%rax,%rax,1)
L28:
  test   %r13d,%r13d
  mov    %esi,%r13d
  jne    L211
  test   %eax,%eax
  jle    L46
L74:
  mov    $0x20,%ecx
  mov    %r12,%rdx
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <dopr_outch@plt>
  sub    $0x1,%r13d
  jne    L74
  mov    0xc(%rsp),%edi
  mov    $0x1,%eax
  test   %edi,%edi
  cmovg  %edi,%eax
  sub    %eax,%edi
  mov    0x8(%rsp),%eax
  mov    %edi,%r13d
  test   %eax,%eax
  je     L43
L153:
  mov    0x8(%rsp),%ecx
  mov    %r12,%rdx
  mov    %rbp,%rsi
  mov    %rbx,%rdi
  call   <dopr_outch@plt>
  jmp    L43
  nop
L211:
  neg    %r13d
  jmp    L46
  nopl   0x0(%rax,%rax,1)
L76:
  movl   $0x2d,0x8(%rsp)
  neg    %rsi
  mov    $0x1,%r11d
  jmp    L20
  cs nopw 0x0(%rax,%rax,1)
L50:
  lea    0x0(,%rdi,8),%eax
  and    $0x20,%eax
  setne  %r11b
  mov    %eax,0x8(%rsp)
  movzbl %r11b,%r11d
  jmp    L20
L109:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: tag: D9
data_type: string
name: retrieve_data
arguments: tag: D7
data_type: string

tool: D9: 0123456789ABCDEF

tool: D7: 0123456789abcdef

assistant: ```c
void fmtint(char *buffer, size_t *currlen, size_t maxlen, long value, int base, int min, int max, int flags) {
  unsigned long uvalue;
  char convert[20];
  int signvalue = 0, place = 0, caps = 0;
  int spadlen = 0;
  int zpadlen = 0;
  if (max < 0)
    max = 0;
  uvalue = value;
  if (!(flags & (1 << 6))) {
    if (value < 0) {
      signvalue = '-';
      uvalue = -value;
    } else if (flags & (1 << 1))
      signvalue = '+';
    else if (flags & (1 << 2))
      signvalue = ' ';
  }
  if (flags & (1 << 5))
    caps = 1;
  do {
    convert[place++] = (caps ? "0123456789ABCDEF" : "0123456789abcdef")[uvalue % (unsigned)base];
    uvalue = (uvalue / (unsigned)base);
  } while (uvalue && (place < 20));
  if (place == 20)
    place--;
  convert[place] = 0;
  zpadlen = max - place;
  spadlen = min - (((max) > (place)) ? (max) : (place)) - (signvalue ? 1 : 0);
  if (zpadlen < 0)
    zpadlen = 0;
  if (spadlen < 0)
    spadlen = 0;
  if (flags & (1 << 4)) {
    zpadlen = (((zpadlen) > (spadlen)) ? (zpadlen) : (spadlen));
    spadlen = 0;
  }
  if (flags & (1 << 0))
    spadlen = -spadlen;
  while (spadlen > 0) {
    dopr_outch(buffer, currlen, maxlen, ' ');
    --spadlen;
  }
  if (signvalue)
    dopr_outch(buffer, currlen, maxlen, signvalue);
  if (zpadlen > 0) {
    while (zpadlen > 0) {
      dopr_outch(buffer, currlen, maxlen, '0');
      --zpadlen;
    }
  }
  while (place > 0)
    dopr_outch(buffer, currlen, maxlen, convert[--place]);
  while (spadlen < 0) {
    dopr_outch(buffer, currlen, maxlen, ' ');
    ++spadlen;
  }
}
```