// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: c_vsnprintf
int c_vsnprintf(char *buf, size_t buf_size, const char *fmt, va_list ap) {
  int ch, i = 0, len_mod, flags, precision, field_width;

  while ((ch = *fmt++) != '\0') {
    if (ch != '%') {
      C_SNPRINTF_APPEND_CHAR(ch);
    } else {
      /*
       * Conversion specification:
       *   zero or more flags (one of: # 0 - <space> + ')
       *   an optional minimum  field  width (digits)
       *   an  optional precision (. followed by digits, or *)
       *   an optional length modifier (one of: hh h l ll L q j z t)
       *   conversion specifier (one of: d i o u x X e E f F g G a A c s p n)
       */
      flags = field_width = precision = len_mod = 0;

      /* Flags. only zero-pad flag is supported. */
      if (*fmt == '0') {
        flags |= C_SNPRINTF_FLAG_ZERO;
      }

      /* Field width */
      while (*fmt >= '0' && *fmt <= '9') {
        field_width *= 10;
        field_width += *fmt++ - '0';
      }
      /* Dynamic field width */
      if (*fmt == '*') {
        field_width = va_arg(ap, int);
        fmt++;
      }

      /* Precision */
      if (*fmt == '.') {
        fmt++;
        if (*fmt == '*') {
          precision = va_arg(ap, int);
          fmt++;
        } else {
          while (*fmt >= '0' && *fmt <= '9') {
            precision *= 10;
            precision += *fmt++ - '0';
          }
        }
      }

      /* Length modifier */
      switch (*fmt) {
        case 'h':
        case 'l':
        case 'L':
        case 'I':
        case 'q':
        case 'j':
        case 'z':
        case 't':
          len_mod = *fmt++;
          if (*fmt == 'h') {
            len_mod = 'H';
            fmt++;
          }
          if (*fmt == 'l') {
            len_mod = 'q';
            fmt++;
          }
          break;
      }

      ch = *fmt++;
      if (ch == 's') {
        const char *s = va_arg(ap, const char *); /* Always fetch parameter */
        int j;
        int pad = field_width - (precision >= 0 ? c_strnlen(s, precision) : 0);
        for (j = 0; j < pad; j++) {
          C_SNPRINTF_APPEND_CHAR(' ');
        }

        /* `s` may be NULL in case of %.*s */
        if (s != NULL) {
          /* Ignore negative and 0 precisions */
          for (j = 0; (precision <= 0 || j < precision) && s[j] != '\0'; j++) {
            C_SNPRINTF_APPEND_CHAR(s[j]);
          }
        }
      } else if (ch == 'c') {
        ch = va_arg(ap, int); /* Always fetch parameter */
        C_SNPRINTF_APPEND_CHAR(ch);
      } else if (ch == 'd' && len_mod == 0) {
        i += c_itoa(buf + i, buf_size - i, va_arg(ap, int), 10, flags,
                    field_width);
      } else if (ch == 'd' && len_mod == 'l') {
        i += c_itoa(buf + i, buf_size - i, va_arg(ap, long), 10, flags,
                    field_width);
#ifdef SSIZE_MAX
      } else if (ch == 'd' && len_mod == 'z') {
        i += c_itoa(buf + i, buf_size - i, va_arg(ap, ssize_t), 10, flags,
                    field_width);
#endif
      } else if (ch == 'd' && len_mod == 'q') {
        i += c_itoa(buf + i, buf_size - i, va_arg(ap, int64_t), 10, flags,
                    field_width);
      } else if ((ch == 'x' || ch == 'u') && len_mod == 0) {
        i += c_itoa(buf + i, buf_size - i, va_arg(ap, unsigned),
                    ch == 'x' ? 16 : 10, flags, field_width);
      } else if ((ch == 'x' || ch == 'u') && len_mod == 'l') {
        i += c_itoa(buf + i, buf_size - i, va_arg(ap, unsigned long),
                    ch == 'x' ? 16 : 10, flags, field_width);
      } else if ((ch == 'x' || ch == 'u') && len_mod == 'z') {
        i += c_itoa(buf + i, buf_size - i, va_arg(ap, size_t),
                    ch == 'x' ? 16 : 10, flags, field_width);
      } else if (ch == 'p') {
        unsigned long num = (unsigned long) (uintptr_t) va_arg(ap, void *);
        C_SNPRINTF_APPEND_CHAR('0');
        C_SNPRINTF_APPEND_CHAR('x');
        i += c_itoa(buf + i, buf_size - i, num, 16, flags, 0);
      } else {
#ifndef NO_LIBC
        /*
         * TODO(lsm): abort is not nice in a library, remove it
         * Also, ESP8266 SDK doesn't have it
         */
        abort();
#endif
      }
    }
  }

  /* Zero-terminate the result */
  if (buf_size > 0) {
    buf[i < (int) buf_size ? i : (int) buf_size - 1] = '\0';
  }

  return i;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r11
movq %rdx, %r13
movq %rsi, %r15
movslq %r15d, %rcx
xorl %edx, %edx
movq %rdi, 0x10(%rsp)
movq %rsi, 0x20(%rsp)
movq %r11, 0x8(%rsp)
movq %rcx, 0x18(%rsp)
movzbl (%r13), %eax
movslq %edx, %rbx
cmpl $0x25, %eax
je 0x6b1f
testl %eax, %eax
je 0x6f3e
cmpl %r15d, %edx
jge 0x6b18
movb %al, (%rdi,%rbx)
incq %r13
incl %edx
jmp 0x6afb
movq %rdx, (%rsp)
movb 0x1(%r13), %cl
addq $0x2, %r13
xorl %ebp, %ebp
movl %ecx, %eax
leal -0x30(%rax), %edx
cmpb $0x9, %dl
ja 0x6b48
imull $0xa, %ebp, %eax
movzbl %dl, %ebp
addl %eax, %ebp
movb (%r13), %al
incq %r13
jmp 0x6b2f
xorl %r8d, %r8d
cmpb $0x30, %cl
sete %cl
cmpb $0x2a, %al
jne 0x6b6d
movl (%r11), %edx
cmpq $0x28, %rdx
ja 0x6b72
movq %rdx, %rax
addq 0x10(%r11), %rax
addl $0x8, %edx
movl %edx, (%r11)
jmp 0x6b7e
decq %r13
jmp 0x6b84
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rdx
movq %rdx, 0x8(%r11)
movl (%rax), %ebp
movb (%r13), %al
xorl %edx, %edx
cmpb $0x2e, %al
jne 0x6baa
movb 0x1(%r13), %al
cmpb $0x2a, %al
jne 0x6baf
movl (%r11), %esi
cmpq $0x28, %rsi
ja 0x6bd2
movq %rsi, %rax
addq 0x10(%r11), %rax
addl $0x8, %esi
movl %esi, (%r11)
jmp 0x6bde
xorl %r12d, %r12d
jmp 0x6be9
incq %r13
xorl %r12d, %r12d
leal -0x30(%rax), %esi
cmpb $0x9, %sil
ja 0x6be9
imull $0xa, %r12d, %eax
movzbl %sil, %r12d
addl %eax, %r12d
movb 0x1(%r13), %al
incq %r13
jmp 0x6bb5
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rsi
movq %rsi, 0x8(%r11)
movl (%rax), %r12d
movb 0x2(%r13), %al
addq $0x2, %r13
movzbl %al, %esi
leal -0x49(%rsi), %r9d
cmpl $0x31, %r9d
ja 0x6c45
movabsq $0x2090a80000009, %r10  # imm = 0x2090A80000009
btq %r9, %r10
jae 0x6c45
leaq 0x1(%r13), %rax
leaq 0x2(%r13), %rdx
xorl %r10d, %r10d
cmpb $0x68, 0x1(%r13)
pushq $0x48
popq %r9
cmovel %r9d, %esi
sete %r10b
cmoveq %rdx, %rax
xorl %r9d, %r9d
cmpb $0x6c, 0x1(%r10,%r13)
pushq $0x71
popq %rdx
cmovel %edx, %esi
sete %r9b
movzbl %sil, %edx
leaq (%rax,%r9), %r13
movb (%rax,%r9), %al
incq %r13
cmpb $0x63, %al
je 0x6c70
movzbl %al, %esi
cmpl $0x73, %esi
jne 0x6c8f
movl (%r11), %ecx
cmpq $0x28, %rcx
movq (%rsp), %rdx
ja 0x6cc1
movq %rcx, %rax
addq 0x10(%r11), %rax
addl $0x8, %ecx
movl %ecx, (%r11)
jmp 0x6ccd
movl (%r11), %ecx
cmpq $0x28, %rcx
ja 0x6d76
movq %rcx, %rax
addq 0x10(%r11), %rax
addl $0x8, %ecx
movl %ecx, (%r11)
jmp 0x6d82
movb %cl, %r8b
cmpb $0x64, %al
jne 0x6d9c
testl %edx, %edx
jne 0x6d9c
movl (%r11), %ecx
cmpq $0x28, %rcx
ja 0x6dcf
movq %rcx, %rax
addq 0x10(%r11), %rax
addl $0x8, %ecx
movl %ecx, (%r11)
jmp 0x6ddb
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r11)
movq (%rax), %r14
xorl %r15d, %r15d
movl $0x0, %eax
testl %r12d, %r12d
js 0x6cf1
movl %r12d, %esi
movq %r14, %rdi
callq 0x6ab2
movq (%rsp), %rdx
movq 0x8(%rsp), %r11
subl %eax, %ebp
testl %ebp, %ebp
cmovlel %r15d, %ebp
negl %ebp
movl %edx, %eax
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
cmpl %r15d, %ebp
je 0x6d1f
cmpq %rcx, %rbx
jge 0x6d15
movb $0x20, (%rdi,%rbx)
incq %rbx
decl %r15d
incl %eax
jmp 0x6d07
subl %r15d, %edx
testq %r14, %r14
movq 0x20(%rsp), %r15
je 0x6afb
movslq %r12d, %rcx
leaq (%rdi,%rbx), %rdx
xorl %esi, %esi
testl %r12d, %r12d
setle %r8b
leaq (%rbx,%rsi), %r10
cmpq %rcx, %rsi
setl %r9b
orb %r8b, %r9b
cmpb $0x1, %r9b
jne 0x6d6f
movb (%r14,%rsi), %r8b
testb %r8b, %r8b
je 0x6d6f
cmpq 0x18(%rsp), %r10
jge 0x6d68
movb %r8b, (%rdx,%rsi)
incq %rsi
incl %eax
jmp 0x6d39
movl %eax, %edx
jmp 0x6afb
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r11)
movq (%rsp), %rdx
cmpl %r15d, %edx
jge 0x6b1b
movb (%rax), %al
movslq %edx, %rcx
movb %al, (%rdi,%rcx)
jmp 0x6b1b
cmpb $0x64, %al
jne 0x6da5
cmpl $0x6c, %edx
je 0x6db7
cmpb $0x64, %al
jne 0x6dae
cmpl $0x7a, %edx
je 0x6db7
cmpb $0x64, %al
jne 0x6e21
cmpl $0x71, %edx
jne 0x6e21
movl (%r11), %ecx
cmpq $0x28, %rcx
ja 0x6de9
movq %rcx, %rax
addq 0x10(%r11), %rax
addl $0x8, %ecx
movl %ecx, (%r11)
jmp 0x6df5
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r11)
addq %rbx, %rdi
movq %r15, %rsi
subq %rbx, %rsi
movslq (%rax), %rdx
jmp 0x6e01
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r11)
addq %rbx, %rdi
movq %r15, %rsi
subq %rbx, %rsi
movq (%rax), %rdx
pushq $0xa
popq %rcx
movl %ebp, %r9d
callq 0x6f69
movq 0x10(%rsp), %rdi
movq (%rsp), %rdx
addl %eax, %edx
movq 0x8(%rsp), %r11
jmp 0x6afb
cmpb $0x78, %al
sete %sil
cmpb $0x75, %al
sete %cl
orb %sil, %cl
cmpb $0x1, %cl
jne 0x6e50
testl %edx, %edx
jne 0x6e50
movl (%r11), %edx
cmpq $0x28, %rdx
ja 0x6e81
movq %rdx, %rcx
addq 0x10(%r11), %rcx
addl $0x8, %edx
movl %edx, (%r11)
jmp 0x6e8d
cmpl $0x6c, %edx
setne %sil
xorb $0x1, %cl
orb %cl, %sil
je 0x6e69
cmpl $0x7a, %edx
setne %dl
orb %dl, %cl
jne 0x6ec4
movl (%r11), %edx
cmpq $0x28, %rdx
ja 0x6e9c
movq %rdx, %rcx
addq 0x10(%r11), %rcx
addl $0x8, %edx
movl %edx, (%r11)
jmp 0x6ea8
movq 0x8(%r11), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%r11)
addq %rbx, %rdi
movq %r15, %rsi
subq %rbx, %rsi
cmpb $0x78, %al
movl (%rcx), %edx
jmp 0x6eb6
movq 0x8(%r11), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%r11)
addq %rbx, %rdi
movq %r15, %rsi
subq %rbx, %rsi
cmpb $0x78, %al
movq (%rcx), %rdx
pushq $0xa
popq %rcx
pushq $0x10
popq %rax
cmovel %eax, %ecx
jmp 0x6e04
cmpb $0x70, %al
jne 0x6f64
movl (%r11), %ecx
cmpq $0x28, %rcx
ja 0x6ee4
movq %rcx, %rax
addq 0x10(%r11), %rax
addl $0x8, %ecx
movl %ecx, (%r11)
jmp 0x6ef0
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r11)
movq (%rax), %rdx
cmpl %r15d, (%rsp)
jge 0x6efd
movb $0x30, (%rdi,%rbx)
leaq 0x1(%rbx), %rax
cmpl %r15d, %eax
jge 0x6f0a
movb $0x78, (%rdi,%rax)
addq %rbx, %rdi
addq $0x2, %rdi
addq $0x2, %rbx
movq %r15, %rsi
subq %rbx, %rsi
pushq $0x10
popq %rcx
xorl %r9d, %r9d
callq 0x6f69
movq 0x10(%rsp), %rdi
movq (%rsp), %rdx
addl %eax, %edx
addl $0x2, %edx
movq 0x8(%rsp), %r11
jmp 0x6afb
testq %r15, %r15
je 0x6f53
leal -0x1(%r15), %eax
cmpl %r15d, %edx
cmovll %edx, %eax
cltq
movb $0x0, (%rdi,%rax)
movl %edx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3090