// File: /workspace/github_c_makefile_star2_O3/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, %r15d
testq %rdi, %rdi
sete %al
testl %esi, %esi
setle %cl
xorl %r13d, %r13d
orb %al, %cl
jne 0x6b91e
movl %esi, %r14d
movq %rdi, %rbx
movl %r9d, -0x48(%rbp)
movq %rdx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movl %esi, %r12d
movq %r12, %rsi
callq 0x6b930
movq %rax, -0x50(%rbp)
testl %eax, %eax
jle 0x6b91e
cmpb $0x2d, (%rbx)
jne 0x6b91e
cmpb $0x2d, 0x1(%rbx)
jne 0x6b91e
cmpb $0xa, 0x2(%rbx)
je 0x6b91e
xorl %eax, %eax
movl %r14d, -0x2c(%rbp)
movq -0x50(%rbp), %r13
movl -0x48(%rbp), %edx
cmpb $0xa, (%rbx,%rax)
je 0x6b7b8
incq %rax
cmpq %rax, %r12
jne 0x6b7a5
movq %r12, %rax
jmp 0x6b7bb
movl %eax, %r12d
incl %r12d
cmpb $0xa, (%rbx,%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnel %eax, %r12d
xorl %eax, %eax
movq -0x40(%rbp), %rcx
movb %al, (%rcx)
movq -0x38(%rbp), %rcx
movb %al, (%rcx)
movslq %r15d, %rax
movq %rax, -0x60(%rbp)
movslq %edx, %rax
movq %rax, -0x48(%rbp)
movq %r12, -0x58(%rbp)
movslq %r12d, %rcx
leaq (%rbx,%rcx), %r15
movl %r13d, %eax
movl $0x0, %r14d
subl %ecx, %eax
jle 0x6b816
movl %eax, %ecx
xorl %r14d, %r14d
cmpb $0xa, (%r15,%r14)
je 0x6b816
incq %r14
cmpq %r14, %rcx
jne 0x6b804
movl %eax, %r14d
movl %r14d, %eax
incl %r14d
cmpb $0xa, (%r15,%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnel %eax, %r14d
testl %r14d, %r14d
jle 0x6b892
movl $0x15, %edx
leaq 0xc885(%rip), %rdi      # 0x780c0
movq %r15, %rsi
callq 0x69234
testl %eax, %eax
jne 0x6b88a
addq $0x15, %r15
leal -0x17(%r14), %eax
movslq %eax, %r13
movq %r15, %rdi
movq %r13, %rsi
leaq 0xa12f(%rip), %rdx      # 0x7598e
movq -0x38(%rbp), %rcx
movq -0x60(%rbp), %r8
callq 0x693a2
movq %r15, %rdi
movq %r13, %rsi
movq -0x50(%rbp), %r13
leaq 0xbd83(%rip), %rdx      # 0x77600
movq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r8
callq 0x693a2
addl %r14d, %r12d
jmp 0x6b7eb
movq -0x58(%rbp), %r14
leal (%r14,%r13), %eax
addl $-0x2, %eax
movq %r13, %rcx
xorl %r13d, %r13d
cmpl -0x2c(%rbp), %eax
jge 0x6b91e
leal -0x2(%r14), %eax
cltq
movq %rax, -0x40(%rbp)
movl %ecx, %eax
movq %rax, -0x38(%rbp)
leaq (%rbx,%rax), %r15
addl %ecx, %r14d
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
cmpb $0x2d, (%r15)
jne 0x6b8de
movq %rbx, %rdi
movq %r15, %rsi
movq -0x40(%rbp), %rdx
callq 0xc7c0
testl %eax, %eax
je 0x6b8f6
incq %r15
leal (%r14,%r12), %eax
incl %eax
movl %r12d, %ecx
incl %ecx
movl %ecx, %r12d
cmpl -0x2c(%rbp), %eax
jl 0x6b8c5
jmp 0x6b91e
movq 0x18(%rbp), %rax
testq %rax, %rax
je 0x6b902
movl %r12d, (%rax)
movq -0x50(%rbp), %rax
leal (%rax,%r12), %r13d
addl $0x2, %r13d
movq 0x10(%rbp), %rax
testq %rax, %rax
je 0x6b91e
addq -0x38(%rbp), %rbx
movq %rbx, (%rax)
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq