// File: /workspace/github_cpp_makefile_star2_O2/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 0x2924
movq %rsi, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movq 0x68(%rax), %rcx
leaq -0x58(%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 -0x70(%rbp), %rdi
pushq $0x4
popq %rdx
leaq -0x29(%rbp), %rcx
callq 0x2a20
movq -0x70(%rbp), %r13
movq -0x68(%rbp), %r12
shlq $0x5, -0x38(%rbp)
xorl %r15d, %r15d
leaq (%r15,%r13), %rax
cmpq %r12, %rax
je 0x2871
movzbl (%rax), %eax
movq (%r14), %rcx
leaq 0x48fa(%rip), %rdx      # 0x7138
movq (%rdx), %rdx
movq (%rdx,%rax,8), %rax
xorq (%rcx,%r15), %rax
leaq 0x48d0(%rip), %rcx      # 0x7120
movq (%rcx), %rcx
addq -0x38(%rbp), %rcx
xorq (%r15,%rcx), %rax
movq %rax, -0x58(%rbp)
movq %rbx, %rdi
leaq -0x58(%rbp), %rsi
callq 0x2a56
addq $0x8, %r15
jmp 0x2828
xorl %r13d, %r13d
leaq -0x58(%rbp), %r15
leaq 0x4(%r13), %r12
cmpq $0x10, %r12
jae 0x2909
movq (%r14), %rax
movq (%rbx), %rcx
movq (%rcx,%r13,8), %rcx
xorq 0x20(%rax,%r13,8), %rcx
movq %rcx, -0x58(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x252c
movq (%r14), %rax
movq (%rbx), %rcx
movq 0x8(%rcx,%r13,8), %rcx
xorq 0x28(%rax,%r13,8), %rcx
movq %rcx, -0x58(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x252c
movq (%r14), %rax
movq (%rbx), %rcx
movq 0x10(%rcx,%r13,8), %rcx
xorq 0x30(%rax,%r13,8), %rcx
movq %rcx, -0x58(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x252c
movq (%r14), %rax
movq (%rbx), %rcx
movq 0x18(%rcx,%r13,8), %rcx
xorq 0x38(%rax,%r13,8), %rcx
movq %rcx, -0x58(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x252c
movq %r12, %r13
jmp 0x2878
leaq -0x70(%rbp), %rdi
callq 0x24ee
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1769(%rip), %rdi      # 0x4094
leaq 0x177a(%rip), %rsi      # 0x40ac
leaq 0x1784(%rip), %rcx      # 0x40bd
pushq $0x14
popq %rdx
callq 0x20d0
movq %rax, %r14
jmp 0x295a
jmp 0x294e
jmp 0x294e
jmp 0x294e
jmp 0x294e
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0x24ee
movq %rbx, %rdi
callq 0x24ee
movq %r14, %rdi
callq 0x21e0