// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/liball/../libcperciva/aws/aws_sign.c
// Function: aws_sign_s3_querystr
char *
aws_sign_s3_querystr(const char * key_id, const char * key_secret,
    const char * region, const char * method, const char * bucket,
    const char * path, int expiry)
{
	time_t t_now;
	struct tm r_result;
	char date[9];
	char datetime[17];
	char * s;
	char hhex[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;
	}

	/* Construct Canonical Request string. */
	if (asprintf(&s,
	    "%s\n"
	    "%s\n"
	    "X-Amz-Algorithm=AWS4-HMAC-SHA256&"
	    "X-Amz-Credential=%s%%2F%s%%2F%s%%2F%s%%2Faws4_request&"
	    "X-Amz-Date=%s&"
	    "X-Amz-Expires=%d&"
	    "X-Amz-SignedHeaders=host\n"
	    "host:%s.s3.amazonaws.com\n"
	    "\n"
	    "host\n"
	    "UNSIGNED-PAYLOAD",
	    method, path, key_id, date, region, "s3", datetime, expiry,
	    bucket) == -1)
		goto err0;

	if (aws_sign(key_secret, date, datetime, region, "s3", s, hhex))
		goto err1;

	/* Free the Canonical Request string. */
	free(s);

	/* Construct the query parameters. */
	if (asprintf(&s,
	    "X-Amz-Algorithm=AWS4-HMAC-SHA256&"
	    "X-Amz-Credential=%s%%2F%s%%2F%s%%2F%s%%2Faws4_request&"
	    "X-Amz-Date=%s&"
	    "X-Amz-Expires=%d&"
	    "X-Amz-SignedHeaders=host&"
	    "X-Amz-Signature=%s",
	    key_id, date, region, "s3", datetime, expiry, hhex) == -1)
		goto err0;

	/* Success! */
	return (s);

err1:
	free(s);
err0:
	/* Failure! */
	return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, %rbp
movq %r8, %r13
movq %rcx, %r15
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r14
leaq 0x18(%rsp), %rdi
callq 0x3320
cmpq $-0x1, %rax
je 0xd0c4
leaq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x3660
leaq 0x5b45(%rip), %rdx      # 0x12b0c
leaq 0xf(%rsp), %rdi
movl $0x9, %esi
movq %rax, %rcx
callq 0x3270
testq %rax, %rax
je 0xd0ae
leaq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x3660
leaq 0x5b1b(%rip), %rdx      # 0x12b13
leaq 0x20(%rsp), %rdi
movl $0x11, %esi
movq %rax, %rcx
callq 0x3270
testq %rax, %rax
je 0xd0ae
movl 0xf0(%rsp), %r11d
subq $0x8, %rsp
leaq 0x5b6b(%rip), %r10      # 0x12b91
leaq 0x5bdc(%rip), %rsi      # 0x12c09
movq %r14, %r8
xorl %r14d, %r14d
leaq 0x8(%rsp), %rdi
leaq 0x17(%rsp), %r9
movq %r15, %rdx
movq %rbp, %rcx
movq %r8, %r15
xorl %eax, %eax
pushq %r13
pushq %r11
leaq 0x38(%rsp), %r11
pushq %r11
pushq %r10
pushq %rbx
callq 0xe160
addq $0x30, %rsp
cmpl $-0x1, %eax
je 0xd104
movq (%rsp), %r9
subq $0x8, %rsp
leaq 0x78(%rsp), %r13
leaq 0x5b15(%rip), %r8       # 0x12b91
leaq 0x17(%rsp), %rsi
leaq 0x28(%rsp), %r14
movq %r12, %rdi
movq %r14, %rdx
movq %rbx, %rcx
pushq %r13
callq 0xcdc2
addq $0x10, %rsp
movl %eax, %ebp
movq (%rsp), %rdi
callq 0x3450
testl %ebp, %ebp
je 0xd119
xorl %r14d, %r14d
jmp 0xd104
callq 0x3040
cmpl $0x0, (%rax)
je 0xd0ea
movq %rax, %rbx
leaq 0x47bb(%rip), %rdi      # 0x1187d
jmp 0xd0d8
callq 0x3040
cmpl $0x0, (%rax)
je 0xd0f3
movq %rax, %rbx
leaq 0x47a9(%rip), %rdi      # 0x11881
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x57b8
movl $0x0, (%rbx)
jmp 0xd104
leaq 0x478c(%rip), %rdi      # 0x1187d
jmp 0xd0fa
leaq 0x4787(%rip), %rdi      # 0x11881
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x58d7
movq %r14, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subq $0x8, %rsp
leaq 0x5baa(%rip), %rsi      # 0x12cce
leaq 0x5a66(%rip), %r9       # 0x12b91
movq %r14, %r11
xorl %r14d, %r14d
leaq 0x8(%rsp), %rdi
leaq 0x17(%rsp), %rcx
movq %r15, %rdx
movq %rbx, %r8
xorl %eax, %eax
pushq %r13
movl 0x100(%rsp), %r10d
pushq %r10
pushq %r11
callq 0xe160
addq $0x20, %rsp
cmpl $-0x1, %eax
je 0xd104
movq (%rsp), %r14
jmp 0xd104