// File: /workspace/github_c_makefile_star2_O1/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, %r13d
testq %rdi, %rdi
sete %al
testl %esi, %esi
setle %cl
xorl %r12d, %r12d
orb %al, %cl
jne 0x6d4a0
movl %esi, %r14d
movq %rdi, %rbx
movl %r9d, -0x38(%rbp)
movq %rdx, -0x40(%rbp)
movq %r8, -0x48(%rbp)
movl %esi, %r15d
movq %r15, %rsi
callq 0x6d4b2
movq %rax, -0x50(%rbp)
testl %eax, %eax
jle 0x6d4a0
cmpb $0x2d, (%rbx)
jne 0x6d4a0
cmpb $0x2d, 0x1(%rbx)
jne 0x6d4a0
cmpb $0xa, 0x2(%rbx)
je 0x6d4a0
testl %r14d, %r14d
movl %r14d, -0x2c(%rbp)
jle 0x6d32d
xorl %ecx, %ecx
movl -0x38(%rbp), %esi
cmpb $0xa, (%rbx,%rcx)
je 0x6d332
incq %rcx
cmpq %rcx, %r15
jne 0x6d31a
movl %r15d, %ecx
jmp 0x6d332
xorl %ecx, %ecx
movl -0x38(%rbp), %esi
movl %ecx, %eax
incl %ecx
cmpb $0xa, (%rbx,%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnel %eax, %ecx
xorl %eax, %eax
movq -0x48(%rbp), %rdx
movb %al, (%rdx)
movq -0x40(%rbp), %rdx
movb %al, (%rdx)
movslq %r13d, %rax
movq %rax, -0x38(%rbp)
movslq %esi, %rax
movq %rax, -0x60(%rbp)
movq %rcx, -0x58(%rbp)
movl %ecx, %r12d
movq -0x50(%rbp), %r15
movslq %r12d, %rcx
leaq (%rbx,%rcx), %r13
movl %r15d, %eax
movl $0x0, %r14d
subl %ecx, %eax
jle 0x6d395
movl %eax, %ecx
xorl %r14d, %r14d
cmpb $0xa, (%r13,%r14)
je 0x6d395
incq %r14
cmpq %r14, %rcx
jne 0x6d382
movl %eax, %r14d
movl %r14d, %eax
incl %r14d
cmpb $0xa, (%r13,%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnel %eax, %r14d
testl %r14d, %r14d
jle 0x6d412
movl $0x15, %edx
leaq 0xcd05(%rip), %rdi      # 0x7a0c0
movq %r13, %rsi
callq 0x6ae41
testl %eax, %eax
jne 0x6d40a
addq $0x15, %r13
leal -0x17(%r14), %eax
movslq %eax, %r15
movq %r13, %rdi
movq %r15, %rsi
leaq 0xa5a4(%rip), %rdx      # 0x77983
movq -0x40(%rbp), %rcx
movq -0x38(%rbp), %r8
callq 0x6af98
movq %r13, %rdi
movq %r15, %rsi
movq -0x50(%rbp), %r15
leaq 0xc1f8(%rip), %rdx      # 0x795f5
movq -0x48(%rbp), %rcx
movq -0x60(%rbp), %r8
callq 0x6af98
addl %r14d, %r12d
jmp 0x6d369
movq -0x58(%rbp), %rdx
leal (%r15,%rdx), %eax
addl $-0x2, %eax
xorl %r12d, %r12d
cmpl -0x2c(%rbp), %eax
jge 0x6d4a0
leal -0x2(%rdx), %eax
movq %r15, %rcx
cltq
movq %rax, -0x48(%rbp)
movl %ecx, %eax
movq %rax, -0x40(%rbp)
leaq (%rbx,%rax), %r13
addl %ecx, %edx
movq %rdx, %r15
movl $0xfffffffe, %r14d      # imm = 0xFFFFFFFE
cmpb $0x2d, (%r13)
jne 0x6d460
movq %rbx, %rdi
movq %r13, %rsi
movq -0x48(%rbp), %rdx
callq 0xc7c0
testl %eax, %eax
je 0x6d478
incq %r13
leal (%r15,%r14), %eax
incl %eax
movl %r14d, %ecx
incl %ecx
movl %ecx, %r14d
cmpl -0x2c(%rbp), %eax
jl 0x6d446
jmp 0x6d4a0
movq 0x18(%rbp), %rax
testq %rax, %rax
je 0x6d484
movl %r14d, (%rax)
movq -0x50(%rbp), %rax
leal (%rax,%r14), %r12d
addl $0x2, %r12d
movq 0x10(%rbp), %rax
testq %rax, %rax
je 0x6d4a0
addq -0x40(%rbp), %rbx
movq %rbx, (%rax)
movl %r12d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq