// File: /workspace/github_cpp_makefile_star2_O2/masaers[P]blind/blind_test.cpp
// Function: main
int main(const int argc, const char** argv) {
  using namespace std;
  using namespace com::masaers::blind;
  using namespace std::placeholders;

  {
    const auto f = blind(foo(), 1);
    int i = 2;
    int j = f(cref(i));
    f(i);
    assert(i == 3);
    assert(j == 3);
  }
  {
    const auto f = blind(foo2(), _1, 1);
    int i = 2;
    int j = f(cref(i));
    f(i);
    assert(i == 3);
    assert(j == 3);
  }

  {
    const auto rsort = blind(BLIND_FUNC(sort), _1, _2, [](auto&& a, auto&& b) { return a > b; });
    vector<int> vec{ 1, 2, 3, 4 };
    rsort(begin(vec), end(vec));
    {
      auto it = begin(vec);
      assert(*it++ == 4);
      assert(*it++ == 3);
      assert(*it++ == 2);
      assert(*it++ == 1);
      assert(it == end(vec));
    }

    deque<string> dq{ "a", "b", "c", "d" };
    rsort(begin(dq), end(dq));
    {
      auto it = begin(dq);
      assert(*it++ == "d");
      assert(*it++ == "c");
      assert(*it++ == "b");
      assert(*it++ == "a");
      assert(it == end(dq));
    }
  }
  {
    ostringstream os;
    const auto p = blind(BLIND_FUNC(print), ref(os));
    p(1, 1.0, '1', "1") << 2;
    assert(os.str() == "11112");
  }
  {
    vector<int> vec{ 1, 2, 3, 4 };
    auto sort_vec = blind(BLIND_FUNC(sort), begin(vec), end(vec));
    sort_vec([](auto&& a, auto&& b) { return a > b; });
    {
      auto it = begin(vec);
      assert(*it++ == 4);
      assert(*it++ == 3);
      assert(*it++ == 2);
      assert(*it++ == 1);
      assert(it == end(vec));
    }
    sort_vec();
    {
      auto it = begin(vec);
      assert(*it++ == 1);
      assert(*it++ == 2);
      assert(*it++ == 3);
      assert(*it++ == 4);
      assert(it == end(vec));
    }
  }
  {
    auto f = blind(BLIND_FUNC(bar<int, int>), _1, 1);
    assert(f(2) == 3);
  }
  return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movaps 0x2c98(%rip), %xmm0     # 0x5010
leaq 0x130(%rsp), %rsi
movaps %xmm0, (%rsi)
leaq 0x8(%rsp), %rdi
pushq $0x4
popq %rdx
leaq 0x40(%rsp), %rcx
callq 0x3c74
movq 0x8(%rsp), %r14
movq 0x10(%rsp), %rbx
cmpq %rbx, %r14
je 0x23fc
movq %rbx, %r15
subq %r14, %r15
movq %r15, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2cb6
cmpq $0x41, %r15
jl 0x23f1
leaq 0x40(%r14), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x2e7b
cmpq %rbx, %r15
je 0x23fc
movq %r15, %rdi
callq 0x2ed8
addq $0x4, %r15
jmp 0x23de
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2e7b
movq 0x8(%rsp), %rax
cmpl $0x4, (%rax)
jne 0x29ef
cmpl $0x3, 0x4(%rax)
jne 0x2a0b
cmpl $0x2, 0x8(%rax)
jne 0x2a27
cmpl $0x1, 0xc(%rax)
jne 0x2a43
addq $0x10, %rax
cmpq 0x10(%rsp), %rax
jne 0x2a5f
leaq 0x2c4f(%rip), %rsi      # 0x508d
leaq 0x130(%rsp), %r14
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x3caa
leaq 0x150(%rsp), %r15
leaq 0x2c2d(%rip), %rsi      # 0x508f
leaq 0x110(%rsp), %rdx
movq %r15, %rdi
callq 0x3caa
leaq 0x170(%rsp), %r15
leaq 0x2c10(%rip), %rsi      # 0x5091
leaq 0x2e8(%rsp), %rdx
movq %r15, %rdi
callq 0x3caa
leaq 0x190(%rsp), %r15
leaq 0x2ca8(%rip), %rsi      # 0x5148
leaq 0x2c8(%rsp), %rdx
movq %r15, %rdi
callq 0x3caa
leaq 0x40(%rsp), %rdi
leaq 0x130(%rsp), %rsi
pushq $0x4
popq %rdx
leaq 0x2a8(%rsp), %rcx
callq 0x3ce6
pushq $0x60
popq %rbx
leaq (%rsp,%rbx), %rdi
addq $0x130, %rdi            # imm = 0x130
callq 0x20a0
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x24d0
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %rax
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %r8
movq 0x80(%rsp), %r9
movq 0x88(%rsp), %r10
movq %rdi, 0xb0(%rsp)
movq %rdx, 0xb8(%rsp)
movq %rcx, 0xc0(%rsp)
movq %rax, 0xc8(%rsp)
movq %rsi, 0x90(%rsp)
movq %r8, 0x98(%rsp)
movq %r9, 0xa0(%rsp)
movq %r10, 0xa8(%rsp)
cmpq %rsi, %rdi
je 0x2728
leaq 0x2c8(%rsp), %rbx
movq %rdi, (%rbx)
movq %rdx, 0x8(%rbx)
movq %rcx, 0x10(%rbx)
movq %rax, 0x18(%rbx)
leaq 0x2a8(%rsp), %r14
movq %rsi, (%r14)
movq %r8, 0x8(%r14)
movq %r9, 0x10(%r14)
movq %r10, 0x18(%r14)
leaq 0x90(%rsp), %r15
leaq 0xb0(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x3daf
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2eec
movaps (%r12), %xmm0
movaps 0x10(%r12), %xmm1
leaq 0xd0(%rsp), %rbx
movaps %xmm0, (%rbx)
movaps %xmm1, 0x10(%rbx)
movaps (%r15), %xmm0
movaps 0x10(%r15), %xmm1
leaq 0xf0(%rsp), %rdi
movaps %xmm0, (%rdi)
movaps %xmm1, 0x10(%rdi)
movq %rbx, %rsi
callq 0x3daf
movq (%rbx), %rcx
cmpq $0x11, %rax
jl 0x26d0
leaq 0x20(%rsp), %rbx
movq %rcx, (%rbx)
leaq 0xd0(%rsp), %rsi
movups 0x8(%rsi), %xmm0
movups %xmm0, 0x8(%rbx)
movq 0x18(%rsi), %rax
movq %rax, 0x18(%rbx)
leaq 0x110(%rsp), %r14
pushq $0x10
popq %rdx
movq %r14, %rdi
callq 0x3e1f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3841
leaq 0x2e8(%rsp), %rbx
leaq 0xd0(%rsp), %rsi
pushq $0x10
popq %rdx
movq %rbx, %rdi
callq 0x3e1f
movq 0xf0(%rsp), %r14
movq (%rbx), %rbp
movq 0x8(%rbx), %r15
movq 0x10(%rbx), %r13
movq 0x18(%rbx), %r12
leaq 0x130(%rsp), %rbx
cmpq %r14, %rbp
je 0x2714
movq %rbp, 0x130(%rsp)
movq %r15, 0x138(%rsp)
movq %r13, 0x140(%rsp)
movq %r12, 0x148(%rsp)
movq %rbx, %rdi
callq 0x3999
addq $0x20, %rbp
cmpq %r13, %rbp
jne 0x2681
movq 0x8(%r12), %r15
addq $0x8, %r12
leaq 0x200(%r15), %r13
movq %r15, %rbp
jmp 0x2681
leaq 0x130(%rsp), %rdi
movq %rcx, (%rdi)
movups 0xd8(%rsp), %xmm0
movups %xmm0, 0x8(%rdi)
movq 0xe8(%rsp), %rax
movq %rax, 0x18(%rdi)
movaps 0xf0(%rsp), %xmm0
movaps 0x100(%rsp), %xmm1
leaq 0x20(%rsp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm1, 0x10(%rsi)
callq 0x3841
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %rax
leaq 0x130(%rsp), %rsi
movq %rdi, (%rsi)
movq %rdx, 0x8(%rsi)
movq %rcx, 0x10(%rsi)
movq %rax, 0x18(%rsi)
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3d38
movq (%rbx), %rdi
leaq 0x29f0(%rip), %rsi      # 0x5148
callq 0x3d2a
testb %al, %al
je 0x2a7b
leaq 0x20(%rsp), %rbx
leaq 0x130(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3d38
movq (%rbx), %rdi
leaq 0x290b(%rip), %rsi      # 0x5091
callq 0x3d2a
testb %al, %al
je 0x2a97
leaq 0x20(%rsp), %rbx
leaq 0x130(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3d38
movq (%rbx), %rdi
leaq 0x28db(%rip), %rsi      # 0x508f
callq 0x3d2a
testb %al, %al
je 0x2ab3
leaq 0x20(%rsp), %rbx
leaq 0x130(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x3d38
movq (%rbx), %rdi
leaq 0x28ab(%rip), %rsi      # 0x508d
callq 0x3d2a
testb %al, %al
je 0x2acf
movq 0x130(%rsp), %rax
cmpq 0x70(%rsp), %rax
jne 0x2aeb
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x3d58
leaq 0x8(%rsp), %rdi
callq 0x46e4
leaq 0x130(%rsp), %r14
movq %r14, %rdi
callq 0x2180
leaq 0x20(%rsp), %rsi
movl $0x1, (%rsi)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, (%rbx)
leaq 0x110(%rsp), %rcx
movb $0x31, (%rcx)
leaq 0x2829(%rip), %r8       # 0x507c
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
callq 0x41ff
pushq $0x2
popq %rsi
movq %rax, %rdi
callq 0x2200
leaq 0x138(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x21c0
leaq 0x2851(%rip), %rsi      # 0x50d5
leaq 0x40(%rsp), %rdi
callq 0x3d2a
testb %al, %al
je 0x2b07
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
callq 0x20a0
leaq 0x130(%rsp), %rdi
callq 0x2040
movaps 0x2759(%rip), %xmm0     # 0x5010
movaps %xmm0, (%rbx)
leaq 0x130(%rsp), %rdi
leaq 0x40(%rsp), %rsi
pushq $0x4
popq %rdx
leaq 0x20(%rsp), %rcx
callq 0x3c74
movq 0x130(%rsp), %rbx
movq 0x138(%rsp), %r14
cmpq %r14, %rbx
je 0x2941
movq %r14, %r15
subq %rbx, %r15
movq %r15, %rax
sarq $0x2, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3a3d
cmpq $0x41, %r15
jl 0x2936
leaq 0x40(%rbx), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3c02
cmpq %r14, %r15
je 0x2941
movq %r15, %rdi
callq 0x3c5f
addq $0x4, %r15
jmp 0x2923
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3c02
movq 0x130(%rsp), %rax
cmpl $0x4, (%rax)
jne 0x2b23
cmpl $0x3, 0x4(%rax)
jne 0x2b3f
cmpl $0x2, 0x8(%rax)
jne 0x2b5b
cmpl $0x1, 0xc(%rax)
jne 0x2b77
addq $0x10, %rax
cmpq 0x138(%rsp), %rax
jne 0x2b93
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4288
movq 0x130(%rsp), %rax
cmpl $0x1, (%rax)
jne 0x2bac
cmpl $0x2, 0x4(%rax)
jne 0x2bc5
cmpl $0x3, 0x8(%rax)
jne 0x2bde
cmpl $0x4, 0xc(%rax)
jne 0x2bf7
addq $0x10, %rax
cmpq 0x138(%rsp), %rax
jne 0x2c10
leaq 0x130(%rsp), %rdi
callq 0x46e4
xorl %eax, %eax
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x265c(%rip), %rdi      # 0x5052
leaq 0x2623(%rip), %rsi      # 0x5020
leaq 0x262b(%rip), %rcx      # 0x502f
pushq $0x40
jmp 0x2c27
leaq 0x264b(%rip), %rdi      # 0x505d
leaq 0x2607(%rip), %rsi      # 0x5020
leaq 0x260f(%rip), %rcx      # 0x502f
pushq $0x41
jmp 0x2c27
leaq 0x263a(%rip), %rdi      # 0x5068
leaq 0x25eb(%rip), %rsi      # 0x5020
leaq 0x25f3(%rip), %rcx      # 0x502f
pushq $0x42
jmp 0x2c27
leaq 0x2629(%rip), %rdi      # 0x5073
leaq 0x25cf(%rip), %rsi      # 0x5020
leaq 0x25d7(%rip), %rcx      # 0x502f
pushq $0x43
jmp 0x2c27
leaq 0x2618(%rip), %rdi      # 0x507e
leaq 0x25b3(%rip), %rsi      # 0x5020
leaq 0x25bb(%rip), %rcx      # 0x502f
pushq $0x44
jmp 0x2c27
leaq 0x2611(%rip), %rdi      # 0x5093
leaq 0x2597(%rip), %rsi      # 0x5020
leaq 0x259f(%rip), %rcx      # 0x502f
pushq $0x4b
jmp 0x2c27
leaq 0x2602(%rip), %rdi      # 0x50a0
leaq 0x257b(%rip), %rsi      # 0x5020
leaq 0x2583(%rip), %rcx      # 0x502f
pushq $0x4c
jmp 0x2c27
leaq 0x25f3(%rip), %rdi      # 0x50ad
leaq 0x255f(%rip), %rsi      # 0x5020
leaq 0x2567(%rip), %rcx      # 0x502f
pushq $0x4d
jmp 0x2c27
leaq 0x25e4(%rip), %rdi      # 0x50ba
leaq 0x2543(%rip), %rsi      # 0x5020
leaq 0x254b(%rip), %rcx      # 0x502f
pushq $0x4e
jmp 0x2c27
leaq 0x25d5(%rip), %rdi      # 0x50c7
leaq 0x2527(%rip), %rsi      # 0x5020
leaq 0x252f(%rip), %rcx      # 0x502f
pushq $0x4f
jmp 0x2c27
leaq 0x25cd(%rip), %rdi      # 0x50db
leaq 0x250b(%rip), %rsi      # 0x5020
leaq 0x2513(%rip), %rcx      # 0x502f
pushq $0x56
jmp 0x2c27
leaq 0x2528(%rip), %rdi      # 0x5052
leaq 0x24ef(%rip), %rsi      # 0x5020
leaq 0x24f7(%rip), %rcx      # 0x502f
pushq $0x5e
jmp 0x2c27
leaq 0x2517(%rip), %rdi      # 0x505d
leaq 0x24d3(%rip), %rsi      # 0x5020
leaq 0x24db(%rip), %rcx      # 0x502f
pushq $0x5f
jmp 0x2c27
leaq 0x2506(%rip), %rdi      # 0x5068
leaq 0x24b7(%rip), %rsi      # 0x5020
leaq 0x24bf(%rip), %rcx      # 0x502f
pushq $0x60
jmp 0x2c27
leaq 0x24f5(%rip), %rdi      # 0x5073
leaq 0x249b(%rip), %rsi      # 0x5020
leaq 0x24a3(%rip), %rcx      # 0x502f
pushq $0x61
jmp 0x2c27
leaq 0x24e4(%rip), %rdi      # 0x507e
leaq 0x247f(%rip), %rsi      # 0x5020
leaq 0x2487(%rip), %rcx      # 0x502f
pushq $0x62
jmp 0x2c27
leaq 0x24c0(%rip), %rdi      # 0x5073
leaq 0x2466(%rip), %rsi      # 0x5020
leaq 0x246e(%rip), %rcx      # 0x502f
pushq $0x67
jmp 0x2c27
leaq 0x249c(%rip), %rdi      # 0x5068
leaq 0x244d(%rip), %rsi      # 0x5020
leaq 0x2455(%rip), %rcx      # 0x502f
pushq $0x68
jmp 0x2c27
leaq 0x2478(%rip), %rdi      # 0x505d
leaq 0x2434(%rip), %rsi      # 0x5020
leaq 0x243c(%rip), %rcx      # 0x502f
pushq $0x69
jmp 0x2c27
leaq 0x2454(%rip), %rdi      # 0x5052
leaq 0x241b(%rip), %rsi      # 0x5020
leaq 0x2423(%rip), %rcx      # 0x502f
pushq $0x6a
jmp 0x2c27
leaq 0x2467(%rip), %rdi      # 0x507e
leaq 0x2402(%rip), %rsi      # 0x5020
leaq 0x240a(%rip), %rcx      # 0x502f
pushq $0x6b
popq %rdx
callq 0x20c0
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x3d58
jmp 0x2c8d
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
jmp 0x2c92
jmp 0x2c99
jmp 0x2c9e
movq %rax, %rbx
pushq $0x60
popq %r14
leaq (%rsp,%r14), %rdi
addq $0x130, %rdi            # imm = 0x130
callq 0x20a0
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x2c54
jmp 0x2c8d
jmp 0x2c74
jmp 0x2c74
movq %rax, %rbx
addq $-0x20, %r15
movq %r15, %rdi
callq 0x20a0
cmpq %r14, %r15
jne 0x2c77
jmp 0x2c8d
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x46e4
jmp 0x2cae
movq %rax, %rbx
jmp 0x2cae
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x2210