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

```asm
<build_string>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rsi,%rbx
  mov    %rdx,%rbp
  test   %rdi,%rdi
  je     L405
  mov    %rdi,%r15
  mov    %r8d,%r12d
  movzbl (%rdi),%edx
  mov    $0x0,%eax
  test   %dl,%dl
  je     L472
  cmpb   $0x0,(%rcx)
  jne    L606
  add    $0x1,%r15
  mov    %r15,%r13
  mov    $0x1,%r12d
  jmp    L197
L405:
  lea    D32(%rip),%r12
  mov    $0x4e,%edi
  jmp    L552
L244:
  mov    %r12,%r13
  mov    %dil,(%rbx)
  lea    0x1(%rbx),%rbx
L89:
  movzbl 0x0(%r13),%edi
  add    $0x1,%r12
  test   %dil,%dil
  je     L26
L552:
  test   %rbx,%rbx
  je     L273
  test   %rbp,%rbp
  je     L244
  cmp    %rbx,%rbp
  ja     L244
  lea    D55(%rip),%rdi
  call   <puts@plt>
  mov    $0xffffffff,%eax
  jmp    L472
L273:
  mov    %r12,%r13
  movsbl %dil,%edi
  call   <putchar@plt>
  jmp    L89
L26:
  mov    $0xc,%eax
  jmp    L472
L245:
  mov    %r13,%r14
  mov    %dl,(%rbx)
  lea    0x1(%rbx),%rbx
L37:
  mov    %r12d,%eax
  sub    %r15d,%eax
  add    %r13d,%eax
  movzbl (%r14),%edx
  add    $0x1,%r13
  test   %dl,%dl
  je     L458
L197:
  test   %rbx,%rbx
  je     L39
  test   %rbp,%rbp
  je     L245
  cmp    %rbx,%rbp
  ja     L245
  lea    D55(%rip),%rdi
  call   <puts@plt>
  mov    $0xffffffff,%eax
  jmp    L472
L39:
  mov    %r13,%r14
  movsbl %dl,%edi
  call   <putchar@plt>
  jmp    L37
L458:
  cwtl
L472:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L606:
  mov    %rcx,%rdi
  call   <atoi@plt>
  mov    %rax,%r14
  movzbl (%r15),%edi
  test   %dil,%dil
  je     L482
  mov    %r15,%rax
  mov    $0x1,%edx
  sub    %r15d,%edx
L391:
  lea    (%rdx,%rax,1),%r13d
  add    $0x1,%rax
  cmpb   $0x0,(%rax)
  jne    L391
  cmp    %r13w,%r14w
  jg     L475
  lea    0x1(%r15),%rax
  mov    %rax,%r13
  mov    $0x1,%r15d
  sub    %eax,%r15d
  jmp    L126
L93:
  movb   $0x20,(%rbx)
  lea    0x1(%rbx),%rbx
L569:
  mov    %r14d,%eax
  sub    (%rsp),%ax
  cmp    %r13w,%ax
  jle    L101
L214:
  lea    0x1(%r12),%eax
  mov    %ax,(%rsp)
  mov    %eax,%r12d
  test   %rbx,%rbx
  je     L134
  test   %rbp,%rbp
  je     L93
  cmp    %rbx,%rbp
  ja     L93
  lea    D55(%rip),%rdi
  call   <puts@plt>
  mov    $0xffffffff,%eax
  jmp    L472
L134:
  mov    $0x20,%edi
  call   <putchar@plt>
  jmp    L569
L101:
  movzbl (%r15),%eax
  test   %al,%al
  je     L585
  add    $0x1,%r15
  jmp    L392
L60:
  mov    %r15,%r13
  mov    %al,(%rbx)
  lea    0x1(%rbx),%rbx
L0:
  movzbl 0x0(%r13),%eax
  add    $0x1,%r15
  test   %al,%al
  je     L585
L392:
  add    $0x1,%r12d
  test   %rbx,%rbx
  je     L499
  test   %rbp,%rbp
  je     L60
  cmp    %rbx,%rbp
  ja     L60
  lea    D55(%rip),%rdi
  call   <puts@plt>
  mov    $0xffffffff,%eax
  jmp    L472
L499:
  mov    %r15,%r13
  movsbl %al,%edi
  call   <putchar@plt>
  jmp    L0
L171:
  mov    %r12,(%rsp)
  mov    %dil,(%rbx)
  lea    0x1(%rbx),%rbx
L511:
  mov    (%rsp),%rax
  movzbl (%rax),%edi
  add    $0x1,%r12
  test   %dil,%dil
  je     L256
L433:
  movzwl 0xe(%rsp),%eax
  lea    (%rax,%r12,1),%r15d
  test   %rbx,%rbx
  je     L35
  test   %rbp,%rbp
  je     L171
  cmp    %rbx,%rbp
  ja     L171
  lea    D55(%rip),%rdi
  call   <puts@plt>
  mov    $0xffffffff,%eax
  jmp    L472
L35:
  mov    %r12,(%rsp)
  movsbl %dil,%edi
  call   <putchar@plt>
  jmp    L511
L563:
  movb   $0x20,(%rbx)
  lea    0x1(%rbx),%rbx
L450:
  mov    %r14d,%eax
  sub    (%rsp),%ax
  add    %r15d,%eax
  cmp    %ax,%r13w
  jge    L585
L488:
  lea    0x1(%r12),%eax
  mov    %ax,(%rsp)
  mov    %eax,%r12d
  test   %rbx,%rbx
  je     L325
  test   %rbp,%rbp
  je     L563
  cmp    %rbx,%rbp
  ja     L563
  lea    D55(%rip),%rdi
  call   <puts@plt>
  mov    $0xffffffff,%eax
  jmp    L472
L325:
  mov    $0x20,%edi
  call   <putchar@plt>
  jmp    L450
L447:
  mov    %r13,%r14
  mov    %dil,(%rbx)
  lea    0x1(%rbx),%rbx
L521:
  movzbl (%r14),%edi
  add    $0x1,%r13
  test   %dil,%dil
  je     L585
L126:
  lea    (%r15,%r13,1),%r12d
  test   %rbx,%rbx
  je     L30
  test   %rbp,%rbp
  je     L447
  cmp    %rbx,%rbp
  ja     L447
  lea    D55(%rip),%rdi
  call   <puts@plt>
  mov    $0xffffffff,%eax
  jmp    L472
L30:
  mov    %r13,%r14
  movsbl %dil,%edi
  call   <putchar@plt>
  jmp    L521
L482:
  test   %ax,%ax
  jle    L46
  mov    $0x0,%r13d
  cmp    $0x2,%r12d
  jne    L353
L441:
  mov    $0x0,%r12d
  jmp    L214
L46:
  mov    $0x0,%r12d
L585:
  movswl %r12w,%eax
  jmp    L472
L475:
  cmp    $0x2,%r12d
  je     L441
  add    $0x1,%r15
  mov    %r15,%r12
  mov    $0x1,%eax
  sub    %r15d,%eax
  mov    %ax,0xe(%rsp)
  jmp    L433
L353:
  mov    $0x0,%r15d
L256:
  mov    %r15d,%r12d
  jmp    L488
```

tool_calls: name: read_data
arguments: data_label: D32
data_type: string
name: read_data
arguments: data_label: D55
data_type: string

tool: D32: ULL_POINTER

tool: D55: s_printf buffer overflow

assistant: ```c
int build_string(char *src, char *dest, char *bufend, char *hdr, int sign) {
  char *cp1;
  short minsize, i, j;
  if (!src) {
    cp1 = "NULL_POINTER";
    while (*cp1) {
      if (dest) {
        if (bufend && (dest >= bufend)) {
          puts("s_printf buffer overflow");
          return (-1);
        }
        *dest++ = *cp1++;
      } else {
        putchar(*cp1++);
      };
    }
    return (12);
  }
  if (!*src)
    return (0);
  if (!hdr[0]) {
    j = 0;
    while (*src) {
      if (dest) {
        if (bufend && (dest >= bufend)) {
          puts("s_printf buffer overflow");
          return (-1);
        }
        *dest++ = *src++;
      } else {
        putchar(*src++);
      };
      j++;
    }
    return (j);
  }
  minsize = (short)atoi(hdr);
  i = 0;
  cp1 = (char *)src;
  while (*cp1) {
    i++;
    cp1++;
  }
  cp1 = (char *)src;
  j = 0;
  if (minsize > i) {
    if (sign == 2) {
      while (minsize > i) {
        j++;
        if (dest) {
          if (bufend && (dest >= bufend)) {
            puts("s_printf buffer overflow");
            return (-1);
          }
          *dest++ = ' ';
        } else {
          if (' ')
            putchar(' ');
        };
        minsize--;
      }
      while (*cp1) {
        j++;
        if (dest) {
          if (bufend && (dest >= bufend)) {
            puts("s_printf buffer overflow");
            return (-1);
          }
          *dest++ = *cp1++;
        } else {
          putchar(*cp1++);
        };
      }
    } else {
      while (*cp1) {
        j++;
        if (dest) {
          if (bufend && (dest >= bufend)) {
            puts("s_printf buffer overflow");
            return (-1);
          }
          *dest++ = *cp1++;
        } else {
          putchar(*cp1++);
        };
      }
      while (minsize > i) {
        j++;
        if (dest) {
          if (bufend && (dest >= bufend)) {
            puts("s_printf buffer overflow");
            return (-1);
          }
          *dest++ = ' ';
        } else {
          if (' ')
            putchar(' ');
        };
        minsize--;
      }
    }
  } else {
    while (*cp1) {
      j++;
      if (dest) {
        if (bufend && (dest >= bufend)) {
          puts("s_printf buffer overflow");
          return (-1);
        }
        *dest++ = *cp1++;
      } else {
        putchar(*cp1++);
      };
    }
  }
  return (j);
}
```