// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %rbx
subq $0xb8, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x5c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xc5c0
cmpl $0x0, %eax
je 0x10183
movl $0xffffffff, -0x5c(%rbp) # imm = 0xFFFFFFFF
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rcx
subq 0x28(%rcx), %rax
imulq $0xf4240, %rax, %rax    # imm = 0xF4240
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rdx
subq 0x30(%rdx), %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x102e4
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0xe1a0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x101e9
movq -0x20(%rbp), %rax
cmpq $-0x1, 0x18(%rax)
je 0x101e9
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x101f1
movq $0x0, -0x58(%rbp)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x10241
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x84(%rbp)
jmp 0x1024b
xorl %eax, %eax
movl %eax, -0x84(%rbp)
jmp 0x1024b
movl -0x84(%rbp), %eax
movl %eax, -0x88(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x1026b
movq -0x50(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x1027b
leaq 0xfaf6(%rip), %rax      # 0x1fd68
movq %rax, -0x90(%rbp)
jmp 0x1027b
movl -0x88(%rbp), %r9d
movq -0x68(%rbp), %r8
movq -0x70(%rbp), %rcx
movq -0x78(%rbp), %rdx
movq -0x80(%rbp), %rdi
movq -0x90(%rbp), %rbx
movq -0x48(%rbp), %r11
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %r10
movq -0x58(%rbp), %rax
leaq 0xfe16(%rip), %rsi      # 0x200ca
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movb $0x0, %al
callq 0xf0f0
cmpq $-0x1, %rax
jne 0x102db
movl $0xffffffff, -0x5c(%rbp) # imm = 0xFFFFFFFF
movq -0x50(%rbp), %rdi
callq 0x2040
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0xd5f0
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rcx
subq $0x1, %rcx
movq %rcx, 0x30(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x58(%rax)
je 0x10322
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rax
movq %rcx, 0x50(%rax)
jmp 0x10332
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x10353
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movq %rcx, 0x58(%rax)
jmp 0x10363
movq -0x28(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
cmpq $0x0, -0x20(%rbp)
jne 0x1036c
jmp 0x103e3
movq -0x20(%rbp), %rax
cmpl $0x1f4, (%rax)          # imm = 0x1F4
je 0x10384
movq -0x20(%rbp), %rax
cmpl $0x1f7, (%rax)          # imm = 0x1F7
jne 0x10386
jmp 0x103e3
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x28(%rbp), %rcx
movq 0x20(%rcx), %rdi
movq -0x20(%rbp), %rsi
callq *%rax
movl %eax, -0x60(%rbp)
cmpl $0x0, -0x60(%rbp)
je 0x103b0
movl -0x60(%rbp), %eax
movl %eax, -0x94(%rbp)
jmp 0x103b9
movl -0x5c(%rbp), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x28(%rbp), %rdi
callq 0x2040
movq -0x30(%rbp), %rdi
callq 0xfe50
cmpl $0x0, %eax
je 0x103db
jmp 0x1044d
movl -0x5c(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0x10454
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x58(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x50(%rax)
jne 0x10418
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x38(%rax)
jmp 0x10428
movq -0x28(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movq %rcx, 0x58(%rax)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x30(%rbp), %rdi
callq 0xfe50
cmpl $0x0, %eax
je 0x10444
jmp 0x1044d
movl $0x0, -0xc(%rbp)
jmp 0x10454
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
movl -0xc(%rbp), %eax
addq $0xb8, %rsp
popq %rbx
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)