// File: /workspace/github_cpp_makefile_star2_O3/skyleaworlder[P]AES/src/KeyExpan.cpp
// Function: next_key(std::vector<std::bitset<8ul>, std::allocator<std::bitset<8ul>>>, unsigned long)
vector<byte> next_key(
    vector<byte> former_key,
    size_t turn
) {
    assert(former_key.size() == 16);
    vector<byte> ret;

    vector<byte> former_key_last_word_after_rot {
        former_key[13], former_key[14],
        former_key[15], former_key[12]
    };
    size_t cnt = 0;
    for (byte elem : former_key_last_word_after_rot) {
        size_t col_index = (elem & byte(0x0F)).to_ulong();
        size_t row_index = (elem & byte(0xF0)).to_ulong() >> 4;
        byte res { former_key[cnt] ^ s_box[row_index * 16 + col_index] ^ rcon[turn*4+cnt]};
        ret.push_back(res);
        ++cnt;
    }

    for (size_t standard = 4; standard < 16; standard += 4) {
        ret.push_back(former_key[standard] ^ ret[standard-4]);
        ret.push_back(former_key[standard+1] ^ ret[standard-3]);
        ret.push_back(former_key[standard+2] ^ ret[standard-2]);
        ret.push_back(former_key[standard+3] ^ ret[standard-1]);
    }
    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, -0x38(%rbp)
movq (%rsi), %rax
movq 0x8(%rsi), %rcx
subq %rax, %rcx
cmpq $0x80, %rcx
jne 0x2a15
movq %rsi, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x68(%rax), %rcx
leaq -0x70(%rbp), %rsi
movq %rcx, (%rsi)
movq 0x70(%rax), %rcx
movq %rcx, 0x8(%rsi)
movq 0x78(%rax), %rcx
movq %rcx, 0x10(%rsi)
movq 0x60(%rax), %rax
movq %rax, 0x18(%rsi)
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rcx
movl $0x4, %edx
callq 0x2ba2
movq -0x50(%rbp), %r13
movq -0x48(%rbp), %r12
cmpq %r12, %r13
je 0x295e
shlq $0x5, -0x38(%rbp)
xorl %r15d, %r15d
movzbl (%r13,%r15), %eax
movq (%r14), %rcx
leaq 0x581c(%rip), %rdx      # 0x8128
movq (%rdx), %rdx
movq (%rdx,%rax,8), %rax
xorq (%rcx,%r15), %rax
leaq 0x57f2(%rip), %rcx      # 0x8110
movq (%rcx), %rcx
addq -0x38(%rbp), %rcx
xorq (%r15,%rcx), %rax
movq %rax, -0x70(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2941
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x294d
movq %rbx, %rdi
leaq -0x70(%rbp), %rdx
callq 0x2fe2
leaq (%r15,%r13), %rax
addq $0x8, %rax
addq $0x8, %r15
cmpq %r12, %rax
jne 0x28fc
xorl %r12d, %r12d
leaq -0x70(%rbp), %r15
movq (%r14), %rax
movq (%rbx), %rcx
movq (%rcx,%r12,8), %rcx
xorq 0x20(%rax,%r12,8), %rcx
movq %rcx, -0x70(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x25b4
movq (%r14), %rax
movq (%rbx), %rcx
movq 0x8(%rcx,%r12,8), %rcx
xorq 0x28(%rax,%r12,8), %rcx
movq %rcx, -0x70(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x25b4
movq (%r14), %rax
movq (%rbx), %rcx
movq 0x10(%rcx,%r12,8), %rcx
xorq 0x30(%rax,%r12,8), %rcx
movq %rcx, -0x70(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x25b4
movq (%r14), %rax
movq (%rbx), %rcx
movq 0x18(%rcx,%r12,8), %rcx
xorq 0x38(%rax,%r12,8), %rcx
movq %rcx, -0x70(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x25b4
addq $0x4, %r12
cmpq $0xc, %r12
jb 0x2965
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x2a03
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x2130
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2678(%rip), %rdi      # 0x5094
leaq 0x2689(%rip), %rsi      # 0x50ac
leaq 0x2693(%rip), %rcx      # 0x50bd
movl $0x14, %edx
callq 0x20b0
movq %rax, %r14
jmp 0x2a59
jmp 0x2a41
jmp 0x2a41
jmp 0x2a41
jmp 0x2a41
movq %rax, %r14
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x2a59
movq -0x40(%rbp), %rsi
subq %rdi, %rsi
callq 0x2130
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x2a6d
movq 0x10(%rbx), %rsi
subq %rdi, %rsi
callq 0x2130
movq %r14, %rdi
callq 0x21b0
nop