// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %r8
movq 0x10(%rbp), %r9
leaq -0xe8(%rbp), %r11
leaq -0xf0(%rbp), %r10
leaq -0xf8(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x13960
cmpl $0x0, %eax
je 0x12c1d
jmp 0x12e49
movq -0x28(%rbp), %rdx
leaq -0x100(%rbp), %rdi
leaq 0xd25f(%rip), %rsi      # 0x1fe8e
movb $0x0, %al
callq 0x15020
cmpl $-0x1, %eax
jne 0x12c40
jmp 0x12e25
movq -0x30(%rbp), %rdx
leaq -0x108(%rbp), %rdi
leaq 0xd256(%rip), %rsi      # 0x1fea8
movb $0x0, %al
callq 0x15020
cmpl $-0x1, %eax
jne 0x12c63
jmp 0x12e19
movq 0x10(%rbp), %rdx
leaq -0x110(%rbp), %rdi
leaq 0xb471(%rip), %rsi      # 0x1e0e6
movb $0x0, %al
callq 0x15020
cmpl $-0x1, %eax
jne 0x12c86
jmp 0x12e0d
leaq 0xd230(%rip), %rax      # 0x1febd
movq %rax, -0x68(%rbp)
leaq 0xd22a(%rip), %rax      # 0x1fec2
movq %rax, -0x60(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x7, -0x58(%rbp)
leaq -0xe0(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0xd1fe(%rip), %rax      # 0x1fec4
movq %rax, -0xe0(%rbp)
movq -0x100(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq 0xd1e7(%rip), %rax      # 0x1fec9
movq %rax, -0xd0(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq 0xd1d6(%rip), %rax      # 0x1fed4
movq %rax, -0xc0(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq 0xd1cf(%rip), %rax      # 0x1fee9
movq %rax, -0xb0(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq 0xd1c0(%rip), %rax      # 0x1fef6
movq %rax, -0xa0(%rbp)
movq -0xf8(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq 0xc42c(%rip), %rax      # 0x1f17e
movq %rax, -0x90(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq 0xd196(%rip), %rax      # 0x1ff04
movq %rax, -0x80(%rbp)
leaq 0xd198(%rip), %rax      # 0x1ff11
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
movq 0x18(%rbp), %rdx
movq 0x20(%rbp), %rcx
movq 0x28(%rbp), %r8
movq -0x100(%rbp), %r9
leaq -0x68(%rbp), %rsi
callq 0x13c60
movq %rax, -0x118(%rbp)
cmpq $0x0, %rax
jne 0x12dac
jmp 0x12e01
movq -0x110(%rbp), %rdi
callq 0x3460
movq -0x108(%rbp), %rdi
callq 0x3460
movq -0x100(%rbp), %rdi
callq 0x3460
movq -0xf8(%rbp), %rdi
callq 0x3460
movq -0xf0(%rbp), %rdi
callq 0x3460
movq -0xe8(%rbp), %rdi
callq 0x3460
movq -0x118(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x12e51
movq -0x110(%rbp), %rdi
callq 0x3460
movq -0x108(%rbp), %rdi
callq 0x3460
movq -0x100(%rbp), %rdi
callq 0x3460
movq -0xf8(%rbp), %rdi
callq 0x3460
movq -0xf0(%rbp), %rdi
callq 0x3460
movq -0xe8(%rbp), %rdi
callq 0x3460
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nop