// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/liball/../libcperciva/aws/aws_sign.c
// Function: aws_sign
static int
aws_sign(const char * key_secret, const char * date, const char * datetime,
    const char * region, const char * service, const char * creq,
    char sigbuf[65])
{
	char * AWS4_key;
	uint8_t kDate[32];
	uint8_t kRegion[32];
	uint8_t kService[32];
	uint8_t kSigning[32];
	uint8_t h_creq[32];
	char hhex_creq[65];
	char * STS;
	uint8_t hmac[32];

	/* Construct "AWS4" + key_secret. */
	if (asprintf(&AWS4_key, "AWS4%s", key_secret) == -1)
		goto err0;

	/* kDate = HMAC("AWS4" + kSecret, Date). */
	HMAC_SHA256_Buf(AWS4_key, strlen(AWS4_key), date, strlen(date), kDate);

	/* kRegion = HMAC(kDate, Region). */
	HMAC_SHA256_Buf(kDate, 32, region, strlen(region), kRegion);

	/* kService = HMAC(kRegion, Service). */
	HMAC_SHA256_Buf(kRegion, 32, service, strlen(service), kService);

	/* kSigning = HMAC(kService, "aws4_request"). */
	HMAC_SHA256_Buf(kService, 32, "aws4_request", strlen("aws4_request"),
	    kSigning);

	/* Free string allocated by asprintf. */
	free(AWS4_key);

	/* Generate the hexified hash of the Canonical Request string. */
	SHA256_Buf(creq, strlen(creq), h_creq);
	hexify(h_creq, hhex_creq, 32);

	/* Construct the String to Sign. */
	if (asprintf(&STS,
	    "AWS4-HMAC-SHA256\n"
	    "%s\n"
	    "%s/%s/%s/aws4_request\n"
	    "%s",
	    datetime, date, region, service, hhex_creq) == -1)
		goto err0;

	/* Sign and hexify the String to Sign. */
	HMAC_SHA256_Buf(kSigning, 32, STS, strlen(STS), hmac);
	hexify(hmac, sigbuf, 32);

	/* Free string allocated by asprintf. */
	free(STS);

	/* Success! */
	return (0);

err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
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)
movq -0x10(%rbp), %rdx
leaq -0x40(%rbp), %rdi
leaq 0xd205(%rip), %rsi      # 0x203ab
movb $0x0, %al
callq 0x15020
cmpl $-0x1, %eax
jne 0x131b7
jmp 0x133a0
movq -0x40(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x40(%rbp), %rdi
callq 0x31a0
movq %rax, -0x198(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x18(%rbp), %rdi
callq 0x31a0
movq -0x1a0(%rbp), %rdi
movq -0x198(%rbp), %rsi
movq -0x190(%rbp), %rdx
movq %rax, %rcx
leaq -0x60(%rbp), %r8
callq 0x15b50
leaq -0x60(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x28(%rbp), %rdi
callq 0x31a0
movq -0x188(%rbp), %rdi
movq -0x180(%rbp), %rdx
movq %rax, %rcx
leaq -0x80(%rbp), %r8
movl $0x20, %esi
callq 0x15b50
leaq -0x80(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x30(%rbp), %rdi
callq 0x31a0
movq -0x178(%rbp), %rdi
movq -0x170(%rbp), %rdx
movq %rax, %rcx
leaq -0xa0(%rbp), %r8
movl $0x20, %esi
callq 0x15b50
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %r8
movl $0x20, %esi
leaq 0xd112(%rip), %rdx      # 0x203b2
movl $0xc, %ecx
callq 0x15b50
movq -0x40(%rbp), %rdi
callq 0x3460
movq -0x38(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x38(%rbp), %rdi
callq 0x31a0
movq -0x168(%rbp), %rdi
movq %rax, %rsi
leaq -0xe0(%rbp), %rdx
callq 0x15790
leaq -0xe0(%rbp), %rdi
leaq -0x130(%rbp), %rsi
movl $0x20, %edx
callq 0x15160
movq -0x20(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x30(%rbp), %r9
leaq -0x130(%rbp), %rax
leaq -0x138(%rbp), %rdi
leaq 0xd0a5(%rip), %rsi      # 0x203bf
movq %rax, (%rsp)
movb $0x0, %al
callq 0x15020
cmpl $-0x1, %eax
jne 0x1332c
jmp 0x133a0
leaq -0xc0(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movq -0x138(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq -0x138(%rbp), %rdi
callq 0x31a0
movq -0x1b0(%rbp), %rdi
movq -0x1a8(%rbp), %rdx
movq %rax, %rcx
leaq -0x160(%rbp), %r8
movl $0x20, %esi
callq 0x15b50
leaq -0x160(%rbp), %rdi
movq 0x10(%rbp), %rsi
movl $0x20, %edx
callq 0x15160
movq -0x138(%rbp), %rdi
callq 0x3460
movl $0x0, -0x4(%rbp)
jmp 0x133a7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
nopw %cs:(%rax,%rax)