// File: /workspace/github_cpp_makefile_star2_O2/alfanick[P]rest-cpp/src/rest/router.cpp
// Function: REST::Router::to_regex(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
std::pair<std::regex, std::vector<std::string>> Router::to_regex(std::string path, bool exact) {
    std::vector<std::string> params;
    path = ((!path.empty()) && (path[0] != '/')) ? "/" + path : path;

    std::string regex = "^";
    regex.reserve(path.size());

    size_t start = 1;

    while (true) {
      regex += "/";
      size_t next = path.find("/", start);

      std::string section = path.substr(start, next - start);
      std::string format;

      if (next >= path.size()+1) {
        size_t dot = section.find(".");

        if (dot != std::string::npos) {
          format = section.substr(dot);
          section = section.substr(0, dot);
        }
      }

      if (section[0] == ':') {
        regex += "([^/]+)";
        params.emplace_back(section.substr(1));
      } else
      if (section[0] == '*') {
        regex += "(.+)";
        params.emplace_back(section.size() == 1 ? "*" : section.substr(1));
      } else {
        regex += section;
      }

      if (next >= path.size()) {
        if (!format.empty())
          regex += "\\" + format;
        break;
      }

      start = next + 1;
    }

    if (exact) {
      regex += "$";
    } else {
      regex += "/?(.*)$";
      params.emplace_back("*");
    }

    return std::make_pair(std::regex(regex), params);
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
vxorps %xmm0, %xmm0, %xmm0
andq $0x0, 0x70(%rsp)
movl %ecx, %ebp
movq %rdx, %r14
movq %rdi, %r15
vmovaps %xmm0, 0x60(%rsp)
cmpq $0x0, 0x8(%rdx)
je 0x37ffa
movq (%r14), %rax
cmpb $0x2f, (%rax)
jne 0x38009
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x328c0
jmp 0x3801d
leaq 0x140c9(%rip), %rsi     # 0x4c0d9
leaq 0x30(%rsp), %rdi
movq %r14, %rdx
callq 0x319b0
leaq 0x30(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x32380
movq %rbx, %rdi
callq 0x33b38
leaq 0x12f91(%rip), %rsi     # 0x4afcd
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x30a10
movq 0x8(%r14), %rsi
movl %ebp, 0xc(%rsp)
movq %r15, 0x50(%rsp)
movq %r14, 0x58(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x32ec0
pushq $0x1
popq %r15
leaq 0x14067(%rip), %r12     # 0x4c0d9
leaq 0x98(%rsp), %rbx
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x33910
movq 0x58(%rsp), %r14
movq %r12, %rbp
movq %r12, %rsi
movq %r15, %rdx
movq %r14, %rdi
callq 0x33aa0
movq %rax, %rcx
movq %rax, %r12
subq %r15, %rcx
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x31ea0
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
andq $0x0, 0x80(%rsp)
movb $0x0, 0x88(%rsp)
movq 0x8(%r14), %rax
incq %rax
cmpq %rax, %r12
jb 0x38150
leaq 0x10(%rsp), %rdi
leaq 0x120df(%rip), %rsi     # 0x4a1cb
xorl %edx, %edx
callq 0x33aa0
cmpq $-0x1, %rax
je 0x38150
movq %rbx, %rdi
movq %rbx, %r14
leaq 0x10(%rsp), %rbx
movq %rax, %r13
movq %rax, %rdx
movq %rbx, %rsi
pushq $-0x1
popq %rcx
callq 0x31ea0
leaq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0x32380
movq %r14, %rdi
callq 0x33b38
movq %r14, %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %r13, %rcx
callq 0x31ea0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32380
movq %r14, %rdi
callq 0x33b38
movq %r14, %rbx
movq 0x10(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x2a, %eax
je 0x381a2
leaq 0x10(%rsp), %rsi
cmpl $0x3a, %eax
jne 0x381d4
leaq 0x30(%rsp), %rdi
leaq 0x12e5c(%rip), %rsi     # 0x4afcf
callq 0x33910
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
pushq $0x1
popq %rdx
pushq $-0x1
popq %rcx
callq 0x31ea0
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x337f0
movq %rbx, %rdi
callq 0x33b38
jmp 0x3820c
leaq 0x30(%rsp), %rdi
leaq 0x12e29(%rip), %rsi     # 0x4afd7
callq 0x33910
movq 0x18(%rsp), %r13
cmpq $0x1, %r13
jne 0x381e0
leaq 0x12e17(%rip), %rsi     # 0x4afdc
leaq 0xb(%rsp), %rdx
movq %rbx, %rdi
callq 0x30a10
jmp 0x381f3
leaq 0x30(%rsp), %rdi
callq 0x33a00
jmp 0x3820c
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
pushq $0x1
popq %rdx
pushq $-0x1
popq %rcx
callq 0x31ea0
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x337f0
movq %rbx, %rdi
callq 0x33b38
cmpq $0x1, %r13
movq 0x58(%rsp), %rax
movq 0x8(%rax), %r13
cmpq %r13, %r12
jae 0x38221
leaq 0x1(%r12), %r15
jmp 0x38255
cmpq $0x0, 0x80(%rsp)
je 0x38255
leaq 0x123f8(%rip), %rsi     # 0x4a62b
leaq 0x78(%rsp), %rdx
movq %rbx, %rdi
callq 0x319b0
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x33a00
movq %rbx, %rdi
callq 0x33b38
leaq 0x78(%rsp), %rdi
callq 0x33b38
leaq 0x10(%rsp), %rdi
callq 0x33b38
cmpq %r13, %r12
movq %rbp, %r12
jb 0x3807a
cmpb $0x0, 0xc(%rsp)
je 0x38294
leaq 0x12d61(%rip), %rsi     # 0x4afe4
leaq 0x30(%rsp), %rdi
callq 0x33910
movq 0x50(%rsp), %rbx
jmp 0x382bb
leaq 0x12d43(%rip), %rsi     # 0x4afde
leaq 0x30(%rsp), %rdi
callq 0x33910
movq 0x50(%rsp), %rbx
leaq 0x12d2b(%rip), %rsi     # 0x4afdc
leaq 0x60(%rsp), %rdi
callq 0x322e0
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
pushq $0x10
popq %rdx
callq 0x30800
leaq 0x10(%rsp), %rsi
leaq 0x60(%rsp), %rdx
movq %rbx, %rdi
callq 0x31370
leaq 0x10(%rsp), %rdi
callq 0x31cd0
leaq 0x30(%rsp), %rdi
callq 0x33b38
leaq 0x60(%rsp), %rdi
callq 0x31420
movq %rbx, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rsp), %rdi
movq %rax, %rbx
callq 0x31cd0
jmp 0x38383
jmp 0x38367
jmp 0x38367
jmp 0x38327
movq %rax, %rbx
jmp 0x3838d
jmp 0x38367
jmp 0x3836c
jmp 0x38348
jmp 0x3836c
jmp 0x3836c
leaq 0x98(%rsp), %rdi
movq %rax, %rbx
callq 0x33b38
jmp 0x3835d
leaq 0x98(%rsp), %rdi
movq %rax, %rbx
callq 0x33b38
jmp 0x3836f
movq %rax, %rbx
cmpq $0x1, %r13
jmp 0x3836f
jmp 0x3836c
jmp 0x38367
movq %rax, %rbx
jmp 0x38383
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x33b38
leaq 0x10(%rsp), %rdi
callq 0x33b38
leaq 0x30(%rsp), %rdi
callq 0x33b38
leaq 0x60(%rsp), %rdi
callq 0x31420
movq %rbx, %rdi
callq 0x33510
nop