// File: 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:
subq $0x218, %rsp            # imm = 0x218
movq %rdx, 0x58(%rsp)
movq %rdi, 0x48(%rsp)
movb %cl, %al
movq %rdi, %rcx
movq %rcx, 0x50(%rsp)
movq %rdi, 0x210(%rsp)
movq %rsi, 0x208(%rsp)
movq %rdx, 0x200(%rsp)
andb $0x1, %al
movb %al, 0x1ff(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0x98310
movq 0x58(%rsp), %rdi
callq 0x977c0
testb $0x1, %al
jne 0xa7236
movq 0x58(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x99640
movq %rax, 0x40(%rsp)
jmp 0xa720c
movq 0x40(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0xa7236
movq 0x58(%rsp), %rdx
leaq 0x3f054(%rip), %rsi     # 0xe6279
leaq 0x1c0(%rsp), %rdi
callq 0x925e0
jmp 0xa7234
jmp 0xa724c
movq 0x58(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0x8f440
jmp 0xa724a
jmp 0xa724c
movq 0x58(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
movq %rsi, 0x30(%rsp)
callq 0x94870
movq 0x30(%rsp), %rdi
callq 0x99830
leaq 0x18f(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x98200
movq 0x38(%rsp), %rdx
leaq 0x3dee2(%rip), %rsi     # 0xe516d
leaq 0x190(%rsp), %rdi
callq 0x95700
jmp 0xa729a
leaq 0x18f(%rsp), %rdi
callq 0x938a0
movq 0x58(%rsp), %rdi
callq 0x91060
movq %rax, %rsi
leaq 0x190(%rsp), %rdi
callq 0x96d70
jmp 0xa72c3
movq $0x1, 0x180(%rsp)
jmp 0xa72d1
leaq 0x3efa1(%rip), %rsi     # 0xe6279
leaq 0x190(%rsp), %rdi
callq 0x92d80
jmp 0xa72e7
movq 0x58(%rsp), %rdi
movq 0x180(%rsp), %rdx
leaq 0x3ef7e(%rip), %rsi     # 0xe6279
callq 0x995d0
movq 0x58(%rsp), %rsi
movq %rax, 0x178(%rsp)
movq 0x180(%rsp), %rdx
movq 0x178(%rsp), %rcx
subq %rdx, %rcx
leaq 0x158(%rsp), %rdi
callq 0x93510
jmp 0xa732f
leaq 0x138(%rsp), %rdi
callq 0x959e0
movq 0x58(%rsp), %rdi
movq 0x178(%rsp), %rax
movq %rax, 0x28(%rsp)
callq 0x91060
movq %rax, %rcx
movq 0x28(%rsp), %rax
addq $0x1, %rcx
cmpq %rcx, %rax
jb 0xa749b
leaq 0x158(%rsp), %rdi
leaq 0x3cf8c(%rip), %rsi     # 0xe4303
xorl %eax, %eax
movl %eax, %edx
callq 0x995d0
movq %rax, 0x130(%rsp)
cmpq $-0x1, 0x130(%rsp)
je 0xa7499
movq 0x130(%rsp), %rdx
leaq 0x110(%rsp), %rdi
leaq 0x158(%rsp), %rsi
movq $-0x1, %rcx
callq 0x93510
jmp 0xa73bd
leaq 0x138(%rsp), %rdi
leaq 0x110(%rsp), %rsi
movq %rsi, 0x20(%rsp)
callq 0x94870
movq 0x20(%rsp), %rdi
callq 0x99830
movq 0x130(%rsp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq 0xf0(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x93510
jmp 0xa7404
leaq 0x158(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x94870
leaq 0xf0(%rsp), %rdi
callq 0x99830
jmp 0xa7499
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0xa78b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
leaq 0x18f(%rsp), %rdi
callq 0x938a0
jmp 0xa78b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0xa78a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0xa77a9
jmp 0xa749b
xorl %eax, %eax
movl %eax, %esi
leaq 0x158(%rsp), %rdi
callq 0x99640
movq %rax, 0x18(%rsp)
jmp 0xa74b3
movq 0x18(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0xa754c
leaq 0x3dca4(%rip), %rsi     # 0xe516f
leaq 0x190(%rsp), %rdi
callq 0x92d80
jmp 0xa74da
leaq 0xd0(%rsp), %rdi
leaq 0x158(%rsp), %rsi
movl $0x1, %edx
movq $-0x1, %rcx
callq 0x93510
jmp 0xa74fd
leaq 0x1e0(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x98c00
jmp 0xa7514
leaq 0xd0(%rsp), %rdi
callq 0x99830
jmp 0xa76b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x99830
jmp 0xa77a9
xorl %eax, %eax
movl %eax, %esi
leaq 0x158(%rsp), %rdi
callq 0x99640
movq %rax, 0x10(%rsp)
jmp 0xa7564
movq 0x10(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
jne 0xa7696
leaq 0x3dbfb(%rip), %rsi     # 0xe5177
leaq 0x190(%rsp), %rdi
callq 0x92d80
jmp 0xa758b
leaq 0x158(%rsp), %rdi
callq 0x91060
movb $0x0, 0xae(%rsp)
cmpq $0x1, %rax
jne 0xa75dd
leaq 0xaf(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x98200
movq 0x8(%rsp), %rdx
movb $0x1, 0xae(%rsp)
leaq 0x3dbb0(%rip), %rsi     # 0xe517c
leaq 0xb0(%rsp), %rdi
callq 0x95700
jmp 0xa75db
jmp 0xa7602
leaq 0xb0(%rsp), %rdi
leaq 0x158(%rsp), %rsi
movl $0x1, %edx
movq $-0x1, %rcx
callq 0x93510
jmp 0xa7600
jmp 0xa7602
leaq 0x1e0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x98c00
jmp 0xa7619
leaq 0xb0(%rsp), %rdi
callq 0x99830
testb $0x1, 0xae(%rsp)
jne 0xa7632
jmp 0xa763f
leaq 0xaf(%rsp), %rdi
callq 0x938a0
jmp 0xa76af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
jmp 0xa7678
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x99830
testb $0x1, 0xae(%rsp)
jne 0xa7684
jmp 0xa7691
leaq 0xaf(%rsp), %rdi
callq 0x938a0
jmp 0xa77a9
leaq 0x190(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x94d40
jmp 0xa76ad
jmp 0xa76af
jmp 0xa76b1
movq 0x58(%rsp), %rdi
movq 0x178(%rsp), %rax
movq %rax, (%rsp)
callq 0x91060
movq %rax, %rcx
movq (%rsp), %rax
cmpq %rcx, %rax
jb 0xa775c
leaq 0x138(%rsp), %rdi
callq 0x977c0
testb $0x1, %al
jne 0xa774f
leaq 0x3d07a(%rip), %rsi     # 0xe4769
leaq 0x88(%rsp), %rdi
leaq 0x138(%rsp), %rdx
callq 0x925e0
jmp 0xa7706
leaq 0x190(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x94d40
jmp 0xa771d
leaq 0x88(%rsp), %rdi
callq 0x99830
jmp 0xa774f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x99830
jmp 0xa77a9
movl $0x3, 0x84(%rsp)
jmp 0xa777b
movq 0x178(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x180(%rsp)
movl $0x0, 0x84(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x99830
leaq 0x158(%rsp), %rdi
callq 0x99830
movl 0x84(%rsp), %eax
testl %eax, %eax
je 0xa77a4
jmp 0xa77a2
jmp 0xa77c8
jmp 0xa72cf
leaq 0x138(%rsp), %rdi
callq 0x99830
leaq 0x158(%rsp), %rdi
callq 0x99830
jmp 0xa78a4
testb $0x1, 0x1ff(%rsp)
je 0xa77ea
leaq 0x3d9ab(%rip), %rsi     # 0xe5184
leaq 0x190(%rsp), %rdi
callq 0x92d80
jmp 0xa77e8
jmp 0xa7818
leaq 0x3d98d(%rip), %rsi     # 0xe517e
leaq 0x190(%rsp), %rdi
callq 0x92d80
jmp 0xa7800
leaq 0x3d975(%rip), %rsi     # 0xe517c
leaq 0x1e0(%rsp), %rdi
callq 0x94670
jmp 0xa7816
jmp 0xa7818
leaq 0x60(%rsp), %rdi
leaq 0x190(%rsp), %rsi
movl $0x10, %edx
callq 0x8eab0
jmp 0xa7831
movq 0x48(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x1e0(%rsp), %rdx
callq 0x92950
jmp 0xa784a
leaq 0x60(%rsp), %rdi
callq 0x92f10
movl $0x1, 0x84(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x99830
leaq 0x1e0(%rsp), %rdi
callq 0x91220
movq 0x50(%rsp), %rax
addq $0x218, %rsp            # imm = 0x218
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1b8(%rsp)
movl %eax, 0x1b4(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x92f10
leaq 0x190(%rsp), %rdi
callq 0x99830
leaq 0x1e0(%rsp), %rdi
callq 0x91220
movq 0x1b8(%rsp), %rdi
callq 0x981c0
nopl (%rax,%rax)