// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]libcperciva/tests/crypto_aesctr/main.c
// Function: selftest_unaligned_access
static size_t
selftest_unaligned_access(size_t keylen)
{
	struct crypto_aesctr * aesctr;
	struct crypto_aes_key * key_exp;
	uint8_t key_unexpanded[32];
	uint8_t * largebuf;
	uint8_t * largebuf_out1;
	uint8_t * largebuf_out2;
	size_t i;
	size_t bytes_processed;
	size_t new_chunk;
	size_t failures = 0;

	/* Prepare a large buffer with repeating 01010101_2 = 85. */
	if ((largebuf = malloc(LARGE_BUFSIZE)) == NULL)
		goto err0;
	memset(largebuf, 85, LARGE_BUFSIZE);

	/* Prepare the key: 00010203... */
	for (i = 0; i < keylen; i++)
		key_unexpanded[i] = (uint8_t)i;
	if ((key_exp = crypto_aes_key_expand(key_unexpanded, keylen)) == NULL)
		goto err1;

	/* Test with a large buffer and unaligned access. */
	printf("Computing %zu-bit AES-CTR of a large buffer two "
	    "different ways...", keylen * 8);

	/* Prepare output buffers. */
	if ((largebuf_out1 = malloc(LARGE_BUFSIZE)) == NULL)
		goto err2;
	if ((largebuf_out2 = malloc(LARGE_BUFSIZE)) == NULL)
		goto err3;

	/* Encrypt with one call. */
	crypto_aesctr_buf(key_exp, 0, largebuf, largebuf_out1, LARGE_BUFSIZE);

	/* Ensure we have a repeatable pattern of random values. */
	srandom(0);

	/* Encrypt with multiple calls. */
	if ((aesctr = crypto_aesctr_init(key_exp, 0)) == NULL)
		goto err4;
	bytes_processed = 0;
	while (bytes_processed < LARGE_BUFSIZE - MAX_CHUNK) {
		/* Get an insecure random number; not used for cryptography. */
		new_chunk = ((unsigned long int)random()) % MAX_CHUNK;

		/* Process that amount of data. */
		crypto_aesctr_stream(aesctr, &largebuf[bytes_processed],
		    &largebuf_out2[bytes_processed], new_chunk);
		bytes_processed += new_chunk;
	}
	new_chunk = LARGE_BUFSIZE - bytes_processed;
	crypto_aesctr_stream(aesctr, &largebuf[bytes_processed],
	    &largebuf_out2[bytes_processed], new_chunk);
	crypto_aesctr_free(aesctr);

	/* Compare ciphertexts. */
	if (memcmp(largebuf_out1, largebuf_out2, LARGE_BUFSIZE)) {
		printf(" FAILED!\n");
		failures++;
	} else
		printf(" PASSED!\n");

	/* Clean up. */
	free(largebuf_out2);
	free(largebuf_out1);
	crypto_aes_key_free(key_exp);
	free(largebuf);

	return (failures);

err4:
	free(largebuf_out2);
err3:
	free(largebuf_out1);
err2:
	crypto_aes_key_free(key_exp);
err1:
	free(largebuf);
err0:
	/* Failure! */
	return (1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r14
movl $0x10000, %edi          # imm = 0x10000
callq 0x20d0
testq %rax, %rax
je 0x36d2
movq %rax, %rbx
movl $0x10000, %edx          # imm = 0x10000
movq %rax, %rdi
movl $0x55, %esi
callq 0x2040
testq %r14, %r14
je 0x359b
leaq 0xf(%r14), %rax
andq $-0x10, %rax
leaq -0x1(%r14), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa %xmm0, 0x20(%rsp)
movdqa 0x2fd3(%rip), %xmm1     # 0x6030
movdqa 0x2fdb(%rip), %xmm2     # 0x6040
movdqa 0x2fe3(%rip), %xmm3     # 0x6050
movdqa 0x2feb(%rip), %xmm4     # 0x6060
movdqa 0x2ff3(%rip), %xmm5     # 0x6070
movdqa 0x2ffb(%rip), %xmm6     # 0x6080
movdqa 0x3003(%rip), %xmm7     # 0x6090
movdqa 0x300a(%rip), %xmm8     # 0x60a0
xorl %ecx, %ecx
movdqa 0x300f(%rip), %xmm9     # 0x60b0
pcmpeqd %xmm10, %xmm10
movdqa 0x20(%rsp), %xmm12
pxor %xmm9, %xmm12
movdqa %xmm8, %xmm13
pxor %xmm9, %xmm13
movdqa %xmm13, %xmm15
pcmpgtd %xmm12, %xmm15
pshufd $0xa0, %xmm15, %xmm14   # xmm14 = xmm15[0,0,2,2]
pshuflw $0xe8, %xmm14, %xmm0    # xmm0 = xmm14[0,2,2,3,4,5,6,7]
pcmpeqd %xmm12, %xmm13
pshufd $0xf5, %xmm13, %xmm13   # xmm13 = xmm13[1,1,3,3]
pshuflw $0xe8, %xmm13, %xmm11   # xmm11 = xmm13[0,2,2,3,4,5,6,7]
pand %xmm0, %xmm11
pshufd $0xf5, %xmm15, %xmm15   # xmm15 = xmm15[1,1,3,3]
pshuflw $0xe8, %xmm15, %xmm0    # xmm0 = xmm15[0,2,2,3,4,5,6,7]
por %xmm11, %xmm0
pxor %xmm10, %xmm0
packssdw %xmm0, %xmm0
movd %xmm0, %edx
testb $0x1, %dl
je 0x310e
movb %cl, (%rsp,%rcx)
pand %xmm14, %xmm13
por %xmm15, %xmm13
packssdw %xmm13, %xmm13
pxor %xmm10, %xmm13
packssdw %xmm13, %xmm13
packsswb %xmm13, %xmm13
movd %xmm13, %edx
shrl $0x8, %edx
testb $0x1, %dl
je 0x3140
leal 0x1(%rcx), %edx
movb %dl, 0x1(%rsp,%rcx)
movdqa %xmm7, %xmm0
pxor %xmm9, %xmm0
movdqa %xmm0, %xmm11
pcmpgtd %xmm12, %xmm11
pshufd $0xa0, %xmm11, %xmm13   # xmm13 = xmm11[0,0,2,2]
pcmpeqd %xmm12, %xmm0
pshufd $0xf5, %xmm0, %xmm14    # xmm14 = xmm0[1,1,3,3]
movdqa %xmm14, %xmm0
pand %xmm13, %xmm0
pshufd $0xf5, %xmm11, %xmm15   # xmm15 = xmm11[1,1,3,3]
por %xmm15, %xmm0
packssdw %xmm0, %xmm0
pxor %xmm10, %xmm0
packssdw %xmm0, %xmm0
packsswb %xmm0, %xmm0
movd %xmm0, %edx
shrl $0x10, %edx
testb $0x1, %dl
je 0x319d
leal 0x2(%rcx), %edx
movb %dl, 0x2(%rsp,%rcx)
pshufhw $0x84, %xmm13, %xmm0    # xmm0 = xmm13[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm14, %xmm11   # xmm11 = xmm14[0,1,2,3,4,5,4,6]
pand %xmm0, %xmm11
pshufhw $0x84, %xmm15, %xmm0    # xmm0 = xmm15[0,1,2,3,4,5,4,6]
por %xmm11, %xmm0
pxor %xmm10, %xmm0
packssdw %xmm0, %xmm0
packsswb %xmm0, %xmm0
movd %xmm0, %edx
shrl $0x18, %edx
testb $0x1, %dl
je 0x31d9
leal 0x3(%rcx), %edx
movb %dl, 0x3(%rsp,%rcx)
movdqa %xmm6, %xmm0
pxor %xmm9, %xmm0
movdqa %xmm0, %xmm11
pcmpgtd %xmm12, %xmm11
pshufd $0xa0, %xmm11, %xmm14   # xmm14 = xmm11[0,0,2,2]
pshuflw $0xe8, %xmm14, %xmm15   # xmm15 = xmm14[0,2,2,3,4,5,6,7]
pcmpeqd %xmm12, %xmm0
pshufd $0xf5, %xmm0, %xmm13    # xmm13 = xmm0[1,1,3,3]
pshuflw $0xe8, %xmm13, %xmm0    # xmm0 = xmm13[0,2,2,3,4,5,6,7]
pand %xmm15, %xmm0
pshufd $0xf5, %xmm11, %xmm15   # xmm15 = xmm11[1,1,3,3]
pshuflw $0xe8, %xmm15, %xmm11   # xmm11 = xmm15[0,2,2,3,4,5,6,7]
por %xmm0, %xmm11
pxor %xmm10, %xmm11
packssdw %xmm11, %xmm0
packsswb %xmm0, %xmm0
pextrw $0x2, %xmm0, %edx
testb $0x1, %dl
je 0x323e
leal 0x4(%rcx), %edx
movb %dl, 0x4(%rsp,%rcx)
pand %xmm14, %xmm13
por %xmm15, %xmm13
packssdw %xmm13, %xmm13
pxor %xmm10, %xmm13
packssdw %xmm13, %xmm0
packsswb %xmm0, %xmm0
pextrw $0x2, %xmm0, %edx
shrl $0x8, %edx
testb $0x1, %dl
je 0x326f
leal 0x5(%rcx), %edx
movb %dl, 0x5(%rsp,%rcx)
movdqa %xmm5, %xmm0
pxor %xmm9, %xmm0
movdqa %xmm0, %xmm11
pcmpgtd %xmm12, %xmm11
pshufd $0xa0, %xmm11, %xmm13   # xmm13 = xmm11[0,0,2,2]
pcmpeqd %xmm12, %xmm0
pshufd $0xf5, %xmm0, %xmm14    # xmm14 = xmm0[1,1,3,3]
movdqa %xmm14, %xmm0
pand %xmm13, %xmm0
pshufd $0xf5, %xmm11, %xmm15   # xmm15 = xmm11[1,1,3,3]
por %xmm15, %xmm0
packssdw %xmm0, %xmm0
pxor %xmm10, %xmm0
packssdw %xmm0, %xmm0
packsswb %xmm0, %xmm0
pextrw $0x3, %xmm0, %edx
testb $0x1, %dl
je 0x32ca
leal 0x6(%rcx), %edx
movb %dl, 0x6(%rsp,%rcx)
pshufhw $0x84, %xmm13, %xmm0    # xmm0 = xmm13[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm14, %xmm11   # xmm11 = xmm14[0,1,2,3,4,5,4,6]
pand %xmm0, %xmm11
pshufhw $0x84, %xmm15, %xmm0    # xmm0 = xmm15[0,1,2,3,4,5,4,6]
por %xmm11, %xmm0
pxor %xmm10, %xmm0
packssdw %xmm0, %xmm0
packsswb %xmm0, %xmm0
pextrw $0x3, %xmm0, %edx
shrl $0x8, %edx
testb $0x1, %dl
je 0x3307
leal 0x7(%rcx), %edx
movb %dl, 0x7(%rsp,%rcx)
movdqa %xmm4, %xmm0
pxor %xmm9, %xmm0
movdqa %xmm0, %xmm11
pcmpgtd %xmm12, %xmm11
pshufd $0xa0, %xmm11, %xmm14   # xmm14 = xmm11[0,0,2,2]
pshuflw $0xe8, %xmm14, %xmm15   # xmm15 = xmm14[0,2,2,3,4,5,6,7]
pcmpeqd %xmm12, %xmm0
pshufd $0xf5, %xmm0, %xmm13    # xmm13 = xmm0[1,1,3,3]
pshuflw $0xe8, %xmm13, %xmm0    # xmm0 = xmm13[0,2,2,3,4,5,6,7]
pand %xmm15, %xmm0
pshufd $0xf5, %xmm11, %xmm15   # xmm15 = xmm11[1,1,3,3]
pshuflw $0xe8, %xmm15, %xmm11   # xmm11 = xmm15[0,2,2,3,4,5,6,7]
por %xmm0, %xmm11
pxor %xmm10, %xmm11
packssdw %xmm11, %xmm11
packsswb %xmm11, %xmm0
pextrw $0x4, %xmm0, %edx
testb $0x1, %dl
je 0x336d
leal 0x8(%rcx), %edx
movb %dl, 0x8(%rsp,%rcx)
pand %xmm14, %xmm13
por %xmm15, %xmm13
packssdw %xmm13, %xmm13
pxor %xmm10, %xmm13
packssdw %xmm13, %xmm13
packsswb %xmm13, %xmm0
pextrw $0x4, %xmm0, %edx
shrl $0x8, %edx
testb $0x1, %dl
je 0x339f
leal 0x9(%rcx), %edx
movb %dl, 0x9(%rsp,%rcx)
movdqa %xmm3, %xmm0
pxor %xmm9, %xmm0
movdqa %xmm0, %xmm11
pcmpgtd %xmm12, %xmm11
pshufd $0xa0, %xmm11, %xmm13   # xmm13 = xmm11[0,0,2,2]
pcmpeqd %xmm12, %xmm0
pshufd $0xf5, %xmm0, %xmm14    # xmm14 = xmm0[1,1,3,3]
movdqa %xmm14, %xmm0
pand %xmm13, %xmm0
pshufd $0xf5, %xmm11, %xmm15   # xmm15 = xmm11[1,1,3,3]
por %xmm15, %xmm0
packssdw %xmm0, %xmm0
pxor %xmm10, %xmm0
packssdw %xmm0, %xmm0
packsswb %xmm0, %xmm0
pextrw $0x5, %xmm0, %edx
testb $0x1, %dl
je 0x33fa
leal 0xa(%rcx), %edx
movb %dl, 0xa(%rsp,%rcx)
pshufhw $0x84, %xmm13, %xmm0    # xmm0 = xmm13[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm14, %xmm11   # xmm11 = xmm14[0,1,2,3,4,5,4,6]
pand %xmm0, %xmm11
pshufhw $0x84, %xmm15, %xmm0    # xmm0 = xmm15[0,1,2,3,4,5,4,6]
por %xmm11, %xmm0
pxor %xmm10, %xmm0
packssdw %xmm0, %xmm0
packsswb %xmm0, %xmm0
pextrw $0x5, %xmm0, %edx
shrl $0x8, %edx
testb $0x1, %dl
je 0x3437
leal 0xb(%rcx), %edx
movb %dl, 0xb(%rsp,%rcx)
movdqa %xmm2, %xmm0
pxor %xmm9, %xmm0
movdqa %xmm0, %xmm11
pcmpgtd %xmm12, %xmm11
pshufd $0xa0, %xmm11, %xmm14   # xmm14 = xmm11[0,0,2,2]
pshuflw $0xe8, %xmm14, %xmm15   # xmm15 = xmm14[0,2,2,3,4,5,6,7]
pcmpeqd %xmm12, %xmm0
pshufd $0xf5, %xmm0, %xmm13    # xmm13 = xmm0[1,1,3,3]
pshuflw $0xe8, %xmm13, %xmm0    # xmm0 = xmm13[0,2,2,3,4,5,6,7]
pand %xmm15, %xmm0
pshufd $0xf5, %xmm11, %xmm15   # xmm15 = xmm11[1,1,3,3]
pshuflw $0xe8, %xmm15, %xmm11   # xmm11 = xmm15[0,2,2,3,4,5,6,7]
por %xmm0, %xmm11
pxor %xmm10, %xmm11
packssdw %xmm11, %xmm0
packsswb %xmm0, %xmm0
pextrw $0x6, %xmm0, %edx
testb $0x1, %dl
je 0x349c
leal 0xc(%rcx), %edx
movb %dl, 0xc(%rsp,%rcx)
pand %xmm14, %xmm13
por %xmm15, %xmm13
packssdw %xmm13, %xmm13
pxor %xmm10, %xmm13
packssdw %xmm13, %xmm0
packsswb %xmm0, %xmm0
pextrw $0x6, %xmm0, %edx
shrl $0x8, %edx
testb $0x1, %dl
je 0x34cd
leal 0xd(%rcx), %edx
movb %dl, 0xd(%rsp,%rcx)
movdqa %xmm1, %xmm0
pxor %xmm9, %xmm0
movdqa %xmm0, %xmm11
pcmpgtd %xmm12, %xmm11
pshufd $0xa0, %xmm11, %xmm13   # xmm13 = xmm11[0,0,2,2]
pcmpeqd %xmm12, %xmm0
pshufd $0xf5, %xmm0, %xmm12    # xmm12 = xmm0[1,1,3,3]
movdqa %xmm12, %xmm0
pand %xmm13, %xmm0
pshufd $0xf5, %xmm11, %xmm14   # xmm14 = xmm11[1,1,3,3]
por %xmm14, %xmm0
packssdw %xmm0, %xmm0
pxor %xmm10, %xmm0
packssdw %xmm0, %xmm0
packsswb %xmm0, %xmm0
pextrw $0x7, %xmm0, %edx
testb $0x1, %dl
je 0x3528
leal 0xe(%rcx), %edx
movb %dl, 0xe(%rsp,%rcx)
pshufhw $0x84, %xmm13, %xmm0    # xmm0 = xmm13[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm12, %xmm11   # xmm11 = xmm12[0,1,2,3,4,5,4,6]
pand %xmm0, %xmm11
pshufhw $0x84, %xmm14, %xmm0    # xmm0 = xmm14[0,1,2,3,4,5,4,6]
por %xmm11, %xmm0
pxor %xmm10, %xmm0
packssdw %xmm0, %xmm0
packsswb %xmm0, %xmm0
pextrw $0x7, %xmm0, %edx
shrl $0x8, %edx
testb $0x1, %dl
je 0x3565
leal 0xf(%rcx), %edx
movb %dl, 0xf(%rsp,%rcx)
addq $0x10, %rcx
movdqa 0x2b4f(%rip), %xmm0     # 0x60c0
paddq %xmm0, %xmm8
paddq %xmm0, %xmm7
paddq %xmm0, %xmm6
paddq %xmm0, %xmm5
paddq %xmm0, %xmm4
paddq %xmm0, %xmm3
paddq %xmm0, %xmm2
paddq %xmm0, %xmm1
cmpq %rcx, %rax
jne 0x30a6
movq %rsp, %rdi
movq %r14, %rsi
callq 0x39bb
testq %rax, %rax
je 0x36da
movq %rax, %r15
shlq $0x3, %r14
leaq 0x30f2(%rip), %rdi      # 0x66af
movq %r14, %rsi
xorl %eax, %eax
callq 0x2030
movl $0x10000, %edi          # imm = 0x10000
callq 0x20d0
movl $0x1, %r13d
testq %rax, %rax
je 0x36c8
movq %rax, %r14
movl $0x10000, %edi          # imm = 0x10000
callq 0x20d0
testq %rax, %rax
je 0x36c0
movq %rax, %r12
movl $0x10000, %r8d          # imm = 0x10000
movq %r15, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x4520
xorl %edi, %edi
callq 0x20f0
movq %r15, %rdi
xorl %esi, %esi
callq 0x423a
testq %rax, %rax
je 0x36b8
movq %rax, %rbp
movq %r14, 0x20(%rsp)
xorl %r13d, %r13d
movq %r13, %r14
callq 0x21f0
movzbl %al, %r13d
leaq (%rbx,%r14), %rsi
leaq (%r12,%r14), %rdx
movq %rbp, %rdi
movq %r13, %rcx
callq 0x4292
addq %r14, %r13
cmpq $0xff00, %r13           # imm = 0xFF00
jb 0x3634
movl $0x10000, %ecx          # imm = 0x10000
subq %r13, %rcx
movq %rbx, %rsi
addq %r13, %rsi
movq %r12, %rdx
addq %r13, %rdx
movq %rbp, %rdi
callq 0x4292
movq %rbp, %rdi
callq 0x44fc
movl $0x10000, %edx          # imm = 0x10000
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x2170
xorl %r13d, %r13d
testl %eax, %eax
setne %r13b
leaq 0x30ba(%rip), %rax      # 0x6762
leaq 0x30aa(%rip), %rdi      # 0x6759
cmovneq %rax, %rdi
callq 0x2080
movq %r12, %rdi
callq 0x2130
movq %r14, %rdi
callq 0x2130
movq %r15, %rdi
callq 0x3a5b
jmp 0x36e0
movl $0x1, %r13d
jmp 0x36e8
movl $0x1, %r13d
movq %rbx, %rdi
callq 0x2130
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq