// File: /workspace/github_c_makefile_star2_O3/bloomsource[P]dns_update/aes.c
// Function: aes_setkey_dec
int aes_setkey_dec( aes_context *ctx, const unsigned char *key, int keysize )
{
    int i, j;
    aes_context cty;
    unsigned long *RK;
    unsigned long *SK;
    int ret;

    switch( keysize )
    {
        case 128: ctx->nr = 10; break;
        case 192: ctx->nr = 12; break;
        case 256: ctx->nr = 14; break;
        default : return( ERR_AES_INVALID_KEY_LENGTH );
    }


    ctx->rk = RK = ctx->buf;

    ret = aes_setkey_enc( &cty, key, keysize );
    if( ret != 0 )
        return( ret );

    SK = cty.rk + cty.nr * 4;

    *RK++ = *SK++;
    *RK++ = *SK++;
    *RK++ = *SK++;
    *RK++ = *SK++;

    for( i = ctx->nr - 1, SK -= 8; i > 0; i--, SK -= 8 )
    {
        for( j = 0; j < 4; j++, SK++ )
        {
            *RK++ = RT0[ FSb[ ( *SK       ) & 0xFF ] ] ^
                    RT1[ FSb[ ( *SK >>  8 ) & 0xFF ] ] ^
                    RT2[ FSb[ ( *SK >> 16 ) & 0xFF ] ] ^
                    RT3[ FSb[ ( *SK >> 24 ) & 0xFF ] ];
        }
    }

    *RK++ = *SK++;
    *RK++ = *SK++;
    *RK++ = *SK++;
    *RK++ = *SK++;

    memset( &cty, 0, sizeof( aes_context ) );

    return( 0 );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %rdi, %rbx
cmpl $0x80, %edx
je 0x6a94
cmpl $0x100, %edx            # imm = 0x100
je 0x6a8d
movl $0xfffff800, %eax       # imm = 0xFFFFF800
cmpl $0xc0, %edx
jne 0x6bc6
movl $0xc, %eax
jmp 0x6a99
movl $0xe, %eax
jmp 0x6a99
movl $0xa, %eax
movl %eax, (%rbx)
leaq 0x10(%rbx), %rax
movq %rax, 0x8(%rbx)
leaq 0x8(%rsp), %rdi
callq 0x6760
testl %eax, %eax
jne 0x6bc6
movq 0x10(%rsp), %rax
movslq 0x8(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
addq $-0x20, %rax
movq 0x20(%rax), %rcx
movq %rcx, 0x10(%rbx)
movq 0x28(%rax), %rcx
movq %rcx, 0x18(%rbx)
movq 0x30(%rax), %rcx
movq %rcx, 0x20(%rbx)
movq 0x38(%rax), %rcx
leaq 0x30(%rbx), %r14
movq %rcx, 0x28(%rbx)
movl (%rbx), %ecx
cmpl $0x2, %ecx
jl 0x6ba6
leaq 0x1ab0(%rip), %rdx      # 0x85b0
leaq 0x1ba9(%rip), %rsi      # 0x86b0
movl $0xff, %edi
leaq 0x239d(%rip), %r8       # 0x8eb0
leaq 0x2b96(%rip), %r9       # 0x96b0
leaq 0x338f(%rip), %r11      # 0x9eb0
movq %r14, %r10
xorl %r14d, %r14d
xorl %ebx, %ebx
movq (%rax,%r14,8), %r15
movzbl %r15b, %r12d
movzbl (%r12,%rdx), %r12d
movl %r15d, %r13d
shrl $0x8, %r13d
andl %edi, %r13d
movzbl (%r13,%rdx), %r13d
movq (%r8,%r13,8), %r13
xorq (%rsi,%r12,8), %r13
movl %r15d, %r12d
shrl $0x10, %r12d
andl %edi, %r12d
movzbl (%r12,%rdx), %r12d
xorq (%r9,%r12,8), %r13
shrl $0x18, %r15d
movzbl (%r15,%rdx), %r15d
xorq (%r11,%r15,8), %r13
movq %r13, (%r10,%r14,8)
addq $-0x8, %rbx
incq %r14
cmpl $0x4, %r14d
jne 0x6b29
leal -0x1(%rcx), %ebp
movq %rax, %r15
subq %rbx, %r15
leaq -0x40(%r15), %rax
movq %r10, %r14
subq %rbx, %r14
cmpl $0x2, %ecx
movl %ebp, %ecx
jg 0x6b21
addq $-0x40, %r15
subq %rbx, %r10
movq %r10, %r14
movq %r15, %rax
movq (%rax), %rcx
movq %rcx, (%r14)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%r14)
movq 0x18(%rax), %rax
movq %rax, 0x18(%r14)
xorl %eax, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq