// File: /workspace/github_cpp_makefile_star2_O1/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
sete %r13b
je 0x9bfe
movq %rsi, %r15
xorl %ebp, %ebp
movl 0x70(%r14), %eax
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x9b8b
movq %r14, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0xa906
jmp 0x9bce
cmpl $0x1, %eax
jne 0x9bb7
movq 0x58(%r14), %rdx
cmpq 0x8(%rbx), %rdx
jne 0x9bb7
testq %rdx, %rdx
je 0x9c9a
movq (%rbx), %rsi
movq 0x50(%r14), %rdi
callq 0x4470
testl %eax, %eax
je 0x9c9a
movq 0x50(%r14), %rsi
movq 0x58(%r14), %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x4770
testq %rax, %rax
je 0x9be7
movq %rbp, %r12
addq $0x198, %r14            # imm = 0x198
movq %r12, %rbp
cmpq 0x40(%r15), %r14
sete %r13b
jne 0x9b69
jmp 0x9c01
movq %r14, %r12
testq %rbp, %rbp
je 0x9bd1
movq 0x58(%rbp), %rax
movq %r14, %r12
cmpq 0x58(%r14), %rax
jae 0x9bce
jmp 0x9bd1
xorl %r12d, %r12d
testq %r12, %r12
je 0x9c5a
cmpl $0x4, 0x70(%r12)
je 0x9c6e
movq 0x38(%r12), %r13
cmpq 0x40(%r12), %r13
je 0x9c5a
cmpq 0x40(%r12), %r13
je 0x9c5a
leaq 0x10(%rsp), %r14
leaq 0x8(%rsp), %r15
movl 0x70(%r13), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x9c4c
movq 0x10(%rsp), %rsi
movq %r13, 0x8(%rsp)
movq %r14, %rdi
movq %r15, %rdx
callq 0xaf12
addq $0x198, %r13            # imm = 0x198
cmpq 0x40(%r12), %r13
jne 0x9c2b
leaq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x9d5e
testq %rax, %rax
cmovneq %rax, %r12
movq %r12, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9c88
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4460
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %r12
testb $0x1, %r13b
jne 0x9c01
jmp 0x9c71
jmp 0x9cad
jmp 0x9cad
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9cc7
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4460
movq %rbx, %rdi
callq 0x4780
nop