// File: simap[P]ecctools/lib/SHA256.cpp
// Function: SHA256::processChunk()
void SHA256::processChunk()
{
    // Round constants for SHA-256.
    static uint32_t const k[64] PROGMEM = {
        0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
        0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
        0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
        0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
        0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
        0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
        0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
        0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
        0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
        0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
        0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
        0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
        0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
        0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
        0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
        0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
    };

    // Convert the first 16 words from big endian to host byte order.
    uint8_t index;
    for (index = 0; index < 16; ++index)
        state.w[index] = be32toh(state.w[index]);

    // Initialise working variables to the current hash value.
    uint32_t a = state.h[0];
    uint32_t b = state.h[1];
    uint32_t c = state.h[2];
    uint32_t d = state.h[3];
    uint32_t e = state.h[4];
    uint32_t f = state.h[5];
    uint32_t g = state.h[6];
    uint32_t h = state.h[7];

    // Perform the first 16 rounds of the compression function main loop.
    uint32_t temp1, temp2;
    for (index = 0; index < 16; ++index) {
        temp1 = h + pgm_read_dword(k + index) + state.w[index] +
                (rightRotate6(e) ^ rightRotate11(e) ^ rightRotate25(e)) +
                ((e & f) ^ ((~e) & g));
        temp2 = (rightRotate2(a) ^ rightRotate13(a) ^ rightRotate22(a)) +
                ((a & b) ^ (a & c) ^ (b & c));
        h = g;
        g = f;
        f = e;
        e = d + temp1;
        d = c;
        c = b;
        b = a;
        a = temp1 + temp2;
    }

    // Perform the 48 remaining rounds.  We expand the first 16 words to
    // 64 in-place in the "w" array.  This saves 192 bytes of memory
    // that would have otherwise need to be allocated to the "w" array.
    for (; index < 64; ++index) {
        // Expand the next word.
        temp1 = state.w[(index - 15) & 0x0F];
        temp2 = state.w[(index - 2) & 0x0F];
        temp1 = state.w[index & 0x0F] =
            state.w[(index - 16) & 0x0F] + state.w[(index - 7) & 0x0F] +
                (rightRotate7(temp1) ^ rightRotate18(temp1) ^ (temp1 >> 3)) +
                (rightRotate17(temp2) ^ rightRotate19(temp2) ^ (temp2 >> 10));

        // Perform the round.
        temp1 = h + pgm_read_dword(k + index) + temp1 +
                (rightRotate6(e) ^ rightRotate11(e) ^ rightRotate25(e)) +
                ((e & f) ^ ((~e) & g));
        temp2 = (rightRotate2(a) ^ rightRotate13(a) ^ rightRotate22(a)) +
                ((a & b) ^ (a & c) ^ (b & c));
        h = g;
        g = f;
        f = e;
        e = d + temp1;
        d = c;
        c = b;
        b = a;
        a = temp1 + temp2;
    }

    // Add the compressed chunk to the current hash value.
    state.h[0] += a;
    state.h[1] += b;
    state.h[2] += c;
    state.h[3] += d;
    state.h[4] += e;
    state.h[5] += f;
    state.h[6] += g;
    state.h[7] += h;

    // Attempt to clean up the stack.
    a = b = c = d = e = f = g = h = temp1 = temp2 = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x48, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movb $0x0, -0x9(%rbp)
movzbl -0x9(%rbp), %eax
cmpl $0x10, %eax
jge 0x68c4
movq -0xc8(%rbp), %rax
movzbl -0x9(%rbp), %ecx
movl 0x28(%rax,%rcx,4), %ecx
movl %ecx, -0x10(%rbp)
movl -0x10(%rbp), %ecx
shrl $0x18, %ecx
andl $0xff, %ecx
movl -0x10(%rbp), %edx
shrl $0x8, %edx
andl $0xff00, %edx           # imm = 0xFF00
orl %edx, %ecx
movl -0x10(%rbp), %edx
shll $0x8, %edx
andl $0xff0000, %edx         # imm = 0xFF0000
orl %edx, %ecx
movl -0x10(%rbp), %edx
shll $0x18, %edx
andl $0xff000000, %edx       # imm = 0xFF000000
orl %edx, %ecx
movl %ecx, -0x14(%rbp)
movl -0x14(%rbp), %edx
movzbl -0x9(%rbp), %ecx
movl %edx, 0x28(%rax,%rcx,4)
movb -0x9(%rbp), %al
addb $0x1, %al
movb %al, -0x9(%rbp)
jmp 0x685b
movq -0xc8(%rbp), %rax
movl 0x8(%rax), %ecx
movl %ecx, -0x18(%rbp)
movl 0xc(%rax), %ecx
movl %ecx, -0x1c(%rbp)
movl 0x10(%rax), %ecx
movl %ecx, -0x20(%rbp)
movl 0x14(%rax), %ecx
movl %ecx, -0x24(%rbp)
movl 0x18(%rax), %ecx
movl %ecx, -0x28(%rbp)
movl 0x1c(%rax), %ecx
movl %ecx, -0x2c(%rbp)
movl 0x20(%rax), %ecx
movl %ecx, -0x30(%rbp)
movl 0x24(%rax), %eax
movl %eax, -0x34(%rbp)
movb $0x0, -0x9(%rbp)
movzbl -0x9(%rbp), %eax
cmpl $0x10, %eax
jge 0x6a41
movq -0xc8(%rbp), %rcx
movl -0x34(%rbp), %eax
movzbl -0x9(%rbp), %edx
movslq %edx, %rsi
leaq 0x187c(%rip), %rdx      # 0x81a0
addl (%rdx,%rsi,4), %eax
movzbl -0x9(%rbp), %edx
addl 0x28(%rcx,%rdx,4), %eax
movl -0x28(%rbp), %ecx
movl %ecx, -0x40(%rbp)
movl -0x40(%rbp), %ecx
shrl $0x6, %ecx
movl -0x40(%rbp), %edx
shll $0x1a, %edx
orl %edx, %ecx
movl %ecx, -0x44(%rbp)
movl -0x44(%rbp), %ecx
movl -0x28(%rbp), %edx
movl %edx, -0x48(%rbp)
movl -0x48(%rbp), %edx
shrl $0xb, %edx
movl -0x48(%rbp), %esi
shll $0x15, %esi
orl %esi, %edx
movl %edx, -0x4c(%rbp)
xorl -0x4c(%rbp), %ecx
movl -0x28(%rbp), %edx
movl %edx, -0x50(%rbp)
movl -0x50(%rbp), %edx
shrl $0x19, %edx
movl -0x50(%rbp), %esi
shll $0x7, %esi
orl %esi, %edx
movl %edx, -0x54(%rbp)
xorl -0x54(%rbp), %ecx
addl %ecx, %eax
movl -0x28(%rbp), %ecx
andl -0x2c(%rbp), %ecx
movl -0x28(%rbp), %edx
xorl $-0x1, %edx
andl -0x30(%rbp), %edx
xorl %edx, %ecx
addl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
shrl $0x2, %eax
movl -0x58(%rbp), %ecx
shll $0x1e, %ecx
orl %ecx, %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl -0x18(%rbp), %ecx
movl %ecx, -0x60(%rbp)
movl -0x60(%rbp), %ecx
shrl $0xd, %ecx
movl -0x60(%rbp), %edx
shll $0x13, %edx
orl %edx, %ecx
movl %ecx, -0x64(%rbp)
xorl -0x64(%rbp), %eax
movl -0x18(%rbp), %ecx
movl %ecx, -0x68(%rbp)
movl -0x68(%rbp), %ecx
shrl $0x16, %ecx
movl -0x68(%rbp), %edx
shll $0xa, %edx
orl %edx, %ecx
movl %ecx, -0x6c(%rbp)
xorl -0x6c(%rbp), %eax
movl -0x18(%rbp), %ecx
andl -0x1c(%rbp), %ecx
movl -0x18(%rbp), %edx
andl -0x20(%rbp), %edx
xorl %edx, %ecx
movl -0x1c(%rbp), %edx
andl -0x20(%rbp), %edx
xorl %edx, %ecx
addl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x38(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x18(%rbp)
movb -0x9(%rbp), %al
addb $0x1, %al
movb %al, -0x9(%rbp)
jmp 0x68ff
jmp 0x6a43
movzbl -0x9(%rbp), %eax
cmpl $0x40, %eax
jge 0x6cc3
movq -0xc8(%rbp), %rcx
movzbl -0x9(%rbp), %eax
subl $0xf, %eax
andl $0xf, %eax
cltq
movl 0x28(%rcx,%rax,4), %eax
movl %eax, -0x38(%rbp)
movzbl -0x9(%rbp), %eax
subl $0x2, %eax
andl $0xf, %eax
cltq
movl 0x28(%rcx,%rax,4), %eax
movl %eax, -0x3c(%rbp)
movzbl -0x9(%rbp), %eax
subl $0x10, %eax
andl $0xf, %eax
cltq
movl 0x28(%rcx,%rax,4), %eax
movzbl -0x9(%rbp), %edx
subl $0x7, %edx
andl $0xf, %edx
movslq %edx, %rdx
addl 0x28(%rcx,%rdx,4), %eax
movl -0x38(%rbp), %edx
movl %edx, -0x70(%rbp)
movl -0x70(%rbp), %edx
shrl $0x7, %edx
movl -0x70(%rbp), %esi
shll $0x19, %esi
orl %esi, %edx
movl %edx, -0x74(%rbp)
movl -0x74(%rbp), %edx
movl -0x38(%rbp), %esi
movl %esi, -0x78(%rbp)
movl -0x78(%rbp), %esi
shrl $0x12, %esi
movl -0x78(%rbp), %edi
shll $0xe, %edi
orl %edi, %esi
movl %esi, -0x7c(%rbp)
xorl -0x7c(%rbp), %edx
movl -0x38(%rbp), %esi
shrl $0x3, %esi
xorl %esi, %edx
addl %edx, %eax
movl -0x3c(%rbp), %edx
movl %edx, -0x80(%rbp)
movl -0x80(%rbp), %edx
shrl $0x11, %edx
movl -0x80(%rbp), %esi
shll $0xf, %esi
orl %esi, %edx
movl %edx, -0x84(%rbp)
movl -0x84(%rbp), %edx
movl -0x3c(%rbp), %esi
movl %esi, -0x88(%rbp)
movl -0x88(%rbp), %esi
shrl $0x13, %esi
movl -0x88(%rbp), %edi
shll $0xd, %edi
orl %edi, %esi
movl %esi, -0x8c(%rbp)
xorl -0x8c(%rbp), %edx
movl -0x3c(%rbp), %esi
shrl $0xa, %esi
xorl %esi, %edx
addl %edx, %eax
movzbl -0x9(%rbp), %edx
andl $0xf, %edx
movslq %edx, %rdx
movl %eax, 0x28(%rcx,%rdx,4)
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
movzbl -0x9(%rbp), %ecx
movslq %ecx, %rdx
leaq 0x164f(%rip), %rcx      # 0x81a0
addl (%rcx,%rdx,4), %eax
addl -0x38(%rbp), %eax
movl -0x28(%rbp), %ecx
movl %ecx, -0x90(%rbp)
movl -0x90(%rbp), %ecx
shrl $0x6, %ecx
movl -0x90(%rbp), %edx
shll $0x1a, %edx
orl %edx, %ecx
movl %ecx, -0x94(%rbp)
movl -0x94(%rbp), %ecx
movl -0x28(%rbp), %edx
movl %edx, -0x98(%rbp)
movl -0x98(%rbp), %edx
shrl $0xb, %edx
movl -0x98(%rbp), %esi
shll $0x15, %esi
orl %esi, %edx
movl %edx, -0x9c(%rbp)
xorl -0x9c(%rbp), %ecx
movl -0x28(%rbp), %edx
movl %edx, -0xa0(%rbp)
movl -0xa0(%rbp), %edx
shrl $0x19, %edx
movl -0xa0(%rbp), %esi
shll $0x7, %esi
orl %esi, %edx
movl %edx, -0xa4(%rbp)
xorl -0xa4(%rbp), %ecx
addl %ecx, %eax
movl -0x28(%rbp), %ecx
andl -0x2c(%rbp), %ecx
movl -0x28(%rbp), %edx
xorl $-0x1, %edx
andl -0x30(%rbp), %edx
xorl %edx, %ecx
addl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
shrl $0x2, %eax
movl -0xa8(%rbp), %ecx
shll $0x1e, %ecx
orl %ecx, %eax
movl %eax, -0xac(%rbp)
movl -0xac(%rbp), %eax
movl -0x18(%rbp), %ecx
movl %ecx, -0xb0(%rbp)
movl -0xb0(%rbp), %ecx
shrl $0xd, %ecx
movl -0xb0(%rbp), %edx
shll $0x13, %edx
orl %edx, %ecx
movl %ecx, -0xb4(%rbp)
xorl -0xb4(%rbp), %eax
movl -0x18(%rbp), %ecx
movl %ecx, -0xb8(%rbp)
movl -0xb8(%rbp), %ecx
shrl $0x16, %ecx
movl -0xb8(%rbp), %edx
shll $0xa, %edx
orl %edx, %ecx
movl %ecx, -0xbc(%rbp)
xorl -0xbc(%rbp), %eax
movl -0x18(%rbp), %ecx
andl -0x1c(%rbp), %ecx
movl -0x18(%rbp), %edx
andl -0x20(%rbp), %edx
xorl %edx, %ecx
movl -0x1c(%rbp), %edx
andl -0x20(%rbp), %edx
xorl %edx, %ecx
addl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x24(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x38(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x18(%rbp)
movb -0x9(%rbp), %al
addb $0x1, %al
movb %al, -0x9(%rbp)
jmp 0x6a43
movq -0xc8(%rbp), %rax
movl -0x18(%rbp), %ecx
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movl -0x1c(%rbp), %ecx
addl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
movl -0x20(%rbp), %ecx
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movl -0x24(%rbp), %ecx
addl 0x14(%rax), %ecx
movl %ecx, 0x14(%rax)
movl -0x28(%rbp), %ecx
addl 0x18(%rax), %ecx
movl %ecx, 0x18(%rax)
movl -0x2c(%rbp), %ecx
addl 0x1c(%rax), %ecx
movl %ecx, 0x1c(%rax)
movl -0x30(%rbp), %ecx
addl 0x20(%rax), %ecx
movl %ecx, 0x20(%rax)
movl -0x34(%rbp), %ecx
addl 0x24(%rax), %ecx
movl %ecx, 0x24(%rax)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x18(%rbp)
addq $0x48, %rsp
popq %rbp
retq
nop