// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../libcperciva/aws/aws_sign.c
// Function: aws_sign_s3_headers
int
aws_sign_s3_headers(const char * key_id, const char * key_secret,
    const char * region, const char * method, const char * bucket,
    const char * path, const uint8_t * body, size_t bodylen,
    char ** x_amz_content_sha256, char ** x_amz_date, char ** authorization)
{
	time_t t_now;
	struct tm r_result;
	char date[9];
	char datetime[17];
	uint8_t hbuf[32];
	char content_sha256[65];
	char * canonical_request;
	char sigbuf[65];

	/* Get the current time. */
	if (time(&t_now) == (time_t)(-1)) {
		warnp("time");
		goto err0;
	}

	/* Construct date string <yyyymmdd>. */
	if (strftime(date, 9, "%Y%m%d", gmtime_r(&t_now, &r_result)) == 0) {
		warnp("strftime");
		goto err0;
	}

	/* Construct date-and-time string <yyyymmddThhmmssZ>. */
	if (strftime(datetime, 17, "%Y%m%dT%H%M%SZ",
	    gmtime_r(&t_now, &r_result)) == 0) {
		warnp("strftime");
		goto err0;
	}

	/* Compute the hexified SHA256 of the payload. */
	SHA256_Buf(body, body ? bodylen : 0, hbuf);
	hexify(hbuf, content_sha256, 32);

	/* Construct Canonical Request. */
	if (asprintf(&canonical_request,
	    "%s\n"
	    "%s\n"
	    "\n"
	    "host:%s.s3.amazonaws.com\n"
	    "x-amz-content-sha256:%s\n"
	    "x-amz-date:%s\n"
	    "\n"
	    "host;x-amz-content-sha256;x-amz-date\n"
	    "%s",
	    method, path, bucket, content_sha256, datetime,
	    content_sha256) == -1)
		goto err0;

	/* Compute request signature. */
	if (aws_sign(key_secret, date, datetime, region,
	    "s3", canonical_request, sigbuf))
		goto err1;

	/* Construct Authorization header. */
	if (asprintf(authorization,
	    "AWS4-HMAC-SHA256 "
	    "Credential=%s/%s/%s/s3/aws4_request,"
	    "SignedHeaders=host;x-amz-content-sha256;x-amz-date,"
	    "Signature=%s",
	    key_id, date, region, sigbuf) == -1)
		goto err1;

	/* Duplicate X-Amz-Content-SHA256 and X-Amz-Date headers. */
	if ((*x_amz_content_sha256 = strdup(content_sha256)) == NULL)
		goto err2;
	if ((*x_amz_date = strdup(datetime)) == NULL)
		goto err3;

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

	/* Success! */
	return (0);

err3:
	free(*x_amz_content_sha256);
err2:
	free(*authorization);
err1:
	free(canonical_request);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq 0x30(%rbp), %rax
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)
leaq -0x40(%rbp), %rdi
callq 0x3360
cmpq $-0x1, %rax
jne 0x12ee2
jmp 0x12ea8
callq 0x3040
cmpl $0x0, (%rax)
je 0x12ecd
leaq 0xbc34(%rip), %rdi      # 0x1eaed
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x12edb
leaq 0xbc19(%rip), %rdi      # 0x1eaed
movb $0x0, %al
callq 0x6930
jmp 0x12edd
jmp 0x13153
leaq -0x81(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x3670
movq -0x168(%rbp), %rdi
movq %rax, %rcx
movl $0x9, %esi
leaq 0xd019(%rip), %rdx      # 0x1ff2c
callq 0x32b0
cmpq $0x0, %rax
jne 0x12f5a
jmp 0x12f20
callq 0x3040
cmpl $0x0, (%rax)
je 0x12f45
leaq 0xbbb8(%rip), %rdi      # 0x1eae9
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x12f53
leaq 0xbb9d(%rip), %rdi      # 0x1eae9
movb $0x0, %al
callq 0x6930
jmp 0x12f55
jmp 0x13153
leaq -0xa0(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x3670
movq -0x170(%rbp), %rdi
movq %rax, %rcx
movl $0x11, %esi
leaq 0xcfa8(%rip), %rdx      # 0x1ff33
callq 0x32b0
cmpq $0x0, %rax
jne 0x12fd2
jmp 0x12f98
callq 0x3040
cmpl $0x0, (%rax)
je 0x12fbd
leaq 0xbb40(%rip), %rdi      # 0x1eae9
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x12fcb
leaq 0xbb25(%rip), %rdi      # 0x1eae9
movb $0x0, %al
callq 0x6930
jmp 0x12fcd
jmp 0x13153
movq 0x10(%rbp), %rax
movq %rax, -0x178(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x12ff1
movq 0x18(%rbp), %rax
movq %rax, -0x180(%rbp)
jmp 0x12ffc
xorl %eax, %eax
movq %rax, -0x180(%rbp)
jmp 0x12ffc
movq -0x178(%rbp), %rdi
movq -0x180(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x15790
leaq -0xc0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl $0x20, %edx
callq 0x15160
movq -0x28(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %r8
leaq -0x110(%rbp), %r9
leaq -0xa0(%rbp), %r10
leaq -0x110(%rbp), %rax
leaq -0x118(%rbp), %rdi
leaq 0xcee5(%rip), %rsi      # 0x1ff42
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x15020
cmpl $-0x1, %eax
jne 0x13077
jmp 0x13153
movq -0x18(%rbp), %rdi
leaq -0x81(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x118(%rbp), %r9
leaq -0x160(%rbp), %rax
leaq 0xcf0f(%rip), %r8       # 0x1ffb1
movq %rax, (%rsp)
callq 0x13170
cmpl $0x0, %eax
je 0x130b5
jmp 0x13147
movq 0x30(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq -0x81(%rbp), %rcx
movq -0x20(%rbp), %r8
leaq -0x160(%rbp), %r9
leaq 0xcede(%rip), %rsi      # 0x1ffb4
movb $0x0, %al
callq 0x15020
cmpl $-0x1, %eax
jne 0x130e4
jmp 0x13147
leaq -0x110(%rbp), %rdi
callq 0x35f0
movq 0x20(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x130ff
jmp 0x1313b
leaq -0xa0(%rbp), %rdi
callq 0x35f0
movq 0x28(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x1311a
jmp 0x1312f
movq -0x118(%rbp), %rdi
callq 0x3460
movl $0x0, -0x4(%rbp)
jmp 0x1315a
movq 0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x3460
movq 0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x3460
movq -0x118(%rbp), %rdi
callq 0x3460
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopw %cs:(%rax,%rax)