// File: /workspace/github_c_makefile_star2_O1/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 0x8f50
xorl %ebx, %ebx
negl %eax
sbbl %ebx, %ebx
cmpq $0x0, 0x20(%r14)
je 0xb46d
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rbp
subq 0x28(%r15), %rax
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
movq %rax, 0x8(%rsp)
subq 0x30(%r15), %rbp
movq 0x38(%r15), %rdi
callq 0xa077
movq %rax, %r13
testq %r12, %r12
je 0xb401
movq 0x18(%r12), %rax
cmpq $-0x1, %rax
jne 0xb403
xorl %eax, %eax
addq 0x8(%rsp), %rbp
movq 0x20(%r14), %rdi
movq 0x8(%r15), %r11
movq (%r11), %rdx
movq 0x8(%r11), %rcx
movq 0x10(%r11), %r8
testq %r12, %r12
movq %rax, 0x10(%rsp)
je 0xb42b
movl (%r12), %r9d
jmp 0xb42e
xorl %r9d, %r9d
testq %r13, %r13
leaq 0x7568(%rip), %r10      # 0x129a0
cmovneq %r13, %r10
leaq 0x77f9(%rip), %rsi      # 0x12c3c
xorl %eax, %eax
pushq 0x10(%rsp)
pushq 0x28(%r11)
pushq %rbp
pushq %r10
callq 0xa973
addq $0x20, %rsp
cmpq $-0x1, %rax
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovel %eax, %ebx
movq %r13, %rdi
callq 0x2040
movq 0x38(%r15), %rdi
callq 0x9947
decq 0x30(%r14)
movq 0x50(%r15), %rax
movq 0x58(%r15), %rcx
testq %rcx, %rcx
movq %rcx, %rdx
cmoveq %r14, %rdx
movq %rax, 0x50(%rdx)
movq 0x50(%r15), %rax
leaq 0x48(%r14), %rdx
leaq 0x58(%rax), %rsi
testq %rax, %rax
cmoveq %rdx, %rsi
movq %rcx, (%rsi)
testq %r12, %r12
je 0xb4bd
movl (%r12), %eax
cmpl $0x1f4, %eax            # imm = 0x1F4
je 0xb4bd
cmpl $0x1f7, %eax            # imm = 0x1F7
jne 0xb4f3
movq 0x40(%r14), %rax
movq %rax, 0x50(%r15)
movq $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 0xb1d6
testl %eax, %eax
jne 0xb514
xorl %ebx, %ebx
jmp 0xb519
movq 0x20(%r15), %rdi
movq %r12, %rsi
callq *0x18(%r15)
movl %eax, %ebp
movq %r15, %rdi
callq 0x2040
movq %r14, %rdi
callq 0xb1d6
testl %eax, %eax
je 0xb52a
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %ebp, %ebp
cmovnel %ebp, %ebx
jmp 0xb519
nopl (%rax)