// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: mg_parse_multipart
int mg_parse_multipart(const char *buf, int buf_len,
                       char *var_name, int var_name_len,
                       char *file_name, int file_name_len,
                       const char **data, int *data_len) {
  static const char cd[] = "Content-Disposition: ";
  //struct mg_connection c;
  int hl, bl, n, ll, pos, cdl = sizeof(cd) - 1;
  //char *p;

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

  // Get boundary length
  bl = 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 = get_line_len(buf + n, hl - n)) > 0; n += ll) {
    if (mg_strncasecmp(cd, buf + n, cdl) == 0) {
      parse_header(buf + n + cdl, ll - (cdl + 2), "name",
                   var_name, var_name_len);
      parse_header(buf + n + cdl, ll - (cdl + 2), "filename",
                   file_name, file_name_len);
    }
  }

  // Scan body, search for terminating boundary
  for (pos = hl; pos + (bl - 2) < buf_len; pos++) {
    if (buf[pos] == '-' && !memcmp(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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %r14d
testq %rdi, %rdi
sete %al
testl %esi, %esi
setle %cl
xorl %r12d, %r12d
orb %al, %cl
jne 0x5c47f
movl %r9d, %r13d
movq %r8, %r15
movq %rdi, %rbx
movq %rdx, -0x38(%rbp)
movl %esi, -0x2c(%rbp)
movl %esi, %esi
callq 0x5c491
movq %rax, -0x48(%rbp)
testl %eax, %eax
jle 0x5c47f
cmpb $0x2d, (%rbx)
jne 0x5c47f
cmpb $0x2d, 0x1(%rbx)
jne 0x5c47f
cmpb $0xa, 0x2(%rbx)
je 0x5c47f
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
callq 0x5c537
xorl %edx, %edx
movq %r15, -0x40(%rbp)
movb %dl, (%r15)
movq -0x38(%rbp), %rcx
movb %dl, (%rcx)
movslq %r14d, %rcx
movq %rcx, -0x60(%rbp)
movslq %r13d, %rcx
movq %rcx, -0x58(%rbp)
movq %rax, -0x50(%rbp)
movl %eax, %r15d
movq -0x48(%rbp), %r12
movslq %r15d, %rax
leaq (%rbx,%rax), %r14
movl %r12d, %esi
subl %eax, %esi
movq %r14, %rdi
callq 0x5c537
testl %eax, %eax
jle 0x5c400
movl %eax, %r13d
leaq 0xbcf7(%rip), %rdi      # 0x680a0
movq %r14, %rsi
pushq $0x15
popq %rdx
callq 0x5a293
testl %eax, %eax
jne 0x5c3fb
addq $0x15, %r14
leal -0x17(%r13), %eax
movslq %eax, %r12
movq %r14, %rdi
movq %r12, %rsi
leaq 0x959e(%rip), %rdx      # 0x6596e
movq -0x38(%rbp), %rcx
movq -0x60(%rbp), %r8
callq 0x5a32e
movq %r14, %rdi
movq %r12, %rsi
movq -0x48(%rbp), %r12
leaq 0xb1f2(%rip), %rdx      # 0x675e0
movq -0x40(%rbp), %rcx
movq -0x58(%rbp), %r8
callq 0x5a32e
addl %r13d, %r15d
jmp 0x5c387
movq -0x50(%rbp), %rcx
leal -0x2(%rcx), %eax
cltq
movq %rax, -0x38(%rbp)
movl %r12d, %eax
movq %rax, -0x40(%rbp)
leaq (%rbx,%rax), %r13
leal (%r12,%rcx), %r14d
addl $-0x2, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
movl -0x2c(%rbp), %ecx
leal (%r14,%r15), %eax
cmpl %ecx, %eax
jge 0x5c47f
cmpb $0x2d, (%r13)
jne 0x5c44e
movq %rbx, %rdi
movq %r13, %rsi
movq -0x38(%rbp), %rdx
callq 0xc800
movl -0x2c(%rbp), %ecx
testl %eax, %eax
je 0x5c456
incq %r13
incl %r15d
jmp 0x5c429
movq 0x18(%rbp), %rcx
testq %rcx, %rcx
je 0x5c465
leal -0x2(%r15), %eax
movl %eax, (%rcx)
movq -0x48(%rbp), %rax
addl %r15d, %eax
movq 0x10(%rbp), %rcx
testq %rcx, %rcx
je 0x5c47c
addq -0x40(%rbp), %rbx
movq %rbx, (%rcx)
movl %eax, %r12d
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq