// File: /workspace/github_c_makefile_star2_O1/mjosaarinen[P]brutus/crypto_aead/norx6444v2/ref/norx.c
// Function: norx_encrypt_data
void norx_encrypt_data(norx_state_t state, unsigned char *out, const unsigned char * in, size_t inlen)
{
    if (inlen > 0)
    {
        size_t i;
        norx_state_t lane[NORX_P];

        /* Initialize states + branch */
        for (i = 0; i < NORX_P; ++i) {
            memcpy(lane[i], state, sizeof lane[i]);
            norx_branch(lane[i], i);
        }

        /* Parallel payload processing */
        for (i = 0; inlen >= BYTES(NORX_R); ++i) {
            norx_encrypt_block(lane[i%NORX_P], out, in);
            #if defined(NORX_DEBUG)
            printf("Encrypt block (lane: %lu)\n", i%NORX_P);
            norx_debug(lane[i%NORX_P], in, BYTES(NORX_R), out, BYTES(NORX_R));
            #endif
            inlen -= BYTES(NORX_R);
            out   += BYTES(NORX_R);
            in    += BYTES(NORX_R);
        }
        norx_encrypt_lastblock(lane[i%NORX_P], out, in, inlen);
        #if defined(NORX_DEBUG)
        printf("Encrypt lastblock (lane: %lu)\n", i%NORX_P);
        norx_debug(lane[i%NORX_P], in, inlen, out, inlen);
        #endif

        /* Merge */
        memset(state, 0, sizeof(norx_state_t));
        for (i = 0; i < NORX_P; ++i) {
            norx_merge(state, lane[i]);
            burn(lane[i], 0, sizeof(norx_state_t));
        }

        #if defined(NORX_DEBUG)
        printf("Encryption finalised\n");
        norx_debug(state, NULL, 0, NULL, 0);
        #endif
    }
}

// Assembly:
testq %rcx, %rcx
je 0x156a
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x278, %rsp            # imm = 0x278
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
movq %rcx, (%rsp)
xorl %ebp, %ebp
movq %rbp, %rax
shlq $0x7, %rax
leaq (%rsp,%rax), %r13
addq $0x70, %r13
vmovups (%rbx), %ymm0
vmovups 0x20(%rbx), %ymm1
vmovups 0x40(%rbx), %ymm2
vmovups 0x60(%rbx), %ymm3
vmovups %ymm3, 0x60(%r13)
vmovups %ymm2, 0x40(%r13)
vmovups %ymm1, 0x20(%r13)
vmovups %ymm0, (%r13)
xorb $0x10, 0x78(%r13)
movl $0x4, %r14d
movq %r13, %rdi
vzeroupper
callq 0x1c28
decq %r14
jne 0x1388
xorq %rbp, 0x68(%r13)
incq %rbp
cmpq $0x4, %rbp
jne 0x1343
movq (%rsp), %r14
cmpq $0x60, %r14
jb 0x143d
leaq -0x60(%r14), %rdx
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
mulxq %rax, %rax, %rax
shrq $0x6, %rax
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
movq %r14, (%rsp)
movl %ebp, %eax
andl $0x3, %eax
shll $0x7, %eax
leaq (%rsp,%rax), %r13
addq $0x70, %r13
xorb $0x2, 0x78(%r13)
movl $0x4, %r14d
movq %r13, %rdi
callq 0x1c28
decq %r14
jne 0x13f0
xorl %eax, %eax
movq (%r13,%rax,8), %rcx
xorq (%r12,%rax,8), %rcx
movq %rcx, (%r13,%rax,8)
movq %rcx, (%r15,%rax,8)
incq %rax
cmpq $0xc, %rax
jne 0x13ff
movq (%rsp), %r14
addq $-0x60, %r14
addq $0x60, %r15
addq $0x60, %r12
leaq 0x1(%rbp), %rax
cmpq 0x8(%rsp), %rbp
movq %rax, %rbp
jne 0x13d1
andl $0x3, %eax
jmp 0x143f
xorl %eax, %eax
shll $0x7, %eax
leaq (%rsp,%rax), %r13
addq $0x70, %r13
vxorps %xmm0, %xmm0, %xmm0
leaq 0x10(%rsp), %rbp
vmovups %ymm0, 0x40(%rbp)
vmovups %ymm0, 0x20(%rbp)
vmovups %ymm0, (%rbp)
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rdx
vzeroupper
callq 0x10b0
movq %r14, %r12
movb $0x1, 0x10(%rsp,%r14)
orb $-0x80, 0x5f(%rbp)
xorb $0x2, 0x78(%r13)
movl $0x4, %r14d
movq %r13, %rdi
callq 0x1c28
decq %r14
jne 0x148b
xorl %eax, %eax
vmovups (%r13,%rax,8), %ymm0
vxorps 0x10(%rsp,%rax,8), %ymm0, %ymm0
vmovups %ymm0, (%r13,%rax,8)
vmovups %ymm0, 0x10(%rsp,%rax,8)
addq $0x4, %rax
cmpq $0xc, %rax
jne 0x149a
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
movq %r12, %rdx
vzeroupper
callq 0x10b0
vxorps %xmm0, %xmm0, %xmm0
vmovups %ymm0, 0x60(%rbx)
vmovups %ymm0, 0x40(%rbx)
vmovups %ymm0, 0x20(%rbx)
vmovups %ymm0, (%rbx)
leaq 0x70(%rsp), %r15
xorl %r12d, %r12d
movq %r12, %rax
shlq $0x7, %rax
leaq (%rsp,%rax), %r14
addq $0x70, %r14
xorb $0x20, 0x78(%r14)
movl $0x4, %r13d
movq %r14, %rdi
vzeroupper
callq 0x1c28
decq %r13
jne 0x150a
xorl %eax, %eax
vmovups (%rbx,%rax,8), %ymm0
vxorps (%r15,%rax,8), %ymm0, %ymm0
vmovups %ymm0, (%rbx,%rax,8)
addq $0x4, %rax
cmpq $0x10, %rax
jne 0x151c
movq 0x38cb(%rip), %rax      # 0x4e08
movl $0x80, %edx
movq %r14, %rdi
xorl %esi, %esi
vzeroupper
callq *%rax
incq %r12
subq $-0x80, %r15
cmpq $0x4, %r12
jne 0x14f0
addq $0x278, %rsp            # imm = 0x278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq