// File: /workspace/github_c_makefile_star2_O1/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 0x3df6
testl %ebx, %ebx
js 0x1c49
movl 0x14(%r14), %eax
cmpl $0x6, %eax
jne 0x1c74
leaq 0x18(%r14), %rdi
leaq -0x21b(%rip), %rcx      # 0x19b0
xorl %esi, %esi
movq %r14, %rdx
callq 0x3d60
testq %rax, %rax
je 0x1d22
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 0x3a85
testl %eax, %eax
je 0x1d14
leaq 0x3479(%rip), %rdi      # 0x50aa
leaq 0x344d(%rip), %rsi      # 0x5085
leaq 0x3594(%rip), %rcx      # 0x51d3
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 0x1d14
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       # 0x1b98
movq %r14, %rdx
callq 0x3d60
testq %rax, %rax
je 0x1d41
movq %rax, %r15
movslq 0x14(%r14), %rax
leaq 0x6470(%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 0x3a85
testl %eax, %eax
jne 0x1d60
movl 0x14(%r14), %esi
leaq 0x34e9(%rip), %rdi      # 0x51f6
xorl %eax, %eax
callq 0x10c0
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x3567(%rip), %rdi      # 0x5290
leaq 0x3355(%rip), %rsi      # 0x5085
leaq 0x349c(%rip), %rcx      # 0x51d3
movl $0x5d, %edx
callq 0x10d0
leaq 0x3548(%rip), %rdi      # 0x5290
leaq 0x3336(%rip), %rsi      # 0x5085
leaq 0x347d(%rip), %rcx      # 0x51d3
movl $0x6c, %edx
callq 0x10d0
leaq 0x3343(%rip), %rdi      # 0x50aa
leaq 0x3317(%rip), %rsi      # 0x5085
leaq 0x345e(%rip), %rcx      # 0x51d3
movl $0x75, %edx
callq 0x10d0
nop