// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../lib/dynamodb/dynamodb_request_queue.c
// Function: callback_reqdone
static int
callback_reqdone(void * cookie, struct http_response * res)
{
	struct request * R = cookie;
	struct dynamodb_request_queue * Q = R->Q;
	struct timeval t_end;
	double treq;
	int rc = 0;
	double capacity = 0.0;
	char * ddberr = NULL;

	/*
	 * If we have a response body, extract the number of capacity units
	 * used, and update our rolling average and current capacity.
	 */
	if ((res != NULL) && (res->bodylen > 0)) {
		if (extractcapacity(res, &capacity))
			rc = -1;
		if (capacity != 0.0) {
			Q->mu_capperreq +=
			    (capacity - Q->mu_capperreq) * 0.01;
			Q->bucket_cap -= capacity;
			if (Q->bucket_cap < 0.0)
				Q->bucket_cap = 0.0;
		}
	}

	/* If we got an HTTP 400 response, extract the DynamoDB error string. */
	if ((res != NULL) && (res->status == 400)) {
		if (dynamodb_request_extracterror(res, &ddberr))
			rc = -1;
	}

	/* Figure out how long this request took. */
	if (monoclock_get(&t_end)) {
		warnp("monoclock_get");
		t_end = R->t_start;
		rc = -1;
	}

	/* Optionally log this request. */
	if (Q->logfile) {
		if (logreq(Q->logfile, R, res, capacity, t_end, ddberr))
			rc = -1;
	}

	/*
	 * This HTTP request has completed; we call done_http here rather
	 * than earlier because it frees the target address, which is printed
	 * to the request log.
	 */
	if (done_http(R, 0))
		rc = -1;

	/* What should we do with this response? */
	if ((ddberr != NULL) &&
	    (strcmp(ddberr, "ProvisionedThroughputExceededException") == 0)) {
		/*
		 * We hit the throughput limits.  Zero out our estimate of
		 * the number of tokens in the bucket; we won't send any
		 * more requests until timer ticks add more tokens to the
		 * modelled bucket.
		 */
		Q->bucket_cap = 0.0;
	} else if ((res != NULL) && (res->status < 500)) {
		/*
		 * Anything which isn't an internal DynamoDB error or a
		 * rate limiting response is something we should pass back
		 * to the upstream code.
		 */

		/* Dequeue the request. */
		ptrheap_delete(Q->reqs, R->rc);

		/* Cancel the request timeout. */
		events_timer_cancel(R->timeout_cookie);

		/*
		 * Update request timeout statistics.  Following the strategy
		 * used in TCP, we compute exponential rolling averages for
		 * the mean and mean deviation; unlike TCP, we update our
		 * statistics even on retries, since we know which attempt
		 * succeeded.
		 */
		treq = timeval_diff(R->t_start, t_end);
		Q->tmu += (treq - Q->tmu) * 0.125;
		if (treq > Q->tmu)
			Q->tmud += ((treq - Q->tmu) - Q->tmud) * 0.25;
		else
			Q->tmud += ((Q->tmu - treq) - Q->tmud) * 0.25;

		/* Invoke the upstream callback. */
		if (rc) {
			(void)(R->callback)(R->cookie, res, ddberr);
		} else {
			rc = (R->callback)(R->cookie, res, ddberr);
		}

		/* Free the request; we're done with it now. */
		free(R->logstr);
		free(R);
	}

	/*
	 * If we didn't send the response upstream, the request is still on
	 * our queue with a timeout callback pending.  We're going to leave
	 * it that way -- we don't want to retry the failed request until
	 * the callback fires.
	 */

	/*
	 * Poke the queue.  If the request failed, it may be possible to
	 * re-issue it; if the request succeeded, we may have ceased to be
	 * at our in-flight limit and might be able to issue a new request;
	 * if we just hit our first congestion, we need to start a timer to
	 * add more tokens to our modelled bucket.
	 */
	if (poke(Q))
		rc = -1;

	/* Free the DynamoDB error string (if any). */
	free(ddberr);

	/* Return status from callback, or our own success/failure. */
	return (rc);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x3c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x8f10
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jbe 0x8f10
movq -0x10(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x94d0
cmpl $0x0, %eax
je 0x8e9d
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
movsd -0x48(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x8eaf
jp 0x8eaf
jmp 0x8f0e
movsd -0x48(%rbp), %xmm0
movq -0x20(%rbp), %rax
subsd 0x20(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd 0x20(%rax), %xmm1
movsd 0x15a12(%rip), %xmm2    # 0x1e8e0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rax)
movsd -0x48(%rbp), %xmm1
movq -0x20(%rbp), %rax
movsd 0x38(%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rax)
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
ucomisd 0x38(%rax), %xmm0
jbe 0x8f0c
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rax)
jmp 0x8f0e
jmp 0x8f10
cmpq $0x0, -0x10(%rbp)
je 0x8f3e
movq -0x10(%rbp), %rax
cmpl $0x190, (%rax)          # imm = 0x190
jne 0x8f3e
movq -0x10(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x12a20
cmpl $0x0, %eax
je 0x8f3c
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
jmp 0x8f3e
leaq -0x30(%rbp), %rdi
callq 0x6300
cmpl $0x0, %eax
je 0x8f9e
jmp 0x8f4e
callq 0x3040
cmpl $0x0, (%rax)
je 0x8f73
leaq 0x159d1(%rip), %rdi     # 0x1e930
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x8f81
leaq 0x159b6(%rip), %rdi     # 0x1e930
movb $0x0, %al
callq 0x6930
jmp 0x8f83
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rcx
movq %rcx, -0x30(%rbp)
movq 0x70(%rax), %rax
movq %rax, -0x28(%rbp)
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
cmpq $0x0, 0x80(%rax)
je 0x8fe3
movq -0x20(%rbp), %rax
movq 0x80(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rdx
movsd -0x48(%rbp), %xmm0
movq -0x50(%rbp), %r9
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %r8
callq 0x9310
cmpl $0x0, %eax
je 0x8fe1
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
jmp 0x8fe3
movq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x91f0
cmpl $0x0, %eax
je 0x8ffa
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
cmpq $0x0, -0x50(%rbp)
je 0x9027
movq -0x50(%rbp), %rdi
leaq 0x1594d(%rip), %rsi     # 0x1e959
callq 0x3500
cmpl $0x0, %eax
jne 0x9027
movq -0x20(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rax)
jmp 0x91c1
cmpq $0x0, -0x10(%rbp)
je 0x91bf
movq -0x10(%rbp), %rax
cmpl $0x1f4, (%rax)          # imm = 0x1F4
jge 0x91bf
movq -0x20(%rbp), %rax
movq 0x70(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x88(%rax), %rsi
callq 0xbc20
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdi
callq 0x6020
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
subq 0x68(%rcx), %rax
cvtsi2sd %rax, %xmm1
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
subq 0x70(%rcx), %rax
cvtsi2sd %rax, %xmm0
movsd 0x15417(%rip), %xmm2    # 0x1e4a8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
movq -0x20(%rbp), %rax
subsd 0x88(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd 0x88(%rax), %xmm1
movsd 0x15825(%rip), %xmm2    # 0x1e8e8
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x88(%rax)
movsd -0x38(%rbp), %xmm0
movq -0x20(%rbp), %rax
ucomisd 0x88(%rax), %xmm0
jbe 0x9129
movsd -0x38(%rbp), %xmm0
movq -0x20(%rbp), %rax
subsd 0x88(%rax), %xmm0
movq -0x20(%rbp), %rax
subsd 0x90(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd 0x90(%rax), %xmm1
movsd 0x15799(%rip), %xmm2    # 0x1e8b0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x90(%rax)
jmp 0x916a
movq -0x20(%rbp), %rax
movsd 0x88(%rax), %xmm0
subsd -0x38(%rbp), %xmm0
movq -0x20(%rbp), %rax
subsd 0x90(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd 0x90(%rax), %xmm1
movsd 0x15756(%rip), %xmm2    # 0x1e8b0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x90(%rax)
cmpl $0x0, -0x3c(%rbp)
je 0x918c
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x38(%rcx), %rdi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq *%rax
jmp 0x91a9
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x38(%rcx), %rdi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq *%rax
movl %eax, -0x3c(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x3460
movq -0x18(%rbp), %rdi
callq 0x3460
jmp 0x91c1
movq -0x20(%rbp), %rdi
callq 0x8770
cmpl $0x0, %eax
je 0x91d6
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
movq -0x50(%rbp), %rdi
callq 0x3460
movl -0x3c(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)