// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %rcx, %r11
movq %rdx, %r13
movq %rsi, %rbp
movslq %ebp, %r12
xorl %r14d, %r14d
movq %rdi, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq %rsi, (%rsp)
movzbl (%r13), %eax
incq %r13
cmpl $0x25, %eax
je 0x6e18
testl %eax, %eax
je 0x724a
cmpl %ebp, %r14d
jge 0x6ff1
movslq %r14d, %rcx
movb %al, (%rdi,%rcx)
jmp 0x6ff1
movb (%r13), %al
xorl %r8d, %r8d
cmpb $0x30, %al
sete %cl
leal -0x30(%rax), %edx
xorl %ebp, %ebp
cmpb $0x9, %dl
ja 0x6e4b
xorl %ebp, %ebp
leal (%rbp,%rbp,4), %edx
addb $-0x30, %al
movzbl %al, %eax
leal (%rax,%rdx,2), %ebp
movb 0x1(%r13), %al
incq %r13
leal -0x30(%rax), %edx
cmpb $0xa, %dl
jb 0x6e30
cmpb $0x2a, %al
jne 0x6e7c
movl (%r11), %edx
cmpq $0x28, %rdx
ja 0x6e67
movq %rdx, %rax
addq 0x10(%r11), %rax
addl $0x8, %edx
movl %edx, (%r11)
jmp 0x6e73
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rdx
movq %rdx, 0x8(%r11)
movl (%rax), %ebp
movb 0x1(%r13), %al
incq %r13
xorl %edx, %edx
cmpb $0x2e, %al
jne 0x6ecd
movb 0x1(%r13), %al
cmpb $0x2a, %al
jne 0x6ea2
movl (%r11), %esi
cmpq $0x28, %rsi
ja 0x6ed1
movq %rsi, %rax
addq 0x10(%r11), %rax
addl $0x8, %esi
movl %esi, (%r11)
jmp 0x6edd
incq %r13
leal -0x30(%rax), %esi
cmpb $0x9, %sil
ja 0x6ecd
xorl %ebx, %ebx
leal (%rbx,%rbx,4), %esi
addb $-0x30, %al
movzbl %al, %eax
leal (%rax,%rsi,2), %ebx
movb 0x1(%r13), %al
incq %r13
leal -0x30(%rax), %esi
cmpb $0xa, %sil
jb 0x6eb0
jmp 0x6ee7
xorl %ebx, %ebx
jmp 0x6ee7
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rsi
movq %rsi, 0x8(%r11)
movl (%rax), %ebx
movb 0x2(%r13), %al
addq $0x2, %r13
movzbl %al, %esi
leal -0x49(%rsi), %r9d
cmpl $0x31, %r9d
ja 0x6f47
movabsq $0x2090a80000009, %r10  # imm = 0x2090A80000009
btq %r9, %r10
jae 0x6f47
leaq 0x1(%r13), %rax
leaq 0x2(%r13), %rdx
xorl %r10d, %r10d
cmpb $0x68, 0x1(%r13)
movl $0x48, %r9d
cmovel %r9d, %esi
sete %r10b
cmoveq %rdx, %rax
xorl %r9d, %r9d
cmpb $0x6c, 0x1(%r10,%r13)
movl $0x71, %edx
cmovel %edx, %esi
sete %r9b
movzbl %sil, %edx
leaq (%rax,%r9), %r13
movb (%rax,%r9), %al
incq %r13
cmpb $0x63, %al
je 0x6f6e
movzbl %al, %esi
cmpl $0x73, %esi
jne 0x6f86
movl (%r11), %ecx
cmpq $0x28, %rcx
ja 0x6fb0
movq %rcx, %rax
addq 0x10(%r11), %rax
addl $0x8, %ecx
movl %ecx, (%r11)
jmp 0x6fbc
movl (%r11), %ecx
cmpq $0x28, %rcx
ja 0x6fd4
movq %rcx, %rax
addq 0x10(%r11), %rax
addl $0x8, %ecx
movl %ecx, (%r11)
jmp 0x6fe0
movb %cl, %r8b
cmpb $0x64, %al
jne 0x6ff9
testl %edx, %edx
jne 0x6ff9
movl (%r11), %ecx
cmpq $0x28, %rcx
ja 0x70b1
movq %rcx, %rax
addq 0x10(%r11), %rax
addl $0x8, %ecx
movl %ecx, (%r11)
jmp 0x70bd
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r11)
movq (%rax), %r15
testl %ebx, %ebx
js 0x703b
movl %ebx, %esi
movq %r15, %rdi
callq 0x6dab
movq 0x10(%rsp), %rdi
jmp 0x703d
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r11)
movq (%rsp), %rbp
cmpl %ebp, %r14d
jge 0x6ff1
movb (%rax), %al
movslq %r14d, %rcx
movb %al, (%rdi,%rcx)
incl %r14d
jmp 0x6def
cmpb $0x64, %al
jne 0x7002
cmpl $0x6c, %edx
je 0x701c
cmpb $0x64, %al
jne 0x700b
cmpl $0x7a, %edx
je 0x701c
cmpb $0x64, %al
jne 0x7113
cmpl $0x71, %edx
jne 0x7113
movl (%r11), %ecx
cmpq $0x28, %rcx
ja 0x70d2
movq %rcx, %rax
addq 0x10(%r11), %rax
addl $0x8, %ecx
movl %ecx, (%r11)
jmp 0x70de
xorl %eax, %eax
movl %ebp, %ecx
subl %eax, %ecx
testl %ecx, %ecx
jle 0x706c
movslq %r14d, %rcx
subl %ebp, %eax
xorl %edx, %edx
movq (%rsp), %rbp
movq 0x8(%rsp), %r11
cmpq %r12, %rcx
jge 0x705e
movb $0x20, (%rdi,%rcx)
incq %rcx
decl %edx
cmpl %edx, %eax
jne 0x7055
subl %edx, %r14d
jmp 0x7075
movq (%rsp), %rbp
movq 0x8(%rsp), %r11
testq %r15, %r15
je 0x6def
movslq %r14d, %r14
xorl %eax, %eax
movb (%r15,%rax), %cl
testb %cl, %cl
je 0x6def
cmpq %r12, %r14
jge 0x7098
movb %cl, (%rdi,%r14)
testl %ebx, %ebx
setle %cl
incq %r14
incq %rax
cmpl %eax, %ebx
setg %dl
orb %cl, %dl
jne 0x7083
jmp 0x6def
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r11)
movslq %r14d, %rcx
addq %rcx, %rdi
movq (%rsp), %r10
movq %r10, %rsi
subq %rcx, %rsi
movslq (%rax), %rdx
jmp 0x70f1
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r11)
movslq %r14d, %rcx
addq %rcx, %rdi
movq (%rsp), %r10
movq %r10, %rsi
subq %rcx, %rsi
movq (%rax), %rdx
movl $0xa, %ecx
movl %ebp, %r9d
movq %r10, %rbp
callq 0x7276
movq 0x10(%rsp), %rdi
addl %eax, %r14d
movq 0x8(%rsp), %r11
jmp 0x6def
cmpb $0x78, %al
sete %sil
cmpb $0x75, %al
sete %cl
orb %sil, %cl
cmpb $0x1, %cl
jne 0x7142
testl %edx, %edx
jne 0x7142
movl (%r11), %edx
cmpq $0x28, %rdx
ja 0x7173
movq %rdx, %rcx
addq 0x10(%r11), %rcx
addl $0x8, %edx
movl %edx, (%r11)
jmp 0x717f
cmpl $0x6c, %edx
setne %sil
xorb $0x1, %cl
orb %cl, %sil
je 0x715b
cmpl $0x7a, %edx
setne %dl
orb %dl, %cl
jne 0x71c8
movl (%r11), %edx
cmpq $0x28, %rdx
ja 0x7195
movq %rdx, %rcx
addq 0x10(%r11), %rcx
addl $0x8, %edx
movl %edx, (%r11)
jmp 0x71a1
movq 0x8(%r11), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%r11)
movslq %r14d, %rdx
addq %rdx, %rdi
movq (%rsp), %r10
movq %r10, %rsi
subq %rdx, %rsi
cmpb $0x78, %al
movl (%rcx), %edx
jmp 0x71b6
movq 0x8(%r11), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%r11)
movslq %r14d, %rdx
addq %rdx, %rdi
movq (%rsp), %r10
movq %r10, %rsi
subq %rdx, %rsi
cmpb $0x78, %al
movq (%rcx), %rdx
movl $0xa, %ecx
movl $0x10, %eax
cmovel %eax, %ecx
jmp 0x70f6
cmpb $0x70, %al
jne 0x7271
movl (%r11), %ecx
cmpq $0x28, %rcx
movq (%rsp), %rbp
ja 0x71ec
movq %rcx, %rax
addq 0x10(%r11), %rax
addl $0x8, %ecx
movl %ecx, (%r11)
jmp 0x71f8
movq 0x8(%r11), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r11)
movq (%rax), %rdx
cmpl %ebp, %r14d
jge 0x7207
movslq %r14d, %rax
movb $0x30, (%rdi,%rax)
movslq %r14d, %rax
leaq 0x1(%rax), %rcx
cmpl %ebp, %ecx
jge 0x7216
movb $0x78, (%rdi,%rcx)
addq %rax, %rdi
addq $0x2, %rdi
addq $0x2, %rax
movq %rbp, %rsi
subq %rax, %rsi
movl $0x10, %ecx
xorl %r9d, %r9d
callq 0x7276
movq 0x10(%rsp), %rdi
addl %eax, %r14d
addl $0x2, %r14d
movq 0x8(%rsp), %r11
jmp 0x6def
testq %rbp, %rbp
je 0x725f
leal -0x1(%rbp), %eax
cmpl %ebp, %r14d
cmovll %r14d, %eax
cltq
movb $0x0, (%rdi,%rax)
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3090