// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $0x15, -0x68(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x15a21
cmpq $0x0, -0x18(%rbp)
ja 0x15a2e
movq $0x0, -0x8(%rbp)
jmp 0x15bf7
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl %eax, %esi
callq 0x10460
cltq
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
ja 0x15a56
movq $0x0, -0x8(%rbp)
jmp 0x15bf7
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x15a7c
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2d, %eax
jne 0x15a7c
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0xa, %eax
jne 0x15a89
movq $0x0, -0x8(%rbp)
jmp 0x15bf7
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15c10
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
addq -0x50(%rbp), %rdi
movq -0x40(%rbp), %rsi
subq -0x50(%rbp), %rsi
callq 0x15c10
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
jbe 0x15b56
movq -0x10(%rbp), %rsi
addq -0x50(%rbp), %rsi
movq -0x68(%rbp), %rdx
leaq 0x992a(%rip), %rdi      # 0x1f410
callq 0x8bf0
cmpl $0x0, %eax
jne 0x15b43
movq -0x10(%rbp), %rax
addq -0x50(%rbp), %rax
addq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x58(%rbp), %rax
movq -0x68(%rbp), %rcx
addq $0x2, %rcx
subq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
leaq -0x78(%rbp), %rdi
leaq 0xa477(%rip), %rsi      # 0x1ff9d
callq 0x12c00
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
leaq -0x78(%rbp), %rdi
leaq 0xa45b(%rip), %rsi      # 0x1ff99
callq 0x12c00
jmp 0x15b45
movq -0x58(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x15ab0
movq -0x40(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x48(%rbp), %rcx
subq $0x2, %rcx
addq %rcx, %rax
cmpq -0x18(%rbp), %rax
jae 0x15bef
movq -0x10(%rbp), %rax
movq -0x60(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0x15bdc
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq -0x60(%rbp), %rsi
movq -0x48(%rbp), %rdx
subq $0x2, %rdx
callq 0x30b0
cmpl $0x0, %eax
jne 0x15bdc
cmpq $0x0, 0x18(%rbp)
je 0x15bbc
movq -0x60(%rbp), %rcx
subq $0x2, %rcx
subq -0x40(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
cmpq $0x0, 0x10(%rbp)
je 0x15bd2
movq -0x10(%rbp), %rcx
addq -0x40(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x15bf7
jmp 0x15bde
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x15b5e
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)