// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xe0, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq %r9, -0x48(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq -0x40(%rbp), %rax
movq (%rax), %rcx
movq -0x40(%rbp), %rax
movq 0x8(%rax), %r8
movq -0x40(%rbp), %rax
movq 0x10(%rax), %r9
movq -0x40(%rbp), %rax
movq 0x30(%rax), %r14
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rbx
leaq -0x88(%rbp), %r11
leaq -0x90(%rbp), %r10
leaq -0x98(%rbp), %rax
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x146f0
cmpl $0x0, %eax
je 0x143ed
jmp 0x146c9
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdx
leaq -0x80(%rbp), %rdi
leaq 0xbfdb(%rip), %rsi      # 0x203db
movb $0x0, %al
callq 0xafe0
cmpl $-0x1, %eax
jne 0x14411
jmp 0x146a5
movq -0x40(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x14439
leaq -0xc0(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0xbcb0(%rip), %rsi      # 0x200e2
movb $0x0, %al
callq 0x2470
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x14485
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
addq $0x5, %rax
movq %rax, -0x68(%rbp)
jmp 0x14495
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rax
addq $0x4, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
shlq $0x4, %rdi
callq 0x2350
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
jne 0x144b1
jmp 0x1469c
movq -0x40(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x144d9
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x40(%rbp), %rax
movq 0x18(%rax), %rdx
shlq $0x4, %rdx
callq 0x2300
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
leaq 0xbefc(%rip), %rcx      # 0x203ef
movq %rcx, (%rax)
movq -0x80(%rbp), %rcx
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rdx
movq 0x18(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
addq $0x1, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
leaq 0xbec5(%rip), %rcx      # 0x203f4
movq %rcx, (%rax)
movq -0x88(%rbp), %rcx
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rdx
movq 0x18(%rdx), %rdx
addq $0x1, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
addq $0x2, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
leaq 0xbe97(%rip), %rcx      # 0x20409
movq %rcx, (%rax)
movq -0x90(%rbp), %rcx
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rdx
movq 0x18(%rdx), %rdx
addq $0x2, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
addq $0x3, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
leaq 0xbe5f(%rip), %rcx      # 0x20414
movq %rcx, (%rax)
movq -0x98(%rbp), %rcx
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rdx
movq 0x18(%rdx), %rdx
addq $0x3, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x40(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x14628
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rcx
movq 0x18(%rcx), %rcx
addq $0x4, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
leaq 0xa339(%rip), %rcx      # 0x1e93c
movq %rcx, (%rax)
leaq -0xc0(%rbp), %rcx
movq -0x60(%rbp), %rax
movq -0x40(%rbp), %rdx
movq 0x18(%rdx), %rdx
addq $0x4, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rdi
movq -0x48(%rbp), %rdx
movq 0x10(%rbp), %rcx
movq 0x18(%rbp), %r8
leaq -0x78(%rbp), %rsi
callq 0x70e0
movq %rax, -0xc8(%rbp)
cmpq $0x0, %rax
jne 0x14650
jmp 0x14693
movq -0x60(%rbp), %rdi
callq 0x2040
movq -0x80(%rbp), %rdi
callq 0x2040
movq -0x98(%rbp), %rdi
callq 0x2040
movq -0x90(%rbp), %rdi
callq 0x2040
movq -0x88(%rbp), %rdi
callq 0x2040
movq -0xc8(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x146d1
movq -0x60(%rbp), %rdi
callq 0x2040
movq -0x80(%rbp), %rdi
callq 0x2040
movq -0x98(%rbp), %rdi
callq 0x2040
movq -0x90(%rbp), %rdi
callq 0x2040
movq -0x88(%rbp), %rdi
callq 0x2040
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0xe0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)