// File: /workspace/github_c_makefile_star2_O0/alexgirao[P]aimant/str.c
// Function: str_vformat
void str_vformat(struct str *sa, int cat, const char *fmt, va_list va)
{
#if 0 /* old implementation */
  char buf0[0x1fff + 1 /* 8192 */], *buf;
  int buf_len;
  int n;

  buf = buf0;
  buf_len = sizeof(buf0);

  assert((n = vsnprintf(buf, buf_len, fmt, va)) >= 0);
  if (n >= buf_len) {
    /* truncated, try with more space
     */
    buf_len = 0xffff + 1/* 64K */;
    assert((buf = malloc(buf_len)) != NULL);
    assert((n = vsnprintf(buf, buf_len, fmt, va)) >= 0);
    if (n >= buf_len) {
      free(buf);
      buf_len = 0xfffff + 1 /* 1M */;
      assert((buf = malloc(buf_len)) != NULL);
      assert((n = vsnprintf(buf, buf_len, fmt, va)) >= 0);
      if (n >= buf_len) {
        free(buf);
        buf_len = 0xffffff + 1; /* 16M ! */
        assert((buf = malloc(buf_len)) != NULL);
        assert((n = vsnprintf(buf, buf_len, fmt, va)) >= 0);
        if (n >= buf_len) {
          /* give up */
          free(buf);
          fprintf(stderr, "error: str_vformat(): too large input (> %i)\n", 0xffffff + 1);
          exit(1);
        }
      }
    }
  }

  assert(buf != NULL);

  if (cat) {
    str_catn(sa, buf, n);
  } else {
    str_copyn(sa, buf, n);
  }

  if (buf && buf != buf0) {
    free(buf);
  }
#else
  int n;
  va_list va2;

  va_copy(va2, va);

  assert(sa->s == NULL || sa->len <= sa->a);

  cat = cat ? sa->len : 0;

  /* get needed size, n does not include the trailing '\0'
   */
  if (sa->s) {
    n = vsnprintf(sa->s + cat, sa->a - cat, fmt, va);
  } else {
    n = vsnprintf(NULL, 0, fmt, va); /* this behaviour requires a C99 standard */
  }
  if (n < 0) {
    /* error */
    perror("vsnprintf()");
    exit(1);
  }

  if (sa->s && (cat + n) < sa->a) {
    /* string is allocated and required space (cat + n) is lesser than
     * allocated buffer, meaning that all non-zero bytes plus the null
     * terminator ('\0') fits in sa->a
     */
    sa->len = cat + n;
  } else {
    /* no buffer or insufficient buffer size
     */
    str_alloc(sa, cat + n + 1); /* +1 for null terminator, snprintf requires it */
    sa->len = cat + vsnprintf(sa->s + cat, sa->a - cat, fmt, va2);
  }

  va_end(va2);
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movups (%rcx), %xmm0
movups %xmm0, (%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0xe817
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jg 0xe819
jmp 0xe838
leaq 0x3c3e(%rip), %rdi      # 0x1245e
leaq 0x3bf1(%rip), %rsi      # 0x12418
movl $0x10a, %edx            # imm = 0x10A
leaq 0x3c4d(%rip), %rcx      # 0x12480
callq 0x21a0
cmpl $0x0, -0xc(%rbp)
je 0xe84a
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x44(%rbp)
jmp 0xe851
xorl %eax, %eax
movl %eax, -0x44(%rbp)
jmp 0xe851
movl -0x44(%rbp), %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0xe88e
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movslq -0xc(%rbp), %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
subl -0xc(%rbp), %eax
movslq %eax, %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x20e0
movl %eax, -0x24(%rbp)
jmp 0xe8a5
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
movq %rsi, %rdi
callq 0x20e0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0xe8c1
leaq 0x3c18(%rip), %rdi      # 0x124ca
callq 0x2310
movl $0x1, %edi
callq 0x2350
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0xe8e9
movl -0xc(%rbp), %eax
addl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jge 0xe8e9
movl -0xc(%rbp), %ecx
addl -0x24(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0xe935
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
addl -0x24(%rbp), %esi
addl $0x1, %esi
callq 0xe370
movl -0xc(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movslq -0xc(%rbp), %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
subl -0xc(%rbp), %eax
movslq %eax, %rsi
movq -0x18(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x20e0
movl -0x48(%rbp), %ecx
addl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8(%rax)
leaq -0x40(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nop