// File: /workspace/github_c_makefile_star2_O1/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 0x20(%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 0xd521
addq $0x20, %rsp
testl %eax, %eax
je 0xcb2c
xorl %ebx, %ebx
jmp 0xccd4
leaq 0x60c3(%rip), %rsi      # 0x12bf6
leaq 0x8(%rsp), %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xe2e0
cmpl $-0x1, %eax
je 0xccb4
leaq 0x60be(%rip), %rsi      # 0x12c10
movq %rsp, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0xe2e0
cmpl $-0x1, %eax
je 0xccaa
leaq 0x4577(%rip), %rsi      # 0x110e6
leaq 0x20(%rsp), %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0xe2e0
cmpl $-0x1, %eax
je 0xcca1
movq 0x118(%rsp), %r8
movq 0x110(%rsp), %rcx
movq 0x108(%rsp), %rdx
leaq 0x607f(%rip), %rax      # 0x12c25
leaq 0x30(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x6075(%rip), %rax      # 0x12c2a
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 0x6053(%rip), %rdi      # 0x12c2c
movq %rdi, (%rax)
movq 0x8(%rsp), %r9
movq %r9, 0x8(%rax)
leaq 0x6045(%rip), %rdi      # 0x12c31
movq %rdi, 0x10(%rax)
movq 0x18(%rsp), %rdi
movq %rdi, 0x18(%rax)
leaq 0x603c(%rip), %rdi      # 0x12c3c
movq %rdi, 0x20(%rax)
movq 0x28(%rsp), %rdi
movq %rdi, 0x28(%rax)
leaq 0x603d(%rip), %rdi      # 0x12c51
movq %rdi, 0x30(%rax)
movq (%rsp), %rdi
movq %rdi, 0x38(%rax)
leaq 0x6037(%rip), %rdi      # 0x12c5e
movq %rdi, 0x40(%rax)
movq 0x10(%rsp), %rdi
movq %rdi, 0x48(%rax)
leaq 0x545f(%rip), %rdi      # 0x1209a
movq %rdi, 0x50(%rax)
movq 0x20(%rsp), %rdi
movq %rdi, 0x58(%rax)
leaq 0x601d(%rip), %rdi      # 0x12c6c
movq %rdi, 0x60(%rax)
leaq 0x601f(%rip), %rdi      # 0x12c79
movq %rdi, 0x68(%rax)
movq %rbx, %rdi
callq 0xd764
movq %rax, %rbx
movq 0x20(%rsp), %rdi
callq 0x3450
testq %rbx, %rbx
je 0xcca1
movq (%rsp), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3450
movq 0x10(%rsp), %rdi
callq 0x3450
movq 0x18(%rsp), %rdi
callq 0x3450
jmp 0xccca
movq (%rsp), %rdi
callq 0x3450
movq 0x8(%rsp), %rdi
callq 0x3450
movq 0x10(%rsp), %rdi
callq 0x3450
movq 0x18(%rsp), %rdi
callq 0x3450
xorl %ebx, %ebx
movq 0x28(%rsp), %rdi
callq 0x3450
movq %rbx, %rax
addq $0xd0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq