// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/liball/../lib/s3/s3_request_queue.c
// Function: callback_reqdone
static int
callback_reqdone(void * cookie, struct http_response * res)
{
	struct request * R = cookie;
	struct s3_request_queue * Q = R->Q;
	struct timeval t_end;
	long t_micros;
	char * addr;
	size_t rslen;
	int rc = 0;
	int rc2;

	/* Compute how long the request took. */
	if (monoclock_get(&t_end))
		rc = -1;
	t_micros = (t_end.tv_sec - R->t_start.tv_sec) * 1000000 +
	    (t_end.tv_usec - R->t_start.tv_usec);

	/* If we have a log file, log the S3 request. */
	if (Q->logfile != NULL) {
		/* Prettyprint the address we used. */
		addr = sock_addr_prettyprint(R->addrs[0]);

		/* Write to the log file. */
		if ((res != NULL) && (res->bodylen != (size_t)(-1)))
			rslen = res->bodylen;
		else
			rslen = 0;
		if (logging_printf(Q->logfile, "|%s|/%s%s|%d|%s|%ld|%zu|%zu",
		    R->request->method, R->request->bucket, R->request->path,
		    (res != NULL) ? res->status : 0,
		    (addr != NULL) ? addr : "(unknown)",
		    t_micros, R->request->bodylen, rslen) == -1)
			rc = -1;

		/* Free the address string. */
		free(addr);
	}

	/* This address has been tried. */
	sock_addr_free(R->addrs[0]);

	/* The number of in-progress requests has just decreased. */
	Q->reqsip -= 1;

	/* Remove from the in-progress queue. */
	if (R->next) {
		R->next->prev = R->prev;
	} else {
		Q->reqs_ip_tail = R->prev;
	}
	if (R->prev) {
		R->prev->next = R->next;
	} else {
		Q->reqs_ip_head = R->next;
	}

	/* If the HTTP connection failed, try this again later. */
	if (res == NULL)
		goto tryagain;

	/* If we got a 500 or 503 response, try this again later. */
	if ((res->status == 500) || (res->status == 503))
		goto tryagain;

	/* Send the response upstream. */
	rc2 = (R->callback)(R->cookie, res);
	rc = rc2 ? rc2 : rc;

	/* Free the request structure. */
	free(R);

	/* Launch another request if possible. */
	if (poke(Q))
		goto err0;

	/* Return status from upstream callback. */
	return (rc);

tryagain:
	/* Add this request back to the queue. */
	R->prev = Q->reqs_queued_tail;
	R->next = NULL;
	if (R->prev == NULL) {
		Q->reqs_queued_head = R;
	} else {
		R->prev->next = R;
	}
	Q->reqs_queued_tail = R;

	/* Poke the queue. */
	if (poke(Q))
		goto err0;

	/* The failure has been successfully handled. */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r12
movq %rdi, %r15
movq (%rdi), %r14
leaq 0x18(%rsp), %rdi
callq 0x82bc
xorl %ebx, %ebx
negl %eax
sbbl %ebx, %ebx
cmpq $0x0, 0x20(%r14)
pushq $-0x1
popq %rbp
je 0xa633
movl %ebx, 0xc(%rsp)
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rbp
subq 0x28(%r15), %rax
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
movq %rax, 0x10(%rsp)
subq 0x30(%r15), %rbp
movq 0x38(%r15), %rdi
callq 0x91f2
movq %rax, %r13
testq %r12, %r12
je 0xa5cd
movq 0x18(%r12), %rbx
cmpq $-0x1, %rbx
jne 0xa5cf
xorl %ebx, %ebx
addq 0x10(%rsp), %rbp
movq 0x20(%r14), %rdi
movq 0x8(%r15), %r11
movq (%r11), %rdx
movq 0x8(%r11), %rcx
movq 0x10(%r11), %r8
testq %r12, %r12
je 0xa5f2
movl (%r12), %r9d
jmp 0xa5f5
xorl %r9d, %r9d
testq %r13, %r13
leaq 0x733c(%rip), %r10      # 0x1193b
cmovneq %r13, %r10
leaq 0x75cd(%rip), %rsi      # 0x11bd7
xorl %eax, %eax
pushq %rbx
pushq 0x28(%r11)
pushq %rbp
pushq %r10
callq 0x9b84
addq $0x20, %rsp
cmpq $-0x1, %rax
pushq $-0x1
popq %rbp
movl 0xc(%rsp), %ebx
cmovel %ebp, %ebx
movq %r13, %rdi
callq 0x2040
movq 0x38(%r15), %rdi
callq 0x8b4b
decq 0x30(%r14)
movq 0x50(%r15), %rax
movq 0x58(%r15), %rcx
testq %rcx, %rcx
movq %rcx, %rdx
cmoveq %r14, %rdx
movq %rax, 0x50(%rdx)
leaq 0x48(%r14), %rdx
leaq 0x58(%rax), %rsi
testq %rax, %rax
cmoveq %rdx, %rsi
movq %rcx, (%rsi)
testq %r12, %r12
je 0xa67f
movl (%r12), %eax
cmpl $0x1f4, %eax            # imm = 0x1F4
je 0xa67f
cmpl $0x1f7, %eax            # imm = 0x1F7
jne 0xa6b2
movq 0x40(%r14), %rax
movq %rax, 0x50(%r15)
andq $0x0, 0x58(%r15)
leaq 0x58(%rax), %rcx
leaq 0x38(%r14), %rdx
testq %rax, %rax
cmoveq %rdx, %rcx
movq %r15, (%rcx)
movq %r15, 0x40(%r14)
movq %r14, %rdi
callq 0xa3b0
testl %eax, %eax
jne 0xa6dd
xorl %ebp, %ebp
jmp 0xa6dd
movq 0x20(%r15), %rdi
movq %r12, %rsi
callq *0x18(%r15)
movl %eax, %r12d
movq %r15, %rdi
callq 0x2040
movq %r14, %rdi
callq 0xa3b0
testl %eax, %eax
jne 0xa6dd
testl %r12d, %r12d
cmovnel %r12d, %ebx
movl %ebx, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop