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

```asm
<fmtstr>:
  endbr64
  push   %r15
  push   %r14
  mov    %rdx,%r14
  push   %r13
  mov    %rsi,%r13
  push   %r12
  mov    %rdi,%r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    0x50(%rsp),%ebp
  test   %rcx,%rcx
  je     L235
  cmpb   $0x0,(%rcx)
  mov    %rcx,%r15
  je     L251
L112:
  mov    $0x1,%eax
  nopl   (%rax)
L179:
  mov    %eax,%edx
  add    $0x1,%rax
  cmpb   $0x0,-0x1(%r15,%rax,1)
  jne    L179
  sub    %edx,%r9d
L251:
  xor    %ebx,%ebx
  test   %r9d,%r9d
  cmovns %r9d,%ebx
  mov    %ebx,0x8(%rsp)
  mov    %r8d,%ebx
  and    $0x1,%ebx
  jne    L183
  test   %r9d,%r9d
  jle    L19
  cmp    $0xffffffff,%ebp
  sete   0xf(%rsp)
  movzbl 0xf(%rsp),%eax
  test   %ebp,%ebp
  jg     L77
  test   %al,%al
  je     L19
L77:
  mov    $0x20,%ecx
  mov    %r14,%rdx
  mov    %r13,%rsi
  mov    %r12,%rdi
  call   <dopr_outch@plt>
  add    $0x1,%ebx
  subl   $0x1,0x8(%rsp)
  je     L19
  cmp    %ebx,%ebp
  jg     L77
  cmpb   $0x0,0xf(%rsp)
  jne    L77
L274:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L183:
  movsbl (%r15),%ecx
  negl   0x8(%rsp)
  xor    %ebx,%ebx
  test   %cl,%cl
  je     L70
L61:
  cmp    $0xffffffff,%ebp
  sete   0xf(%rsp)
  movzbl 0xf(%rsp),%eax
  cmp    %ebx,%ebp
  jle    L116
  nopl   0x0(%rax,%rax,1)
L185:
  add    $0x1,%r15
  mov    %r14,%rdx
  mov    %r13,%rsi
  mov    %r12,%rdi
  call   <dopr_outch@plt>
  movsbl (%r15),%ecx
  add    $0x1,%ebx
  test   %cl,%cl
  je     L70
  cmp    %ebx,%ebp
  jg     L185
  cmpb   $0x0,0xf(%rsp)
  jne    L185
  jmp    L274
  nopw   0x0(%rax,%rax,1)
L70:
  mov    0x8(%rsp),%eax
  test   %eax,%eax
  jns    L274
  cmp    $0xffffffff,%ebp
  sete   0xf(%rsp)
  movzbl 0xf(%rsp),%eax
  cmp    %ebx,%ebp
  jle    L133
L231:
  mov    %ebx,%r15d
  sub    0x8(%rsp),%r15d
  nopl   0x0(%rax)
L193:
  mov    $0x20,%ecx
  mov    %r14,%rdx
  mov    %r13,%rsi
  mov    %r12,%rdi
  call   <dopr_outch@plt>
  add    $0x1,%ebx
  cmp    %r15d,%ebx
  je     L274
  cmp    %ebx,%ebp
  jg     L193
  cmpb   $0x0,0xf(%rsp)
  jne    L193
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L133:
  test   %al,%al
  jne    L231
  jmp    L274
  nopl   0x0(%rax)
L116:
  test   %al,%al
  jne    L185
  jmp    L274
  nopl   (%rax)
L235:
  lea    D8(%rip),%r15
  jmp    L112
L19:
  movsbl (%r15),%ecx
  test   %cl,%cl
  jne    L61
  jmp    L274
```

tool_calls: name: unpack_data
arguments: data_tag: D8
datatype: string

tool: D8: <NULL>

assistant: ```c
void fmtstr(char *buffer, size_t *currlen, size_t maxlen, char *value, int flags, int min, int max) {
  int padlen, strln;
  int cnt = 0;
  if (!value) {
    value = "<NULL>";
  }
  for (strln = 0; value[strln]; ++strln)
    ;
  padlen = min - strln;
  if (padlen < 0)
    padlen = 0;
  if (flags & (1 << 0))
    padlen = -padlen;
  while ((padlen > 0) && (max == -1 || cnt < max)) {
    dopr_outch(buffer, currlen, maxlen, ' ');
    --padlen;
    ++cnt;
  }
  while (*value && (max == -1 || cnt < max)) {
    dopr_outch(buffer, currlen, maxlen, *value++);
    ++cnt;
  }
  while ((padlen < 0) && (max == -1 || cnt < max)) {
    dopr_outch(buffer, currlen, maxlen, ' ');
    ++padlen;
    ++cnt;
  }
}
```