// File: suyash[P]chan/chan_test.cc
// Function: buffered_chan_multi_with_pause_Test::TestBody()
TEST(buffered_chan, multi_with_pause) {
	chan::buffered_chan<int> c(5);

	std::thread pool[100];

	std::atomic<int> blocked_count;
	blocked_count.store(0);

	auto sender = [&blocked_count](chan::write_chan<int>& c){
		blocked_count++;
		c << 1;
	};

	for (int i = 0 ; i < 50 ; i++) {
		pool[i] = std::thread(sender, std::ref(c));
	}

	// wait for 50 threads to get blocked
	while (true) {
		if (blocked_count.load() == 50) {
			break;
		}
	}

	auto receiver = [](chan::read_chan<int>& c){
		int _ = 0;
		c >> _;
	};

	for (int i = 50 ; i < 100 ; i++) {
		pool[i] = std::thread(receiver, std::ref(c));
	}

	for (int i = 0 ; i < 100 ; i++) {
		pool[i].join();
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4f0, %rsp            # imm = 0x4F0
movq %rdi, -0x38(%rbp)
leaq -0x100(%rbp), %rdi
movl $0x5, %esi
callq 0x4c3c0
leaq -0x420(%rbp), %rax
movq %rax, %rcx
addq $0x320, %rcx            # imm = 0x320
movq %rcx, -0x488(%rbp)
movq %rax, -0x480(%rbp)
movq -0x480(%rbp), %rdi
movq %rdi, -0x490(%rbp)
callq 0x4c730
movq -0x490(%rbp), %rax
movq -0x488(%rbp), %rcx
addq $0x8, %rax
cmpq %rcx, %rax
movq %rax, -0x480(%rbp)
jne 0x47bff
leaq -0x424(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x5, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x4a0(%rbp)
movl -0x28(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x4f8c0
movl %eax, -0x494(%rbp)
jmp 0x47c69
movl -0x494(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x4a4(%rbp)
movl -0x24(%rbp), %ecx
movl %ecx, -0x30(%rbp)
subl $0x3, %eax
je 0x47ca3
jmp 0x47c88
movl -0x4a4(%rbp), %eax
subl $0x5, %eax
je 0x47cb1
jmp 0x47c95
movq -0x4a0(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x47cc7
movq -0x4a0(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x47cc7
movq -0x4a0(%rbp), %rcx
movl -0x30(%rbp), %eax
xchgl %eax, (%rcx)
jmp 0x47cc7
movq %rax, %rdi
callq 0x29080
leaq -0x424(%rbp), %rax
movq %rax, -0x430(%rbp)
movl $0x0, -0x434(%rbp)
cmpl $0x32, -0x434(%rbp)
jge 0x47d8b
leaq -0x100(%rbp), %rdi
callq 0x4c750
movq %rax, -0x448(%rbp)
leaq -0x440(%rbp), %rdi
leaq -0x430(%rbp), %rsi
leaq -0x448(%rbp), %rdx
callq 0x47f80
jmp 0x47d1b
movslq -0x434(%rbp), %rax
leaq -0x420(%rbp), %rdi
shlq $0x3, %rax
addq %rax, %rdi
leaq -0x440(%rbp), %rsi
callq 0x4c780
leaq -0x440(%rbp), %rdi
callq 0x4c1f0
movl -0x434(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x434(%rbp)
jmp 0x47cdf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x450(%rbp)
movl %eax, -0x454(%rbp)
leaq -0x420(%rbp), %rax
movq %rax, -0x4b8(%rbp)
addq $0x320, %rax            # imm = 0x320
movq %rax, -0x4b0(%rbp)
jmp 0x47f2a
jmp 0x47d8d
jmp 0x47d8f
leaq -0x424(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x5, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x4c8(%rbp)
movl -0xc(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x4f8c0
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x4bc(%rbp)
decl %eax
subl $0x2, %eax
jb 0x47de9
jmp 0x47dce
movl -0x4bc(%rbp), %eax
subl $0x5, %eax
je 0x47df7
jmp 0x47ddb
movq -0x4c8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x47e03
movq -0x4c8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x47e03
movq -0x4c8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
cmpl $0x32, -0x14(%rbp)
jne 0x47e0b
jmp 0x47e0d
jmp 0x47d8d
movl $0x32, -0x45c(%rbp)
cmpl $0x64, -0x45c(%rbp)
jge 0x47e8d
leaq -0x100(%rbp), %rdi
callq 0x4c750
movq %rax, -0x470(%rbp)
leaq -0x468(%rbp), %rdi
leaq -0x455(%rbp), %rsi
leaq -0x470(%rbp), %rdx
callq 0x48040
jmp 0x47e4f
movslq -0x45c(%rbp), %rax
leaq -0x420(%rbp), %rdi
shlq $0x3, %rax
addq %rax, %rdi
leaq -0x468(%rbp), %rsi
callq 0x4c780
leaq -0x468(%rbp), %rdi
callq 0x4c1f0
movl -0x45c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x45c(%rbp)
jmp 0x47e17
movl $0x0, -0x474(%rbp)
cmpl $0x64, -0x474(%rbp)
jge 0x47ec9
movslq -0x474(%rbp), %rax
leaq -0x420(%rbp,%rax,8), %rdi
callq 0xab70
jmp 0x47eb6
jmp 0x47eb8
movl -0x474(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x474(%rbp)
jmp 0x47e97
leaq -0x420(%rbp), %rax
movq %rax, -0x4d8(%rbp)
addq $0x320, %rax            # imm = 0x320
movq %rax, -0x4d0(%rbp)
movq -0x4d0(%rbp), %rdi
addq $-0x8, %rdi
movq %rdi, -0x4e0(%rbp)
callq 0x4c1f0
movq -0x4d8(%rbp), %rcx
movq -0x4e0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x4d0(%rbp)
jne 0x47ee4
leaq -0x100(%rbp), %rdi
callq 0x4c490
addq $0x4f0, %rsp            # imm = 0x4F0
popq %rbp
retq
movq -0x4b0(%rbp), %rdi
addq $-0x8, %rdi
movq %rdi, -0x4e8(%rbp)
callq 0x4c1f0
movq -0x4b8(%rbp), %rcx
movq -0x4e8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x4b0(%rbp)
jne 0x47f2a
leaq -0x100(%rbp), %rdi
callq 0x4c490
movq -0x450(%rbp), %rdi
callq 0xabc0
nopw %cs:(%rax,%rax)