// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r13
movq %rdi, %r12
movq (%rdi), %r14
andq $0x0, 0x8(%rsp)
testq %rsi, %rsi
je 0x6718
movq %r12, 0x20(%rsp)
movq 0x18(%r13), %r12
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
xorl %r15d, %r15d
testq %r12, %r12
movq %r13, 0x30(%rsp)
je 0x67ff
movq 0x20(%r13), %rdi
addq %rdi, %r12
leaq 0xa127(%rip), %rdx      # 0x107e0
movq %r12, %rsi
callq 0xa790
leaq 0xa129(%rip), %rdx      # 0x107f1
movq %rax, %rdi
movq %r12, %rsi
callq 0xa790
cmpq %r12, %rax
je 0x67ff
movq %rax, %r13
movq %r14, 0x28(%rsp)
pushq $-0x1
popq %r15
xorl %ebp, %ebp
leaq 0xa10e(%rip), %rbx      # 0x107ff
pushq $0x10
popq %r14
movq %r13, %rax
addq %rbp, %rax
cmpq %r12, %rax
jae 0x6729
movzbl (%rax), %esi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x3410
testq %rax, %rax
je 0x6729
incq %rbp
jmp 0x66f5
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
jmp 0x6829
leaq 0x1(%rbp), %rdi
callq 0x34d0
testq %rax, %rax
movq 0x28(%rsp), %r14
je 0x67ff
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x3290
movb $0x0, (%r12,%rbp)
callq 0x3040
movq %rax, %r13
andl $0x0, (%rax)
leaq 0x10(%rsp), %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3270
movq (%rbx), %rcx
pushq $0x16
popq %rax
cmpq %r12, %rcx
je 0x6785
cmpb $0x0, (%rcx)
je 0x6a00
movl %eax, (%r13)
leaq 0xa07f(%rip), %rdi      # 0x1080f
movq %r12, %rsi
xorl %eax, %eax
callq 0x553c
andl $0x0, (%r13)
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movq %r12, %rdi
callq 0x3460
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movsd (%rsp), %xmm4
ucomisd %xmm0, %xmm4
jne 0x67c4
jnp 0x67ff
movsd 0x20(%r14), %xmm1
movsd 0x38(%r14), %xmm2
movapd %xmm4, %xmm3
subsd %xmm1, %xmm3
mulsd 0x9f98(%rip), %xmm3     # 0x10778
addsd %xmm1, %xmm3
movsd %xmm3, 0x20(%r14)
subsd %xmm4, %xmm2
movsd %xmm2, 0x38(%r14)
ucomisd %xmm2, %xmm0
jbe 0x67ff
andq $0x0, 0x38(%r14)
movq 0x30(%rsp), %r13
cmpl $0x190, (%r13)          # imm = 0x190
jne 0x6824
leaq 0x8(%rsp), %rsi
movq %r13, %rdi
callq 0xba50
xorl %ecx, %ecx
negl %eax
sbbl %ecx, %ecx
orl %ecx, %r15d
movq 0x20(%rsp), %r12
leaq 0x10(%rsp), %rdi
callq 0x5134
testl %eax, %eax
je 0x6876
callq 0x3040
cmpl $0x0, (%rax)
je 0x6857
movq %rax, %rbx
leaq 0x9f45(%rip), %rdi      # 0x10790
xorl %eax, %eax
callq 0x53ad
andl $0x0, (%rbx)
jmp 0x6865
leaq 0x9f32(%rip), %rdi      # 0x10790
xorl %eax, %eax
callq 0x553c
movupd 0x68(%r12), %xmm0
movapd %xmm0, 0x10(%rsp)
pushq $-0x1
popq %r15
movq 0x80(%r14), %rdi
testq %rdi, %rdi
movsd (%rsp), %xmm0
je 0x68aa
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %r8
movq %r12, %rsi
movq %r13, %rdx
callq 0x6aff
xorl %ecx, %ecx
negl %eax
sbbl %ecx, %ecx
orl %ecx, %r15d
xorl %ebp, %ebp
movq %r12, %rdi
xorl %esi, %esi
callq 0x6a2f
negl %eax
sbbl %ebp, %ebp
orl %r15d, %ebp
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x68db
leaq 0x9eeb(%rip), %rsi      # 0x107b9
callq 0x3510
testl %eax, %eax
je 0x69d0
testq %r13, %r13
je 0x69d5
cmpl $0x1f3, (%r13)          # imm = 0x1F3
jg 0x69d5
movq 0x70(%r14), %rdi
movq 0x88(%r12), %rsi
callq 0x8137
movq 0x58(%r12), %rdi
callq 0x4fb3
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
subq 0x68(%r12), %rax
cvtsi2sd %rax, %xmm0
subq 0x70(%r12), %rcx
cvtsi2sd %rcx, %xmm1
mulsd 0x9b65(%rip), %xmm1     # 0x10498
addsd %xmm0, %xmm1
movsd 0x88(%r14), %xmm0
movsd 0x90(%r14), %xmm2
movapd %xmm1, %xmm3
subsd %xmm0, %xmm3
mulsd 0x9e27(%rip), %xmm3     # 0x10780
addsd %xmm0, %xmm3
movsd %xmm3, 0x88(%r14)
movapd %xmm3, %xmm0
subsd %xmm1, %xmm0
movapd %xmm1, %xmm4
subsd %xmm3, %xmm4
cmpltsd %xmm1, %xmm3
andpd %xmm3, %xmm4
andnpd %xmm0, %xmm3
orpd %xmm4, %xmm3
subsd %xmm2, %xmm3
mulsd 0x9df5(%rip), %xmm3     # 0x10788
addsd %xmm2, %xmm3
movsd %xmm3, 0x90(%r14)
movq 0x38(%r12), %rdi
movq 0x8(%rsp), %rdx
movq %r13, %rsi
callq *0x30(%r12)
xorl %ebx, %ebx
negl %ebp
sbbl %ebx, %ebx
orl %eax, %ebx
movq 0x28(%r12), %rdi
callq 0x3460
movq %r12, %rdi
callq 0x3460
movl %ebx, %ebp
jmp 0x69d5
andq $0x0, 0x38(%r14)
movq %r14, %rdi
callq 0x624c
xorl %ebx, %ebx
negl %eax
sbbl %ebx, %ebx
orl %ebp, %ebx
movq 0x8(%rsp), %rdi
callq 0x3460
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
pushq $0x22
popq %rax
ja 0x6785
ucomisd 0x9d57(%rip), %xmm0     # 0x10770
ja 0x6785
cmpl $0x0, (%r13)
jne 0x6789
jmp 0x67a3