// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_parse_multipart
size_t mg_parse_multipart(const char *buf, size_t buf_len, char *var_name,
                          size_t var_name_len, char *file_name,
                          size_t file_name_len, const char **data,
                          size_t *data_len) {
  static const char cd[] = "Content-Disposition: ";
  size_t hl, bl, n, ll, pos, cdl = sizeof(cd) - 1;

  if (buf == NULL || buf_len <= 0) return 0;
  if ((hl = mg_http_get_request_len(buf, buf_len)) <= 0) return 0;
  if (buf[0] != '-' || buf[1] != '-' || buf[2] == '\n') return 0;

  /* Get boundary length */
  bl = mg_get_line_len(buf, buf_len);

  /* Loop through headers, fetch variable name and file name */
  var_name[0] = file_name[0] = '\0';
  for (n = bl; (ll = mg_get_line_len(buf + n, hl - n)) > 0; n += ll) {
    if (mg_ncasecmp(cd, buf + n, cdl) == 0) {
      struct mg_str header;
      header.p = buf + n + cdl;
      header.len = ll - (cdl + 2);
      mg_http_parse_header(&header, "name", var_name, var_name_len);
      mg_http_parse_header(&header, "filename", file_name, file_name_len);
    }
  }

  /* Scan through the body, search for terminating boundary */
  for (pos = hl; pos + (bl - 2) < buf_len; pos++) {
    if (buf[pos] == '-' && !strncmp(buf, &buf[pos], bl - 2)) {
      if (data_len != NULL) *data_len = (pos - 2) - hl;
      if (data != NULL) *data = buf + hl;
      return pos;
    }
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r13
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0x101ff
movq %r9, %r15
movq %r8, %r12
movq %rdx, %rbp
movq %rsi, %rbx
movq %rdi, %r14
callq 0xb664
testl %eax, %eax
je 0x101ff
cmpb $0x2d, (%r14)
jne 0x101ff
cmpb $0x2d, 0x1(%r14)
jne 0x101ff
cmpb $0xa, 0x2(%r14)
je 0x101ff
movslq %eax, %rsi
xorl %eax, %eax
movq %r15, 0x28(%rsp)
movq %r13, 0x18(%rsp)
cmpb $0xa, (%r14,%rax)
je 0x100bf
incq %rax
cmpq %rax, %rbx
jne 0x100ad
movq %rbx, %rax
leaq 0x1(%rax), %rcx
xorl %edx, %edx
cmpq %rbx, %rax
movl $0x0, %eax
cmovneq %rcx, %rax
movq %r12, 0x20(%rsp)
movb %dl, (%r12)
movb %dl, (%rbp)
movq %rax, 0x10(%rsp)
movq %rax, %rdx
movq %rsi, 0x8(%rsp)
leaq (%r14,%rdx), %r15
movq %rsi, %rax
xorl %r13d, %r13d
subq %rdx, %rax
jne 0x1018d
movq %r13, %r12
incq %r12
sete %cl
cmpq %rax, %r13
je 0x101a0
testb %cl, %cl
jne 0x101a0
movq %rdx, 0x30(%rsp)
movl $0x15, %edx
leaq 0x5328(%rip), %rdi      # 0x15450
movq %r15, %rsi
callq 0x6bc6
testl %eax, %eax
jne 0x1017b
addq $0x15, %r15
movq %r15, 0x38(%rsp)
addq $-0x16, %r13
movq %r13, 0x40(%rsp)
leaq 0x38(%rsp), %r15
movq %r15, %rdi
leaq 0x5ec9(%rip), %rsi      # 0x1601e
movq %rbp, %rdx
movq 0x18(%rsp), %rcx
callq 0xd5e0
movq %r15, %rdi
leaq 0x5eae(%rip), %rsi      # 0x1601a
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
callq 0xd5e0
movq 0x30(%rsp), %rdx
addq %r12, %rdx
movq 0x8(%rsp), %rsi
jmp 0x100ea
cmpb $0xa, (%r15,%r13)
je 0x100fd
incq %r13
cmpq %r13, %rax
jne 0x1018d
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %rdx
leaq (%rdx,%rcx), %rax
addq $-0x2, %rax
cmpq %rbx, %rax
jae 0x101ff
addq $-0x2, %rdx
leaq (%r14,%rcx), %r12
movq %rdx, 0x10(%rsp)
leaq (%rcx,%rdx), %rbp
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpb $0x2d, (%r12,%r13)
jne 0x101ea
leaq (%r12,%r13), %rsi
movq %r14, %rdi
movq 0x10(%rsp), %rdx
callq 0x30c0
testl %eax, %eax
je 0x10214
leaq 0x1(,%r13), %rax
addq %rbp, %rax
incq %r13
cmpq %rbx, %rax
jb 0x101ce
jmp 0x10202
xorl %r15d, %r15d
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x88(%rsp), %rcx
testq %rcx, %rcx
je 0x10228
leaq -0x2(%r13), %rax
movq %rax, (%rcx)
movq 0x8(%rsp), %r15
addq %r13, %r15
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0x10202
movq %r12, (%rax)
jmp 0x10202