// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../libcperciva/aws/aws_sign.c
// Function: aws_sign_svc_headers
int
aws_sign_svc_headers(const char * key_id, const char * key_secret,
    const char * region, const char * svc,
    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,
	    "POST\n"
	    "/\n"
	    "\n"
	    "host:%s.%s.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",
	    svc, region, content_sha256, datetime, content_sha256) == -1)
		goto err0;

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

	/* Construct Authorization header. */
	if (asprintf(authorization,
	    "AWS4-HMAC-SHA256 "
	    "Credential=%s/%s/%s/%s/aws4_request,"
	    "SignedHeaders=host;x-amz-content-sha256;x-amz-date,"
	    "Signature=%s",
	    key_id, date, region, svc, 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 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 0x136da
jmp 0x136a0
callq 0x3040
cmpl $0x0, (%rax)
je 0x136c5
leaq 0xb43c(%rip), %rdi      # 0x1eaed
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x136d3
leaq 0xb421(%rip), %rdi      # 0x1eaed
movb $0x0, %al
callq 0x6930
jmp 0x136d5
jmp 0x13947
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 0xc821(%rip), %rdx      # 0x1ff2c
callq 0x32b0
cmpq $0x0, %rax
jne 0x13752
jmp 0x13718
callq 0x3040
cmpl $0x0, (%rax)
je 0x1373d
leaq 0xb3c0(%rip), %rdi      # 0x1eae9
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x1374b
leaq 0xb3a5(%rip), %rdi      # 0x1eae9
movb $0x0, %al
callq 0x6930
jmp 0x1374d
jmp 0x13947
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 0xc7b0(%rip), %rdx      # 0x1ff33
callq 0x32b0
cmpq $0x0, %rax
jne 0x137ca
jmp 0x13790
callq 0x3040
cmpl $0x0, (%rax)
je 0x137b5
leaq 0xb348(%rip), %rdi      # 0x1eae9
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x137c3
leaq 0xb32d(%rip), %rdi      # 0x1eae9
movb $0x0, %al
callq 0x6930
jmp 0x137c5
jmp 0x13947
movq -0x30(%rbp), %rax
movq %rax, -0x178(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x137e9
movq -0x38(%rbp), %rax
movq %rax, -0x180(%rbp)
jmp 0x137f4
xorl %eax, %eax
movq %rax, -0x180(%rbp)
jmp 0x137f4
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 -0x20(%rbp), %rcx
leaq -0x110(%rbp), %r8
leaq -0xa0(%rbp), %r9
leaq -0x110(%rbp), %rax
leaq -0x118(%rbp), %rdi
leaq 0xc93f(%rip), %rsi      # 0x20190
movq %rax, (%rsp)
movb $0x0, %al
callq 0x15020
cmpl $-0x1, %eax
jne 0x13866
jmp 0x13947
movq -0x18(%rbp), %rdi
leaq -0x81(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x118(%rbp), %r9
leaq -0x160(%rbp), %rax
movq %rax, (%rsp)
callq 0x13170
cmpl $0x0, %eax
je 0x138a1
jmp 0x1393b
movq 0x20(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq -0x81(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
leaq -0x160(%rbp), %rax
leaq 0xc93a(%rip), %rsi      # 0x20200
movq %rax, (%rsp)
movb $0x0, %al
callq 0x15020
cmpl $-0x1, %eax
jne 0x138d8
jmp 0x1393b
leaq -0x110(%rbp), %rdi
callq 0x35f0
movq 0x10(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x138f3
jmp 0x1392f
leaq -0xa0(%rbp), %rdi
callq 0x35f0
movq 0x18(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x1390e
jmp 0x13923
movq -0x118(%rbp), %rdi
callq 0x3460
movl $0x0, -0x4(%rbp)
jmp 0x1394e
movq 0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x3460
movq 0x20(%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 (%rax,%rax)