// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/liball/../lib/s3/s3_request.c
// Function: s3_request
void *
s3_request(struct sock_addr * const * addrs, const char * key_id,
    const char * key_secret, const char * region,
    struct s3_request * request, size_t maxrlen,
    int (* callback)(void *, struct http_response *), void * cookie)
{
	struct http_request RH;
	char * host;
	char * x_amz_content_sha256;
	char * x_amz_date;
	char * authorization;
	char content_length[sizeof(size_t) * 3 + 1];
	void * http_cookie;

	/* Construct headers needed for authorization. */
	if (aws_sign_s3_headers(key_id, key_secret, region,
	    request->method, request->bucket, request->path, request->body,
	    request->bodylen, &x_amz_content_sha256, &x_amz_date,
	    &authorization))
		goto err0;

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

	/* If we have a message body, construct Content-Length. */
	if (request->body)
		sprintf(content_length, "%zu", request->bodylen);

	/* Construct HTTP request structure. */
	RH.method = request->method;
	RH.path = request->path;
	RH.bodylen = request->bodylen;
	RH.body = request->body;

	/* We have 4 or 5 extra headers. */
	if (request->body)
		RH.nheaders = request->nheaders + 5;
	else
		RH.nheaders = request->nheaders + 4;
	if ((RH.headers =
	    malloc(RH.nheaders * sizeof(struct http_header))) == NULL)
		goto err2;

	/* Construct headers. */
	if (request->nheaders)
		memcpy(RH.headers, request->headers,
		    request->nheaders * sizeof(struct http_header));
	RH.headers[request->nheaders].header = "Host";
	RH.headers[request->nheaders].value = host;
	RH.headers[request->nheaders + 1].header = "X-Amz-Content-SHA256";
	RH.headers[request->nheaders + 1].value = x_amz_content_sha256;
	RH.headers[request->nheaders + 2].header = "X-Amz-Date";
	RH.headers[request->nheaders + 2].value = x_amz_date;
	RH.headers[request->nheaders + 3].header = "Authorization";
	RH.headers[request->nheaders + 3].value = authorization;
	if (request->body) {
		RH.headers[request->nheaders + 4].header = "Content-Length";
		RH.headers[request->nheaders + 4].value = content_length;
	}

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

	/* Free array of headers. */
	free(RH.headers);

	/* Free string allocated by asprintf. */
	free(host);

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

	/* Success! */
	return (http_cookie);

err3:
	free(RH.headers);
err2:
	free(host);
err1:
	free(authorization);
	free(x_amz_date);
	free(x_amz_content_sha256);
err0:
	/* Failure! */
	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, %rbx
movq %r8, %r15
movq %rdi, %r14
movq (%r8), %rax
movq 0x8(%r8), %r8
movq 0x10(%r15), %r9
subq $0x8, %rsp
leaq 0x8(%rsp), %r10
leaq 0x18(%rsp), %r11
leaq 0x20(%rsp), %r12
movq %rsi, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %rax, %rcx
pushq %r10
pushq %r11
pushq %r12
pushq 0x28(%r15)
pushq 0x30(%r15)
callq 0xc68c
addq $0x30, %rsp
testl %eax, %eax
je 0xc4df
xorl %ebx, %ebx
jmp 0xc678
movq 0x8(%r15), %rdx
leaq 0x5a1d(%rip), %rsi      # 0x11f07
leaq 0x8(%rsp), %rdi
xorl %eax, %eax
callq 0x74a4
cmpl $-0x1, %eax
je 0xc659
cmpq $0x0, 0x30(%r15)
je 0xc523
movq 0x28(%r15), %rdx
leaq 0x56de(%rip), %rsi      # 0x11bef
leaq 0x50(%rsp), %rdi
xorl %eax, %eax
callq 0x2460
movq 0x30(%r15), %r13
jmp 0xc526
xorl %r13d, %r13d
movq (%r15), %rax
movq %rax, 0x20(%rsp)
movq 0x10(%r15), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%r15), %rax
movq %rax, 0x40(%rsp)
movq %r13, 0x48(%rsp)
cmpq $0x1, %r13
pushq $0x5
popq %rdi
sbbq $0x0, %rdi
movq 0x18(%r15), %rbp
addq %rbp, %rdi
movq %rdi, 0x30(%rsp)
shlq $0x4, %rdi
callq 0x2340
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0xc64f
movq %rax, %r12
testq %rbp, %rbp
je 0xc58e
movq 0x20(%r15), %rsi
movq %rbp, %rdx
shlq $0x4, %rdx
movq %r12, %rdi
callq 0x22f0
movq 0xb8(%rsp), %r8
shlq $0x4, %rbp
leaq 0x597a(%rip), %rax      # 0x11f1b
movq %rax, (%r12,%rbp)
movq 0x8(%rsp), %rax
movq %rax, 0x8(%r12,%rbp)
leaq 0x596a(%rip), %rax      # 0x11f20
movq %rax, 0x10(%r12,%rbp)
movq 0x18(%rsp), %rax
movq %rax, 0x18(%r12,%rbp)
leaq 0x5969(%rip), %rax      # 0x11f35
movq %rax, 0x20(%r12,%rbp)
movq 0x10(%rsp), %rax
movq %rax, 0x28(%r12,%rbp)
leaq 0x595e(%rip), %rax      # 0x11f40
movq %rax, 0x30(%r12,%rbp)
movq (%rsp), %rax
movq %rax, 0x38(%r12,%rbp)
movq 0xb0(%rsp), %rcx
testq %r13, %r13
je 0xc616
addq %rbp, %r12
leaq 0x3fd0(%rip), %rax      # 0x105d7
movq %rax, 0x40(%r12)
leaq 0x50(%rsp), %rax
movq %rax, 0x48(%r12)
leaq 0x20(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x52a0
movq %rax, %rbx
movq 0x18(%r15), %rdi
callq 0x2040
testq %rbx, %rbx
je 0xc64f
movq 0x8(%rsp), %rdi
callq 0x2040
movq (%rsp), %rdi
callq 0x2040
jmp 0xc664
movq 0x8(%rsp), %rdi
callq 0x2040
movq (%rsp), %rdi
callq 0x2040
xorl %ebx, %ebx
movq 0x10(%rsp), %rdi
callq 0x2040
movq 0x18(%rsp), %rdi
callq 0x2040
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop