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

```asm
<VSprintfPatch>:
  endbr64
  push   %r15
  push   %r14
  mov    %rdi,%r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %rdx,(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  movzbl (%rsi),%eax
  test   %al,%al
  je     L291
  mov    %rsi,%r15
  lea    0x10(%rsp),%rsi
  mov    %rdi,%rbx
  mov    %r15,%rbp
  mov    %rsi,0x8(%rsp)
  mov    %rdi,%r15
  jmp    L524
  nopl   0x0(%rax)
L447:
  test   %r15,%r15
  je     L492
  mov    %al,(%rbx)
  mov    %rbp,%r13
  add    $0x1,%rbx
L8:
  movzbl 0x1(%r13),%eax
  lea    0x1(%r13),%rbp
  test   %al,%al
  je     L388
L524:
  cmp    $0x25,%al
  jne    L447
  lea    0x1(%rbp),%r13
  movzbl 0x1(%rbp),%ebp
  mov    (%rsp),%rax
  cmp    $0x73,%bpl
  je     L280
  mov    (%rax),%rdi
  xor    %r10d,%r10d
  cmp    $0xf,%rdi
  jle    L156
  lea    -0x10(%rdi),%rax
  mov    $0x4,%r10d
  cmp    $0xef,%rax
  jbe    L156
  lea    -0x100(%rdi),%rax
  mov    $0x8,%r10d
  cmp    $0xeff,%rax
  ja     L17
  nopl   0x0(%rax)
L156:
  movzbl %bpl,%eax
  lea    -0x30(%rax),%ecx
  cmp    $0x9,%cl
  jbe    L85
L38:
  mov    %ebp,%eax
  and    $0xffffffd7,%eax
  cmp    $0x50,%al
  jne    L81
  mov    %ebp,%r8d
  and    $0xffffffdf,%ebp
  addq   $0x8,(%rsp)
  mov    0x8(%rsp),%r14
  mov    %rdi,%rax
  and    $0x20,%r8d
  cmp    $0x50,%bpl
  jne    L333
  mov    %r8d,%ecx
  movb   $0x30,0x10(%rsp)
  lea    0x12(%rsp),%r14
  or     $0x58,%ecx
  mov    %cl,0x11(%rsp)
L333:
  xor    %ecx,%ecx
  test   %rdi,%rdi
  je     L153
  nopl   0x0(%rax)
L182:
  mov    %rax,%rdx
  and    $0xf,%edx
  cmp    $0x1,%rdx
  sbb    $0xffffffff,%ecx
  shr    $0x4,%rax
  jne    L182
  lea    -0x4(,%rcx,4),%ecx
L13:
  cmp    %ecx,%r10d
  cmovge %r10d,%ecx
  test   %ecx,%ecx
  js     L219
  mov    %ecx,%r10d
  mov    %r14,%r9
  mov    %ecx,%r11d
  or     $0xfffffffc,%r10d
  nopw   0x0(%rax,%rax,1)
L490:
  mov    %rdi,%rax
  lea    D9(%rip),%rdx
  add    $0x1,%r9
  sar    %cl,%rax
  sub    $0x4,%ecx
  and    $0xf,%eax
  movzbl (%rdx,%rax,1),%esi
  or     %r8d,%esi
  mov    %sil,-0x1(%r9)
  cmp    %r10d,%ecx
  jne    L490
  shr    $0x2,%r11d
  lea    0x1(%r11),%eax
  add    %rax,%r14
L219:
  cmp    0x8(%rsp),%r14
  jbe    L8
  movzbl 0x10(%rsp),%ebp
L387:
  mov    0x8(%rsp),%r12
  jmp    L468
  nopl   0x0(%rax)
L438:
  add    $0x1,%r12
  cmp    %r12,%r14
  jbe    L8
  movzbl (%r12),%ebp
L468:
  test   %r15,%r15
  je     L39
  mov    %bpl,(%rbx)
  add    $0x1,%rbx
L376:
  cmp    $0xa,%bpl
  jne    L438
  mov    $0xd,%edi
  call   <HalSerialPutcRtl8195a@plt>
  jmp    L438
L39:
  movsbl %bpl,%edi
  call   <HalSerialPutcRtl8195a@plt>
  jmp    L376
  nopl   0x0(%rax,%rax,1)
L81:
  cmp    $0x64,%bpl
  je     L384
  cmp    $0x63,%bpl
  jne    L94
  mov    (%rsp),%rax
  movzbl (%rax),%ebp
  add    $0x4,%rax
  mov    %rax,(%rsp)
L94:
  mov    %bpl,0x10(%rsp)
  lea    0x11(%rsp),%r14
  jmp    L387
  nopl   0x0(%rax,%rax,1)
L280:
  movslq (%rax),%r12
  lea    0x4(%rax),%rbp
  movzbl (%r12),%eax
  test   %al,%al
  jne    L295
  jmp    L335
  nopw   0x0(%rax,%rax,1)
L78:
  add    $0x1,%r12
  mov    %al,(%rbx)
  add    $0x1,%rbx
  movzbl (%r12),%eax
  test   %al,%al
  je     L335
L295:
  test   %r15,%r15
  jne    L78
  movsbl %al,%edi
  add    $0x1,%r12
  call   <HalSerialPutcRtl8195a@plt>
  movzbl (%r12),%eax
  test   %al,%al
  jne    L295
  nopl   (%rax)
L335:
  movzbl 0x1(%r13),%eax
  mov    %rbp,(%rsp)
  lea    0x1(%r13),%rbp
  test   %al,%al
  jne    L524
  nopl   (%rax)
L388:
  mov    %ebx,%eax
  mov    %r15,%r14
  sub    %r15d,%eax
L393:
  test   %r14,%r14
  je     L211
  movb   $0x0,(%rbx)
L211:
  mov    0x28(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L6
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L85:
  xor    %ecx,%ecx
  nopw   0x0(%rax,%rax,1)
L300:
  movzbl 0x1(%r13),%ebp
  lea    (%rcx,%rcx,4),%edx
  add    $0x1,%r13
  lea    (%rax,%rdx,2),%r8d
  lea    -0x30(%rbp),%edx
  lea    -0x30(%r8),%ecx
  movzbl %bpl,%eax
  cmp    $0x9,%dl
  jbe    L300
  lea    -0xc4(,%r8,4),%r10d
  jmp    L38
  nopl   (%rax)
L492:
  movsbl %al,%edi
  mov    %rbp,%r13
  call   <HalSerialPutcRtl8195a@plt>
  jmp    L8
L17:
  lea    -0x1000(%rdi),%rax
  mov    $0xc,%r10d
  cmp    $0xefff,%rax
  jbe    L156
  lea    -0x10000(%rdi),%rax
  mov    $0x10,%r10d
  cmp    $0xeffff,%rax
  jbe    L156
  lea    -0x100000(%rdi),%rax
  mov    $0x14,%r10d
  cmp    $0xefffff,%rax
  jbe    L156
  lea    -0x1000000(%rdi),%rax
  cmp    $0xf000000,%rax
  sbb    %r10d,%r10d
  and    $0xfffffffc,%r10d
  add    $0x1c,%r10d
  jmp    L156
L384:
  mov    (%rsp),%rax
  mov    0x8(%rsp),%r8
  xor    %ebp,%ebp
  lea    0x4(%rax),%r9
  mov    (%rax),%eax
  test   %eax,%eax
  js     L319
L146:
  mov    %r8,%r14
  sub    %r8d,%ebp
  nopw   0x0(%rax,%rax,1)
L118:
  mov    %eax,%edx
  mov    $0xcccccccd,%esi
  lea    0x0(%rbp,%r14,1),%r11d
  mov    %r14,%rdi
  imul   %rsi,%rdx
  add    $0x1,%r14
  shr    $0x23,%rdx
  lea    (%rdx,%rdx,4),%ecx
  add    %ecx,%ecx
  sub    %ecx,%eax
  add    $0x30,%eax
  mov    %al,-0x1(%r14)
  mov    %edx,%eax
  test   %edx,%edx
  jne    L118
  test   %r10d,%r10d
  js     L194
  shr    $0x2,%r10d
  mov    %r11d,%eax
  sub    %r10d,%eax
  jmp    L370
L505:
  test   %r11d,%r11d
  jg     L521
  movb   $0x30,(%r14)
  add    $0x1,%r14
L521:
  sub    $0x1,%r11d
L370:
  cmp    %r11d,%eax
  jne    L505
  lea    -0x1(%r14),%rdi
L194:
  cmp    %rdi,%r8
  jae    L230
  nop
L178:
  movzbl (%r8),%edx
  movzbl (%rdi),%eax
  add    $0x1,%r8
  sub    $0x1,%rdi
  mov    %dl,0x1(%rdi)
  mov    %al,-0x1(%r8)
  cmp    %r8,%rdi
  ja     L178
L230:
  mov    %r9,(%rsp)
  jmp    L219
L319:
  movb   $0x2d,0x10(%rsp)
  neg    %eax
  mov    $0x1,%ebp
  lea    0x11(%rsp),%r8
  jmp    L146
L153:
  mov    $0xfffffffc,%ecx
  jmp    L13
L291:
  mov    %rdi,%rbx
  xor    %eax,%eax
  jmp    L393
L6:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: data_tag: D9
datatype: string

tool: D9: 0123456789ABCDEF

assistant: ```c
int VSprintfPatch(char *buf, const char *fmt, const int *dp) {
  char *p, *s;
  s = buf;
  for (; *fmt != '\0'; ++fmt) {
    if (*fmt != '%') {
      if (buf) {
        *s++ = *fmt;
      } else {
        HalSerialPutcRtl8195a(*fmt);
      }
      continue;
    }
    if (*++fmt == 's') {
      for (p = (char *)*dp++; *p != '\0'; p++) {
        if (buf) {
          *s++ = *p;
        } else {
          HalSerialPutcRtl8195a(*p);
        }
      }
    } else {
      char tmp[20], *q = tmp;
      int alt = 0;
      int shift = 0;
      const long *lpforchk = (const long *)dp;
      if ((*lpforchk) < 0x10) {
        shift = 0;
      } else if (((*lpforchk) >= 0x10) && ((*lpforchk) < 0x100)) {
        shift = 4;
      } else if (((*lpforchk) >= 0x100) && ((*lpforchk) < 0x1000)) {
        shift = 8;
      } else if (((*lpforchk) >= 0x1000) && ((*lpforchk) < 0x10000)) {
        shift = 12;
      } else if (((*lpforchk) >= 0x10000) && ((*lpforchk) < 0x100000)) {
        shift = 16;
      } else if (((*lpforchk) >= 0x100000) && ((*lpforchk) < 0x1000000)) {
        shift = 20;
      } else if (((*lpforchk) >= 0x1000000) && ((*lpforchk) < 0x10000000)) {
        shift = 24;
      } else if ((*lpforchk) >= 0x10000000) {
        shift = 28;
      } else {
        shift = 28;
      }
      if ((*fmt >= '0') && (*fmt <= '9')) {
        int width;
        unsigned char fch = *fmt;
        for (width = 0; (fch >= '0') && (fch <= '9'); fch = *++fmt) {
          width = width * 10 + fch - '0';
        }
        shift = (width - 1) * 4;
      }
      if ((*fmt == 'x') || (*fmt == 'X') || (*fmt == 'p') || (*fmt == 'P')) {
        const long *lp = (const long *)dp;
        long h = *lp++;
        int hex_count = 0;
        unsigned long h_back = h;
        int ncase = (*fmt & 0x20);
        dp = (const int *)lp;
        if ((*fmt == 'p') || (*fmt == 'P'))
          alt = 1;
        if (alt) {
          *q++ = '0';
          *q++ = 'X' | ncase;
        }
        while (h_back) {
          hex_count += (h_back & 0xF) ? 1 : 0;
          h_back = h_back >> 4;
        }
        if (shift < (hex_count - 1) * 4)
          shift = (hex_count - 1) * 4;
        for (; shift >= 0; shift -= 4) {
          *q++ = "0123456789ABCDEF"[(h >> shift) & 0xF] | ncase;
        }
      } else if (*fmt == 'd') {
        int i = *dp++;
        char *r;
        int digit_space = 0;
        if (i < 0) {
          *q++ = '-';
          i = -i;
          digit_space++;
        }
        p = q;
        do {
          *q++ = '0' + (i % 10);
          i /= 10;
          digit_space++;
        } while (i);
        for (; shift >= 0; shift -= 4) {
          if (digit_space-- > 0) {
            ;
          } else {
            *q++ = '0';
          }
        }
        r = q;
        while (--r > p) {
          i = *r;
          *r = *p;
          *p++ = i;
        }
      } else if (*fmt == 'c')
        *q++ = *dp++;
      else
        *q++ = *fmt;
      for (p = tmp; p < q; ++p) {
        if (buf) {
          *s++ = *p;
        } else {
          HalSerialPutcRtl8195a(*p);
        }
        if ((*p) == '\n') {
          HalSerialPutcRtl8195a('\r');
        }
      }
    }
  }
  if (buf)
    *s = '\0';
  return (s - buf);
}
```