// File: 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
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
addq $0x8, %rdi
callq 0x38460
movq %rax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x5200
movq -0x1f0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1e8(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x5960
movq -0x1e0(%rbp), %rdx
leaq 0x1b249(%rip), %rsi     # 0x4386b
leaq -0x78(%rbp), %rdi
callq 0x6be0
jmp 0x2862d
movq -0x1e8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x13050
movq %rax, -0x1f8(%rbp)
jmp 0x28646
movq -0x1f8(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x5200
jmp 0x28658
leaq -0x78(%rbp), %rdi
callq 0x5aa8
leaq -0x79(%rbp), %rdi
callq 0x55e0
movl $0xa, -0x90(%rbp)
movl $0x0, -0x94(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x8b40
leaq -0xc8(%rbp), %rdi
callq 0x8b40
movq -0x1f0(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x208(%rbp)
leaq -0xe9(%rbp), %rdi
movq %rdi, -0x200(%rbp)
callq 0x5960
movq -0x200(%rbp), %rdx
leaq 0x1b287(%rip), %rsi     # 0x43952
leaq -0xe8(%rbp), %rdi
callq 0x6be0
jmp 0x286d9
movq -0x208(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x20e30
movq %rax, -0x210(%rbp)
jmp 0x286f5
movq -0x210(%rbp), %rdi
leaq 0x1b24c(%rip), %rsi     # 0x4394f
callq 0x5780
jmp 0x2870a
leaq -0xe8(%rbp), %rdi
callq 0x5aa8
leaq -0xe9(%rbp), %rdi
callq 0x55e0
jmp 0x28724
leaq 0x1b27a(%rip), %rsi     # 0x439a5
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x218(%rbp)
leaq -0x58(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x5270
movq -0x220(%rbp), %rsi
movq -0x218(%rbp), %rdx
movq %rax, %rcx
leaq -0x110(%rbp), %rdi
callq 0x55a0
jmp 0x28765
leaq -0xb0(%rbp), %rdi
callq 0x8f20
leaq -0x110(%rbp), %rdi
leaq 0x1b203(%rip), %rsi     # 0x43982
xorl %eax, %eax
movl %eax, %edx
callq 0x5a70
cmpq $-0x1, %rax
jne 0x28926
movq -0x18(%rbp), %rdi
callq 0x9210
movq %rax, -0x118(%rbp)
movq -0x18(%rbp), %rdi
callq 0x9280
movq %rax, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x9240
testb $0x1, %al
jne 0x287ce
jmp 0x28924
leaq -0x118(%rbp), %rdi
callq 0x18da0
movq %rax, -0x228(%rbp)
leaq 0x1b1bb(%rip), %rsi     # 0x439a3
leaq -0x140(%rbp), %rdi
leaq -0x110(%rbp), %rdx
callq 0x6ad0
jmp 0x287fd
movq -0x228(%rbp), %rdi
leaq -0x140(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x5a90
movq %rax, -0x230(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x5aa8
movq -0x230(%rbp), %rax
cmpq $-0x1, %rax
je 0x28908
leaq -0x118(%rbp), %rdi
callq 0x92b0
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x9130
jmp 0x28855
jmp 0x28908
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x28889
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x5aa8
leaq -0x79(%rbp), %rdi
callq 0x55e0
jmp 0x28cd7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x288c9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x5aa8
leaq -0xe9(%rbp), %rdi
callq 0x55e0
jmp 0x28cb6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x28cb6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x28c70
jmp 0x2890a
leaq -0x118(%rbp), %rdi
xorl %esi, %esi
callq 0x13ae0
movq %rax, -0x148(%rbp)
jmp 0x287a2
jmp 0x2893a
movq -0x18(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x18870
jmp 0x28938
jmp 0x2893a
leaq -0xb0(%rbp), %rdi
callq 0x13c40
testb $0x1, %al
jne 0x28a7e
movl -0x90(%rbp), %eax
cmpl -0x94(%rbp), %eax
jle 0x28a7e
leaq -0xc8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x18870
jmp 0x28975
xorl %eax, %eax
movl %eax, %esi
leaq -0x110(%rbp), %rdi
callq 0x5a80
movq %rax, -0x238(%rbp)
jmp 0x2898e
movq -0x238(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
je 0x28a72
movq -0x1f0(%rbp), %rax
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x248(%rbp)
leaq -0x169(%rbp), %rdi
movq %rdi, -0x240(%rbp)
callq 0x5960
movq -0x240(%rbp), %rdx
leaq 0x1af7c(%rip), %rsi     # 0x43952
leaq -0x168(%rbp), %rdi
callq 0x6be0
jmp 0x289e4
movq -0x248(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x20e30
movq %rax, -0x250(%rbp)
jmp 0x28a00
movq -0x250(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x5050
jmp 0x28a15
leaq -0x168(%rbp), %rdi
callq 0x5aa8
leaq -0x169(%rbp), %rdi
callq 0x55e0
jmp 0x28a72
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x28a61
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x5aa8
leaq -0x169(%rbp), %rdi
callq 0x55e0
jmp 0x28c70
movl -0x90(%rbp), %eax
movl %eax, -0x94(%rbp)
leaq -0x58(%rbp), %rdi
leaq 0x1af1a(%rip), %rsi     # 0x439a3
xorl %eax, %eax
movl %eax, %edx
callq 0x5a70
cmpq $-0x1, %rax
je 0x28b31
leaq 0x1af00(%rip), %rsi     # 0x439a3
xorl %eax, %eax
movl %eax, %edx
leaq -0x58(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x5270
movq -0x258(%rbp), %rsi
movq %rax, %rdx
incq %rdx
leaq -0x190(%rbp), %rdi
movl $0x1, %ecx
callq 0x55a0
jmp 0x28ad7
xorl %eax, %eax
movl %eax, %esi
leaq -0x190(%rbp), %rdi
movl $0xa, %edx
callq 0x41890
movl %eax, -0x25c(%rbp)
jmp 0x28af4
movl -0x25c(%rbp), %eax
movl %eax, -0x90(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x5aa8
jmp 0x28b31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x5aa8
jmp 0x28c70
leaq -0x58(%rbp), %rdi
leaq 0x1ae27(%rip), %rsi     # 0x43963
xorl %eax, %eax
movl %eax, %edx
callq 0x5a70
cmpq $-0x1, %rax
jne 0x28b93
leaq -0xc8(%rbp), %rdi
callq 0x13c40
testb $0x1, %al
jne 0x28b80
movq -0x18(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x18870
jmp 0x28b6d
movb $0x1, -0x1(%rbp)
movl $0x1, -0x194(%rbp)
jmp 0x28c53
movb $0x0, -0x1(%rbp)
movl $0x1, -0x194(%rbp)
jmp 0x28c53
leaq 0x1adcb(%rip), %rsi     # 0x43965
xorl %eax, %eax
movl %eax, %edx
leaq -0x58(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x5270
movq -0x268(%rbp), %rsi
movq %rax, %rdx
leaq -0x1b8(%rbp), %rdi
movq $-0x1, %rcx
callq 0x55a0
jmp 0x28bcd
leaq -0x58(%rbp), %rdi
movq %rdi, -0x270(%rbp)
leaq -0x1b8(%rbp), %rsi
movq %rsi, -0x278(%rbp)
callq 0x56d0
movq -0x278(%rbp), %rdi
callq 0x5aa8
movq -0x270(%rbp), %rdi
leaq 0x1ad64(%rip), %rsi     # 0x43969
xorl %eax, %eax
movl %eax, %edx
callq 0x5270
movq -0x270(%rbp), %rsi
movq %rax, %rdx
leaq -0x1d8(%rbp), %rdi
movq $-0x1, %rcx
callq 0x55a0
jmp 0x28c2d
leaq -0x58(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x56d0
leaq -0x1d8(%rbp), %rdi
callq 0x5aa8
movl $0x0, -0x194(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x5aa8
movl -0x194(%rbp), %eax
testl %eax, %eax
jne 0x28c7e
jmp 0x28c6b
jmp 0x28722
leaq -0x110(%rbp), %rdi
callq 0x5aa8
jmp 0x28cb6
leaq -0xc8(%rbp), %rdi
callq 0x8ec0
leaq -0xb0(%rbp), %rdi
callq 0x8ec0
leaq -0x58(%rbp), %rdi
callq 0x5aa8
leaq -0x38(%rbp), %rdi
callq 0x5aa8
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq
leaq -0xc8(%rbp), %rdi
callq 0x8ec0
leaq -0xb0(%rbp), %rdi
callq 0x8ec0
leaq -0x58(%rbp), %rdi
callq 0x5aa8
leaq -0x38(%rbp), %rdi
callq 0x5aa8
movq -0x88(%rbp), %rdi
callq 0x5950
nopl (%rax)