// File: /workspace/github_cpp_makefile_star2_O1/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 0x1f45c
leaq 0x70(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %rdi
callq 0x6bac
movq (%rbx), %rbx
leaq 0xf8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xef2b(%rip), %rsi      # 0x2589f
leaq 0xef32(%rip), %rdx      # 0x258ad
leaq 0xe8(%rsp), %rdi
callq 0x578e
leaq 0xe8(%rsp), %rsi
movq %rbx, %rdi
callq 0x9f0c
leaq 0xb0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0xa0(%rsp), %rdi
callq 0x6bac
movq 0xe8(%rsp), %rdi
cmpq %r15, %rdi
je 0x169d8
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x4460
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 0xf055(%rip), %rcx      # 0x25a78
xorl %esi, %esi
xorl %edx, %edx
xorl %r8d, %r8d
callq 0x4680
movl $0xa, 0xc(%rsp)
leaq 0xa0(%rsp), %rbx
leaq 0xc8(%rsp), %r13
leaq 0x18(%rsp), %r15
movl $0x3, %ecx
movq %rbx, %rdi
leaq 0xef6e(%rip), %rsi      # 0x259c9
xorl %edx, %edx
callq 0x4650
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x4480
movl $0x1, %ecx
movq %r13, %rdi
leaq 0xef25(%rip), %rsi      # 0x259a6
xorl %edx, %edx
callq 0x4770
cmpq $-0x1, %rax
je 0x16c38
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0xcbac
movq 0x40(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x16af3
movl 0xc(%rsp), %eax
cmpl 0x38(%rsp), %eax
jle 0x16af3
leaq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0xcbac
movq 0xc8(%rsp), %rax
cmpb $0x2a, (%rax)
movl 0xc(%rsp), %eax
movq %rax, 0x38(%rsp)
je 0x16af3
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x4230
movl 0xc(%rsp), %eax
movq %rax, 0x38(%rsp)
movl $0x1, %ecx
movq %rbx, %rdi
leaq 0xeec5(%rip), %rsi      # 0x259c7
xorl %edx, %edx
callq 0x4770
cmpq $-0x1, %rax
je 0x16b68
movl $0x1, %ecx
movq %rbx, %rdi
leaq 0xeea9(%rip), %rsi      # 0x259c7
xorl %edx, %edx
callq 0x4650
leaq 0x1(%rax), %rdx
movl $0x1, %ecx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4480
movq %r15, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x244f4
movl %eax, 0xc(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x16b68
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4460
movl $0x1, %ecx
movq %rbx, %rdi
leaq 0xee10(%rip), %rsi      # 0x25987
xorl %edx, %edx
callq 0x4770
movq %rax, %rbp
cmpq $-0x1, %rax
je 0x16ca3
movl $0x3, %ecx
movq %rbx, %rdi
leaq 0xedef(%rip), %rsi      # 0x25989
xorl %edx, %edx
callq 0x4650
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
movq $-0x1, %rcx
callq 0x4480
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4560
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x16bdd
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4460
movl $0x1a, %ecx
movq %rbx, %rdi
leaq 0xeda1(%rip), %rsi      # 0x2598d
xorl %edx, %edx
callq 0x4650
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
movq $-0x1, %rcx
callq 0x4480
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4560
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x16cc5
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x16cc5
movq (%r14), %rbp
cmpq 0x8(%r14), %rbp
je 0x16a9f
movq %r15, %rdi
leaq 0xed78(%rip), %rsi      # 0x259c7
movq %r13, %rdx
callq 0x567a
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rcx
movq %rbp, %rdi
xorl %edx, %edx
callq 0x4770
movq %rax, %r12
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x16c8a
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4460
cmpq $-0x1, %r12
je 0x16c9d
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x6a94
addq $0x20, %rbp
jmp 0x16c3b
movq 0x80(%rsp), %rax
cmpq 0x88(%rsp), %rax
je 0x16cc5
movq %r14, %rdi
leaq 0x80(%rsp), %rsi
callq 0xcbac
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x16cea
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x4460
cmpq $-0x1, %rbp
jne 0x16a4c
leaq 0x80(%rsp), %rdi
callq 0x69ba
leaq 0x40(%rsp), %rdi
callq 0x69ba
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x16d30
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x16d4c
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4460
movq 0x10(%rsp), %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x16db5
movq %rax, %rbx
jmp 0x16e42
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r15, %rdi
je 0x16e42
movq 0xf8(%rsp), %rsi
jmp 0x16e3a
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x16dc1
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x4460
jmp 0x16dc1
jmp 0x16dbe
jmp 0x16dbe
jmp 0x16dbe
movq %rax, %rbx
jmp 0x16de6
jmp 0x16dbe
jmp 0x16dbe
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x16de6
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x4460
leaq 0x80(%rsp), %rdi
callq 0x69ba
leaq 0x40(%rsp), %rdi
callq 0x69ba
movq 0x10(%rsp), %rax
movq (%rax), %rdi
movq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x16e1d
movq (%rax), %rsi
incq %rsi
callq 0x4460
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x16e42
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x4460
leaq 0x70(%rsp), %rax
movq 0x60(%rsp), %rdi
cmpq %rax, %rdi
je 0x16e5e
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x4460
movq %rbx, %rdi
callq 0x4780