// File: solaldunckel[P]webserv/srcs/Config/RequestConfig.cpp
// Function: RequestConfig::getLocationForRequest(ServerConfig*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
ServerConfig *RequestConfig::getLocationForRequest(ServerConfig *server, std::string &target) {
  ServerConfig *location = NULL;

  std::vector<ServerConfig*> reg_locations;

  for (std::vector<ServerConfig>::iterator it = server->locations_.begin(); it != server->locations_.end(); it++) {
    if (it->modifier_ != 2 && it->modifier_ != 3) {
      if (it->modifier_ == 1 && it->uri_ == target)
        return &(*it);
      else if (target.find(it->uri_) == 0) {
        if (location && location->uri_.length() < it->uri_.length())
          location = &(*it);
        else if (!location)
          location = &(*it);
      }
    }
    else
      reg_locations.push_back(&(*it));
  }

  if (location && location->modifier_ == 4)
    return location;

  if (location && !location->locations_.empty()) {
    for (std::vector<ServerConfig>::iterator it = location->locations_.begin(); it != location->locations_.end(); it++) {
      if (it->modifier_ == 2 || it->modifier_ == 3) {
        reg_locations.insert(reg_locations.begin(), &(*it));
      }
    }
  }

  ServerConfig *reg = match_regexp(reg_locations, target);

  if (reg)
    return reg;

  return location;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq $0x0, -0x28(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x13650
movq -0x18(%rbp), %rdi
addq $0x38, %rdi
callq 0xef90
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
addq $0x38, %rdi
callq 0xbdd0
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x13670
testb $0x1, %al
jne 0x127fb
jmp 0x12951
leaq -0x48(%rbp), %rdi
callq 0x136b0
cmpl $0x2, 0x70(%rax)
je 0x12903
leaq -0x48(%rbp), %rdi
callq 0x136b0
cmpl $0x3, 0x70(%rax)
je 0x12903
leaq -0x48(%rbp), %rdi
callq 0x136b0
cmpl $0x1, 0x70(%rax)
jne 0x12868
leaq -0x48(%rbp), %rdi
callq 0x136b0
movq %rax, %rdi
addq $0x50, %rdi
movq -0x20(%rbp), %rsi
callq 0x13770
testb $0x1, %al
jne 0x1284f
jmp 0x12868
leaq -0x48(%rbp), %rdi
callq 0x13850
movq %rax, -0x8(%rbp)
movl $0x1, -0x54(%rbp)
jmp 0x12ad0
movq -0x20(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x136b0
movq -0xc8(%rbp), %rdi
movq %rax, %rsi
addq $0x50, %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x5a90
cmpq $0x0, %rax
jne 0x128ff
cmpq $0x0, -0x28(%rbp)
je 0x128e7
movq -0x28(%rbp), %rdi
addq $0x50, %rdi
callq 0x5830
movq %rax, -0xd0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x136b0
movq %rax, %rdi
addq $0x50, %rdi
callq 0x5830
movq %rax, %rcx
movq -0xd0(%rbp), %rax
cmpq %rcx, %rax
jae 0x128e7
leaq -0x48(%rbp), %rdi
callq 0x13850
movq %rax, -0x28(%rbp)
jmp 0x128fd
cmpq $0x0, -0x28(%rbp)
jne 0x128fb
leaq -0x48(%rbp), %rdi
callq 0x13850
movq %rax, -0x28(%rbp)
jmp 0x128fd
jmp 0x128ff
jmp 0x12901
jmp 0x1293b
leaq -0x48(%rbp), %rdi
callq 0x13850
movq %rax, -0x60(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x13820
jmp 0x1291f
jmp 0x1293b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x13b60
jmp 0x12ae6
jmp 0x1293d
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x138b0
movq %rax, -0x78(%rbp)
jmp 0x127d4
cmpq $0x0, -0x28(%rbp)
je 0x12976
movq -0x28(%rbp), %rax
cmpl $0x4, 0x70(%rax)
jne 0x12976
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x54(%rbp)
jmp 0x12ad0
cmpq $0x0, -0x28(%rbp)
je 0x12a78
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
callq 0x9390
testb $0x1, %al
jne 0x12a78
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
callq 0xef90
movq %rax, -0x80(%rbp)
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
callq 0xbdd0
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x13670
testb $0x1, %al
jne 0x129d4
jmp 0x12a76
leaq -0x80(%rbp), %rdi
callq 0x136b0
cmpl $0x2, 0x70(%rax)
je 0x129f2
leaq -0x80(%rbp), %rdi
callq 0x136b0
cmpl $0x3, 0x70(%rax)
jne 0x12a5d
leaq -0x40(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x13a20
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x13c00
leaq -0x80(%rbp), %rdi
callq 0x13850
movq -0xe0(%rbp), %rdi
movq %rax, -0xa0(%rbp)
movq -0x90(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x13bc0
movq %rax, -0xd8(%rbp)
jmp 0x12a4f
movq -0xd8(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0x12a5f
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
callq 0x138b0
movq %rax, -0xb0(%rbp)
jmp 0x129a7
jmp 0x12a78
movq -0xc0(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq -0x40(%rbp), %rsi
callq 0x12bb0
movq %rax, -0xe8(%rbp)
jmp 0x12a95
movq -0xe8(%rbp), %rax
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0xb8(%rbp)
je 0x12ac1
movq -0xb8(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x54(%rbp)
jmp 0x12ad0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0x54(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x13b60
movq -0x8(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x5950
nop