// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_avprintf
int mg_avprintf(char **buf, size_t size, const char *fmt, va_list ap) {
  va_list ap_copy;
  int len;

  va_copy(ap_copy, ap);
  len = vsnprintf(*buf, size, fmt, ap_copy);
  va_end(ap_copy);

  if (len < 0) {
    /* eCos and Windows are not standard-compliant and return -1 when
     * the buffer is too small. Keep allocating larger buffers until we
     * succeed or out of memory. */
    *buf = NULL; /* LCOV_EXCL_START */
    while (len < 0) {
      MG_FREE(*buf);
      if (size == 0) {
        size = 5;
      }
      size *= 2;
      if ((*buf = (char *) MG_MALLOC(size)) == NULL) {
        len = -1;
        break;
      }
      va_copy(ap_copy, ap);
      len = vsnprintf(*buf, size - 1, fmt, ap_copy);
      va_end(ap_copy);
    }

    /*
     * Microsoft version of vsnprintf() is not always null-terminated, so put
     * the terminator manually
     */
    (*buf)[len] = 0;
    /* LCOV_EXCL_STOP */
  } else if (len >= (int) size) {
    /* Standard-compliant code path. Allocate a buffer that is large enough. */
    if ((*buf = (char *) MG_MALLOC(len + 1)) == NULL) {
      len = -1; /* LCOV_EXCL_LINE */
    } else {    /* LCOV_EXCL_LINE */
      va_copy(ap_copy, ap);
      len = vsnprintf(*buf, len + 1, fmt, ap_copy);
      va_end(ap_copy);
    }
  }

  return len;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%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
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x3110
movl %eax, -0x44(%rbp)
leaq -0x40(%rbp), %rax
cmpl $0x0, -0x44(%rbp)
jge 0xa2a0
movq -0x8(%rbp), %rax
movq $0x0, (%rax)
cmpl $0x0, -0x44(%rbp)
jge 0xa28f
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x3050
cmpq $0x0, -0x10(%rbp)
jne 0xa227
movq $0x5, -0x10(%rbp)
movq -0x10(%rbp), %rax
shlq %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3420
movq -0x8(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0xa251
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
jmp 0xa28f
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
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
subq $0x1, %rsi
movq -0x18(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x3110
movl %eax, -0x44(%rbp)
leaq -0x40(%rbp), %rax
jmp 0xa202
movq -0x8(%rbp), %rax
movq (%rax), %rax
movslq -0x44(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0xa30d
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl %ecx, %eax
jl 0xa30b
movl -0x44(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x3420
movq -0x8(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0xa2cf
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
jmp 0xa309
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
movq (%rax), %rdi
movl -0x44(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
movq -0x18(%rbp), %rdx
leaq -0x40(%rbp), %rcx
callq 0x3110
movl %eax, -0x44(%rbp)
leaq -0x40(%rbp), %rax
jmp 0xa30b
jmp 0xa30d
movl -0x44(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)