// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x130, %rsp            # imm = 0x130
movl 0x10(%rbp), %eax
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq %r9, -0x48(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3360
cmpq $-0x1, %rax
jne 0x13434
jmp 0x133fa
callq 0x3040
cmpl $0x0, (%rax)
je 0x1341f
leaq 0xb6e2(%rip), %rdi      # 0x1eaed
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x1342d
leaq 0xb6c7(%rip), %rdi      # 0x1eaed
movb $0x0, %al
callq 0x6930
jmp 0x1342f
jmp 0x13640
leaq -0x91(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3670
movq -0x108(%rbp), %rdi
movq %rax, %rcx
movl $0x9, %esi
leaq 0xcac4(%rip), %rdx      # 0x1ff2c
callq 0x32b0
cmpq $0x0, %rax
jne 0x134af
jmp 0x13475
callq 0x3040
cmpl $0x0, (%rax)
je 0x1349a
leaq 0xb663(%rip), %rdi      # 0x1eae9
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x134a8
leaq 0xb648(%rip), %rdi      # 0x1eae9
movb $0x0, %al
callq 0x6930
jmp 0x134aa
jmp 0x13640
leaq -0xb0(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3670
movq -0x110(%rbp), %rdi
movq %rax, %rcx
movl $0x11, %esi
leaq 0xca50(%rip), %rdx      # 0x1ff33
callq 0x32b0
cmpq $0x0, %rax
jne 0x1352a
jmp 0x134f0
callq 0x3040
cmpl $0x0, (%rax)
je 0x13515
leaq 0xb5e8(%rip), %rdi      # 0x1eae9
movb $0x0, %al
callq 0x66e0
callq 0x3040
movl $0x0, (%rax)
jmp 0x13523
leaq 0xb5cd(%rip), %rdi      # 0x1eae9
movb $0x0, %al
callq 0x6930
jmp 0x13525
jmp 0x13640
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %rcx
movq -0x20(%rbp), %r8
leaq -0x91(%rbp), %r9
movq -0x30(%rbp), %r14
leaq -0xb0(%rbp), %r11
movl 0x10(%rbp), %r10d
movq -0x40(%rbp), %rax
leaq -0xb8(%rbp), %rdi
leaq 0xcacb(%rip), %rsi      # 0x20029
leaq 0xca4c(%rip), %rbx      # 0x1ffb1
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movb $0x0, %al
callq 0x15020
cmpl $-0x1, %eax
jne 0x1358e
jmp 0x13640
movq -0x28(%rbp), %rdi
leaq -0x91(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0xb8(%rbp), %r9
leaq -0x100(%rbp), %rax
leaq 0xc9f8(%rip), %r8       # 0x1ffb1
movq %rax, (%rsp)
callq 0x13170
cmpl $0x0, %eax
je 0x135c9
jmp 0x13634
movq -0xb8(%rbp), %rdi
callq 0x3460
movq -0x20(%rbp), %rdx
leaq -0x91(%rbp), %rcx
movq -0x30(%rbp), %r8
leaq -0xb0(%rbp), %r11
movl 0x10(%rbp), %r10d
leaq -0x100(%rbp), %rax
leaq -0xb8(%rbp), %rdi
leaq 0xcaea(%rip), %rsi      # 0x200ee
leaq 0xc9a6(%rip), %r9       # 0x1ffb1
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x15020
cmpl $-0x1, %eax
jne 0x13627
jmp 0x13640
movq -0xb8(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x13648
movq -0xb8(%rbp), %rdi
callq 0x3460
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax,%rax)