// File: /workspace/github_c_makefile_star2_O1/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 0xd244
leaq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x3660
leaq 0x5b4d(%rip), %rdx      # 0x12c94
leaq 0xf(%rsp), %rdi
movl $0x9, %esi
movq %rax, %rcx
callq 0x3270
testq %rax, %rax
je 0xd22e
leaq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x3660
leaq 0x5b23(%rip), %rdx      # 0x12c9b
leaq 0x20(%rsp), %rdi
movl $0x11, %esi
movq %rax, %rcx
callq 0x3270
testq %rax, %rax
je 0xd22e
movl 0xf0(%rsp), %r11d
subq $0x8, %rsp
leaq 0x5b73(%rip), %r10      # 0x12d19
leaq 0x5be4(%rip), %rsi      # 0x12d91
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 0xe2e0
addq $0x30, %rsp
cmpl $-0x1, %eax
je 0xd284
movq (%rsp), %r9
subq $0x8, %rsp
leaq 0x78(%rsp), %r13
leaq 0x5b1d(%rip), %r8       # 0x12d19
leaq 0x17(%rsp), %rsi
leaq 0x28(%rsp), %r14
movq %r12, %rdi
movq %r14, %rdx
movq %rbx, %rcx
pushq %r13
callq 0xcf42
addq $0x10, %rsp
movl %eax, %ebp
movq (%rsp), %rdi
callq 0x3450
testl %ebp, %ebp
je 0xd299
xorl %r14d, %r14d
jmp 0xd284
callq 0x3040
cmpl $0x0, (%rax)
je 0xd26a
movq %rax, %rbx
leaq 0x47c3(%rip), %rdi      # 0x11a05
jmp 0xd258
callq 0x3040
cmpl $0x0, (%rax)
je 0xd273
movq %rax, %rbx
leaq 0x47b1(%rip), %rdi      # 0x11a09
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x578c
movl $0x0, (%rbx)
jmp 0xd284
leaq 0x4794(%rip), %rdi      # 0x11a05
jmp 0xd27a
leaq 0x478f(%rip), %rdi      # 0x11a09
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x58ab
movq %r14, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subq $0x8, %rsp
leaq 0x5bb2(%rip), %rsi      # 0x12e56
leaq 0x5a6e(%rip), %r9       # 0x12d19
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 0xe2e0
addq $0x20, %rsp
cmpl $-0x1, %eax
je 0xd284
movq (%rsp), %r14
jmp 0xd284