// File: /workspace/github_cpp_makefile_star2_O1/andyn[P]libdlmm/dltest.cc
// Function: main
int main(void) {
    Dl dl("./libuseless.so");

    // Reading variables from a dynamic library

    std::cout << "Reading and modifying a local copy of variable in library..."
              << std::endl;
    int my_answer =
        dl.symbol<int>("answer_to_life_the_universe_and_everything");
    my_answer = -1;
    (void)my_answer;
    if (dl.symbol<int>("answer_to_life_the_universe_and_everything") != 42) {
        std::cout << "TEST FAILED: variable was changed inside library."
                  << std::endl;
        return -1;
    }

    std::cout << "Reading and changing a referenced variable in library..."
              << std::endl;
    int &my_better_answer =
        dl.symbol<int>("answer_to_life_the_universe_and_everything");
    if (my_better_answer != 42) {
        std::cout << "TEST FAILED: Expected 42, got " << my_better_answer
                  << std::endl;
        return -1;
    }
    my_better_answer = 11; // This one goes to eleven!
    if (dl.symbol<int>("answer_to_life_the_universe_and_everything") != 11) {
        std::cout << "TEST FAILED: could not change variable inside library."
                  << std::endl;
        return -1;
    }

    // Calling functions from a dynamic library

    std::cout << "Calling function in library... " << std::endl;
    auto print_and_increment =
        dl.symbol<int(std::ostringstream &, std::string const &, int)>(
            "print_and_increment");

    std::string input_string = "Hello World!";
    std::ostringstream output_string;
    int incremented_via_reference =
        print_and_increment(output_string, input_string, 100);
    if (output_string.str() != input_string) {
        std::cout << "TEST FAILED: function did not stream correct value "
                  << "(expected " << input_string << ", got "
                  << output_string.str() << ")." << std::endl;
        return -1;
    }
    if (101 != incremented_via_reference) {
        std::cout << "TEST FAILED: function did not return correct value "
                  << "(expected " << 101 << ", got "
                  << incremented_via_reference << ")." << std::endl;
        return -1;
    }

    // Catching exceptions

    std::cout << "Loading nonexistent library..." << std::endl;
    try {
        Dl dl2("DOES_NOT_EXIST");
        std::cout << "TEST FAILED: nonexistent library did not throw."
                  << std::endl;
        return -1;
    } catch (std::runtime_error &) {
    }

    std::cout << "Loading nonexistent symbol..." << std::endl;
    try {
        std::cout << dl.symbol<int>("DOES_NOT_EXIST");
        std::cout << "TEST FAILED: nonexistent symbol did not throw."
                  << std::endl;
        return -1;
    } catch (std::runtime_error &) {
    }

    std::cout << "Loading nonexistent version of an existing symbol..."
              << std::endl;
    try {
        std::cout << dl.symbol<int>(
            "answer_to_life_the_universe_and_everything", "DOES_NOT_EXIST");
        std::cout << "TEST FAILED: nonexistent version of existing symbol did "
                     "not throw."
                  << std::endl;
        return -1;
    } catch (std::runtime_error &) {
    }

    std::cout << "Done testing." << std::endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
leaq 0x80(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1c64(%rip), %rsi      # 0x4004
leaq 0x1c6c(%rip), %rdx      # 0x4013
leaq 0x70(%rsp), %rdi
callq 0x35b6
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x1, %edx
callq 0x2dec
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x23df
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x3bea(%rip), %rbx      # 0x5fd0
leaq 0x1c27(%rip), %rsi      # 0x4014
movl $0x3c, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq 0x3bb8(%rip), %rdi      # 0x5fd0
callq 0x2030
movq %rax, %rdi
callq 0x20d0
leaq 0x70(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1c1d(%rip), %rsi      # 0x4051
leaq 0x1c40(%rip), %rdx      # 0x407b
callq 0x35b6
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2f8e
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x2469
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
leaq 0x70(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1bd9(%rip), %rsi      # 0x4051
leaq 0x1bfc(%rip), %rdx      # 0x407b
callq 0x35b6
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2f8e
movl (%rax), %ebx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x24af
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
cmpl $0x2a, %ebx
jne 0x26b6
movq 0x3b11(%rip), %rbx      # 0x5fd0
leaq 0x1be8(%rip), %rsi      # 0x40ae
movl $0x38, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq 0x3adf(%rip), %rdi      # 0x5fd0
callq 0x2030
movq %rax, %rdi
callq 0x20d0
leaq 0x70(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1b44(%rip), %rsi      # 0x4051
leaq 0x1b67(%rip), %rdx      # 0x407b
callq 0x35b6
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2f8e
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x2545
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
cmpl $0x2a, (%rbx)
jne 0x2706
movl $0xb, (%rbx)
leaq 0x70(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1aee(%rip), %rsi      # 0x4051
leaq 0x1b11(%rip), %rdx      # 0x407b
callq 0x35b6
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2f8e
movl (%rax), %ebx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x259a
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
cmpl $0xb, %ebx
jne 0x2745
movq 0x3a26(%rip), %rbx      # 0x5fd0
leaq 0x1b8c(%rip), %rsi      # 0x413d
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq 0x39f4(%rip), %rdi      # 0x5fd0
callq 0x2030
movq %rax, %rdi
callq 0x20d0
leaq 0x70(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1b65(%rip), %rsi      # 0x415d
leaq 0x1b71(%rip), %rdx      # 0x4170
callq 0x35b6
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x312a
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x2630
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
leaq 0x40(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1b31(%rip), %rsi      # 0x4171
leaq 0x1b36(%rip), %rdx      # 0x417d
leaq 0x30(%rsp), %rdi
callq 0x35b6
leaq 0x70(%rsp), %rdi
callq 0x2190
leaq 0x70(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movl $0x64, %edx
callq *%rbx
movl %eax, %ebx
leaq 0x78(%rsp), %r14
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x21d0
movq 0x18(%rsp), %rdx
movb $0x1, %bpl
cmpq 0x38(%rsp), %rdx
jne 0x27ac
testq %rdx, %rdx
je 0x27aa
movq 0x30(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x2170
testl %eax, %eax
setne %bpl
jmp 0x27ac
movq 0x3913(%rip), %rbx      # 0x5fd0
leaq 0x19b8(%rip), %rsi      # 0x407c
movl $0x31, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq 0x38e1(%rip), %rdi      # 0x5fd0
callq 0x2030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x20d0
jmp 0x278c
movq 0x38c3(%rip), %rdi      # 0x5fd0
leaq 0x19d3(%rip), %rsi      # 0x40e7
movl $0x1e, %edx
callq 0x2180
movl (%rbx), %esi
movq 0x38a9(%rip), %rdi      # 0x5fd0
callq 0x2210
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
jmp 0x2774
movq 0x3884(%rip), %rbx      # 0x5fd0
leaq 0x19b3(%rip), %rsi      # 0x4106
movl $0x36, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x20d0
movq 0x8(%rsp), %rdi
callq 0x2100
movl %ebx, %eax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
leaq 0x20(%rsp), %r12
movq -0x10(%r12), %rdi
cmpq %r12, %rdi
je 0x27c8
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
testb %bpl, %bpl
je 0x28ab
movq 0x37f8(%rip), %rdi      # 0x5fd0
leaq 0x199f(%rip), %rsi      # 0x417e
movl $0x33, %edx
callq 0x2180
movq 0x37e0(%rip), %rdi      # 0x5fd0
leaq 0x19bb(%rip), %rsi      # 0x41b2
movl $0xa, %edx
callq 0x2180
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x37be(%rip), %rdi      # 0x5fd0
callq 0x2180
movq %rax, %rbx
leaq 0x18de(%rip), %rsi      # 0x40ff
movl $0x6, %edx
movq %rax, %rdi
callq 0x2180
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x21d0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rbx, %rdi
callq 0x2180
movq %rax, %rbx
leaq 0x1966(%rip), %rsi      # 0x41bd
movl $0x2, %edx
movq %rax, %rdi
callq 0x2180
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x2990
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2990
cmpl $0x65, %ebx
jne 0x299a
movq 0x3715(%rip), %rbx      # 0x5fd0
leaq 0x1932(%rip), %rsi      # 0x41f4
movl $0x1e, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq 0x36e3(%rip), %rdi      # 0x5fd0
callq 0x2030
movq %rax, %rdi
callq 0x20d0
leaq 0x10(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x190a(%rip), %rsi      # 0x4213
leaq 0x1911(%rip), %rdx      # 0x4221
callq 0x35b6
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl $0x1, %edx
callq 0x2dec
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x2940
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x3689(%rip), %rbx      # 0x5fd0
leaq 0x18d4(%rip), %rsi      # 0x4222
movl $0x2f, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq 0x3657(%rip), %rdi      # 0x5fd0
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movq 0x50(%rsp), %rdi
callq 0x2100
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x2a3f
movq 0x362f(%rip), %rdi      # 0x5fd0
leaq 0x1818(%rip), %rsi      # 0x41c0
movl $0x33, %edx
callq 0x2180
movq 0x3617(%rip), %rdi      # 0x5fd0
leaq 0x17f2(%rip), %rsi      # 0x41b2
movl $0xa, %edx
callq 0x2180
movq 0x35ff(%rip), %rdi      # 0x5fd0
movl $0x65, %esi
callq 0x2210
movq %rax, %r14
leaq 0x171a(%rip), %rsi      # 0x40ff
movl $0x6, %edx
movq %rax, %rdi
callq 0x2180
movq %r14, %rdi
movl %ebx, %esi
callq 0x2210
movq %rax, %rbx
leaq 0x17b7(%rip), %rsi      # 0x41bd
movl $0x2, %edx
movq %rax, %rdi
callq 0x2180
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x20d0
movq 0x3582(%rip), %rsi      # 0x5fc8
leaq 0x70(%rsp), %rdi
callq 0x20b0
leaq 0xe0(%rsp), %rdi
callq 0x2060
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x278c
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x278c
movq %rdx, %r14
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x2ab9
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2ab9
movq %rdx, %r14
movq %rax, %rbx
jmp 0x2ab9
jmp 0x2d57
movq %rdx, %r14
movq %rax, %rbx
movq 0x50(%rsp), %rdi
callq 0x2100
cmpl $0x1, %r14d
jne 0x2d5a
movq %rbx, %rdi
callq 0x2070
callq 0x21f0
movq 0x34f9(%rip), %rdi      # 0x5fd0
leaq 0x1774(%rip), %rsi      # 0x4252
movl $0x1d, %edx
callq 0x2180
movq 0x34e1(%rip), %rdi      # 0x5fd0
callq 0x2090
leaq 0x10(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x1710(%rip), %rsi      # 0x4213
leaq 0x1717(%rip), %rdx      # 0x4221
callq 0x35b6
leaq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2f8e
movl (%rax), %esi
movq 0x34a9(%rip), %rdi      # 0x5fd0
callq 0x2210
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x2b43
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x3486(%rip), %rdi      # 0x5fd0
leaq 0x171f(%rip), %rsi      # 0x4270
movl $0x2e, %edx
callq 0x2180
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x3469(%rip), %rdi      # 0x5fd0
callq 0x2090
jmp 0x2a3f
jmp 0x2b78
jmp 0x2d57
movq %rdx, %r14
movq %rax, %rbx
jmp 0x2b9d
movq %rdx, %r14
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x2b9d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
movl $0x1, %ebp
cmpl %ebp, %r14d
jne 0x2d5a
movq %rbx, %rdi
callq 0x2070
callq 0x21f0
movq 0x3411(%rip), %rdi      # 0x5fd0
leaq 0x16d9(%rip), %rsi      # 0x429f
movl $0x34, %edx
callq 0x2180
movq 0x33f9(%rip), %rdi      # 0x5fd0
callq 0x2090
leaq 0x10(%rsp), %rdi
movq %r12, (%rdi)
leaq 0x1466(%rip), %rsi      # 0x4051
leaq 0x1489(%rip), %rdx      # 0x407b
callq 0x35b6
leaq 0x60(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x160c(%rip), %rsi      # 0x4213
leaq 0x1613(%rip), %rdx      # 0x4221
leaq 0x50(%rsp), %rdi
callq 0x35b6
leaq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x32c6
movl (%rax), %esi
movq 0x339b(%rip), %rdi      # 0x5fd0
callq 0x2210
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x2c51
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x2c68
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x3361(%rip), %rdi      # 0x5fd0
leaq 0x165e(%rip), %rsi      # 0x42d4
movl $0x42, %edx
callq 0x2180
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x3344(%rip), %rdi      # 0x5fd0
callq 0x2090
jmp 0x2a3f
jmp 0x2cd6
movq %rdx, %r14
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x2cbd
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2cbd
movq %rdx, %r14
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x2cdc
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2cdc
movq %rdx, %r14
movq %rax, %rbx
cmpl %ebp, %r14d
jne 0x2d5a
movq %rbx, %rdi
callq 0x2070
callq 0x21f0
movq 0x32db(%rip), %rdi      # 0x5fd0
leaq 0x161b(%rip), %rsi      # 0x4317
movl $0xd, %edx
callq 0x2180
xorl %ebx, %ebx
movq 0x32c1(%rip), %rdi      # 0x5fd0
callq 0x2090
jmp 0x2a3f
jmp 0x2d57
jmp 0x2d57
jmp 0x2d57
movq %rax, %rbx
jmp 0x2d78
jmp 0x2dd6
jmp 0x2d8d
jmp 0x2dd6
jmp 0x2d8d
jmp 0x2dd6
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x2d5a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2d5a
jmp 0x2d8d
jmp 0x2dd6
movq %rax, %rbx
movq 0x3267(%rip), %rsi      # 0x5fc8
leaq 0x70(%rsp), %rdi
callq 0x20b0
leaq 0xe0(%rsp), %rdi
callq 0x2060
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x2dd9
movq 0x40(%rsp), %rsi
jmp 0x2da2
jmp 0x2d8d
jmp 0x2dd6
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x2dd9
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2dd9
jmp 0x2dd6
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x2de3
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2de3
movq %rax, %rbx
jmp 0x2de3
jmp 0x2dd6
jmp 0x2dd6
movq %rax, %rbx
movq 0x8(%rsp), %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x2220
nop