// File: 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
subq $0x180, %rsp            # imm = 0x180
movq %rsi, -0x128(%rbp)
movq %rdi, %rax
movq -0x128(%rbp), %rdi
movq %rax, -0x120(%rbp)
movq %rax, %rcx
movq %rcx, -0x118(%rbp)
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
callq 0x2770
cmpq $0x10, %rax
jne 0x36e6
jmp 0x3705
leaq 0x59a7(%rip), %rdi      # 0x9094
leaq 0x59b8(%rip), %rsi      # 0x90ac
movl $0x14, %edx
leaq 0x59bd(%rip), %rcx      # 0x90bd
callq 0x20e0
movq -0x120(%rbp), %rdi
movb $0x0, -0x19(%rbp)
callq 0x2790
movq -0x128(%rbp), %rdi
movl $0xd, %esi
callq 0x2820
movq -0x128(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movl $0xe, %esi
callq 0x2820
movq -0x128(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movl $0xf, %esi
callq 0x2820
movq -0x128(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movl $0xc, %esi
callq 0x2820
movq (%rax), %rax
movq %rax, -0x50(%rbp)
leaq -0x68(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x4, -0x40(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x28f0
movq -0x130(%rbp), %rcx
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x3e20
jmp 0x37af
leaq -0x69(%rbp), %rdi
callq 0x2ae0
movq $0x0, -0x88(%rbp)
leaq -0x38(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
callq 0x2f40
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
callq 0x2d90
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3ea0
testb $0x1, %al
jne 0x3810
jmp 0x39c2
leaq -0x98(%rbp), %rdi
callq 0x3400
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x140(%rbp)
movl $0xf, %esi
callq 0x3f20
movq -0x140(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x3ee0
movq %rax, -0xb8(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x3f70
movq %rax, -0x138(%rbp)
jmp 0x386d
movq -0x138(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0xd8(%rbp), %rdi
movq %rdi, -0x150(%rbp)
movl $0xf0, %esi
callq 0x3f20
movq -0x150(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x3ee0
movq %rax, -0xd0(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3f70
movq %rax, -0x148(%rbp)
jmp 0x38c2
movq -0x128(%rbp), %rdi
movq -0x148(%rbp), %rax
shrq $0x4, %rax
movq %rax, -0xc8(%rbp)
movq -0x88(%rbp), %rsi
callq 0x2820
movq %rax, -0x158(%rbp)
movq -0xc8(%rbp), %rsi
shlq $0x4, %rsi
movq -0xb0(%rbp), %rax
addq %rax, %rsi
leaq 0xa8ae(%rip), %rdi      # 0xe1b8
callq 0x3f90
movq -0x158(%rbp), %rdi
movq %rax, %rsi
callq 0x27e0
movq %rax, -0xe8(%rbp)
movq -0x18(%rbp), %rcx
movq -0x88(%rbp), %rax
leaq (%rax,%rcx,4), %rsi
leaq 0xa865(%rip), %rdi      # 0xe1a0
callq 0x3f90
movq %rax, %rsi
leaq -0xe8(%rbp), %rdi
callq 0x27e0
movq -0x120(%rbp), %rdi
movq %rax, -0xe0(%rbp)
leaq -0xe0(%rbp), %rsi
callq 0x3fb0
jmp 0x396b
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x4020
jmp 0x37f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x69(%rbp), %rdi
callq 0x2ae0
jmp 0x3b9d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2840
jmp 0x3b9d
movq $0x4, -0xf0(%rbp)
cmpq $0x10, -0xf0(%rbp)
jae 0x3b6e
movq -0x128(%rbp), %rdi
movq -0xf0(%rbp), %rsi
callq 0x2820
movq -0x120(%rbp), %rdi
movq %rax, -0x160(%rbp)
movq -0xf0(%rbp), %rsi
addq $-0x4, %rsi
callq 0x2820
movq -0x160(%rbp), %rdi
movq %rax, %rsi
callq 0x27e0
movq -0x120(%rbp), %rdi
movq %rax, -0xf8(%rbp)
leaq -0xf8(%rbp), %rsi
callq 0x27b0
jmp 0x3a37
movq -0x128(%rbp), %rdi
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x2820
movq -0x120(%rbp), %rdi
movq %rax, -0x168(%rbp)
movq -0xf0(%rbp), %rsi
addq $-0x3, %rsi
callq 0x2820
movq -0x168(%rbp), %rdi
movq %rax, %rsi
callq 0x27e0
movq -0x120(%rbp), %rdi
movq %rax, -0x100(%rbp)
leaq -0x100(%rbp), %rsi
callq 0x27b0
jmp 0x3a96
movq -0x128(%rbp), %rdi
movq -0xf0(%rbp), %rsi
addq $0x2, %rsi
callq 0x2820
movq -0x120(%rbp), %rdi
movq %rax, -0x170(%rbp)
movq -0xf0(%rbp), %rsi
addq $-0x2, %rsi
callq 0x2820
movq -0x170(%rbp), %rdi
movq %rax, %rsi
callq 0x27e0
movq -0x120(%rbp), %rdi
movq %rax, -0x108(%rbp)
leaq -0x108(%rbp), %rsi
callq 0x27b0
jmp 0x3af6
movq -0x128(%rbp), %rdi
movq -0xf0(%rbp), %rsi
addq $0x3, %rsi
callq 0x2820
movq -0x120(%rbp), %rdi
movq %rax, -0x178(%rbp)
movq -0xf0(%rbp), %rsi
decq %rsi
callq 0x2820
movq -0x178(%rbp), %rdi
movq %rax, %rsi
callq 0x27e0
movq -0x120(%rbp), %rdi
movq %rax, -0x110(%rbp)
leaq -0x110(%rbp), %rsi
callq 0x27b0
jmp 0x3b55
jmp 0x3b57
movq -0xf0(%rbp), %rax
addq $0x4, %rax
movq %rax, -0xf0(%rbp)
jmp 0x39cd
movb $0x1, -0x19(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2840
testb $0x1, -0x19(%rbp)
jne 0x3b8d
movq -0x120(%rbp), %rdi
callq 0x2840
movq -0x118(%rbp), %rax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
movq -0x120(%rbp), %rdi
callq 0x2840
movq -0x78(%rbp), %rdi
callq 0x22b0
nopw %cs:(%rax,%rax)
nopl (%rax)