// File: /workspace/github_cpp_makefile_star2_O2/joncampbell123[P]haxcc/haxpp.cpp
// Function: do_macro_expand(std::vector<token, std::allocator<token>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>&, __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void do_macro_expand(token_string &tokens,const string &ident,string::iterator &li,const string::iterator lie,const int32_t lineno,const string &source) {
    auto mi = macro_store.find(ident);
    if (mi != macro_store.end()) {
        const macro_t &macro = mi->second;
        bool variadic_given = false;
        vector<string> param;
        string fstr;

        if (macro.parens) {
            parse_skip_whitespace(li,lie);
            if (strit_next_match_inc(li,lie,'(')) {
                do {
                    bool variad = macro.last_param_variadic && (param.size()+size_t(1)) == macro.param.size();

                    if (variad)
                        variadic_given = variad;

                    parse_skip_whitespace(li,lie);
                    if (li == lie) throw invalid_argument("macro invocation parameter list ended suddenly");
                    if (strit_next_match_inc(li,lie,')')) break;

                    if (param.size() >= macro.param.size())
                        throw invalid_argument("macro invocation parameter list with too many parameters");
                    param.push_back(do_macro_expand_read_invoke_param(li,lie,variad));

                    parse_skip_whitespace(li,lie);
                    if (li == lie) throw invalid_argument("macro invocation parameter list ended suddenly");
                    if (strit_next_match_inc(li,lie,')'))
                        break;
                    else if (!strit_next_match_inc(li,lie,','))
                        throw invalid_argument(string("macro invocation parameter list unexpected char ") + *li);
                } while(1);

                /* enforce required param count. the one for the variadic macro is not required to be present. */
                size_t reqd_params = macro.param.size();
                if (macro.last_param_variadic && macro.last_param_optional && reqd_params != size_t(0)) reqd_params--;
                if (param.size() < reqd_params)
                    throw invalid_argument("macro invocation parameter list has too few parameters");

                /* fill in the rest with blank */
                while (param.size() < macro.param.size())
                    param.push_back(string());

                parse_skip_whitespace(li,lie);
            }
            else {
                throw invalid_argument("macro invoked without parenthesis when defined with parameters");
            }
        }

        for (vector<token>::const_iterator si=macro.subst.begin();si!=macro.subst.end();) {
            if (do_macro_expand_val(fstr,si,macro.subst.end(),param,macro,variadic_given)) {
                while (si != macro.subst.end() && (*si).tval == token::TOKEN_PASTE) {
                    si++;
                    if (si == macro.subst.end())
                        throw invalid_argument("token paste must be followed by another token");
                    if (!do_macro_expand_val(fstr,si,macro.subst.end(),param,macro,variadic_given))
                        throw invalid_argument("token paste was not followed by expandable value");
                }

                if (si != macro.subst.end())
                    fstr += " ";
            }
            else if ((*si).tval == token::STRINGIFY) {
                si++;
                if (si == macro.subst.end())
                    throw invalid_argument("macro stringify with nothing to stringify");

                string tmpr;
                if (!do_macro_expand_val(tmpr,si,macro.subst.end(),param,macro,variadic_given))
                    throw invalid_argument("stringify was not followed by expandable value");

                if (!tmpr.empty())
                    fstr += pp_stringify(tmpr) + " ";
            }
            else if ((*si).tval == token::COMMA) {
                si++;
                auto si2 = si;
                if (si2 != macro.subst.end() && (*si2).tval == token::TOKEN_PASTE) { /* , ## */
                    si2++;
                    if (si2 != macro.subst.end() && (*si2).tval == token::VA_ARGS) { /* , ## __VA_ARGS__ */
                        si = si2;

                        if (variadic_given) {
                            fstr += ",";
                            do_macro_expand_val(fstr,si,macro.subst.end(),param,macro,variadic_given);
                        }
                        else {
                            si++;
                        }

                        continue;
                    }
                }

                fstr += ",";
            }
            else {
                throw invalid_argument("unexpected token in macro expansion");
            }
        }

        parse_tokens(tokens,fstr.begin(),fstr.end(),lineno,source);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r9, 0x60(%rsp)
movl %r8d, 0x54(%rsp)
movq %rcx, %r13
movq %rdx, %r12
movq %rdi, 0x58(%rsp)
leaq 0x12d90(%rip), %rdi     # 0x18220
callq 0xd03c
movq %rax, %r15
leaq 0x12d89(%rip), %rax     # 0x18228
cmpq %rax, %r15
je 0x58b5
xorps %xmm0, %xmm0
andq $0x0, 0x20(%rsp)
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movaps %xmm0, 0x10(%rsp)
movb $0x0, (%rax)
cmpb $0x1, 0x72(%r15)
jne 0x5671
movq %r12, %rdi
movq %r13, %rsi
callq 0x3055
movq (%r12), %rax
cmpq %r13, %rax
je 0x5a52
cmpb $0x28, (%rax)
jne 0x5a52
movl $0x0, 0x4(%rsp)
leaq 0x30(%rsp), %rbx
leaq 0x10(%rsp), %r14
incq %rax
movq %rax, (%r12)
cmpb $0x1, 0x70(%r15)
jne 0x5547
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x5, %rax
incq %rax
movq 0x60(%r15), %rcx
subq 0x58(%r15), %rcx
sarq $0x5, %rcx
cmpq %rcx, %rax
sete %bpl
movl 0x4(%rsp), %eax
orb %bpl, %al
movl %eax, 0x4(%rsp)
jmp 0x5549
xorl %ebp, %ebp
movq %r12, %rdi
movq %r13, %rsi
callq 0x3055
movq (%r12), %rax
cmpq %r13, %rax
je 0x5913
cmpb $0x29, (%rax)
je 0x55d3
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
movq 0x60(%r15), %rcx
subq 0x58(%r15), %rcx
cmpq %rcx, %rax
jae 0x592f
movzbl %bpl, %ecx
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x52f4
movq %r14, %rdi
movq %rbx, %rsi
callq 0xd0c6
movq %rbx, %rdi
callq 0x2408
movq %r12, %rdi
movq %r13, %rsi
callq 0x3055
movq (%r12), %rax
cmpq %r13, %rax
je 0x594b
movzbl (%rax), %ecx
cmpl $0x2c, %ecx
je 0x5508
cmpl $0x29, %ecx
jne 0x59ee
incq %rax
movq %rax, (%r12)
movq 0x58(%r15), %rcx
movq 0x60(%r15), %rax
movq %rax, %rdi
subq %rcx, %rdi
sarq $0x5, %rdi
cmpb $0x1, 0x70(%r15)
jne 0x5603
cmpq %rcx, %rax
setne %dl
andb 0x71(%r15), %dl
movzbl %dl, %edx
subq %rdx, %rdi
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq %rsi, %r8
subq %rdx, %r8
sarq $0x5, %r8
cmpq %rdi, %r8
jb 0x5a84
leaq 0x40(%rsp), %rbp
leaq 0x10(%rsp), %rbx
leaq 0x30(%rsp), %r14
subq %rcx, %rax
subq %rdx, %rsi
cmpq %rax, %rsi
jae 0x5675
movq %rbp, 0x30(%rsp)
andq $0x0, 0x38(%rsp)
movb $0x0, 0x40(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd0c6
movq %r14, %rdi
callq 0x2408
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x58(%r15), %rcx
movq 0x60(%r15), %rax
jmp 0x562f
xorl %ecx, %ecx
jmp 0x5684
movq %r12, %rdi
movq %r13, %rsi
callq 0x3055
movl 0x4(%rsp), %ecx
movq %r15, %r12
addq $0x40, %r12
movq 0x40(%r15), %rax
leaq 0x8(%rsp), %r13
movq %rax, (%r13)
movl %ecx, 0x4(%rsp)
movzbl %cl, %ebx
andl $0x1, %ebx
leaq 0x88(%rsp), %rbp
leaq 0x10(%rsp), %r14
movq 0x48(%r15), %rdx
cmpq %rdx, %rax
je 0x5878
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rcx
movq %r12, %r8
movl %ebx, %r9d
callq 0x5b7a
testb %al, %al
je 0x571e
movq 0x48(%r15), %rdx
movq 0x8(%rsp), %rax
cmpq %rdx, %rax
je 0x5861
cmpl $0x7b, (%rax)
jne 0x5841
addq $0x70, %rax
movq %rax, 0x8(%rsp)
cmpq %rdx, %rax
je 0x58c7
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rcx
movq %r12, %r8
movl %ebx, %r9d
callq 0x5b7a
testb %al, %al
jne 0x56d4
jmp 0x58e3
movq 0x8(%rsp), %rax
movl (%rax), %ecx
cmpl $0x17, %ecx
je 0x57e3
cmpl $0x7a, %ecx
jne 0x597b
addq $0x70, %rax
movq %rax, 0x8(%rsp)
movq 0x48(%r15), %rdx
cmpq %rdx, %rax
je 0x59cf
leaq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
andq $0x0, 0x38(%rsp)
movb $0x0, 0x40(%rsp)
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rcx
movq %r12, %r8
movl %ebx, %r9d
callq 0x5b7a
testb %al, %al
je 0x599a
cmpq $0x0, 0x38(%rsp)
je 0x57d7
leaq 0xa8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x53bf
leaq 0x68(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0xa481(%rip), %rdx      # 0xfc2f
callq 0xb244
movq %rbp, %rdi
leaq 0x68(%rsp), %rsi
callq 0x23e0
leaq 0x68(%rsp), %rdi
callq 0x2408
leaq 0xa8(%rsp), %rdi
callq 0x2408
leaq 0x30(%rsp), %rdi
callq 0x2408
jmp 0x5861
leaq 0x70(%rax), %rdx
movq %rdx, 0x8(%rsp)
movq 0x48(%r15), %rcx
cmpq %rcx, %rdx
je 0x5852
cmpl $0x7b, (%rdx)
jne 0x5852
leaq 0xe0(%rax), %rdx
cmpq %rcx, %rdx
je 0x5852
cmpl $0x7c, (%rdx)
jne 0x5852
movq %rdx, 0x8(%rsp)
testb $0x1, 0x4(%rsp)
je 0x586b
movq %rbp, %rdi
leaq 0xa8df(%rip), %rsi      # 0x10100
callq 0x23b0
movq 0x48(%r15), %rdx
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rcx
movq %r12, %r8
pushq $0x1
popq %r9
callq 0x5b7a
jmp 0x5861
movq %rbp, %rdi
leaq 0xa3e4(%rip), %rsi      # 0xfc2f
callq 0x23b0
jmp 0x5861
movq %rbp, %rdi
leaq 0xa8a4(%rip), %rsi      # 0x10100
callq 0x23b0
movq 0x8(%rsp), %rax
jmp 0x56af
addq $0x150, %rax            # imm = 0x150
movq %rax, 0x8(%rsp)
jmp 0x5861
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
addq %rsi, %rdx
movq 0x58(%rsp), %rdi
movl 0x54(%rsp), %ecx
movq 0x60(%rsp), %r8
callq 0x5dab
leaq 0x88(%rsp), %rdi
callq 0x2408
leaq 0x10(%rsp), %rdi
callq 0xb3da
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0xa76f(%rip), %rsi      # 0x10048
movq %rax, %rdi
callq 0x23a0
jmp 0x58fd
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0xa781(%rip), %rsi      # 0x10076
movq %rax, %rdi
callq 0x23a0
movq 0x126d4(%rip), %rsi     # 0x17fd8
movq 0x126b5(%rip), %rdx     # 0x17fc0
movq %r14, %rdi
callq 0x2340
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0xa614(%rip), %rsi      # 0xff39
movq %rax, %rdi
callq 0x23a0
jmp 0x5965
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0xa627(%rip), %rsi      # 0xff68
movq %rax, %rdi
callq 0x23a0
jmp 0x5965
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0xa5dc(%rip), %rsi      # 0xff39
movq %rax, %rdi
callq 0x23a0
movq 0x1266c(%rip), %rsi     # 0x17fd8
movq 0x1264d(%rip), %rdx     # 0x17fc0
movq %r14, %rdi
callq 0x2340
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0xa775(%rip), %rsi      # 0x10102
movq %rax, %rdi
callq 0x23a0
jmp 0x58fd
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0xa725(%rip), %rsi      # 0x100d1
movq %rax, %rdi
callq 0x23a0
movq 0x1261d(%rip), %rsi     # 0x17fd8
movq 0x125fe(%rip), %rdx     # 0x17fc0
movq %r14, %rdi
callq 0x2340
jmp 0x5ab4
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0xa6c6(%rip), %rsi      # 0x100a7
movq %rax, %rdi
callq 0x23a0
jmp 0x58fd
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0xa5a1(%rip), %rsi      # 0xffa1
leaq 0x68(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0xb1b8
movq (%r12), %rax
movsbl (%rax), %edx
leaq 0x30(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0xb200
movb $0x1, %bpl
leaq 0x30(%rsp), %rsi
movq %r14, %rdi
callq 0x2360
xorl %ebp, %ebp
movq 0x12597(%rip), %rsi     # 0x17fd8
movq 0x12578(%rip), %rdx     # 0x17fc0
movq %r14, %rdi
callq 0x2340
jmp 0x5ab4
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0xa5a5(%rip), %rsi      # 0x10009
movq %rax, %rdi
callq 0x23a0
movq 0x12565(%rip), %rsi     # 0x17fd8
movq 0x12546(%rip), %rdx     # 0x17fc0
movq %r14, %rdi
callq 0x2340
jmp 0x5ab4
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %r14
leaq 0xa53c(%rip), %rsi      # 0xffd2
movq %rax, %rdi
callq 0x23a0
movq 0x12533(%rip), %rsi     # 0x17fd8
movq 0x12514(%rip), %rdx     # 0x17fc0
movq %r14, %rdi
callq 0x2340
jmp 0x5b58
jmp 0x5b49
jmp 0x5b49
jmp 0x5b58
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2408
jmp 0x5add
movq %rax, %rbx
movb $0x1, %bpl
leaq 0x68(%rsp), %rdi
callq 0x2408
testb %bpl, %bpl
jne 0x5b4c
jmp 0x5b5b
jmp 0x5b49
jmp 0x5b49
jmp 0x5b36
movq %rax, %rbx
movq %r14, %rdi
callq 0x2160
jmp 0x5b39
jmp 0x5b49
jmp 0x5b49
jmp 0x5b49
jmp 0x5b49
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x2408
jmp 0x5b1b
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x2408
jmp 0x5b39
jmp 0x5b36
jmp 0x5b36
jmp 0x5b58
jmp 0x5b36
jmp 0x5b58
jmp 0x5b58
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2408
jmp 0x5b5b
jmp 0x5b58
jmp 0x5b49
movq %rax, %rbx
movq %r14, %rdi
callq 0x2160
jmp 0x5b5b
jmp 0x5b58
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x2408
leaq 0x10(%rsp), %rdi
callq 0xb3da
movq %rbx, %rdi
callq 0x2370