// File: /workspace/github_c_makefile_star2_O0/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
subq $0x50, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movl $0x15, -0x4c(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xb51fa
cmpl $0x0, -0x14(%rbp)
jg 0xb5206
movl $0x0, -0x4(%rbp)
jmp 0xb53cd
movq -0x10(%rbp), %rdi
movslq -0x14(%rbp), %rsi
callq 0xb53e0
movl %eax, -0x38(%rbp)
cmpl $0x0, %eax
jg 0xb5227
movl $0x0, -0x4(%rbp)
jmp 0xb53cd
movq -0x10(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0xb524d
movq -0x10(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2d, %eax
jne 0xb524d
movq -0x10(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0xa, %eax
jne 0xb5259
movl $0x0, -0x4(%rbp)
jmp 0xb53cd
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xb5530
movl %eax, -0x3c(%rbp)
movq -0x30(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x40(%rbp), %rax
addq %rax, %rdi
movl -0x38(%rbp), %esi
subl -0x40(%rbp), %esi
callq 0xb5530
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
jle 0xb5336
movq -0x10(%rbp), %rsi
movslq -0x40(%rbp), %rax
addq %rax, %rsi
movslq -0x4c(%rbp), %rdx
leaq 0x1174c(%rip), %rdi     # 0xc6a00
callq 0xb2e40
cmpl $0x0, %eax
jne 0xb5326
movq -0x10(%rbp), %rdi
movslq -0x40(%rbp), %rax
addq %rax, %rdi
movslq -0x4c(%rbp), %rax
addq %rax, %rdi
movl -0x44(%rbp), %eax
movl -0x4c(%rbp), %ecx
addl $0x2, %ecx
subl %ecx, %eax
movslq %eax, %rsi
movq -0x20(%rbp), %rcx
movslq -0x24(%rbp), %r8
leaq 0xeb82(%rip), %rdx      # 0xc3e6f
callq 0xb3010
movq -0x10(%rbp), %rdi
movslq -0x40(%rbp), %rax
addq %rax, %rdi
movslq -0x4c(%rbp), %rax
addq %rax, %rdi
movl -0x44(%rbp), %eax
movl -0x4c(%rbp), %ecx
addl $0x2, %ecx
subl %ecx, %eax
movslq %eax, %rsi
movq -0x30(%rbp), %rcx
movslq -0x34(%rbp), %r8
leaq 0x107b8(%rip), %rdx     # 0xc5ad9
callq 0xb3010
jmp 0xb5328
movl -0x44(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0xb527c
movl -0x38(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl -0x3c(%rbp), %ecx
subl $0x2, %ecx
addl %ecx, %eax
cmpl -0x14(%rbp), %eax
jge 0xb53c6
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2d, %eax
jne 0xb53b6
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rsi
movslq -0x48(%rbp), %rax
addq %rax, %rsi
movl -0x3c(%rbp), %eax
subl $0x2, %eax
movslq %eax, %rdx
callq 0xddb0
cmpl $0x0, %eax
jne 0xb53b6
cmpq $0x0, 0x18(%rbp)
je 0xb5395
movl -0x48(%rbp), %ecx
subl $0x2, %ecx
subl -0x38(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, 0x10(%rbp)
je 0xb53ae
movq -0x10(%rbp), %rcx
movslq -0x38(%rbp), %rax
addq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xb53cd
jmp 0xb53b8
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xb533c
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)