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

```asm
<append_str>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  test   %rdi,%rdi
  je     L104
  mov    %rdi,%rbp
  mov    %esi,%ebx
  mov    %edx,%r14d
  mov    %ecx,%r12d
  test   %esi,%esi
  jle    L6
L172:
  movslq D88(%rip),%rcx
  movslq %ebx,%rdx
  mov    D35(%rip),%r8
  mov    %rcx,%rax
  lea    0x50(%rcx,%rdx,1),%rcx
  movslq D193(%rip),%rdx
  cmp    %rdx,%rcx
  jae    L100
  test   %r8,%r8
  je     L12
L16:
  lea    -0x1(%rbx),%esi
  test   %ebx,%ebx
  jle    L145
  lea    D160(%rip),%r13
  jmp    L189
  nopl   0x0(%rax)
L122:
  movslq D88(%rip),%rdx
  mov    D35(%rip),%r8
  mov    %esi,%ebx
  mov    %rdi,%rbp
  lea    -0x1(%rbx),%esi
  lea    0x1(%rdx),%eax
  mov    %cl,(%r8,%rdx,1)
  mov    %eax,D149(%rip)
  test   %ebx,%ebx
  jle    L107
L189:
  movzbl 0x0(%rbp),%ecx
  lea    0x1(%rbp),%rdi
  cmp    $0x25,%cl
  jne    L122
  cmpb   $0x64,0x1(%rbp)
  jne    L122
  mov    %rsp,%r15
  mov    %r14d,%edx
  mov    %r13,%rsi
  sub    $0x2,%ebx
  mov    %r15,%rdi
  add    $0x2,%rbp
  mov    %r12d,%r14d
  call   <sprintf@plt>
  mov    %r15,%rsi
  movslq D149(%rip),%rdi
  add    D35(%rip),%rdi
  call   <strcpy@plt>
  movslq D149(%rip),%rdi
  add    D35(%rip),%rdi
  call   <strlen@plt>
  add    D149(%rip),%eax
  lea    -0x1(%rbx),%esi
  mov    %eax,D149(%rip)
  test   %ebx,%ebx
  jg     L189
  nopl   0x0(%rax)
L107:
  mov    D35(%rip),%r8
L35:
  cltq
  movb   $0x0,(%r8,%rax,1)
L76:
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L160
  add    $0x38,%rsp
  mov    %r8,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L6:
  je     L102
  add    %esi,D149(%rip)
  js     L164
L102:
  mov    %rbp,%rdi
  call   <strlen@plt>
  mov    %eax,%ebx
  jmp    L172
  nopl   0x0(%rax)
L100:
  lea    0x118(%rax,%rbx,1),%esi
  mov    %r8,%rdi
  mov    %esi,D149(%rip)
  call   <realloc@plt>
  mov    %rax,%r8
  mov    %rax,D149(%rip)
  test   %r8,%r8
  jne    L16
L12:
  lea    D149(%rip),%r8
  jmp    L76
  nopl   0x0(%rax)
L104:
  movl   $0x0,D149(%rip)
  mov    D149(%rip),%r8
  jmp    L76
  cs nopw 0x0(%rax,%rax,1)
L145:
  mov    D149(%rip),%eax
  jmp    L35
L164:
  mov    $0xbd6,%esi
  lea    D216(%rip),%rdi
  call   <myassert@plt>
  jmp    L102
L160:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: data_tag: D160
datatype: string
name: read_data
arguments: data_tag: D149
datatype: string
name: read_data
arguments: data_tag: D216
datatype: string

tool: D160: %d

tool: 

tool: D216: /scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Mitali-Sodhi/CodeLingo/refs/heads/2.0/Dataset/c/lemon.c

assistant: ```c
char *append_str(char *zText, int n, int p1, int p2) {
  static char *z = 0;
  static int alloced = 0;
  static int used = 0;
  int i, c;
  char zInt[40];
  if (zText == 0) {
    used = 0;
    return z;
  }
  if (n <= 0) {
    if (n < 0) {
      used += n;
      if (!(used >= 0))
        myassert("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Mitali-Sodhi/CodeLingo/refs/heads/2.0/Dataset/c/lemon.c", 3030);
    }
    n = strlen(zText);
  }
  if (n + sizeof(zInt) * 2 + used >= alloced) {
    alloced = n + sizeof(zInt) * 2 + used + 200;
    z = realloc(z, alloced);
  }
  if (z == 0)
    return "";
  while (n-- > 0) {
    c = *(zText++);
    if (c == '%' && zText[0] == 'd') {
      sprintf(zInt, "%d", p1);
      p1 = p2;
      strcpy(&z[used], zInt);
      used += strlen(&z[used]);
      zText++;
      n--;
    } else {
      z[used++] = c;
    }
  }
  z[used] = 0;
  return z;
}
```