// File: /workspace/github_cpp_makefile_star2_O2/solaldunckel[P]webserv/srcs/HTTP/Response.cpp
// Function: Response::localization(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>>>>&)
bool Response::localization(std::vector<std::string> &matches){
  std::string path = file_.getPath();
  std::string all = config_.getHeader("Accept-Language");
  int q = 10;
  int max = 0;
  std::vector<std::string> new_matches;
  std::vector<std::string> select_matches;

  headers_["Content-Language"] = "fr";
  while (1) {
    std::string str = all.substr(0, all.find_first_of(" ,;\0"));
    new_matches.clear();
    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] != '*')
        headers_["Content-Language"] = 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;
        return (1);
      }
      return (0);
    }
    all = all.substr(all.find_first_of(" ,;"));
    all = all.substr(all.find_first_of("abcdefghijklmnoprstuvwxyz*"));
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %rbx
movq %rdi, %r14
addq $0x8, %rdi
callq 0x17e90
leaq 0xe8(%rsp), %rdi
movq %rax, %rsi
callq 0x45e0
movq %r14, %r15
movq (%r14), %r14
leaq 0xacc5(%rip), %rsi      # 0x1c82e
leaq 0xc8(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x5328
leaq 0xc8(%rsp), %rsi
movq %r14, %rdi
callq 0x8e56
leaq 0x68(%rsp), %rdi
movq %rax, %rsi
callq 0x45e0
leaq 0xc8(%rsp), %rdi
callq 0x4898
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
leaq 0xad4d(%rip), %rsi      # 0x1c915
leaq 0x88(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x5328
movq %r15, %rdi
addq $0x190, %rdi            # imm = 0x190
leaq 0x88(%rsp), %rsi
movq %rdi, 0x60(%rsp)
callq 0xdd56
leaq 0xad12(%rip), %rsi      # 0x1c912
movq %rax, %rdi
callq 0x4830
leaq 0x88(%rsp), %r15
movq %r15, %rdi
callq 0x4898
movq $0x0, 0x18(%rsp)
pushq $0xa
popq %rax
leaq 0x68(%rsp), %r14
leaq 0x20(%rsp), %rbp
leaq 0xad31(%rip), %r13      # 0x1c966
leaq 0xa8(%rsp), %r12
movl %eax, 0x4(%rsp)
movl %eax, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r14, %rdi
leaq 0xad14(%rip), %rsi      # 0x1c968
xorl %edx, %edx
callq 0x4200
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x44a0
movq %rbp, %rdi
callq 0x60b0
movq %r15, %rdi
leaq 0xacc8(%rip), %rsi      # 0x1c945
xorl %edx, %edx
callq 0x4870
cmpq $-0x1, %rax
je 0x11d28
movq %rbp, %rdi
movq %rbx, %rsi
callq 0xb01e
movq 0x20(%rsp), %rax
cmpq 0x28(%rsp), %rax
je 0x11d77
movq 0x18(%rsp), %rax
cmpl %eax, 0x4(%rsp)
leaq 0x68(%rsp), %r14
jle 0x11d7c
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0xb01e
movq 0x88(%rsp), %rax
cmpb $0x2a, (%rax)
movl 0x4(%rsp), %eax
movq %rax, 0x18(%rsp)
leaq 0x68(%rsp), %r14
je 0x11d7c
movq %r12, %rdi
leaq 0xac22(%rip), %rsi      # 0x1c915
leaq 0xf(%rsp), %rdx
callq 0x5328
movq 0x60(%rsp), %rdi
movq %r12, %rsi
callq 0xdd56
movq %rax, %rdi
movq %r15, %rsi
callq 0x4240
movq %r12, %rdi
callq 0x4898
movl 0x4(%rsp), %eax
movq %rax, 0x18(%rsp)
jmp 0x11d7c
movq (%rbx), %r14
cmpq 0x8(%rbx), %r14
je 0x11c99
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x52b1
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x4880
movq %rax, %rbp
movq %r12, %rdi
callq 0x4898
cmpq $-0x1, %rbp
leaq 0x20(%rsp), %rbp
je 0x11d71
movq %rbp, %rdi
movq %r14, %rsi
callq 0x6170
addq $0x20, %r14
jmp 0x11d2b
leaq 0x68(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x4870
cmpq $-0x1, %rax
je 0x11dc7
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x4200
leaq 0x1(%rax), %rdx
movq %r12, %rdi
movq %r14, %rsi
pushq $0x1
popq %rcx
callq 0x44a0
movq %r12, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x1b536
movl %eax, 0x4(%rsp)
movq %r12, %rdi
callq 0x4898
movq %r14, %rdi
leaq 0xab55(%rip), %rsi      # 0x1c926
xorl %edx, %edx
callq 0x4870
movq %r14, %rbp
movq %rax, %r14
cmpq $-0x1, %rax
je 0x11e74
movq %r14, %rbx
movq %r15, %r14
movq %r13, %r15
movq %rbp, %rdi
leaq 0xab2d(%rip), %rsi      # 0x1c928
xorl %edx, %edx
callq 0x4200
movq %r12, %rdi
movq %rbp, %rsi
movq %rax, %rdx
pushq $-0x1
popq %r13
movq %r13, %rcx
callq 0x44a0
movq %rbp, %rdi
movq %r12, %rsi
callq 0x4560
movq %r12, %rdi
callq 0x4898
movq %rbp, %rdi
leaq 0xaaf8(%rip), %rsi      # 0x1c92c
xorl %edx, %edx
callq 0x4200
movq %r12, %rdi
movq %rbp, %rsi
movq %rax, %rdx
movq %r13, %rcx
callq 0x44a0
movq %rbp, %rdi
movq %r12, %rsi
callq 0x4560
movq %r12, %rdi
callq 0x4898
leaq 0x20(%rsp), %rbp
movq %r15, %r13
movq %r14, %r15
movq %rbx, %r14
movq 0x10(%rsp), %rbx
jmp 0x11e9d
movq 0x40(%rsp), %rax
cmpq 0x48(%rsp), %rax
leaq 0x20(%rsp), %rbp
je 0x11eb6
movb $0x1, %al
movl %eax, 0x8(%rsp)
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
leaq 0x40(%rsp), %rsi
callq 0xb01e
movq %r15, %rdi
callq 0x4898
cmpq $-0x1, %r14
leaq 0x68(%rsp), %r14
jne 0x11c4a
jmp 0x11ec0
movl $0x0, 0x8(%rsp)
jmp 0x11e6d
leaq 0x40(%rsp), %rdi
callq 0x608e
leaq 0x20(%rsp), %rdi
callq 0x608e
leaq 0x68(%rsp), %rdi
callq 0x4898
leaq 0xe8(%rsp), %rdi
callq 0x4898
movl 0x8(%rsp), %eax
andb $0x1, %al
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x11f35
movq %rax, %rbx
jmp 0x11f6c
jmp 0x11f3e
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x11f67
jmp 0x11f3e
jmp 0x11f21
jmp 0x11f3e
jmp 0x11f3e
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x4898
jmp 0x11f41
jmp 0x11f3e
movq %rax, %rbx
jmp 0x11f4e
jmp 0x11f3e
jmp 0x11f3e
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x4898
leaq 0x40(%rsp), %rdi
callq 0x608e
leaq 0x20(%rsp), %rdi
callq 0x608e
leaq 0x68(%rsp), %rdi
callq 0x4898
leaq 0xe8(%rsp), %rdi
callq 0x4898
movq %rbx, %rdi
callq 0x4750
nop