// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x48, %rsp
movq 0x9bf6(%rip), %rdi      # 0xbfc0
leaq 0x5c33(%rip), %rsi      # 0x8004
callq 0x2140
movq 0x9be3(%rip), %rdi      # 0xbfc0
callq 0x20d0
leaq 0x5c33(%rip), %rsi      # 0x801c
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x2060
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x2a25
leaq 0x28(%rsp), %rdi
callq 0x2258
movq 0x9ba8(%rip), %rdi      # 0xbfc0
leaq 0x5d4b(%rip), %rsi      # 0x816a
callq 0x2140
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x2120
leaq 0x5d30(%rip), %rsi      # 0x8168
movq %rax, %rdi
callq 0x2140
movq 0x9b79(%rip), %rdi      # 0xbfc0
callq 0x20d0
leaq 0x8(%rsp), %rdi
callq 0x2258
movq 0x9b63(%rip), %rdi      # 0xbfc0
leaq 0x5ba0(%rip), %rsi      # 0x8004
callq 0x2140
movq 0x9b50(%rip), %rdi      # 0xbfc0
callq 0x20d0
andq $0x0, 0x9ceb(%rip)      # 0xc168
movq 0x9cdc(%rip), %rax      # 0xc160
movb $0x0, (%rax)
leaq 0x5cf3(%rip), %rsi      # 0x8181
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x2060
leaq 0x9cbc(%rip), %rsi      # 0xc160
leaq 0x8(%rsp), %rdi
callq 0x2962
leaq 0x8(%rsp), %rdi
callq 0x2258
movq 0x9b01(%rip), %rdi      # 0xbfc0
leaq 0x5dd1(%rip), %rsi      # 0x8297
callq 0x2140
leaq 0x9c8e(%rip), %rsi      # 0xc160
movq %rax, %rdi
callq 0x2120
leaq 0x5c87(%rip), %rsi      # 0x8168
movq %rax, %rdi
callq 0x2140
movq 0x9ad0(%rip), %rdi      # 0xbfc0
callq 0x20d0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r14
retq
jmp 0x2512
jmp 0x2524
movq %rdx, %rbx
movq %rax, %r14
leaq 0x28(%rsp), %rdi
jmp 0x251d
jmp 0x2524
movq %rdx, %rbx
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x2258
jmp 0x252a
movq %rdx, %rbx
movq %rax, %r14
movq %r14, %rdi
callq 0x2070
cmpl $0x2, %ebx
jne 0x25a6
movq %rax, %r14
movq 0x9aa7(%rip), %rdi      # 0xbfe8
leaq 0x5d94(%rip), %rsi      # 0x82dc
callq 0x2140
movq %rax, %rbx
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2140
leaq 0x5bfd(%rip), %rsi      # 0x8168
movq %rax, %rdi
callq 0x2140
movq 0x9a6e(%rip), %rdi      # 0xbfe8
leaq 0x5d4a(%rip), %rsi      # 0x82cb
callq 0x2140
leaq 0x9bd3(%rip), %rsi      # 0xc160
movq %rax, %rdi
callq 0x2120
leaq 0x5bcc(%rip), %rsi      # 0x8168
movq %rax, %rdi
callq 0x2140
jmp 0x25ea
movq 0x9a3b(%rip), %rdi      # 0xbfe8
leaq 0x5cfb(%rip), %rsi      # 0x82af
callq 0x2140
movq 0x9a28(%rip), %rdi      # 0xbfe8
leaq 0x5d04(%rip), %rsi      # 0x82cb
callq 0x2140
leaq 0x9b8d(%rip), %rsi      # 0xc160
movq %rax, %rdi
callq 0x2120
leaq 0x5b86(%rip), %rsi      # 0x8168
movq %rax, %rdi
callq 0x2140
callq 0x2200
jmp 0x24f5
movq %rax, %rbx
callq 0x2200
jmp 0x2606
movq %rax, %rbx
callq 0x2200
movq %rbx, %rdi
callq 0x2230
movq %rax, %rdi
callq 0x2616