// File: /workspace/github_c_makefile_star2_O2/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 0x3330
cmpq $-0x1, %rax
je 0xc26f
leaq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x3670
leaq 0x591f(%rip), %rdx      # 0x11a97
leaq 0xf(%rsp), %rdi
pushq $0x9
popq %rsi
movq %rax, %rcx
callq 0x3280
testq %rax, %rax
je 0xc259
leaq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x3670
leaq 0x58f7(%rip), %rdx      # 0x11a9e
leaq 0x20(%rsp), %rdi
pushq $0x11
popq %rsi
movq %rax, %rcx
callq 0x3280
testq %rax, %rax
je 0xc259
movl 0xf0(%rsp), %r11d
subq $0x8, %rsp
leaq 0x5949(%rip), %r10      # 0x11b1c
leaq 0x59ba(%rip), %rsi      # 0x11b94
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 0xd27c
addq $0x30, %rsp
cmpl $-0x1, %eax
je 0xc2ac
movq (%rsp), %r9
subq $0x8, %rsp
leaq 0x78(%rsp), %r13
leaq 0x58f3(%rip), %r8       # 0x11b1c
leaq 0x17(%rsp), %rsi
leaq 0x28(%rsp), %r14
movq %r12, %rdi
movq %r14, %rdx
movq %rbx, %rcx
pushq %r13
callq 0xbf79
popq %rcx
popq %rdx
movl %eax, %ebp
movq (%rsp), %rdi
callq 0x3460
testl %ebp, %ebp
je 0xc2c1
xorl %r14d, %r14d
jmp 0xc2ac
callq 0x3040
cmpl $0x0, (%rax)
je 0xc292
movq %rax, %rbx
leaq 0x45e0(%rip), %rdi      # 0x1084d
jmp 0xc283
callq 0x3040
cmpl $0x0, (%rax)
je 0xc29b
movq %rax, %rbx
leaq 0x45ce(%rip), %rdi      # 0x10851
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x53ad
andl $0x0, (%rbx)
jmp 0xc2ac
leaq 0x45b4(%rip), %rdi      # 0x1084d
jmp 0xc2a2
leaq 0x45af(%rip), %rdi      # 0x10851
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x553c
movq %r14, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subq $0x8, %rsp
leaq 0x598d(%rip), %rsi      # 0x11c59
leaq 0x5849(%rip), %r9       # 0x11b1c
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 0xd27c
addq $0x20, %rsp
cmpl $-0x1, %eax
je 0xc2ac
movq (%rsp), %r14
jmp 0xc2ac