// File: /workspace/github_c_makefile_star2_O3/rouming[P]io/zmtp-test.c
// Function: on_write
static int on_write(struct io_req *req, int len)
{
	struct peer *peer = req->data;
	int err;

	io_req_put(req);
	if (len < 0)
		list_add_tail(&peer->list, &peer->ctx->peers_to_free);
	else if (peer->sent == ARRAY_SIZE(replies)) {
		/* Queue is ready for new requests */
		req = io_req_create(&peer->q, REQ_RD, peer, on_read);
		assert(req);
		req->buf = (struct io_buf){
			.iov_num  = 1,
			.is_vari_len = true,
		};
		err = io_queue_submit(req);
		assert(err == 0);
	} else {
		int flags = REQ_WR;
		int err;

		peer->sent++;

		flags |= peer->sent == ARRAY_SIZE(replies) ? 0 : REQ_MORE;
		req = io_req_create(&peer->q, flags, peer, on_write);
		assert(req);
		req->buf = (struct io_buf){
			.iov[0] = {
				.iov_base = (char *)replies[peer->sent-1],
				.iov_len  = strlen(replies[peer->sent-1])
			},
			.iov_num  = 1,
		};
		err = io_queue_submit(req);
		assert(err == 0);

		printf(" #%d chunk is sent\n", peer->sent);
		/*
		  sleep(1);
		*/
	}

	return len;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq 0x18(%rdi), %r14
callq 0x3c7a
testl %ebx, %ebx
js 0x1bcd
movl 0x14(%r14), %eax
cmpl $0x6, %eax
jne 0x1bf8
leaq 0x18(%r14), %rdi
leaq -0x21b(%rip), %rcx      # 0x1934
xorl %esi, %esi
movq %r14, %rdx
callq 0x3be7
testq %rax, %rax
je 0x1ca6
movq %rax, %r14
movq %rax, %rdi
addq $0x28, %rdi
movl $0x120, %edx            # imm = 0x120
xorl %esi, %esi
callq 0x10e0
movq $0x1, 0x148(%r14)
movb $0x1, 0x150(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x151(%r14)
movups %xmm0, 0x160(%r14)
movq %r14, %rdi
callq 0x3902
testl %eax, %eax
je 0x1c98
leaq 0x34d5(%rip), %rdi      # 0x508a
leaq 0x34a9(%rip), %rsi      # 0x5065
leaq 0x35f0(%rip), %rcx      # 0x51b3
movl $0x63, %edx
callq 0x10d0
movq 0x1c0(%r14), %rax
leaq 0x270(%rax), %rcx
movq 0x278(%rax), %rdx
movq %r14, 0x278(%rax)
movq %rcx, (%r14)
movq %rdx, 0x8(%r14)
movq %r14, (%rdx)
jmp 0x1c98
incl %eax
movl %eax, 0x14(%r14)
xorl %ecx, %ecx
cmpl $0x6, %eax
setne %cl
leal 0x1(%rcx,%rcx), %esi
leaq 0x18(%r14), %rdi
leaq -0xf9(%rip), %rcx       # 0x1b1c
movq %r14, %rdx
callq 0x3be7
testq %rax, %rax
je 0x1cc5
movq %rax, %r15
movslq 0x14(%r14), %rax
leaq 0x64ec(%rip), %rcx      # 0x8120
movq -0x8(%rcx,%rax,8), %r12
movq %r12, %rdi
callq 0x10a0
movq %r12, 0x28(%r15)
movq %rax, 0x30(%r15)
movq %r15, %rdi
addq $0x38, %rdi
movl $0x110, %edx            # imm = 0x110
xorl %esi, %esi
callq 0x10e0
movq $0x1, 0x148(%r15)
xorps %xmm0, %xmm0
movups %xmm0, 0x150(%r15)
movups %xmm0, 0x160(%r15)
movq %r15, %rdi
callq 0x3902
testl %eax, %eax
jne 0x1ce4
movl 0x14(%r14), %esi
leaq 0x3545(%rip), %rdi      # 0x51d6
xorl %eax, %eax
callq 0x10c0
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x35c3(%rip), %rdi      # 0x5270
leaq 0x33b1(%rip), %rsi      # 0x5065
leaq 0x34f8(%rip), %rcx      # 0x51b3
movl $0x5d, %edx
callq 0x10d0
leaq 0x35a4(%rip), %rdi      # 0x5270
leaq 0x3392(%rip), %rsi      # 0x5065
leaq 0x34d9(%rip), %rcx      # 0x51b3
movl $0x6c, %edx
callq 0x10d0
leaq 0x339f(%rip), %rdi      # 0x508a
leaq 0x3373(%rip), %rsi      # 0x5065
leaq 0x34ba(%rip), %rcx      # 0x51b3
movl $0x75, %edx
callq 0x10d0
nop