// File: /workspace/github_cpp_makefile_star2_O3/klmr[P]multifunction/example.cpp
// Function: main
int main() {
    static_assert(
        std::is_same<
            util::multifunction<void(int)>::argument_type,
            int
        >::value,
        "util::multifunction member types are wrong");

    util::multifunction<void(int)> event;

    cout << "Adding f, g, h\n";
    auto f_tok = event += f;
    auto g_tok = event += g();
    auto h_tok = event += h;

    event(1);

    cout << "\nRemoving g\n";
    event -= g_tok;
    event(2);

    cout << "\nRemoving h\n";
    event -= h_tok;
    event(3);

    cout << "\nRemoving g (again!)\n";
    event -= g_tok;
    event(4);

    cout << "\nRemoving f\n";
    event -= f_tok;
    event(5);

    cout << "\nOnce more, with lambdas\n";
    event += [](int n) { cout << "[](" << n << ")\n"; };
    event += [=](int n) { cout << "[=](" << n << ")\n"; };
    event += [&](int n) { cout << "[&](" << n << ")\n"; };
    int n = 6;
    event(n);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x50, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq 0x3cb8(%rip), %rdi      # 0x4fd8
leaq 0x1ce3(%rip), %rsi      # 0x300a
movl $0xf, %edx
callq 0x10c0
leaq -0xcc(%rip), %rsi       # 0x126c
leaq 0x20(%rsp), %rdi
callq 0x1844
movl %eax, %ebx
leaq 0x20(%rsp), %rdi
callq 0x1cac
movl %eax, %ebp
leaq -0xa5(%rip), %rsi       # 0x12b2
leaq 0x20(%rsp), %rdi
callq 0x1dd4
movl %eax, %r14d
movq %rsp, %rsi
movl $0x1, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x1ed2
movq 0x3c5a(%rip), %rdi      # 0x4fd8
leaq 0x1c95(%rip), %rsi      # 0x301a
movl $0xc, %edx
callq 0x10c0
leaq 0x20(%rsp), %rdi
movl %ebp, %esi
callq 0x1fdc
movq %rsp, %rsi
movl $0x2, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x1ed2
movq 0x3c23(%rip), %rdi      # 0x4fd8
leaq 0x1c6b(%rip), %rsi      # 0x3027
movl $0xc, %edx
callq 0x10c0
leaq 0x20(%rsp), %rdi
movl %r14d, %esi
callq 0x1fdc
movq %rsp, %rsi
movl $0x3, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x1ed2
movq 0x3beb(%rip), %rdi      # 0x4fd8
leaq 0x1c40(%rip), %rsi      # 0x3034
movl $0x15, %edx
callq 0x10c0
leaq 0x20(%rsp), %rdi
movl %ebp, %esi
callq 0x1fdc
movq %rsp, %rsi
movl $0x4, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x1ed2
movq 0x3bb4(%rip), %rdi      # 0x4fd8
leaq 0x1c1f(%rip), %rsi      # 0x304a
movl $0xc, %edx
callq 0x10c0
leaq 0x20(%rsp), %rdi
movl %ebx, %esi
callq 0x1fdc
movq %rsp, %rsi
movl $0x5, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x1ed2
movq 0x3b7d(%rip), %rdi      # 0x4fd8
leaq 0x1bf5(%rip), %rsi      # 0x3057
movl $0x19, %edx
callq 0x10c0
xorps %xmm0, %xmm0
movq %rsp, %rsi
movaps %xmm0, (%rsi)
leaq 0x214(%rip), %rax       # 0x1690
movq %rax, 0x18(%rsi)
leaq 0x24f(%rip), %rax       # 0x16d6
movq %rax, 0x10(%rsi)
leaq 0x20(%rsp), %rdi
callq 0x191a
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x14ac
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
leaq 0x38(%rsp), %rbx
movq -0x10(%rbx), %rax
movq 0x8(%rbx), %rsi
subq -0x18(%rbx), %rax
sarq $0x5, %rax
decq %rax
movq %rax, (%rsp)
cmpq 0x10(%rbx), %rsi
je 0x14dc
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x40(%rsp)
jmp 0x14e7
movq %rsp, %rdx
movq %rbx, %rdi
callq 0x1b70
xorps %xmm0, %xmm0
movq %rsp, %rsi
movaps %xmm0, (%rsi)
leaq 0x1f7(%rip), %rax       # 0x16ee
movq %rax, 0x18(%rsi)
leaq 0x232(%rip), %rax       # 0x1734
movq %rax, 0x10(%rsi)
leaq 0x20(%rsp), %rdi
callq 0x191a
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x1527
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x28(%rsp), %rax
movq 0x40(%rsp), %rsi
subq 0x20(%rsp), %rax
sarq $0x5, %rax
decq %rax
movq %rax, (%rsp)
cmpq 0x48(%rsp), %rsi
je 0x1556
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x40(%rsp)
jmp 0x1561
movq %rsp, %rdx
movq %rbx, %rdi
callq 0x1b70
xorps %xmm0, %xmm0
movq %rsp, %rsi
movaps %xmm0, (%rsi)
leaq 0x1db(%rip), %rax       # 0x174c
movq %rax, 0x18(%rsi)
leaq 0x216(%rip), %rax       # 0x1792
movq %rax, 0x10(%rsi)
leaq 0x20(%rsp), %rdi
callq 0x191a
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x15a1
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x28(%rsp), %rax
movq 0x40(%rsp), %rsi
subq 0x20(%rsp), %rax
sarq $0x5, %rax
decq %rax
movq %rax, (%rsp)
cmpq 0x48(%rsp), %rsi
je 0x15d0
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x40(%rsp)
jmp 0x15db
movq %rsp, %rdx
movq %rbx, %rdi
callq 0x1b70
movq %rsp, %rsi
movl $0x6, (%rsi)
leaq 0x20(%rsp), %rdi
callq 0x2146
leaq 0x20(%rsp), %rdi
callq 0x17aa
xorl %eax, %eax
addq $0x50, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x1663
jmp 0x1663
jmp 0x1663
jmp 0x167b
movq %rax, %rbx
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x167e
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x167e
jmp 0x1663
movq %rax, %rbx
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x167e
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x167e
jmp 0x1663
movq %rax, %rbx
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x167e
movq %rsp, %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x167e
movq %rax, %rdi
callq 0x17fb
jmp 0x167b
jmp 0x167b
jmp 0x167b
jmp 0x167b
jmp 0x167b
jmp 0x167b
jmp 0x167b
jmp 0x167b
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x17aa
movq %rbx, %rdi
callq 0x1110