user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<command_format>:
  endbr64
  push   %r15
  mov    %esi,%r15d
  lea    D5(%rip),%rsi
  push   %r14
  mov    %rdi,%r14
  push   %r13
  mov    %rdx,%r13
  mov    %r8d,%edx
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %rcx,0x8(%rsp)
  lea    0x20(%rsp),%r12
  mov    %r12,%rdi
  mov    %fs:0x28,%rax
  mov    %rax,0x48(%rsp)
  xor    %eax,%eax
  call   <sprintf@plt>
  movzbl 0x0(%r13),%eax
  test   %r14,%r14
  setne  %bpl
  test   %al,%al
  je     L2
  xor    %ebx,%ebx
  jmp    L163
  nop
L151:
  test   %dl,%dl
  je     L72
  movslq %ebx,%rdx
  mov    %al,(%r14,%rdx,1)
L72:
  add    $0x1,%ebx
  mov    %r13,%rcx
L213:
  movzbl 0x1(%rcx),%eax
  lea    0x1(%rcx),%r13
  test   %al,%al
  je     L160
L163:
  cmp    %ebx,%r15d
  lea    0x1(%r13),%rcx
  setg   %dl
  and    %ebp,%edx
  cmp    $0x25,%al
  jne    L151
  movzbl 0x1(%r13),%esi
  test   %sil,%sil
  je     L151
  cmp    $0x48,%sil
  je     L87
  cmp    $0x50,%sil
  je     L113
  cmp    $0x25,%sil
  je     L217
  test   %dl,%dl
  jne    L11
L134:
  lea    0x1(%rbx),%eax
  cmp    %eax,%r15d
  jle    L194
  test   %bpl,%bpl
  je     L194
  movzbl 0x1(%r13),%edx
  cltq
  mov    %dl,(%r14,%rax,1)
L194:
  movzbl 0x1(%rcx),%eax
  add    $0x2,%ebx
  lea    0x1(%rcx),%r13
  test   %al,%al
  jne    L163
L160:
  lea    0x1(%rbx),%eax
L8:
  cmp    %ebx,%r15d
  jle    L16
  test   %bpl,%bpl
  je     L16
  movslq %ebx,%rbx
  movb   $0x0,(%r14,%rbx,1)
L16:
  mov    0x48(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L181
  add    $0x58,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L217:
  test   %dl,%dl
  je     L223
  movslq %ebx,%rax
  movb   $0x25,(%r14,%rax,1)
L223:
  add    $0x1,%ebx
  jmp    L213
  nopl   0x0(%rax)
L113:
  mov    %r12,%rdi
  mov    %dl,0x1f(%rsp)
  mov    %rcx,0x10(%rsp)
  call   <strlen@plt>
  movzbl 0x1f(%rsp),%edx
  mov    0x10(%rsp),%rcx
  mov    %eax,%r13d
  test   %dl,%dl
  jne    L149
L204:
  add    %r13d,%ebx
  jmp    L213
  nopw   0x0(%rax,%rax,1)
L87:
  mov    0x8(%rsp),%rdi
  mov    %dl,0x1f(%rsp)
  mov    %rcx,0x10(%rsp)
  call   <strlen@plt>
  movzbl 0x1f(%rsp),%edx
  mov    0x10(%rsp),%rcx
  mov    %eax,%r13d
  test   %dl,%dl
  je     L204
  mov    %r15d,%eax
  mov    0x8(%rsp),%rsi
  movslq %ebx,%rdi
  sub    %ebx,%eax
  cmp    %r13d,%eax
  cmovg  %r13d,%eax
  add    %r14,%rdi
  mov    %eax,%edx
  call   <strncpy@plt>
  mov    0x10(%rsp),%rcx
  jmp    L204
  nopl   0x0(%rax)
L11:
  movslq %ebx,%rax
  movb   $0x25,(%r14,%rax,1)
  jmp    L134
  nopl   (%rax)
L149:
  mov    %r15d,%eax
  movslq %ebx,%rdi
  mov    %r12,%rsi
  sub    %ebx,%eax
  cmp    %r13d,%eax
  cmovg  %r13d,%eax
  add    %r14,%rdi
  mov    %eax,%edx
  call   <strncpy@plt>
  mov    0x10(%rsp),%rcx
  jmp    L204
  xchg   %ax,%ax
L2:
  mov    $0x1,%eax
  xor    %ebx,%ebx
  jmp    L8
L181:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: tag: D5
type_infered: string

tool: D5: %d

assistant: ```c
int command_format(char *buffer, int buflen, const char *format, const char *host, int port) {
  int len = 0;
  char portbuf[32];
  sprintf(portbuf, "%d", port);
  for (const char *f = format; *f; f++) {
    if (*f == '%' && f[1]) {
      switch (*++f) {
      case 'H':
        do {
          const char *scp = (host);
          int sl = strlen(scp);
          if (buffer && len < buflen) {
            int cp = buflen - len;
            if (sl < cp)
              cp = sl;
            strncpy(buffer + len, (scp), cp);
          }
          len += sl;
        } while (0);
        break;
      case 'P':
        do {
          const char *scp = (portbuf);
          int sl = strlen(scp);
          if (buffer && len < buflen) {
            int cp = buflen - len;
            if (sl < cp)
              cp = sl;
            strncpy(buffer + len, (scp), cp);
          }
          len += sl;
        } while (0);
        break;
      case '%':
        do {
          if (buffer && len < buflen) {
            buffer[len] = ('%');
          }
          len++;
        } while (0);
        break;
      default:
        do {
          if (buffer && len < buflen) {
            buffer[len] = ('%');
          }
          len++;
        } while (0);
        do {
          if (buffer && len < buflen) {
            buffer[len] = (*f);
          }
          len++;
        } while (0);
        break;
      }
    } else {
      do {
        if (buffer && len < buflen) {
          buffer[len] = (*f);
        }
        len++;
      } while (0);
    }
  }
  do {
    if (buffer && len < buflen) {
      buffer[len] = ('\0');
    }
    len++;
  } while (0);
  return len;
}
```