// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/dynamodb-kv/capacity.c
// Function: callback_readmetadata
static int
callback_readmetadata(void * cookie, struct http_response * res)
{
	struct capacity_reader * M = cookie;
	const uint8_t * buf;
	const uint8_t * end;
	const uint8_t * capstr;
	long capr, capw;
	char * ddberr = NULL;

	/* This request is no longer in progress. */
	M->http_cookie = NULL;

	/* Don't need these any more. */
	sock_addr_free(M->addrs[0]);
	M->addrs[0] = NULL;
	free(M->ddbreq);
	M->ddbreq = NULL;

	/* If we got an HTTP 400 response, warn and bail. */
	if ((res != NULL) && (res->status == 400)) {
		if (dynamodb_request_extracterror(res, &ddberr)) {
			/* Failed to parse. */
			warn0("dynamodb_request_extracterror failed");
			goto err0;
		} else {
			/* Parsed ok; show error and bail. */
			warn0("DescribeTable failed: %s", ddberr);
			free(ddberr);
			goto err0;
		}
	}

	/* If we have a response, pull data out of it. */
	if ((res != NULL) && (res->body != NULL)) {
		/*
		 * Overwrite the last byte of the JSON response with a NUL;
		 * this allows us to use string functions, and it's safe
		 * since we own the buffer now anyway.
		 */
		if (res->bodylen == 0)
			goto doneparse;
		res->body[res->bodylen - 1] = '\0';

		/* Look for Table->BillingModeSummary->BillingMode. */
		buf = res->body;
		end = &buf[res->bodylen];
		buf = json_find(buf, end, "Table");
		buf = json_find(buf, end, "BillingModeSummary");
		buf = json_find(buf, end, "BillingMode");

		/*
		 * The table has unlimited capacity if we found the string
		 * "PAY_PER_REQUEST"; if we didn't find anything (possible if
		 * the table has always been in provisioned mode, since for
		 * backwards compatibility DynamoDB doesn't always fill in
		 * this field) or we found "PROVISIONED" then we have limited
		 * capacity.
		 */
		if ((&buf[17] <= end) &&
		    (memcmp(buf, "\"PAY_PER_REQUEST\"", 17) == 0)) {
			dynamodb_request_queue_setcapacity(M->QR, 0);
			dynamodb_request_queue_setcapacity(M->QW, 0);
			goto doneparse;
		}

		/* Get Table->ProvisionedThroughput. */
		buf = res->body;
		end = &buf[res->bodylen];
		buf = json_find(buf, end, "Table");
		buf = json_find(buf, end, "ProvisionedThroughput");

		/* Get ReadCapacityUnits and WriteCapacityUnits. */
		capstr = json_find(buf, end, "ReadCapacityUnits");
		if (PARSENUM_EX(&capr, (const char *)capstr, 0, LONG_MAX,
		    10, 1)) {
			warnp("parsenum failed on %s", capstr);
			goto doneparse;
		}
		capstr = json_find(buf, end, "WriteCapacityUnits");
		if (PARSENUM_EX(&capw, (const char *)capstr, 0, LONG_MAX,
		    10, 1)) {
			warnp("parsenum failed on %s", capstr);
			goto doneparse;
		}

		/* Set new capacities. */
		dynamodb_request_queue_setcapacity(M->QR, capr);
		dynamodb_request_queue_setcapacity(M->QW, capw);

doneparse:
		/* Free the response body. */
		free(res->body);

		/* We have fetched capacity parameters. */
		M->done = 1;
	}

	/*
	 * Perform another read 15 seconds from now -- unless we haven't
	 * succeeded yet, in which case wait only 1 second.
	 */
	if ((M->timer_cookie = events_timer_register_double(callback_timer,
	    M, M->done ? 15.0 : 1.0)) == NULL)
		goto err0;

	/* Success! */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0xef80
movq -0x20(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x3460
movq -0x20(%rbp), %rax
movq $0x0, 0x38(%rax)
cmpq $0x0, -0x18(%rbp)
je 0x4ca0
movq -0x18(%rbp), %rax
cmpl $0x190, (%rax)          # imm = 0x190
jne 0x4ca0
movq -0x18(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x11b10
cmpl $0x0, %eax
je 0x4c73
jmp 0x4c55
leaq 0x1e78d(%rip), %rdi     # 0x233e9
movb $0x0, %al
callq 0x10250
callq 0x3040
movl $0x0, (%rax)
jmp 0x5100
jmp 0x4c75
movq -0x50(%rbp), %rsi
leaq 0x1e78e(%rip), %rdi     # 0x2340e
movb $0x0, %al
callq 0x10250
callq 0x3040
movl $0x0, (%rax)
movq -0x50(%rbp), %rdi
callq 0x3460
jmp 0x5100
cmpq $0x0, -0x18(%rbp)
je 0x509a
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x509a
movq -0x18(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x4cca
jmp 0x5082
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
addq 0x18(%rcx), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x1e6d6(%rip), %rdx     # 0x233e3
callq 0xd6a0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x1e702(%rip), %rdx     # 0x23427
callq 0xd6a0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x1e6fd(%rip), %rdx     # 0x2343a
callq 0xd6a0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
addq $0x11, %rax
cmpq -0x30(%rbp), %rax
ja 0x4d95
movq -0x28(%rbp), %rdi
leaq 0x1e6e7(%rip), %rsi     # 0x23446
movl $0x11, %edx
callq 0x31a0
cmpl $0x0, %eax
jne 0x4d95
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x12130
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x12130
jmp 0x5082
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
addq 0x18(%rcx), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x1e623(%rip), %rdx     # 0x233e3
callq 0xd6a0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x1e680(%rip), %rdx     # 0x23458
callq 0xd6a0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x1e67e(%rip), %rdx     # 0x2346e
callq 0xd6a0
movq %rax, -0x38(%rbp)
callq 0x3040
movl $0x0, (%rax)
movq $0x1, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
jle 0x4e55
movq 0x281b5(%rip), %rax     # 0x2cfe0
movq (%rax), %rdi
leaq 0x1e64b(%rip), %rsi     # 0x23480
leaq 0x1e6a2(%rip), %rdx     # 0x234de
leaq 0x1e6b1(%rip), %rcx     # 0x234f4
movl $0x97, %r8d
movb $0x0, %al
callq 0x3540
callq 0x31f0
movq $-0x1, -0x40(%rbp)
movb $0x1, %al
testb $0x1, %al
jne 0x4e65
jmp 0x4ea9
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
cmovlel %eax, %eax
movslq %eax, %rsi
movq -0x40(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
cmpq $0x0, %rcx
cmovleq %rax, %rdx
movl $0xa, %ecx
movl $0x1, %r8d
callq 0x5110
movq %rax, -0x40(%rbp)
jmp 0x4ed4
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
movabsq $0x7fffffffffffffff, %rdx # imm = 0x7FFFFFFFFFFFFFFF
movl $0xa, %r8d
movl $0x1, %r9d
callq 0x51d0
movq %rax, -0x40(%rbp)
callq 0x3040
cmpl $0x0, (%rax)
je 0x4f22
jmp 0x4ee0
callq 0x3040
cmpl $0x0, (%rax)
je 0x4f09
movq -0x38(%rbp), %rsi
leaq 0x1e60a(%rip), %rdi     # 0x234ff
movb $0x0, %al
callq 0x10000
callq 0x3040
movl $0x0, (%rax)
jmp 0x4f1b
movq -0x38(%rbp), %rsi
leaq 0x1e5eb(%rip), %rdi     # 0x234ff
movb $0x0, %al
callq 0x10250
jmp 0x4f1d
jmp 0x5082
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq 0x1e5e4(%rip), %rdx     # 0x23515
callq 0xd6a0
movq %rax, -0x38(%rbp)
callq 0x3040
movl $0x0, (%rax)
movq $0x1, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
jle 0x4f96
movq 0x28074(%rip), %rax     # 0x2cfe0
movq (%rax), %rdi
leaq 0x1e50a(%rip), %rsi     # 0x23480
leaq 0x1e561(%rip), %rdx     # 0x234de
leaq 0x1e570(%rip), %rcx     # 0x234f4
movl $0x9d, %r8d
movb $0x0, %al
callq 0x3540
callq 0x31f0
movq $-0x1, -0x48(%rbp)
movb $0x1, %al
testb $0x1, %al
jne 0x4fa6
jmp 0x4fea
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
cmovlel %eax, %eax
movslq %eax, %rsi
movq -0x48(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
cmpq $0x0, %rcx
cmovleq %rax, %rdx
movl $0xa, %ecx
movl $0x1, %r8d
callq 0x5110
movq %rax, -0x48(%rbp)
jmp 0x5015
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
movabsq $0x7fffffffffffffff, %rdx # imm = 0x7FFFFFFFFFFFFFFF
movl $0xa, %r8d
movl $0x1, %r9d
callq 0x51d0
movq %rax, -0x48(%rbp)
callq 0x3040
cmpl $0x0, (%rax)
je 0x5060
jmp 0x5021
callq 0x3040
cmpl $0x0, (%rax)
je 0x504a
movq -0x38(%rbp), %rsi
leaq 0x1e4c9(%rip), %rdi     # 0x234ff
movb $0x0, %al
callq 0x10000
callq 0x3040
movl $0x0, (%rax)
jmp 0x505c
movq -0x38(%rbp), %rsi
leaq 0x1e4aa(%rip), %rdi     # 0x234ff
movb $0x0, %al
callq 0x10250
jmp 0x505e
jmp 0x5082
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x12130
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x48(%rbp), %rsi
callq 0x12130
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x3460
movq -0x20(%rbp), %rax
movl $0x1, 0x60(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
movl 0x60(%rax), %eax
movsd 0x1e307(%rip), %xmm0    # 0x233b8
movsd 0x1e307(%rip), %xmm1    # 0x233c0
movsd %xmm1, -0x60(%rbp)
cmpl $0x0, %eax
movsd %xmm0, -0x58(%rbp)
jne 0x50d2
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x68(%rbp), %rsi
movsd -0x58(%rbp), %xmm0
leaq 0x1ae(%rip), %rdi       # 0x5290
callq 0x7ed0
movq -0x20(%rbp), %rcx
movq %rax, 0x58(%rcx)
cmpq $0x0, %rax
jne 0x50f7
jmp 0x5100
movl $0x0, -0x4(%rbp)
jmp 0x5107
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq