// File: /workspace/github_cpp_makefile_star2_O3/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 0x360e
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x1, %edx
callq 0x2df0
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 0x360e
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2fa6
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 0x360e
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2fa6
movl (%rax), %ebx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x24af
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
cmpl $0x2a, %ebx
jne 0x26b7
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 0x360e
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2fa6
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x2545
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
cmpl $0x2a, (%rbx)
jne 0x2707
movl $0xb, (%rbx)
leaq 0x70(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1aee(%rip), %rsi      # 0x4051
leaq 0x1b11(%rip), %rdx      # 0x407b
callq 0x360e
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2fa6
movl (%rax), %ebx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x259a
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
cmpl $0xb, %ebx
jne 0x2746
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 0x360e
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x3158
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x2630
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
leaq 0x40(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1b30(%rip), %rsi      # 0x4171
leaq 0x1b35(%rip), %rdx      # 0x417d
leaq 0x30(%rsp), %rdi
callq 0x360e
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
cmpq 0x38(%rsp), %rdx
jne 0x27ab
movq 0x10(%rsp), %r15
testq %rdx, %rdx
je 0x27b5
movq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x2170
testl %eax, %eax
setne %bpl
jmp 0x27b7
movq 0x3912(%rip), %rbx      # 0x5fd0
leaq 0x19b7(%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 0x38e0(%rip), %rdi      # 0x5fd0
callq 0x2030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x20d0
jmp 0x278d
movq 0x38c2(%rip), %rdi      # 0x5fd0
leaq 0x19d2(%rip), %rsi      # 0x40e7
movl $0x1e, %edx
callq 0x2180
movl (%rbx), %esi
movq 0x38a8(%rip), %rdi      # 0x5fd0
callq 0x2210
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
jmp 0x2775
movq 0x3883(%rip), %rbx      # 0x5fd0
leaq 0x19b2(%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
movb $0x1, %bpl
movq 0x10(%rsp), %r15
jmp 0x27b7
xorl %ebp, %ebp
leaq 0x20(%rsp), %r13
cmpq %r13, %r15
je 0x27d1
movq 0x20(%rsp), %rsi
incq %rsi
movq %r15, %rdi
callq 0x2160
testb %bpl, %bpl
je 0x28b4
movq 0x37ef(%rip), %rdi      # 0x5fd0
leaq 0x1996(%rip), %rsi      # 0x417e
movl $0x33, %edx
callq 0x2180
movq 0x37d7(%rip), %rdi      # 0x5fd0
leaq 0x19b2(%rip), %rsi      # 0x41b2
movl $0xa, %edx
callq 0x2180
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x37b5(%rip), %rdi      # 0x5fd0
callq 0x2180
movq %rax, %rbx
leaq 0x18d5(%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 0x195d(%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 %r13, %rdi
je 0x2999
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2999
cmpl $0x65, %ebx
jne 0x29a3
movq 0x370c(%rip), %rbx      # 0x5fd0
leaq 0x1929(%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 0x36da(%rip), %rdi      # 0x5fd0
callq 0x2030
movq %rax, %rdi
callq 0x20d0
leaq 0x10(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x1901(%rip), %rsi      # 0x4213
leaq 0x1908(%rip), %rdx      # 0x4221
callq 0x360e
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl $0x1, %edx
callq 0x2df0
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x2949
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x3680(%rip), %rbx      # 0x5fd0
leaq 0x18cb(%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 0x364e(%rip), %rdi      # 0x5fd0
callq 0x2030
movq %rax, %rdi
callq 0x20d0
movq 0x50(%rsp), %rdi
callq 0x2100
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x2a48
movq 0x3626(%rip), %rdi      # 0x5fd0
leaq 0x180f(%rip), %rsi      # 0x41c0
movl $0x33, %edx
callq 0x2180
movq 0x360e(%rip), %rdi      # 0x5fd0
leaq 0x17e9(%rip), %rsi      # 0x41b2
movl $0xa, %edx
callq 0x2180
movq 0x35f6(%rip), %rdi      # 0x5fd0
movl $0x65, %esi
callq 0x2210
movq %rax, %r14
leaq 0x1711(%rip), %rsi      # 0x40ff
movl $0x6, %edx
movq %rax, %rdi
callq 0x2180
movq %r14, %rdi
movl %ebx, %esi
callq 0x2210
movq %rax, %rbx
leaq 0x17ae(%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 0x3579(%rip), %rsi      # 0x5fc8
leaq 0x70(%rsp), %rdi
callq 0x20b0
leaq 0xe0(%rsp), %rdi
callq 0x2060
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x278d
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x278d
movq %rdx, %r14
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x2ac2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2ac2
movq %rdx, %r14
movq %rax, %rbx
jmp 0x2ac2
jmp 0x2d5b
movq %rdx, %r14
movq %rax, %rbx
movq 0x50(%rsp), %rdi
callq 0x2100
cmpl $0x1, %r14d
jne 0x2d5e
movq %rbx, %rdi
callq 0x2070
callq 0x21f0
movq 0x34f0(%rip), %rdi      # 0x5fd0
leaq 0x176b(%rip), %rsi      # 0x4252
movl $0x1d, %edx
callq 0x2180
movq 0x34d8(%rip), %rdi      # 0x5fd0
callq 0x2090
leaq 0x10(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x1707(%rip), %rsi      # 0x4213
leaq 0x170e(%rip), %rdx      # 0x4221
callq 0x360e
leaq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2fa6
movl (%rax), %esi
movq 0x34a0(%rip), %rdi      # 0x5fd0
callq 0x2210
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x2b4c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x347d(%rip), %rdi      # 0x5fd0
leaq 0x1716(%rip), %rsi      # 0x4270
movl $0x2e, %edx
callq 0x2180
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x3460(%rip), %rdi      # 0x5fd0
callq 0x2090
jmp 0x2a48
jmp 0x2b81
jmp 0x2d5b
movq %rdx, %r15
movq %rax, %rbx
jmp 0x2ba6
movq %rdx, %r15
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x2ba6
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
cmpl %r14d, %r15d
jne 0x2d5e
movq %rbx, %rdi
callq 0x2070
callq 0x21f0
movq 0x340d(%rip), %rdi      # 0x5fd0
leaq 0x16d5(%rip), %rsi      # 0x429f
movl $0x34, %edx
callq 0x2180
movq 0x33f5(%rip), %rdi      # 0x5fd0
callq 0x2090
leaq 0x10(%rsp), %rdi
movq %r13, (%rdi)
leaq 0x1462(%rip), %rsi      # 0x4051
leaq 0x1485(%rip), %rdx      # 0x407b
callq 0x360e
leaq 0x60(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1608(%rip), %rsi      # 0x4213
leaq 0x160f(%rip), %rdx      # 0x4221
leaq 0x50(%rsp), %rdi
callq 0x360e
leaq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x330a
movl (%rax), %esi
movq 0x3397(%rip), %rdi      # 0x5fd0
callq 0x2210
movq 0x50(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2c55
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x2c6c
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
movq 0x335d(%rip), %rdi      # 0x5fd0
leaq 0x165a(%rip), %rsi      # 0x42d4
movl $0x42, %edx
callq 0x2180
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x3340(%rip), %rdi      # 0x5fd0
callq 0x2090
jmp 0x2a48
jmp 0x2cda
movq %rdx, %r15
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2cc1
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2cc1
movq %rdx, %r15
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x2ce0
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2ce0
movq %rdx, %r15
movq %rax, %rbx
cmpl %r14d, %r15d
jne 0x2d5e
movq %rbx, %rdi
callq 0x2070
callq 0x21f0
movq 0x32d7(%rip), %rdi      # 0x5fd0
leaq 0x1617(%rip), %rsi      # 0x4317
movl $0xd, %edx
callq 0x2180
xorl %ebx, %ebx
movq 0x32bd(%rip), %rdi      # 0x5fd0
callq 0x2090
jmp 0x2a48
jmp 0x2d5b
jmp 0x2d5b
jmp 0x2d5b
movq %rax, %rbx
jmp 0x2d7c
jmp 0x2dda
jmp 0x2d91
jmp 0x2dda
jmp 0x2d91
jmp 0x2dda
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x2d5e
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2d5e
jmp 0x2d91
jmp 0x2dda
movq %rax, %rbx
movq 0x3263(%rip), %rsi      # 0x5fc8
leaq 0x70(%rsp), %rdi
callq 0x20b0
leaq 0xe0(%rsp), %rdi
callq 0x2060
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x2ddd
movq 0x40(%rsp), %rsi
jmp 0x2da6
jmp 0x2d91
jmp 0x2dda
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x2ddd
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2ddd
jmp 0x2dda
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r14, %rdi
je 0x2de7
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2160
jmp 0x2de7
movq %rax, %rbx
jmp 0x2de7
jmp 0x2dda
jmp 0x2dda
movq %rax, %rbx
movq 0x8(%rsp), %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x2220
nop