// File: /workspace/github_cpp_makefile_star2_O1/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 0x9ac4(%rip), %rdi      # 0xbfc0
leaq 0x5b01(%rip), %rsi      # 0x8004
movl $0x17, %edx
callq 0x2150
movq 0x9aac(%rip), %rdi      # 0xbfc0
callq 0x20c0
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x5af3(%rip), %rsi      # 0x801c
leaq 0x5c39(%rip), %rdx      # 0x8169
leaq 0x20(%rsp), %rdi
callq 0x2826
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x2cda
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x255e
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2140
movq 0x9a5b(%rip), %rdi      # 0xbfc0
leaq 0x5bfe(%rip), %rsi      # 0x816a
movl $0x16, %edx
callq 0x2150
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x9a3a(%rip), %rdi      # 0xbfc0
callq 0x2150
leaq 0x5bd6(%rip), %rsi      # 0x8168
movl $0x1, %edx
movq %rax, %rdi
callq 0x2150
movq 0x9a1a(%rip), %rdi      # 0xbfc0
callq 0x20c0
leaq 0x10(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %r15, %rdi
je 0x25c6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2140
movq 0x99f3(%rip), %rdi      # 0xbfc0
leaq 0x5a30(%rip), %rsi      # 0x8004
movl $0x17, %edx
callq 0x2150
movq 0x99db(%rip), %rdi      # 0xbfc0
callq 0x20c0
movq $0x0, 0x9b83(%rip) # 0xc178
movq 0x9b74(%rip), %rax      # 0xc170
movb $0x0, (%rax)
movq %rsp, %rdi
movq %r15, (%rdi)
leaq 0x5b75(%rip), %rsi      # 0x8181
leaq 0x5c83(%rip), %rdx      # 0x8296
callq 0x2826
leaq 0x9b51(%rip), %rsi      # 0xc170
movq %rsp, %rdi
callq 0x2c10
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x263d
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2140
movq 0x997c(%rip), %rdi      # 0xbfc0
leaq 0x5c4c(%rip), %rsi      # 0x8297
movl $0x17, %edx
callq 0x2150
movq 0x9b14(%rip), %rsi      # 0xc170
movq 0x9b15(%rip), %rdx      # 0xc178
movq 0x9956(%rip), %rdi      # 0xbfc0
callq 0x2150
leaq 0x5af2(%rip), %rsi      # 0x8168
movl $0x1, %edx
movq %rax, %rdi
callq 0x2150
movq 0x9936(%rip), %rdi      # 0xbfc0
callq 0x20c0
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 0x26db
jmp 0x26f0
jmp 0x26ea
movq %rdx, %rbx
movq %rax, %r14
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x26f0
movq 0x30(%rsp), %rsi
jmp 0x26e0
jmp 0x26ea
movq %rdx, %rbx
movq %rax, %r14
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x26f0
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2140
jmp 0x26f0
movq %rdx, %rbx
movq %rax, %r14
movq %r14, %rdi
callq 0x2060
cmpl $0x2, %ebx
jne 0x2790
movq %rax, %r14
movq 0x98dd(%rip), %rdi      # 0xbfe8
leaq 0x5bca(%rip), %rsi      # 0x82dc
movl $0x13, %edx
callq 0x2150
movq (%r14), %rax
movq %r14, %rdi
callq *0x10(%rax)
movq 0x98bc(%rip), %rdi      # 0xbfe8
movq %rax, %rsi
callq 0x2130
leaq 0x5a2d(%rip), %rsi      # 0x8168
movl $0x1, %edx
movq %rax, %rdi
callq 0x2150
movq 0x9899(%rip), %rdi      # 0xbfe8
leaq 0x5b75(%rip), %rsi      # 0x82cb
movl $0x10, %edx
callq 0x2150
movq 0x9a09(%rip), %rsi      # 0xc170
movq 0x9a0a(%rip), %rdx      # 0xc178
movq 0x9873(%rip), %rdi      # 0xbfe8
callq 0x2150
leaq 0x59e7(%rip), %rsi      # 0x8168
movl $0x1, %edx
movq %rax, %rdi
callq 0x2150
jmp 0x27ee
movq 0x9851(%rip), %rdi      # 0xbfe8
leaq 0x5b11(%rip), %rsi      # 0x82af
movl $0x1b, %edx
callq 0x2150
movq 0x9839(%rip), %rdi      # 0xbfe8
leaq 0x5b15(%rip), %rsi      # 0x82cb
movl $0x10, %edx
callq 0x2150
movq 0x99a9(%rip), %rsi      # 0xc170
movq 0x99aa(%rip), %rdx      # 0xc178
movq 0x9813(%rip), %rdi      # 0xbfe8
callq 0x2150
leaq 0x5987(%rip), %rsi      # 0x8168
movl $0x1, %edx
movq %rax, %rdi
callq 0x2150
callq 0x2210
jmp 0x268f
movq %rax, %rbx
callq 0x2210
jmp 0x280a
movq %rax, %rbx
callq 0x2210
movq %rbx, %rdi
callq 0x2240
movq %rax, %rdi
callq 0x281a