// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x38(%rsi), %r14
cmpq 0x40(%rsi), %r14
je 0x9cad
movq %rsi, %r15
xorl %ebp, %ebp
leaq 0x8(%rsp), %r13
movq %rbp, %r12
movl 0x70(%r14), %eax
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x9be3
movq %r14, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xa960
jmp 0x9c2d
cmpl $0x1, %eax
jne 0x9c13
movq 0x58(%r14), %rbp
cmpq 0x8(%rbx), %rbp
jne 0x9c17
testq %rbp, %rbp
je 0x9cc6
movq (%rbx), %rsi
movq 0x50(%r14), %rdi
movq %rbp, %rdx
callq 0x4480
testl %eax, %eax
jne 0x9c17
jmp 0x9cc6
movq 0x58(%r14), %rbp
movq 0x50(%r14), %rsi
movq %rbx, %rdi
xorl %edx, %edx
movq %rbp, %rcx
callq 0x4780
testq %rax, %rax
je 0x9c3f
movq %r12, %rbp
addq $0x198, %r14            # imm = 0x198
cmpq 0x40(%r15), %r14
jne 0x9bc0
jmp 0x9c57
movq %r14, %rbp
testq %r12, %r12
je 0x9c30
movq 0x58(%r12), %rax
movq %r14, %rbp
cmpq 0x58(%r14), %rax
jae 0x9c2d
jmp 0x9c30
testq %rbp, %rbp
je 0x9cad
cmpl $0x4, 0x70(%rbp)
je 0x9cc3
movq 0x38(%rbp), %r12
movq 0x40(%rbp), %rax
cmpq %rax, %r12
je 0x9caf
leaq 0x10(%rsp), %r14
leaq 0x8(%rsp), %r15
movl 0x70(%r12), %ecx
andl $-0x2, %ecx
cmpl $0x2, %ecx
jne 0x9c9f
movq 0x10(%rsp), %rsi
movq %r12, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rdx
callq 0xaf7e
movq 0x40(%rbp), %rax
addq $0x198, %r12            # imm = 0x198
cmpq %rax, %r12
jne 0x9c79
jmp 0x9caf
xorl %ebp, %ebp
leaq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x9db8
testq %rax, %rax
cmovneq %rax, %rbp
movq %rbp, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9cdd
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9cf3
jmp 0x9cf3
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9d0d
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4790
nop