// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/elmd1001v2/ref/aes_round_6.h
// Function: AES_set_decrypt_key_6
int AES_set_decrypt_key_6(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_6(userKey, bits, key);
	if (status < 0)
		return status;

	rk = 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[Te1[(rk[0] >> 24)       ] & 0xff] ^
			Td1[Te1[(rk[0] >> 16) & 0xff] & 0xff] ^
			Td2[Te1[(rk[0] >>  8) & 0xff] & 0xff] ^
			Td3[Te1[(rk[0]      ) & 0xff] & 0xff];
		rk[1] =
			Td0[Te1[(rk[1] >> 24)       ] & 0xff] ^
			Td1[Te1[(rk[1] >> 16) & 0xff] & 0xff] ^
			Td2[Te1[(rk[1] >>  8) & 0xff] & 0xff] ^
			Td3[Te1[(rk[1]      ) & 0xff] & 0xff];
		rk[2] =
			Td0[Te1[(rk[2] >> 24)       ] & 0xff] ^
			Td1[Te1[(rk[2] >> 16) & 0xff] & 0xff] ^
			Td2[Te1[(rk[2] >>  8) & 0xff] & 0xff] ^
			Td3[Te1[(rk[2]      ) & 0xff] & 0xff];
		rk[3] =
			Td0[Te1[(rk[3] >> 24)       ] & 0xff] ^
			Td1[Te1[(rk[3] >> 16) & 0xff] & 0xff] ^
			Td2[Te1[(rk[3] >>  8) & 0xff] & 0xff] ^
			Td3[Te1[(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 0x1060
testl %eax, %eax
js 0x1448
movl 0xf0(%rbx), %eax
shll $0x2, %eax
cltq
xorl %ecx, %ecx
cmpq %rax, %rcx
jge 0x12d7
movl (%rbx,%rcx,4), %edx
movl (%rbx,%rax,4), %esi
movl %esi, (%rbx,%rcx,4)
movl %edx, (%rbx,%rax,4)
movl 0x4(%rbx,%rcx,4), %edx
movl 0x4(%rbx,%rax,4), %esi
movl %esi, 0x4(%rbx,%rcx,4)
movl %edx, 0x4(%rbx,%rax,4)
movl 0x8(%rbx,%rcx,4), %edx
movl 0x8(%rbx,%rax,4), %esi
movl %esi, 0x8(%rbx,%rcx,4)
movl %edx, 0x8(%rbx,%rax,4)
movl 0xc(%rbx,%rcx,4), %edx
movl 0xc(%rbx,%rax,4), %esi
movl %esi, 0xc(%rbx,%rcx,4)
movl %edx, 0xc(%rbx,%rax,4)
addq $0x4, %rcx
addq $-0x4, %rax
jmp 0x128c
leaq 0x1c(%rbx), %rax
pushq $0x1
popq %rcx
leaq 0x291b(%rip), %rdx      # 0x3c00
leaq 0x2d44(%rip), %rsi      # 0x4030
movl $0x3fc, %edi            # imm = 0x3FC
leaq 0x3138(%rip), %r8       # 0x4430
movl $0xff, %r9d
leaq 0x352b(%rip), %r10      # 0x4830
leaq 0x3924(%rip), %r11      # 0x4c30
cmpl 0xf0(%rbx), %ecx
jge 0x1446
movl -0xc(%rax), %r15d
movl -0x8(%rax), %r14d
movl %r15d, %r12d
shrl $0x18, %r12d
movzbl (%rdx,%r12,4), %r12d
movl %r15d, %r13d
shrl $0xe, %r13d
andl %edi, %r13d
movzbl (%r13,%rdx), %r13d
movl (%r8,%r13,4), %ebp
xorl (%rsi,%r12,4), %ebp
movl %r15d, %r12d
shrl $0x8, %r12d
andl %r9d, %r12d
movzbl (%rdx,%r12,4), %r12d
xorl (%r10,%r12,4), %ebp
andl %r9d, %r15d
movzbl (%rdx,%r15,4), %r15d
xorl (%r11,%r15,4), %ebp
movl %ebp, -0xc(%rax)
movl %r14d, %r15d
shrl $0x18, %r15d
movzbl (%rdx,%r15,4), %r15d
movl %r14d, %r12d
shrl $0xe, %r12d
andl %edi, %r12d
movzbl (%r12,%rdx), %r12d
movl (%r8,%r12,4), %ebp
xorl (%rsi,%r15,4), %ebp
movl %r14d, %r15d
shrl $0x8, %r15d
andl %r9d, %r15d
movzbl (%rdx,%r15,4), %r15d
xorl (%r10,%r15,4), %ebp
andl %r9d, %r14d
movzbl (%rdx,%r14,4), %r14d
xorl (%r11,%r14,4), %ebp
movl %ebp, -0x8(%rax)
movl -0x4(%rax), %r14d
movl %r14d, %r15d
shrl $0x18, %r15d
movzbl (%rdx,%r15,4), %r15d
movl %r14d, %r12d
shrl $0xe, %r12d
andl %edi, %r12d
movzbl (%r12,%rdx), %r12d
movl (%r8,%r12,4), %ebp
xorl (%rsi,%r15,4), %ebp
movl %r14d, %r15d
shrl $0x8, %r15d
andl %r9d, %r15d
movzbl (%rdx,%r15,4), %r15d
xorl (%r10,%r15,4), %ebp
andl %r9d, %r14d
movzbl (%rdx,%r14,4), %r14d
xorl (%r11,%r14,4), %ebp
movl %ebp, -0x4(%rax)
movl (%rax), %r14d
movl %r14d, %r15d
shrl $0x18, %r15d
movzbl (%rdx,%r15,4), %r15d
movl %r14d, %r12d
shrl $0xe, %r12d
andl %edi, %r12d
movzbl (%r12,%rdx), %r12d
movl (%r8,%r12,4), %ebp
xorl (%rsi,%r15,4), %ebp
movl %r14d, %r15d
shrl $0x8, %r15d
andl %r9d, %r15d
movzbl (%rdx,%r15,4), %r15d
xorl (%r10,%r15,4), %ebp
andl %r9d, %r14d
movzbl (%rdx,%r14,4), %r14d
xorl (%r11,%r14,4), %ebp
movl %ebp, (%rax)
incl %ecx
addq $0x10, %rax
jmp 0x130c
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq