// File: /workspace/github_cpp_makefile_star2_O3/cjxgm[P]libgpp/src/memory-pp.cpp
// Function: main
int main() try
{
    {
        std::cout << "Start preprocessing...\n";
        std::cout.flush();

        auto result = libgpp::preprocess(
            "#define BLOCK(X)    X\n"
            "#define EXPAND      BLOCK(#defeval DO_EXPAND #1#2#3#4#5#6#7#8#9\n"
            "DO_EXPAND)\n"
            "\n"
            "#define ANSWER_EVERYTHING    42\n"
            "#define ANSWER_TO(WHAT)      EXPAND(ANSWER_,WHAT)\n"
            "ANSWER_TO(EVERYTHING)        // Should give result: 42\n"
            "\n"
            "#define DOUBLE(X)            #eval (X)*2\n"
            "EXPAND(DOU,BLE,(21))         // Should give result: 42\n"
            "\n"
        );

        std::cout
            << "Preprocessed. Result:\n"
            << result
            << "\n"
        ;
        std::cout.flush();
    }

    {
        std::cout << "Start preprocessing...\n";
        std::cout.flush();

        output_buffer.clear();
        libgpp::preprocess_to_buffer(
            "#define BLOCK(X)    X\n"
            "#define EXPAND      BLOCK(#defeval DO_EXPAND #1#2#3#4#5#6#7#8#9\n"
            "DO_EXPAND)\n"
            "\n"
            "#define ANSWER_EVERYTHING    42\n"
            "#define ANSWER_TO(WHAT)      EXPAND(ANSWER_,WHAT)\n"
            "ANSWER_TO(EVERYTHING)        // Should give result: 42\n"
            "\n"
            "#define #DOUBLE(X)           #eval (X)*2\n"
            , output_buffer
        );

        std::cout
            << "SHOULD NOT REACH HERE:\n"
            << output_buffer
            << "\n"
        ;
        std::cout.flush();
    }
}
catch (std::exception const& e) {
    std::cerr << "\e[1;31m ERROR \e[0m " << e.what() << "\n";
    std::cerr << "Partial result:\n" << output_buffer << "\n";
}
catch (...) {
    std::cerr << "\e[1;31m UNKNOWN ERROR \e[0m\n";
    std::cerr << "Partial result:\n" << output_buffer << "\n";
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x40, %rsp
movq 0x9af4(%rip), %rdi      # 0xbfc0
leaq 0x5b31(%rip), %rsi      # 0x8004
movl $0x17, %edx
callq 0x2160
movq 0x9adc(%rip), %rdi      # 0xbfc0
callq 0x20d0
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x5b23(%rip), %rsi      # 0x801c
leaq 0x5c69(%rip), %rdx      # 0x8169
leaq 0x20(%rsp), %rdi
callq 0x27f6
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x2c9f
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x252e
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x9a8b(%rip), %rdi      # 0xbfc0
leaq 0x5c2e(%rip), %rsi      # 0x816a
movl $0x16, %edx
callq 0x2160
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x9a6a(%rip), %rdi      # 0xbfc0
callq 0x2160
leaq 0x5c06(%rip), %rsi      # 0x8168
movl $0x1, %edx
movq %rax, %rdi
callq 0x2160
movq 0x9a4a(%rip), %rdi      # 0xbfc0
callq 0x20d0
leaq 0x10(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %r15, %rdi
je 0x2596
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x9a23(%rip), %rdi      # 0xbfc0
leaq 0x5a60(%rip), %rsi      # 0x8004
movl $0x17, %edx
callq 0x2160
movq 0x9a0b(%rip), %rdi      # 0xbfc0
callq 0x20d0
movq $0x0, 0x9bbb(%rip) # 0xc180
movq 0x9bac(%rip), %rax      # 0xc178
movb $0x0, (%rax)
movq %rsp, %rdi
movq %r15, (%rdi)
leaq 0x5ba5(%rip), %rsi      # 0x8181
leaq 0x5cb3(%rip), %rdx      # 0x8296
callq 0x27f6
leaq 0x9b89(%rip), %rsi      # 0xc178
movq %rsp, %rdi
callq 0x2bdf
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x260d
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2150
movq 0x99ac(%rip), %rdi      # 0xbfc0
leaq 0x5c7c(%rip), %rsi      # 0x8297
movl $0x17, %edx
callq 0x2160
movq 0x9b4c(%rip), %rsi      # 0xc178
movq 0x9b4d(%rip), %rdx      # 0xc180
movq 0x9986(%rip), %rdi      # 0xbfc0
callq 0x2160
leaq 0x5b22(%rip), %rsi      # 0x8168
movl $0x1, %edx
movq %rax, %rdi
callq 0x2160
movq 0x9966(%rip), %rdi      # 0xbfc0
callq 0x20d0
xorl %eax, %eax
addq $0x40, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rdx, %rbx
movq %rax, %r14
movq (%rsp), %rdi
cmpq %r15, %rdi
jne 0x26ab
jmp 0x26c0
jmp 0x26ba
movq %rdx, %rbx
movq %rax, %r14
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x26c0
movq 0x30(%rsp), %rsi
jmp 0x26b0
jmp 0x26ba
movq %rdx, %rbx
movq %rax, %r14
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x26c0
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2150
jmp 0x26c0
movq %rdx, %rbx
movq %rax, %r14
movq %r14, %rdi
callq 0x2060
cmpl $0x2, %ebx
jne 0x2760
movq %rax, %r14
movq 0x990d(%rip), %rdi      # 0xbfe8
leaq 0x5bfa(%rip), %rsi      # 0x82dc
movl $0x13, %edx
callq 0x2160
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movq 0x98ec(%rip), %rdi      # 0xbfe8
movq %rax, %rsi
callq 0x2140
leaq 0x5a5d(%rip), %rsi      # 0x8168
movl $0x1, %edx
movq %rax, %rdi
callq 0x2160
movq 0x98c9(%rip), %rdi      # 0xbfe8
leaq 0x5ba5(%rip), %rsi      # 0x82cb
movl $0x10, %edx
callq 0x2160
movq 0x9a41(%rip), %rsi      # 0xc178
movq 0x9a42(%rip), %rdx      # 0xc180
movq 0x98a3(%rip), %rdi      # 0xbfe8
callq 0x2160
leaq 0x5a17(%rip), %rsi      # 0x8168
movl $0x1, %edx
movq %rax, %rdi
callq 0x2160
jmp 0x27be
movq 0x9881(%rip), %rdi      # 0xbfe8
leaq 0x5b41(%rip), %rsi      # 0x82af
movl $0x1b, %edx
callq 0x2160
movq 0x9869(%rip), %rdi      # 0xbfe8
leaq 0x5b45(%rip), %rsi      # 0x82cb
movl $0x10, %edx
callq 0x2160
movq 0x99e1(%rip), %rsi      # 0xc178
movq 0x99e2(%rip), %rdx      # 0xc180
movq 0x9843(%rip), %rdi      # 0xbfe8
callq 0x2160
leaq 0x59b7(%rip), %rsi      # 0x8168
movl $0x1, %edx
movq %rax, %rdi
callq 0x2160
callq 0x2220
jmp 0x265f
movq %rax, %rbx
callq 0x2220
jmp 0x27da
movq %rax, %rbx
callq 0x2220
movq %rbx, %rdi
callq 0x2250
movq %rax, %rdi
callq 0x27ea