// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %rsi, %r15
movq %rdi, %r14
movq (%rdi), %rbx
leaq 0x8(%rsp), %rdi
callq 0x8fbc
negl %eax
movl $0x0, %ebp
sbbl %ebp, %ebp
cmpq $0x0, 0x20(%rbx)
je 0xb4a6
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %r13
subq 0x28(%r14), %rax
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
subq 0x30(%r14), %r13
addq %rax, %r13
movq 0x38(%r14), %rdi
callq 0xa0bf
movq %rax, %r12
testq %r15, %r15
movq %r15, (%rsp)
je 0xb44b
movq 0x18(%r15), %rax
xorl %r10d, %r10d
cmpq $-0x1, %rax
cmovneq %rax, %r10
movl (%r15), %r9d
jmp 0xb451
xorl %r10d, %r10d
xorl %r9d, %r9d
movq 0x20(%rbx), %rdi
movq 0x8(%r14), %r11
movq (%r11), %rdx
movq 0x8(%r11), %rcx
movq 0x10(%r11), %r8
testq %r12, %r12
leaq 0x7572(%rip), %r15      # 0x129e0
cmovneq %r12, %r15
leaq 0x7803(%rip), %rsi      # 0x12c7c
xorl %eax, %eax
pushq %r10
pushq 0x28(%r11)
pushq %r13
pushq %r15
callq 0xa9bb
addq $0x20, %rsp
cmpq $-0x1, %rax
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovel %eax, %ebp
movq %r12, %rdi
callq 0x2040
movq (%rsp), %r15
movq 0x38(%r14), %rdi
callq 0x99ae
decq 0x30(%rbx)
movq 0x50(%r14), %rax
movq 0x58(%r14), %rcx
testq %rcx, %rcx
movq %rcx, %rdx
cmoveq %rbx, %rdx
movq %rax, 0x50(%rdx)
leaq 0x48(%rbx), %rdx
leaq 0x58(%rax), %rsi
testq %rax, %rax
cmoveq %rdx, %rsi
movq %rcx, (%rsi)
testq %r15, %r15
je 0xb4f1
movl (%r15), %eax
cmpl $0x1f4, %eax            # imm = 0x1F4
je 0xb4f1
cmpl $0x1f7, %eax            # imm = 0x1F7
jne 0xb527
movq 0x40(%rbx), %rax
movq %rax, 0x50(%r14)
movq $0x0, 0x58(%r14)
leaq 0x58(%rax), %rcx
leaq 0x38(%rbx), %rdx
testq %rax, %rax
cmoveq %rdx, %rcx
movq %r14, (%rcx)
movq %r14, 0x40(%rbx)
movq %rbx, %rdi
callq 0xb212
testl %eax, %eax
jne 0xb549
xorl %ebp, %ebp
jmp 0xb54e
movq 0x20(%r14), %rdi
movq %r15, %rsi
callq *0x18(%r14)
movl %eax, %r15d
movq %r14, %rdi
callq 0x2040
movq %rbx, %rdi
callq 0xb212
testl %eax, %eax
je 0xb55f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %r15d, %r15d
cmovnel %r15d, %ebp
jmp 0xb54e