// File: lmclaramunt[P]AES-Crypto/Cipher.cpp
// Function: Cipher::encrypt(Sequence*, unsigned char**)
void Cipher::encrypt(Sequence* input, unsigned char** key) {
    State state(input);
    addRoudKey(0, key, state.getStateArray());
    
    for (int i=1; i < Nr; i++) {
        unsigned char** s2 = new unsigned char*[4];
        subBytes(state.getStateArray());
        shiftRows(state.getStateArray());
        mixColumns(state.getStateArray(), s2);
        state.setStateArray(s2);
        addRoudKey(i, key, state.getStateArray());
    }

    subBytes(state.getStateArray());
    shiftRows(state.getStateArray());
    addRoudKey(Nr, key, state.getStateArray());
    input->updateSequence(state.toSequence());

    /* State cleanup as it can leave traces in memory */
    state.~State();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x20(%rbp), %rdi
movq %rdi, -0x70(%rbp)
callq 0x7280
movq -0x70(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
callq 0x73b0
movq %rax, -0x60(%rbp)
jmp 0x95b7
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %rdx
movq -0x78(%rbp), %rdi
xorl %esi, %esi
callq 0x94e0
movl $0x1, -0x30(%rbp)
movq -0x78(%rbp), %rcx
movl -0x30(%rbp), %eax
cmpl 0x1c(%rcx), %eax
jge 0x96df
movl $0x20, %edi
callq 0x3030
movq %rax, -0x80(%rbp)
jmp 0x95f1
movq -0x80(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0x88(%rbp)
jmp 0x960b
movq -0x88(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x8f90
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0x90(%rbp)
jmp 0x962d
movq -0x90(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x91c0
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0x98(%rbp)
jmp 0x964f
movq -0x98(%rbp), %rsi
movq -0x78(%rbp), %rdi
movq -0x38(%rbp), %rdx
callq 0x9340
jmp 0x9665
movq -0x38(%rbp), %rsi
leaq -0x20(%rbp), %rdi
callq 0x7470
jmp 0x9674
movl -0x30(%rbp), %eax
movl %eax, -0xac(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0xa0(%rbp)
jmp 0x969a
movq -0xa0(%rbp), %rcx
movq -0xa8(%rbp), %rdx
movl -0xac(%rbp), %esi
movq -0x78(%rbp), %rdi
callq 0x94e0
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x95d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x7350
jmp 0x97df
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0xb8(%rbp)
jmp 0x96f1
movq -0xb8(%rbp), %rsi
movq -0x78(%rbp), %rdi
callq 0x8f90
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0xc0(%rbp)
jmp 0x9713
movq -0x78(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x91c0
movq -0x78(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0xd4(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x73b0
movq %rax, -0xc8(%rbp)
jmp 0x974d
movq -0xc8(%rbp), %rcx
movq -0xd0(%rbp), %rdx
movl -0xd4(%rbp), %esi
movq -0x78(%rbp), %rdi
callq 0x94e0
movq -0x10(%rbp), %rax
movq %rax, -0xf0(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x73d0
movl %edx, -0xe4(%rbp)
movq %rax, -0xe0(%rbp)
jmp 0x978d
movq -0xf0(%rbp), %rdi
movl -0xe4(%rbp), %eax
movq -0xe0(%rbp), %rcx
movq %rcx, -0x58(%rbp)
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rsi
movl -0x40(%rbp), %edx
callq 0x4b70
jmp 0x97c4
leaq -0x20(%rbp), %rdi
callq 0x7350
leaq -0x20(%rbp), %rdi
callq 0x7350
addq $0xf0, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x34d0
nopl (%rax,%rax)