// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/aezv4/aesni/encrypt.c
// Function: aez_setup
void aez_setup(unsigned char *key, unsigned keylen, aez_ctx_t *ctx) {
    block tmp;
    if (keylen==48) {
        ctx->I[0] = loadu(key);
        ctx->J[0] = loadu(key+16);
        ctx->L    = loadu(key+32);
    } else {
        blake2b(ctx, 48, 0, 0, key, keylen);    /* Puts IJL into ctx */
        ctx->J[0] = ctx->I[1];                  /* Rearrange.        */
        ctx->L    = ctx->I[2];
    }
    /* Fill ctx with J doublings */
    ctx->I[1] = bswap16(tmp = double_block(bswap16(ctx->I[0])));
    ctx->I[2] = bswap16(tmp = double_block(tmp));
    ctx->J[1] = bswap16(tmp = double_block(bswap16(ctx->J[0])));
    ctx->J[2] = bswap16(tmp = double_block(tmp));
    ctx->delta3_cache = zero;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe0, %rsp
movq %rdx, %rbx
movq %rdi, %r14
cmpl $0x30, %esi
jne 0x120e
vmovdqu (%r14), %xmm1
vmovdqa %xmm1, (%rbx)
vmovdqu 0x10(%r14), %xmm0
vmovdqa %xmm0, 0x30(%rbx)
vmovups 0x20(%r14), %xmm2
jmp 0x1356
xorl %eax, %eax
leaq 0x2ea9(%rip), %rcx      # 0x40c0
cmpq $0x40, %rax
je 0x122f
movq (%rax,%rcx), %rdx
movq %rdx, 0x80(%rsp,%rax)
addq $0x8, %rax
jmp 0x1217
xorl $0x1010030, 0x80(%rsp) # imm = 0x1010030
vpxor %xmm0, %xmm0, %xmm0
vmovdqu %xmm0, 0xc0(%rsp)
andq $0x0, 0xd0(%rsp)
movq $0x30, 0xd8(%rsp)
xorl %eax, %eax
cmpq $0x80, %rax
je 0x126f
movb $0x0, (%rsp,%rax)
incq %rax
jmp 0x125e
movl %esi, %r12d
xorl %r13d, %r13d
movq %rsp, %r15
movq 0xd0(%rsp), %rax
cmpq %r13, %r12
je 0x12cf
cmpq $0x80, %rax
jne 0x12b7
movq 0xc0(%rsp), %rax
subq $-0x80, %rax
movq %rax, 0xc0(%rsp)
jb 0x12ab
incq 0xc8(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x2f3a
xorl %eax, %eax
movb (%r14,%r13), %cl
leaq 0x1(%rax), %rdx
movq %rdx, 0xd0(%rsp)
movb %cl, (%rsp,%rax)
incq %r13
jmp 0x1278
addq %rax, 0xc0(%rsp)
jae 0x12fb
incq 0xc8(%rsp)
jmp 0x12fb
leaq 0x1(%rax), %rcx
movq %rcx, 0xd0(%rsp)
movb $0x0, (%rsp,%rax)
movq 0xd0(%rsp), %rax
cmpq $0x7f, %rax
jbe 0x12e3
movq %rsp, %r14
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x2f3a
xorl %eax, %eax
movq 0xd8(%r14), %rcx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x1343
movq %rdx, %rsi
andq $-0x8, %rsi
movl %eax, %edi
andb $0x38, %dil
shrxq %rdi, 0x80(%rsp,%rsi), %rsi
movb %sil, (%rbx,%rdx)
incq %rdx
addq $0x8, %rax
jmp 0x131a
vmovaps (%rbx), %xmm1
vmovaps 0x10(%rbx), %xmm0
vmovaps 0x20(%rbx), %xmm2
vmovaps %xmm0, 0x30(%rbx)
vmovaps %xmm2, 0x60(%rbx)
vmovdqa 0x2c9d(%rip), %xmm2     # 0x4000
vpshufb %xmm2, %xmm1, %xmm1
vpshufd $0x93, %xmm1, %xmm3     # xmm3 = xmm1[3,0,1,2]
vpsrad $0x1f, %xmm3, %xmm3
vpshufd $0x93, 0x2c95(%rip), %xmm4 # xmm4 = mem[3,0,1,2]
vpaddd %xmm1, %xmm1, %xmm1
vpternlogd $0x6c, %xmm4, %xmm1, %xmm3
vpshufb %xmm2, %xmm3, %xmm5
vmovdqa %xmm5, 0x10(%rbx)
vpshufd $0x93, %xmm1, %xmm1     # xmm1 = xmm1[3,0,1,2]
vpsrad $0x1f, %xmm1, %xmm1
vpaddd %xmm3, %xmm3, %xmm3
vpternlogd $0x78, %xmm4, %xmm1, %xmm3
vpshufb %xmm2, %xmm3, %xmm1
vmovdqa %xmm1, 0x20(%rbx)
vpshufb %xmm2, %xmm0, %xmm0
vpshufd $0x93, %xmm0, %xmm1     # xmm1 = xmm0[3,0,1,2]
vpsrad $0x1f, %xmm1, %xmm1
vpaddd %xmm0, %xmm0, %xmm0
vpternlogd $0x6c, %xmm4, %xmm0, %xmm1
vpshufb %xmm2, %xmm1, %xmm3
vmovdqa %xmm3, 0x40(%rbx)
vpshufd $0x93, %xmm0, %xmm0     # xmm0 = xmm0[3,0,1,2]
vpsrad $0x1f, %xmm0, %xmm0
vpaddd %xmm1, %xmm1, %xmm1
vpternlogd $0x78, %xmm4, %xmm0, %xmm1
vpshufb %xmm2, %xmm1, %xmm0
vmovdqa %xmm0, 0x50(%rbx)
vpxor %xmm0, %xmm0, %xmm0
vmovdqa %xmm0, 0x70(%rbx)
addq $0xe0, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq