// File: /workspace/github_cpp_makefile_star2_O2/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 0x17e90
leaq 0xc8(%rsp), %rdi
movq %rax, %rsi
callq 0x45e0
movq (%rbx), %rbx
leaq 0xa87d(%rip), %rsi      # 0x1c83e
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x5328
leaq 0xa8(%rsp), %rsi
movq %rbx, %rdi
callq 0x8e56
leaq 0x68(%rsp), %rdi
movq %rax, %rsi
callq 0x45e0
leaq 0xa8(%rsp), %rdi
callq 0x4898
movq 0x10(%rsp), %rdi
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
leaq 0xa9f5(%rip), %rsi      # 0x1ca2a
callq 0x4830
movq $0x0, 0x18(%rsp)
pushq $0xa
popq %rax
leaq 0x68(%rsp), %rbx
leaq 0x88(%rsp), %r13
leaq 0xa90c(%rip), %rbp      # 0x1c966
leaq 0xe8(%rsp), %r15
movl %eax, 0xc(%rsp)
movq %rbx, %rdi
leaq 0xa8f8(%rip), %rsi      # 0x1c968
xorl %edx, %edx
callq 0x4200
movq %r13, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x44a0
movq %r13, %rdi
leaq 0xa8b4(%rip), %rsi      # 0x1c945
xorl %edx, %edx
callq 0x4870
cmpq $-0x1, %rax
je 0x121f6
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0xb01e
movq 0x20(%rsp), %rax
cmpq 0x28(%rsp), %rax
je 0x12100
movl 0xc(%rsp), %eax
cmpl 0x18(%rsp), %eax
jle 0x12100
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xb01e
movq 0x88(%rsp), %rax
cmpb $0x2a, (%rax)
movl 0xc(%rsp), %eax
movq %rax, 0x18(%rsp)
je 0x12100
movq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x4240
movl 0xc(%rsp), %eax
movq %rax, 0x18(%rsp)
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x4870
cmpq $-0x1, %rax
je 0x12150
movq %rbx, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x4200
leaq 0x1(%rax), %rdx
movq %r15, %rdi
movq %rbx, %rsi
pushq $0x1
popq %rcx
callq 0x44a0
movq %r15, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x1b536
movl %eax, 0xc(%rsp)
movq %r15, %rdi
callq 0x4898
movq %rbx, %rdi
leaq 0xa7cc(%rip), %rsi      # 0x1c926
xorl %edx, %edx
callq 0x4870
movq %rbx, %r12
movq %rax, %rbx
cmpq $-0x1, %rax
je 0x12242
movq %rbx, 0x60(%rsp)
movq %r13, %rbx
movq %rbp, %r13
movq %r12, %rdi
leaq 0xa7a2(%rip), %rsi      # 0x1c928
xorl %edx, %edx
callq 0x4200
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
pushq $-0x1
popq %rbp
movq %rbp, %rcx
callq 0x44a0
movq %r12, %rdi
movq %r15, %rsi
callq 0x4560
movq %r15, %rdi
callq 0x4898
movq %r12, %rdi
leaq 0xa76e(%rip), %rsi      # 0x1c92c
xorl %edx, %edx
callq 0x4200
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
movq %rbp, %rcx
callq 0x44a0
movq %r12, %rdi
movq %r15, %rsi
callq 0x4560
movq %r15, %rdi
callq 0x4898
movq %r13, %rbp
movq %rbx, %r13
movq 0x60(%rsp), %rbx
jmp 0x1225b
movq (%r14), %rbx
cmpq 0x8(%r14), %rbx
je 0x120af
movq %r15, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x52b1
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x4880
movq %rax, %r12
movq %r15, %rdi
callq 0x4898
cmpq $-0x1, %r12
je 0x1223c
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x6170
addq $0x20, %rbx
jmp 0x121f9
movq 0x40(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x1225b
movq %r14, %rdi
leaq 0x40(%rsp), %rsi
callq 0xb01e
movq %r13, %rdi
callq 0x4898
cmpq $-0x1, %rbx
leaq 0x68(%rsp), %rbx
jne 0x12066
leaq 0x40(%rsp), %rdi
callq 0x608e
leaq 0x20(%rsp), %rdi
callq 0x608e
leaq 0x68(%rsp), %rdi
callq 0x4898
leaq 0xc8(%rsp), %rdi
callq 0x4898
movq 0x10(%rsp), %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x122e0
movq %rax, %rbx
jmp 0x12321
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x1231c
jmp 0x122e9
jmp 0x122e9
jmp 0x122e9
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x4898
jmp 0x122ec
movq %rax, %rbx
jmp 0x122f9
jmp 0x122e9
jmp 0x122e9
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x4898
leaq 0x40(%rsp), %rdi
callq 0x608e
leaq 0x20(%rsp), %rdi
callq 0x608e
movq 0x10(%rsp), %rdi
callq 0x4898
leaq 0x68(%rsp), %rdi
callq 0x4898
leaq 0xc8(%rsp), %rdi
callq 0x4898
movq %rbx, %rdi
callq 0x4750