// File: /workspace/github_c_makefile_star2_O1/ls4154[P]hash-c/sha512.c
// Function: sha512_iterate
static void _sha512_iterate(struct sha512_ctx *ctx, byte_t *chunk)
{
	word_t w[80];

	for (int i = 0; i < 16; ++i) {
		w[i] = 0;
		for (int j = 0; j < 8; ++j)
			w[i] |= (word_t)*(chunk + 8 * i + j) << 8 * (7 - j);
	}

	for (int i = 16; i < 80; ++i) {
		word_t s0 = ROR(w[i - 15], 1) ^ ROR(w[i - 15], 8) ^ SHR(w[i - 15], 7);
		word_t s1 = ROR(w[i - 2], 19) ^ ROR(w[i - 2], 61) ^ SHR(w[i - 2], 6);
		w[i] = w[i - 16] + s0 + w[i - 7] + s1;
	}

	word_t a = ctx->h[0];
	word_t b = ctx->h[1];
	word_t c = ctx->h[2];
	word_t d = ctx->h[3];
	word_t e = ctx->h[4];
	word_t f = ctx->h[5];
	word_t g = ctx->h[6];
	word_t h = ctx->h[7];

	for (int i = 0; i < 80; ++i) {
		word_t s1 = ROR(e, 14) ^ ROR(e, 18) ^ ROR(e, 41);
		word_t ch = (e & f) ^ ((~e) & g);
		word_t tmp1 = h + s1 + ch + k[i] + w[i];
		word_t s0 = ROR(a, 28) ^ ROR(a, 34) ^ ROR(a, 39);
		word_t maj = (a & b) ^ (a & c) ^ (b & c);
		word_t tmp2 = s0 + maj;

		h = g;
		g = f;
		f = e;
		e = d + tmp1;
		d = c;
		c = b;
		b = a;
		a = tmp1 + tmp2;
	}

	ctx->h[0] += a;
	ctx->h[1] += b;
	ctx->h[2] += c;
	ctx->h[3] += d;
	ctx->h[4] += e;
	ctx->h[5] += f;
	ctx->h[6] += g;
	ctx->h[7] += h;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
xorl %eax, %eax
movq $0x0, -0x40(%rsp,%rax,8)
movl $0x38, %ecx
movq %rsi, %r8
xorl %edx, %edx
movzbl (%r8), %r9d
shlq %cl, %r9
orq %r9, %rdx
incq %r8
addq $-0x8, %rcx
cmpq $-0x8, %rcx
jne 0x136a
movq %rdx, -0x40(%rsp,%rax,8)
incq %rax
addq $0x8, %rsi
cmpq $0x10, %rax
jne 0x1357
movl $0x10, %eax
movq -0xb8(%rsp,%rax,8), %rcx
movq %rcx, %rdx
rorq %rdx
movq -0x50(%rsp,%rax,8), %rsi
movq %rcx, %r8
rolq $0x38, %r8
xorq %rdx, %r8
movq %rsi, %rdx
rolq $0x2d, %rdx
shrq $0x7, %rcx
movq %rsi, %r9
rolq $0x3, %r9
xorq %r8, %rcx
xorq %rdx, %r9
shrq $0x6, %rsi
xorq %r9, %rsi
addq -0xc0(%rsp,%rax,8), %rcx
addq -0x78(%rsp,%rax,8), %rcx
addq %rsi, %rcx
movq %rcx, -0x40(%rsp,%rax,8)
incq %rax
cmpq $0x50, %rax
jne 0x1398
movq (%rdi), %r11
movq 0x8(%rdi), %r13
movq 0x10(%rdi), %rcx
movq 0x18(%rdi), %r9
movq 0x20(%rdi), %r8
movq 0x28(%rdi), %r14
movq 0x30(%rdi), %rbx
movq 0x38(%rdi), %r12
xorl %r15d, %r15d
leaq 0xc15(%rip), %rbp       # 0x2030
movq %r11, -0x80(%rsp)
movq %r13, -0x78(%rsp)
movq %r12, -0x48(%rsp)
movq %rbx, -0x50(%rsp)
movq %r14, -0x58(%rsp)
movq %r8, -0x60(%rsp)
movq %r9, -0x68(%rsp)
movq %rcx, -0x70(%rsp)
movq %rcx, %rdx
movq %r8, %rax
movq %r14, %r10
rolq $0x32, %r8
movq %rbx, %rsi
movq %rax, %rbx
rolq $0x2e, %rbx
movq %r13, %rcx
movq %rax, %r14
rolq $0x17, %r14
xorq %r8, %rbx
xorq %rbx, %r14
movq %r10, %rbx
xorq %rsi, %rbx
andq %rax, %rbx
xorq %rsi, %rbx
addq %r12, %rbx
addq %r14, %rbx
addq (%r15,%rbp), %rbx
addq -0x40(%rsp,%r15), %rbx
movq %r11, %r13
movq %r11, %r8
rolq $0x24, %r8
rolq $0x1e, %r11
xorq %r8, %r11
movq %r13, %r8
rolq $0x19, %r8
xorq %r11, %r8
movq %rcx, %r14
xorq %rdx, %r14
andq %r13, %r14
movq %rcx, %r11
andq %rdx, %r11
xorq %r14, %r11
addq %r8, %r11
movq %r9, %r8
addq %rbx, %r8
addq %rbx, %r11
addq $0x8, %r15
movq %rsi, %r12
movq %r10, %rbx
movq %rax, %r14
movq %rdx, %r9
cmpq $0x280, %r15            # imm = 0x280
jne 0x1443
addq -0x80(%rsp), %r11
movq %r11, (%rdi)
addq -0x78(%rsp), %r13
movq %r13, 0x8(%rdi)
addq -0x70(%rsp), %rcx
movq %rcx, 0x10(%rdi)
addq -0x68(%rsp), %rdx
movq %rdx, 0x18(%rdi)
addq -0x60(%rsp), %r8
movq %r8, 0x20(%rdi)
addq -0x58(%rsp), %rax
movq %rax, 0x28(%rdi)
addq -0x50(%rsp), %r10
movq %r10, 0x30(%rdi)
addq -0x48(%rsp), %rsi
movq %rsi, 0x38(%rdi)
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq