// File: /workspace/github_cpp_makefile_star2_O3/solaldunckel[P]webserv/srcs/HTTP/Response.cpp
// Function: Response::accept_charset(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&)
std::string Response::accept_charset(std::vector<std::string> &matches){
  std::string path = file_.getPath();
  std::string all = config_.getHeader("Accept-Charset");
  int q = 10;
  int max = 0;
  std::string ret;
  std::vector<std::string> new_matches;
  std::vector<std::string> select_matches;

  ret = "";
  while (1) {
    std::string str = all.substr(0, all.find_first_of(" ,;\0"));

    if (str.find("*") == std::string::npos){
      for(std::vector<std::string>::iterator it = matches.begin() ; it != matches.end() ; it++)
        if (it->find("." + str) != std::string::npos)
          new_matches.push_back(*it);
    }
    else
      new_matches = matches;;
    if (!new_matches.empty() && (q > max)) {
        select_matches = new_matches;
      if(str[0] != '*')
         ret = str;
      max = q;
    }
    if (all.find(".") != std::string::npos)
      q = ft::stoi(all.substr(all.find_first_of(".") + 1, 1));
    if (all.find(",") == std::string::npos){
        if (!select_matches.empty())
          matches = select_matches;
      break ;
    }
    all = all.substr(all.find_first_of(" ,;"));
    all = all.substr(all.find_first_of("abcdefghijklmnoprstuvwxyz*"));
  }
  return (ret);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, 0x10(%rsp)
leaq 0x8(%rsi), %rdi
callq 0x1f480
leaq 0x70(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %rdi
callq 0x6c2a
movq (%rbx), %rbx
leaq 0xf8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xee95(%rip), %rsi      # 0x2589f
leaq 0xee9c(%rip), %rdx      # 0x258ad
leaq 0xe8(%rsp), %rdi
callq 0x579e
leaq 0xe8(%rsp), %rsi
movq %rbx, %rdi
callq 0x9f62
leaq 0xb0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0xa0(%rsp), %rdi
callq 0x6c2a
movq 0xe8(%rsp), %rdi
cmpq %r15, %rdi
je 0x16a6e
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x10(%rsp), %rdi
leaq 0x10(%rdi), %rax
movq %rax, 0xc0(%rsp)
movq %rax, (%rdi)
xorl %eax, %eax
movq %rax, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
movq %rax, 0x50(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq %rax, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
leaq 0xefbf(%rip), %rcx      # 0x25a78
xorl %esi, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x4690
movl $0xa, 0xc(%rsp)
leaq 0xa0(%rsp), %rbx
leaq 0xc8(%rsp), %r13
leaq 0x18(%rsp), %r15
movl $0x3, %ecx
movq %rbx, %rdi
leaq 0xeed8(%rip), %rsi      # 0x259c9
xorl %edx, %edx
callq 0x4660
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4490
movl $0x1, %ecx
movq %r13, %rdi
leaq 0xee8f(%rip), %rsi      # 0x259a6
xorl %edx, %edx
callq 0x4780
cmpq $-0x1, %rax
je 0x16cce
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0xcc34
movq 0x40(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x16b89
movl 0xc(%rsp), %eax
cmpl 0x38(%rsp), %eax
jle 0x16b89
leaq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0xcc34
movq 0xc8(%rsp), %rax
cmpb $0x2a, (%rax)
movl 0xc(%rsp), %eax
movq %rax, 0x38(%rsp)
je 0x16b89
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x4230
movl 0xc(%rsp), %eax
movq %rax, 0x38(%rsp)
movl $0x1, %ecx
movq %rbx, %rdi
leaq 0xee2f(%rip), %rsi      # 0x259c7
xorl %edx, %edx
callq 0x4780
cmpq $-0x1, %rax
je 0x16bfe
movl $0x1, %ecx
movq %rbx, %rdi
leaq 0xee13(%rip), %rsi      # 0x259c7
xorl %edx, %edx
callq 0x4660
leaq 0x1(%rax), %rdx
movl $0x1, %ecx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4490
movq %r15, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x24471
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x16bfe
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4470
movl $0x1, %ecx
movq %rbx, %rdi
leaq 0xed7a(%rip), %rsi      # 0x25987
xorl %edx, %edx
callq 0x4780
movq %rax, %rbp
cmpq $-0x1, %rax
je 0x16d39
movl $0x3, %ecx
movq %rbx, %rdi
leaq 0xed59(%rip), %rsi      # 0x25989
xorl %edx, %edx
callq 0x4660
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
movq $-0x1, %rcx
callq 0x4490
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4570
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x16c73
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4470
movl $0x1a, %ecx
movq %rbx, %rdi
leaq 0xed0b(%rip), %rsi      # 0x2598d
xorl %edx, %edx
callq 0x4660
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
movq $-0x1, %rcx
callq 0x4490
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4570
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x16d5b
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x16d5b
movq (%r14), %rbp
cmpq 0x8(%r14), %rbp
je 0x16b35
movq %r15, %rdi
leaq 0xece2(%rip), %rsi      # 0x259c7
movq %r13, %rdx
callq 0x568a
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rcx
movq %rbp, %rdi
xorl %edx, %edx
callq 0x4780
movq %rax, %r12
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x16d20
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4470
cmpq $-0x1, %r12
je 0x16d33
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x6b0a
addq $0x20, %rbp
jmp 0x16cd1
movq 0x80(%rsp), %rax
cmpq 0x88(%rsp), %rax
je 0x16d5b
movq %r14, %rdi
leaq 0x80(%rsp), %rsi
callq 0xcc34
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x16d80
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x4470
cmpq $-0x1, %rbp
jne 0x16ae2
leaq 0x80(%rsp), %rdi
callq 0x6a2c
leaq 0x40(%rsp), %rdi
callq 0x6a2c
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x16dc6
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x16de2
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4470
movq 0x10(%rsp), %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x16e4b
movq %rax, %rbx
jmp 0x16ed8
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r15, %rdi
je 0x16ed8
movq 0xf8(%rsp), %rsi
jmp 0x16ed0
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x16e57
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4470
jmp 0x16e57
jmp 0x16e54
jmp 0x16e54
jmp 0x16e54
movq %rax, %rbx
jmp 0x16e7c
jmp 0x16e54
jmp 0x16e54
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x16e7c
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0x80(%rsp), %rdi
callq 0x6a2c
leaq 0x40(%rsp), %rdi
callq 0x6a2c
movq 0x10(%rsp), %rax
movq (%rax), %rdi
movq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x16eb3
movq (%rax), %rsi
incq %rsi
callq 0x4470
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x16ed8
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4470
leaq 0x70(%rsp), %rax
movq 0x60(%rsp), %rdi
cmpq %rax, %rdi
je 0x16ef4
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4790