// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/liball/../lib/dynamodb/dynamodb_request.c
// Function: dynamodb_request
void *
dynamodb_request(struct sock_addr * const * addrs, const char * key_id,
    const char * key_secret, const char * region, const char * op,
    const uint8_t * body, size_t bodylen, size_t maxrlen,
    int (* callback)(void *, struct http_response *), void * cookie)
{
	struct http_request RH;
	struct http_header RHH[7];
	char * x_amz_content_sha256;
	char * x_amz_date;
	char * authorization;
	char * host;
	char * x_amz_target;
	char * content_length;
	void * http_cookie;

	/* Construct headers needed for authorization. */
	if (aws_sign_dynamodb_headers(key_id, key_secret, region, op, body,
	    bodylen, &x_amz_content_sha256, &x_amz_date, &authorization))
		goto err0;

	/* Construct Host header. */
	if (asprintf(&host, "dynamodb.%s.amazonaws.com", region) == -1)
		goto err1;

	/* Construct X-Amz-Target header. */
	if (asprintf(&x_amz_target, "DynamoDB_20120810.%s", op) == -1)
		goto err2;

	/* Construct Content-Length header. */
	if (asprintf(&content_length, "%zu", bodylen) ==  -1)
		goto err3;

	/* Construct HTTP request structure. */
	RH.method = "POST";
	RH.path = "/";
	RH.bodylen = bodylen;
	RH.body = body;
	RH.nheaders = 7;
	RH.headers = RHH;

	/* Fill in headers. */
	RHH[0].header = "Host";
	RHH[0].value = host;
	RHH[1].header = "X-Amz-Date";
	RHH[1].value = x_amz_date;
	RHH[2].header = "X-Amz-Content-SHA256";
	RHH[2].value = x_amz_content_sha256;
	RHH[3].header = "X-Amz-Target";
	RHH[3].value = x_amz_target;
	RHH[4].header = "Authorization";
	RHH[4].value = authorization;
	RHH[5].header = "Content-Length";
	RHH[5].value = content_length;
	RHH[6].header = "Content-Type";
	RHH[6].value = "application/x-amz-json-1.0";

	/* Send the request. */
	if ((http_cookie = https_request(addrs, &RH, maxrlen,
	    callback, cookie, host)) == NULL)
		goto err4;

	/* Free strings allocated by asprintf. */
	free(content_length);
	free(x_amz_target);
	free(host);

	/* Free headers used for authorization. */
	free(authorization);
	free(x_amz_date);
	free(x_amz_content_sha256);

	/* Success! */
	return (http_cookie);

err4:
	free(content_length);
err3:
	free(x_amz_target);
err2:
	free(host);
err1:
	free(authorization);
	free(x_amz_date);
	free(x_amz_content_sha256);
err0:
	/* Failure! */
	return (NULL);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd0, %rsp
movq %r9, %r14
movq %r8, %r12
movq %rcx, %r13
movq %rdi, %rbx
movq 0x100(%rsp), %r15
subq $0x8, %rsp
leaq 0x18(%rsp), %rax
leaq 0x28(%rsp), %r10
leaq 0x30(%rsp), %r11
movq %rsi, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %rcx
movq %r9, %r8
movq %r15, %r9
pushq %rax
pushq %r10
pushq %r11
callq 0xd3a1
addq $0x20, %rsp
testl %eax, %eax
je 0xc9b4
xorl %ebx, %ebx
jmp 0xcb52
leaq 0x60b3(%rip), %rsi      # 0x12a6e
leaq 0x8(%rsp), %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe160
cmpl $-0x1, %eax
je 0xcb32
leaq 0x60ae(%rip), %rsi      # 0x12a88
movq %rsp, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe160
cmpl $-0x1, %eax
je 0xcb28
leaq 0x46ef(%rip), %rsi      # 0x110e6
leaq 0x18(%rsp), %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xe160
cmpl $-0x1, %eax
je 0xcb1f
movq 0x118(%rsp), %r8
movq 0x110(%rsp), %rcx
movq 0x108(%rsp), %rdx
leaq 0x606f(%rip), %rax      # 0x12a9d
leaq 0x30(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x6065(%rip), %rax      # 0x12aa2
movq %rax, 0x8(%rsi)
movq %r15, 0x20(%rsi)
movq %r14, 0x28(%rsi)
movq $0x7, 0x10(%rsi)
leaq 0x60(%rsp), %rax
movq %rax, 0x18(%rsi)
leaq 0x6043(%rip), %rdi      # 0x12aa4
movq %rdi, (%rax)
movq 0x8(%rsp), %r9
movq %r9, 0x8(%rax)
leaq 0x6035(%rip), %rdi      # 0x12aa9
movq %rdi, 0x10(%rax)
movq 0x20(%rsp), %rdi
movq %rdi, 0x18(%rax)
leaq 0x602c(%rip), %rdi      # 0x12ab4
movq %rdi, 0x20(%rax)
movq 0x28(%rsp), %rdi
movq %rdi, 0x28(%rax)
leaq 0x602d(%rip), %rdi      # 0x12ac9
movq %rdi, 0x30(%rax)
movq (%rsp), %rdi
movq %rdi, 0x38(%rax)
leaq 0x6027(%rip), %rdi      # 0x12ad6
movq %rdi, 0x40(%rax)
movq 0x10(%rsp), %rdi
movq %rdi, 0x48(%rax)
leaq 0x544f(%rip), %rdi      # 0x11f12
movq %rdi, 0x50(%rax)
movq 0x18(%rsp), %rdi
movq %rdi, 0x58(%rax)
leaq 0x600d(%rip), %rdi      # 0x12ae4
movq %rdi, 0x60(%rax)
leaq 0x600f(%rip), %rdi      # 0x12af1
movq %rdi, 0x68(%rax)
movq %rbx, %rdi
callq 0xd5e4
movq %rax, %rbx
movq 0x18(%rsp), %rdi
callq 0x3450
testq %rbx, %rbx
je 0xcb1f
movq (%rsp), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3450
movq 0x10(%rsp), %rdi
callq 0x3450
jmp 0xcb3e
movq (%rsp), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3450
movq 0x10(%rsp), %rdi
callq 0x3450
xorl %ebx, %ebx
movq 0x20(%rsp), %rdi
callq 0x3450
movq 0x28(%rsp), %rdi
callq 0x3450
movq %rbx, %rax
addq $0xd0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop