// File: /workspace/github_c_makefile_star2_O3/rouming[P]io/io.c
// Function: complete_req
static int complete_req(struct io_req *req, int len)
{
	struct io_queue *q = req->q;

	bool keep_in_queue = false;
	int off, dir;

	dir = req->flags & REQ_RDWR_MASK;
	io_req_get(req);
	list_del_init(&req->list);
	off = req->io_fn(req, len);
	if (dir == REQ_RD) {
		/* Read path */
		if (off == 0) {
			/* Return to the request queue, continue filling in */
			list_add(&req->list, &q->queue);
			keep_in_queue = true;
		} else {
			if (off > 0 && off != len) {
				/* Stash the rest or everything. */
				off = stash_rest(req, off, len);
			}
		}
	}
	io_req_put(req);
	if (!keep_in_queue) {
		assert(q->reqs_num[dir] > 0);
		q->reqs_num[dir]--;
	}

	return off;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x24(%rdi), %eax
testl %eax, %eax
jle 0x3fd6
movl %esi, %ebp
movq %rdi, %rbx
movq 0x10(%rdi), %r12
movl 0x20(%rdi), %r13d
andl $0x1, %r13d
incl %eax
movl %eax, 0x24(%rdi)
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
movq %rcx, 0x8(%rax)
movq %rax, (%rcx)
movq %rdi, (%rdi)
movq %rdi, 0x8(%rdi)
callq *0x178(%rdi)
movl %eax, %r15d
testl %r13d, %r13d
je 0x3ee1
movq %rbx, %rdi
callq 0x3c7a
movl 0x148(%r12,%r13,4), %eax
testl %eax, %eax
jle 0x3ff5
decl %eax
movl %eax, 0x148(%r12,%r13,4)
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r15d, %r15d
je 0x3f48
setle %al
cmpl %ebp, %r15d
sete %cl
orb %al, %cl
jne 0x3ead
movq 0x10(%rbx), %r14
xorl %eax, %eax
cmpl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
cmovnel %r15d, %eax
cmpq $0x0, 0x160(%r14)
jne 0x4014
cmpq $0x0, 0x168(%r14)
jne 0x4033
movslq %ebp, %r15
movq %rax, %rbp
subq %rax, %r15
movq 0x158(%r14), %rdi
testq %rdi, %rdi
je 0x3f7b
callq 0x1120
movq 0x158(%r14), %rdx
cmpq %r15, %rax
jb 0x3f7d
jmp 0x3fa2
leaq 0x138(%r12), %rax
movq 0x138(%r12), %rcx
movq %rbx, 0x8(%rcx)
movq %rcx, (%rbx)
movq %rax, 0x8(%rbx)
movq %rbx, 0x138(%r12)
movq %rbx, %rdi
callq 0x3c7a
xorl %r15d, %r15d
jmp 0x3ecf
xorl %edx, %edx
leaq 0xfff(%r15), %rsi
andq $-0x1000, %rsi          # imm = 0xF000
movq %rdx, %rdi
callq 0x11b0
testq %rax, %rax
je 0x3fcb
movq %rax, %rdx
movq %rax, 0x158(%r14)
leaq 0x28(%rbx), %rdi
movq %rbp, %rsi
movq %r15, %rcx
callq 0x2a7f
cltq
cmpq %rax, %r15
jne 0x4052
movq %r15, 0x160(%r14)
xorl %r15d, %r15d
jmp 0x3ead
movl $0xfffffff4, %r15d      # imm = 0xFFFFFFF4
jmp 0x3ead
leaq 0x1574(%rip), %rdi      # 0x5551
leaq 0x148e(%rip), %rsi      # 0x5472
leaq 0x1574(%rip), %rcx      # 0x555f
movl $0x3eb, %edx            # imm = 0x3EB
callq 0x10d0
leaq 0x1654(%rip), %rdi      # 0x5650
leaq 0x146f(%rip), %rsi      # 0x5472
leaq 0x165b(%rip), %rcx      # 0x5665
movl $0x227, %edx            # imm = 0x227
callq 0x10d0
leaq 0x1671(%rip), %rdi      # 0x568c
leaq 0x1450(%rip), %rsi      # 0x5472
leaq 0x1674(%rip), %rcx      # 0x569d
movl $0x171, %edx            # imm = 0x171
callq 0x10d0
leaq 0x1693(%rip), %rdi      # 0x56cd
leaq 0x1431(%rip), %rsi      # 0x5472
leaq 0x1655(%rip), %rcx      # 0x569d
movl $0x172, %edx            # imm = 0x172
callq 0x10d0
leaq 0x1686(%rip), %rdi      # 0x56df
leaq 0x1412(%rip), %rsi      # 0x5472
leaq 0x1636(%rip), %rcx      # 0x569d
movl $0x17b, %edx            # imm = 0x17B
callq 0x10d0