// File: /workspace/github_c_makefile_star2_O3/mjosaarinen[P]brutus/crypto_aead/aes128n8t8clocv2/ref/aes_core.c
// Function: AES_set_decrypt_key
int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
			 AES_KEY *key) {

        u32 *rk;
	int i, j, status;
	u32 temp;

	/* first, start with an encryption schedule */
	status = AES_set_encrypt_key(userKey, bits, key);
	if (status < 0)
		return status;

	rk = (u32*) key->rd_key;

	/* invert the order of the round keys: */
	for (i = 0, j = 4*(key->rounds); i < j; i += 4, j -= 4) {
		temp = rk[i    ]; rk[i    ] = rk[j    ]; rk[j    ] = temp;
		temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
		temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
		temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
	}
	/* apply the inverse MixColumn transform to all round keys but the first and the last: */
	for (i = 1; i < (key->rounds); i++) {
		rk += 4;
		rk[0] =
			Td0[Te4[(rk[0] >> 24)       ] & 0xff] ^
			Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^
			Td2[Te4[(rk[0] >>  8) & 0xff] & 0xff] ^
			Td3[Te4[(rk[0]      ) & 0xff] & 0xff];
		rk[1] =
			Td0[Te4[(rk[1] >> 24)       ] & 0xff] ^
			Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^
			Td2[Te4[(rk[1] >>  8) & 0xff] & 0xff] ^
			Td3[Te4[(rk[1]      ) & 0xff] & 0xff];
		rk[2] =
			Td0[Te4[(rk[2] >> 24)       ] & 0xff] ^
			Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^
			Td2[Te4[(rk[2] >>  8) & 0xff] & 0xff] ^
			Td3[Te4[(rk[2]      ) & 0xff] & 0xff];
		rk[3] =
			Td0[Te4[(rk[3] >> 24)       ] & 0xff] ^
			Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^
			Td2[Te4[(rk[3] >>  8) & 0xff] & 0xff] ^
			Td3[Te4[(rk[3]      ) & 0xff] & 0xff];
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
callq 0x10a0
testl %eax, %eax
js 0x172b
movl 0xf0(%rbx), %eax
testl %eax, %eax
jle 0x1729
shll $0x2, %eax
cltq
addq $-0x4, %rax
xorl %ecx, %ecx
movl (%rbx,%rcx,4), %edx
movl 0x10(%rbx,%rax,4), %esi
movl %esi, (%rbx,%rcx,4)
movl %edx, 0x10(%rbx,%rax,4)
movl 0x4(%rbx,%rcx,4), %edx
movl 0x14(%rbx,%rax,4), %esi
movl %esi, 0x4(%rbx,%rcx,4)
movl %edx, 0x14(%rbx,%rax,4)
movl 0x8(%rbx,%rcx,4), %edx
movl 0x18(%rbx,%rax,4), %esi
movl %esi, 0x8(%rbx,%rcx,4)
movl %edx, 0x18(%rbx,%rax,4)
movl 0xc(%rbx,%rcx,4), %edx
movl 0x1c(%rbx,%rax,4), %esi
movl %esi, 0xc(%rbx,%rcx,4)
movl %edx, 0x1c(%rbx,%rax,4)
addq $0x4, %rcx
leaq -0x4(%rax), %rdx
cmpq %rax, %rcx
movq %rdx, %rax
jl 0x155c
xorl %eax, %eax
cmpl $0x2, 0xf0(%rbx)
jl 0x172b
leaq 0x1c(%rbx), %rcx
movl $0x1, %edx
leaq 0x2a37(%rip), %rsi      # 0x4000
leaq 0x2e60(%rip), %rdi      # 0x4430
movl $0x3fc, %r8d            # imm = 0x3FC
leaq 0x3253(%rip), %r9       # 0x4830
movl $0xff, %r10d
leaq 0x3646(%rip), %r11      # 0x4c30
leaq 0x3a3f(%rip), %r14      # 0x5030
movl -0xc(%rcx), %r12d
movl -0x8(%rcx), %r15d
movl %r12d, %r13d
shrl $0x18, %r13d
movzbl (%rsi,%r13,4), %r13d
movl %r12d, %ebp
shrl $0xe, %ebp
andl %r8d, %ebp
movzbl (%rbp,%rsi), %ebp
movl (%r9,%rbp,4), %ebp
xorl (%rdi,%r13,4), %ebp
movl %r12d, %r13d
shrl $0x8, %r13d
andl %r10d, %r13d
movzbl (%rsi,%r13,4), %r13d
xorl (%r11,%r13,4), %ebp
andl %r10d, %r12d
movzbl (%rsi,%r12,4), %r12d
xorl (%r14,%r12,4), %ebp
movl %ebp, -0xc(%rcx)
movl %r15d, %r12d
shrl $0x18, %r12d
movzbl (%rsi,%r12,4), %r12d
movl %r15d, %r13d
shrl $0xe, %r13d
andl %r8d, %r13d
movzbl (%r13,%rsi), %r13d
movl (%r9,%r13,4), %ebp
xorl (%rdi,%r12,4), %ebp
movl %r15d, %r12d
shrl $0x8, %r12d
andl %r10d, %r12d
movzbl (%rsi,%r12,4), %r12d
xorl (%r11,%r12,4), %ebp
andl %r10d, %r15d
movzbl (%rsi,%r15,4), %r15d
xorl (%r14,%r15,4), %ebp
movl %ebp, -0x8(%rcx)
movl -0x4(%rcx), %r15d
movl %r15d, %r12d
shrl $0x18, %r12d
movzbl (%rsi,%r12,4), %r12d
movl %r15d, %r13d
shrl $0xe, %r13d
andl %r8d, %r13d
movzbl (%r13,%rsi), %r13d
movl (%r9,%r13,4), %ebp
xorl (%rdi,%r12,4), %ebp
movl %r15d, %r12d
shrl $0x8, %r12d
andl %r10d, %r12d
movzbl (%rsi,%r12,4), %r12d
xorl (%r11,%r12,4), %ebp
andl %r10d, %r15d
movzbl (%rsi,%r15,4), %r15d
xorl (%r14,%r15,4), %ebp
movl %ebp, -0x4(%rcx)
movl (%rcx), %r15d
movl %r15d, %r12d
shrl $0x18, %r12d
movzbl (%rsi,%r12,4), %r12d
movl %r15d, %r13d
shrl $0xe, %r13d
andl %r8d, %r13d
movzbl (%r13,%rsi), %r13d
movl (%r9,%r13,4), %ebp
xorl (%rdi,%r12,4), %ebp
movl %r15d, %r12d
shrl $0x8, %r12d
andl %r10d, %r12d
movzbl (%rsi,%r12,4), %r12d
xorl (%r11,%r12,4), %ebp
andl %r10d, %r15d
movzbl (%rsi,%r15,4), %r15d
xorl (%r14,%r15,4), %ebp
movl %ebp, (%rcx)
incl %edx
addq $0x10, %rcx
cmpl 0xf0(%rbx), %edx
jl 0x15f1
jmp 0x172b
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq