// File: /workspace/github_c_makefile_star2_O2/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 0xc53c
addq $0x20, %rsp
testl %eax, %eax
je 0xbb7d
xorl %ebx, %ebx
jmp 0xbd1b
leaq 0x5e75(%rip), %rsi      # 0x119f9
leaq 0x8(%rsp), %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xd27c
cmpl $-0x1, %eax
je 0xbcfb
leaq 0x5e70(%rip), %rsi      # 0x11a13
movq %rsp, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xd27c
cmpl $-0x1, %eax
je 0xbcf1
leaq 0x4526(%rip), %rsi      # 0x100e6
leaq 0x18(%rsp), %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xd27c
cmpl $-0x1, %eax
je 0xbce8
movq 0x118(%rsp), %r8
movq 0x110(%rsp), %rcx
movq 0x108(%rsp), %rdx
leaq 0x5e31(%rip), %rax      # 0x11a28
leaq 0x30(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x5e27(%rip), %rax      # 0x11a2d
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 0x5e05(%rip), %rdi      # 0x11a2f
movq %rdi, (%rax)
movq 0x8(%rsp), %r9
movq %r9, 0x8(%rax)
leaq 0x5df7(%rip), %rdi      # 0x11a34
movq %rdi, 0x10(%rax)
movq 0x20(%rsp), %rdi
movq %rdi, 0x18(%rax)
leaq 0x5dee(%rip), %rdi      # 0x11a3f
movq %rdi, 0x20(%rax)
movq 0x28(%rsp), %rdi
movq %rdi, 0x28(%rax)
leaq 0x5def(%rip), %rdi      # 0x11a54
movq %rdi, 0x30(%rax)
movq (%rsp), %rdi
movq %rdi, 0x38(%rax)
leaq 0x5de9(%rip), %rdi      # 0x11a61
movq %rdi, 0x40(%rax)
movq 0x10(%rsp), %rdi
movq %rdi, 0x48(%rax)
leaq 0x5256(%rip), %rdi      # 0x10ee2
movq %rdi, 0x50(%rax)
movq 0x18(%rsp), %rdi
movq %rdi, 0x58(%rax)
leaq 0x5dcf(%rip), %rdi      # 0x11a6f
movq %rdi, 0x60(%rax)
leaq 0x5dd1(%rip), %rdi      # 0x11a7c
movq %rdi, 0x68(%rax)
movq %rbx, %rdi
callq 0xc770
movq %rax, %rbx
movq 0x18(%rsp), %rdi
callq 0x3460
testq %rbx, %rbx
je 0xbce8
movq (%rsp), %rdi
callq 0x3460
movq 0x8(%rsp), %rdi
callq 0x3460
movq 0x10(%rsp), %rdi
callq 0x3460
jmp 0xbd07
movq (%rsp), %rdi
callq 0x3460
movq 0x8(%rsp), %rdi
callq 0x3460
movq 0x10(%rsp), %rdi
callq 0x3460
xorl %ebx, %ebx
movq 0x20(%rsp), %rdi
callq 0x3460
movq 0x28(%rsp), %rdi
callq 0x3460
movq %rbx, %rax
addq $0xd0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop