// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %rdi, %r14
movq (%rdi), %r13
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
xorpd %xmm3, %xmm3
testq %rsi, %rsi
je 0x6d80
movq 0x18(%r15), %r12
testq %r12, %r12
je 0x6d80
movq %r13, 0x18(%rsp)
movq 0x20(%r15), %rdi
addq %rdi, %r12
leaq 0xad95(%rip), %rdx      # 0x11998
movq %r12, %rsi
callq 0xb438
leaq 0xad97(%rip), %rdx      # 0x119a9
movq %rax, %rdi
movq %r12, %rsi
callq 0xb438
xorpd %xmm0, %xmm0
cmpq %r12, %rax
je 0x6c71
movq %rax, %r13
jae 0x6c81
movq %r12, %rax
subq %r13, %rax
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
leaq 0xad78(%rip), %rbx      # 0x119b7
movzbl (%r13,%rbp), %esi
movl $0x10, %edx
movq %rbx, %rdi
callq 0x3400
testq %rax, %rax
je 0x6c83
leaq 0x1(,%rbp), %rax
addq %r13, %rax
incq %rbp
cmpq %r12, %rax
jb 0x6c3f
movq 0x8(%rsp), %rbp
jmp 0x6c83
xorl %ebp, %ebp
xorpd %xmm3, %xmm3
movq 0x18(%rsp), %r13
jmp 0x6d36
xorl %ebp, %ebp
leaq 0x1(%rbp), %rdi
callq 0x34c0
testq %rax, %rax
je 0x6d24
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x3280
movb $0x0, (%r12,%rbp)
callq 0x3040
movq %rax, %r13
movl $0x0, (%rax)
leaq 0x20(%rsp), %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3260
movq (%rbx), %rcx
movl $0x16, %eax
cmpq %r12, %rcx
je 0x6cdf
cmpb $0x0, (%rcx)
je 0x6fa1
movl %eax, (%r13)
cmpl $0x0, (%r13)
je 0x6d07
leaq 0xacd6(%rip), %rdi      # 0x119c7
movq %r12, %rsi
xorl %eax, %eax
callq 0x58ab
movl $0x0, (%r13)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rsp), %r13
movq %r12, %rdi
callq 0x3450
xorl %ebp, %ebp
movsd 0x8(%rsp), %xmm3
jmp 0x6d32
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorpd %xmm3, %xmm3
movq 0x18(%rsp), %r13
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm3
jne 0x6d3e
jnp 0x6d80
movsd 0x20(%r13), %xmm0
movapd %xmm3, %xmm1
subsd %xmm0, %xmm1
mulsd 0xabdc(%rip), %xmm1     # 0x11930
movsd 0x38(%r13), %xmm2
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%r13)
subsd %xmm3, %xmm2
movsd %xmm2, 0x38(%r13)
xorpd %xmm0, %xmm0
ucomisd %xmm2, %xmm0
jbe 0x6d80
movq $0x0, 0x38(%r13)
testq %r15, %r15
movsd %xmm3, 0x8(%rsp)
je 0x6da9
cmpl $0x190, (%r15)          # imm = 0x190
jne 0x6da9
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0xc9f4
xorl %ecx, %ecx
negl %eax
sbbl %ecx, %ecx
orl %ecx, %ebp
leaq 0x20(%rsp), %rdi
callq 0x54d0
testl %eax, %eax
je 0x6df9
callq 0x3040
cmpl $0x0, (%rax)
je 0x6dda
movq %rax, %rbx
leaq 0xab7d(%rip), %rdi      # 0x11948
xorl %eax, %eax
callq 0x578c
movl $0x0, (%rbx)
jmp 0x6de8
leaq 0xab67(%rip), %rdi      # 0x11948
xorl %eax, %eax
callq 0x58ab
movupd 0x68(%r14), %xmm0
movapd %xmm0, 0x20(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x80(%r13), %rdi
testq %rdi, %rdi
movsd 0x8(%rsp), %xmm0
je 0x6e2d
movq 0x10(%rsp), %r9
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %r8
movq %r14, %rsi
movq %r15, %rdx
callq 0x709d
xorl %ecx, %ecx
negl %eax
sbbl %ecx, %ecx
orl %ecx, %ebp
movq (%r14), %rax
xorl %ebx, %ebx
movq %rbx, 0x50(%r14)
decq 0x68(%rax)
movq 0x40(%r14), %rdi
callq 0xc0c7
movq %rbx, 0x40(%r14)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x6e65
leaq 0xab19(%rip), %rsi      # 0x11971
callq 0x3500
testl %eax, %eax
je 0x6f58
testq %r15, %r15
je 0x6f60
cmpl $0x1f3, (%r15)          # imm = 0x1F3
jg 0x6f60
movq 0x70(%r13), %rdi
movq 0x88(%r14), %rsi
callq 0x8842
movq 0x58(%r14), %rdi
callq 0x5349
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
subq 0x68(%r14), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
subq 0x70(%r14), %rcx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
mulsd 0xa60a(%rip), %xmm1     # 0x114c8
addsd %xmm0, %xmm1
movsd 0x88(%r13), %xmm0
movsd 0x90(%r13), %xmm2
movapd %xmm1, %xmm3
subsd %xmm0, %xmm3
mulsd 0xaa54(%rip), %xmm3     # 0x11938
addsd %xmm0, %xmm3
movsd %xmm3, 0x88(%r13)
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 0xaa22(%rip), %xmm3     # 0x11940
addsd %xmm2, %xmm3
movsd %xmm3, 0x90(%r13)
movq 0x38(%r14), %rdi
movq 0x10(%rsp), %rdx
movq %r15, %rsi
callq *0x30(%r14)
xorl %ebx, %ebx
negl %ebp
sbbl %ebx, %ebx
orl %eax, %ebx
movq 0x28(%r14), %rdi
callq 0x3450
movq %r14, %rdi
callq 0x3450
movl %ebx, %ebp
jmp 0x6f60
movq $0x0, 0x38(%r13)
cmpq $0x0, 0x60(%r13)
jne 0x6f86
leaq -0x715(%rip), %rdi      # 0x6859
xorl %ebx, %ebx
movq %r13, %rsi
xorl %edx, %edx
callq 0x44e4
movq %rax, 0x60(%r13)
cmpq $0x1, %rax
sbbl %ebx, %ebx
orl %ebx, %ebp
movq 0x10(%rsp), %rdi
callq 0x3450
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
movl $0x22, %eax
ja 0x6cdf
ucomisd 0xa96c(%rip), %xmm0     # 0x11928
jbe 0x6ce3
jmp 0x6cdf