// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xc0, %rsp
movq $0x0, -0x88(%rbp)
movq $0x2, -0x90(%rbp)
callq 0x18b0
cmpl $0x0, %eax
je 0x1687
callq 0x1f10
cmpl $0x1, %eax
je 0x1685
jmp 0x1667
leaq 0x499c(%rip), %rdi      # 0x600a
movb $0x0, %al
callq 0x58b0
callq 0x1150
movl $0x0, (%rax)
jmp 0x185d
jmp 0x1687
leaq 0x4b70(%rip), %rdi      # 0x61fe
callq 0x1920
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x90(%rbp), %rax
jae 0x1841
leaq 0x76ed(%rip), %rax      # 0x8da0
imulq $0x18, -0x80(%rbp), %rcx
addq %rcx, %rax
leaq -0x50(%rbp), %rdx
leaq -0x60(%rbp), %rcx
leaq -0x38(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movq (%rax), %r8
movq %r8, (%rsp)
movq 0x8(%rax), %r8
movq %r8, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x1970
cmpl $0x0, %eax
je 0x170e
jmp 0x16f0
leaq 0x4947(%rip), %rdi      # 0x603e
movb $0x0, %al
callq 0x58b0
callq 0x1150
movl $0x0, (%rax)
jmp 0x185d
movq -0x78(%rbp), %rsi
shlq $0x3, %rsi
leaq 0x7683(%rip), %rax      # 0x8da0
imulq $0x18, -0x80(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
leaq 0x4aeb(%rip), %rdi      # 0x621b
movb $0x0, %al
callq 0x1030
callq 0x1f10
cmpl $0x1, %eax
jne 0x1796
leaq -0x50(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movdqu (%rax), %xmm0
movdqa %xmm0, -0xa0(%rbp)
movdqa -0xa0(%rbp), %xmm0
movq -0x38(%rbp), %rdi
callq 0x3bf0
movdqa %xmm0, -0xa0(%rbp)
leaq -0x70(%rbp), %rax
movdqa -0xa0(%rbp), %xmm0
movq %rax, -0x8(%rbp)
movdqa %xmm0, -0x20(%rbp)
movdqa -0x20(%rbp), %xmm0
movq -0x8(%rbp), %rax
movdqu %xmm0, (%rax)
jmp 0x17a7
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0x20a0
leaq -0x70(%rbp), %rax
leaq -0x60(%rbp), %rcx
movups (%rcx), %xmm1
movups (%rax), %xmm0
pcmpeqb %xmm1, %xmm0
pmovmskb %xmm0, %eax
subl $0xffff, %eax           # imm = 0xFFFF
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x1819
leaq 0x4a68(%rip), %rdi      # 0x623c
movb $0x0, %al
callq 0x1030
leaq -0x70(%rbp), %rsi
leaq 0x4a60(%rip), %rdi      # 0x6246
movl $0x10, %edx
callq 0x1cd0
leaq -0x60(%rbp), %rsi
leaq 0x4a5a(%rip), %rdi      # 0x6255
movl $0x10, %edx
callq 0x1cd0
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x1827
leaq 0x4a43(%rip), %rdi      # 0x6263
movb $0x0, %al
callq 0x1030
movq -0x38(%rbp), %rdi
callq 0x20f0
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x169b
cmpq $0x0, -0x88(%rbp)
je 0x1854
movl $0x1, -0x2c(%rbp)
jmp 0x1864
movl $0x0, -0x2c(%rbp)
jmp 0x1864
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq