// File: /workspace/github_c_makefile_star2_O2/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 0x3833
testl %ebx, %ebx
js 0x1bb3
movl 0x14(%r14), %eax
cmpl $0x6, %eax
jne 0x1bde
leaq 0x18(%r14), %rdi
leaq -0x219(%rip), %rcx      # 0x191f
xorl %esi, %esi
movq %r14, %rdx
callq 0x37a0
testq %rax, %rax
je 0x1c8c
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 0x3515
testl %eax, %eax
je 0x1c7e
leaq 0x34ec(%rip), %rdi      # 0x508a
leaq 0x34c0(%rip), %rsi      # 0x5065
leaq 0x3607(%rip), %rcx      # 0x51b3
pushq $0x63
jmp 0x1cd5
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 0x1c7e
incl %eax
movl %eax, 0x14(%r14)
xorl %ecx, %ecx
cmpl $0x6, %eax
setne %cl
leal 0x1(%rcx,%rcx), %esi
leaq 0x18(%r14), %rdi
leaq -0xf6(%rip), %rcx       # 0x1b05
movq %r14, %rdx
callq 0x37a0
testq %rax, %rax
je 0x1ca5
movq %rax, %r15
movslq 0x14(%r14), %rax
leaq 0x6506(%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 0x3515
testl %eax, %eax
jne 0x1cbe
movl 0x14(%r14), %esi
leaq 0x355f(%rip), %rdi      # 0x51d6
xorl %eax, %eax
callq 0x10c0
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x35dd(%rip), %rdi      # 0x5270
leaq 0x33cb(%rip), %rsi      # 0x5065
leaq 0x3512(%rip), %rcx      # 0x51b3
pushq $0x5d
jmp 0x1cd5
leaq 0x35c4(%rip), %rdi      # 0x5270
leaq 0x33b2(%rip), %rsi      # 0x5065
leaq 0x34f9(%rip), %rcx      # 0x51b3
pushq $0x6c
jmp 0x1cd5
leaq 0x33c5(%rip), %rdi      # 0x508a
leaq 0x3399(%rip), %rsi      # 0x5065
leaq 0x34e0(%rip), %rcx      # 0x51b3
pushq $0x75
popq %rdx
callq 0x10d0
nop