// File: /workspace/github_c_makefile_star2_O1/Tarsnap[P]libcperciva/tests/crypto_aes/main.c
// Function: selftest
static int
selftest(void)
{
	struct crypto_aes_key * key_exp;
	uint8_t plaintext_arr[MAX_PLAINTEXT_LENGTH];
	uint8_t ciphertext_arr[MAX_PLAINTEXT_LENGTH];
	uint8_t cbuf[MAX_PLAINTEXT_LENGTH];
	size_t keylen;
	size_t i;
	size_t failures = 0;
	size_t num_tests = sizeof(tests) / sizeof(tests[0]);
#ifdef CPUSUPPORT_X86_AESNI
	__m128i bufsse;
#endif
#ifdef CPUSUPPORT_ARM_AES
	uint8x16_t bufarm;
#endif

	/* Sanity check. */
#ifdef CPUSUPPORT_X86_AESNI
	if (cpusupport_x86_aesni()) {
		if (crypto_aes_can_use_intrinsics() != 1) {
			warn0("Unexpected error with AESNI");
			goto err0;
		}
	}
#endif

	/* Inform user about the hardware optimization status. */
	print_hardware("Checking test vectors of AES");

	/* Run regular test cases. */
	for (i = 0; i < num_tests; i++) {
		/* Prepare for the test case. */
		if (parse_testcase(tests[i], &key_exp, &keylen,
		    plaintext_arr, ciphertext_arr)) {
			warn0("parse_testcase");
			goto err0;
		}
		printf("Computing %zu-bit AES of \"%s\"...",
		    keylen * 8, tests[i].plaintext_hex);

		/* Run AES. */
#ifdef CPUSUPPORT_X86_AESNI
		if (crypto_aes_can_use_intrinsics() == 1) {
			bufsse = _mm_loadu_si128(
			    (const __m128i *)plaintext_arr);
			bufsse = crypto_aes_encrypt_block_aesni_m128i(bufsse,
			    key_exp);
			_mm_storeu_si128((__m128i *)cbuf, bufsse);
		} else
#endif
#ifdef CPUSUPPORT_ARM_AES
		if (crypto_aes_can_use_intrinsics() == 2) {
			bufarm = vld1q_u8(plaintext_arr);
			bufarm = crypto_aes_encrypt_block_arm_u8(bufarm,
			    key_exp);
			vst1q_u8(cbuf, bufarm);
		} else
#endif
		crypto_aes_encrypt_block(plaintext_arr, cbuf, key_exp);

		/* Check result. */
		if (memcmp(cbuf, ciphertext_arr, 16)) {
			printf(" FAILED!\n");
			print_arr("Computed AES:\t", cbuf, 16);
			print_arr("Correct AES:\t", ciphertext_arr, 16);
			failures++;
		} else {
			printf(" PASSED!\n");
		}

		/* Clean up. */
		crypto_aes_key_free(key_exp);
	}

	/* Report overall success to exit code. */
	if (failures)
		return (1);
	else
		return (0);

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
leaq 0x57fc(%rip), %rbx      # 0x721c
cmpl $0x0, (%rbx)
je 0x1a3b
callq 0x1ec0
cmpl $0x1, %eax
je 0x1a4c
leaq 0x25d4(%rip), %rdi      # 0x400a
jmp 0x1b6a
leaq 0x57de(%rip), %r14      # 0x7220
cmpl $0x0, (%r14)
je 0x1b90
leaq 0x277d(%rip), %rdi      # 0x41d0
callq 0x1bef
leaq 0x5341(%rip), %r13      # 0x6da0
leaq 0x50(%rsp), %r15
leaq 0x40(%rsp), %r12
leaq 0x30(%rsp), %rbp
xorl %r14d, %r14d
xorl %ebx, %ebx
movq 0x10(%r14,%r13), %rax
movq %rax, 0x10(%rsp)
movups (%r14,%r13), %xmm0
movups %xmm0, (%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x1c4f
testl %eax, %eax
jne 0x1b63
movq 0x28(%rsp), %rsi
shlq $0x3, %rsi
movq 0x8(%r14,%r13), %rdx
leaq 0x2735(%rip), %rdi      # 0x41ed
xorl %eax, %eax
callq 0x1030
callq 0x1ec0
cmpl $0x1, %eax
jne 0x1adf
movaps 0x50(%rsp), %xmm0
movq 0x20(%rsp), %rdi
callq 0x2685
movaps %xmm0, 0x30(%rsp)
jmp 0x1aef
movq 0x20(%rsp), %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x2019
movdqa 0x30(%rsp), %xmm0
pcmpeqb 0x40(%rsp), %xmm0
pmovmskb %xmm0, %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0x1b35
leaq 0x27c5(%rip), %rdi      # 0x42d2
callq 0x1070
leaq 0x26f5(%rip), %rdi      # 0x420e
movq %rbp, %rsi
callq 0x1e4d
leaq 0x26f5(%rip), %rdi      # 0x421d
movq %r12, %rsi
callq 0x1e4d
incq %rbx
jmp 0x1b41
leaq 0x278d(%rip), %rdi      # 0x42c9
callq 0x1070
movq 0x20(%rsp), %rdi
callq 0x202b
addq $0x18, %r14
cmpq $0x18, %r14
je 0x1a73
xorl %eax, %eax
testq %rbx, %rbx
setne %al
jmp 0x1b81
leaq 0x24d4(%rip), %rdi      # 0x403e
xorl %eax, %eax
callq 0x33cb
callq 0x1190
movl $0x0, (%rax)
movl $0x1, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1e98
movl %eax, (%rbx)
movl $0x1, (%r14)
testl %eax, %eax
jne 0x1a25
jmp 0x1a4c