// File: /workspace/github_c_makefile_star2_O2/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
movabsq $0x38, %rdx
cmpq $0x10, %rax
je 0x1368
movq %rsi, %r8
movq %rdx, %rcx
xorl %r9d, %r9d
cmpq $-0x8, %rcx
je 0x135a
movzbl (%r8), %r10d
shlq %cl, %r10
orq %r10, %r9
addq $-0x8, %rcx
incq %r8
jmp 0x1341
movq %r9, -0x40(%rsp,%rax,8)
incq %rax
addq $0x8, %rsi
jmp 0x1332
movabsq $0x10, %rax
cmpq $0x50, %rax
je 0x13ce
movq -0xb8(%rsp,%rax,8), %rcx
movq %rcx, %rdx
rorq %rdx
movq %rcx, %rsi
rolq $0x38, %rsi
movq -0x50(%rsp,%rax,8), %r8
xorq %rdx, %rsi
shrq $0x7, %rcx
xorq %rsi, %rcx
movq %r8, %rdx
rolq $0x2d, %rdx
movq %r8, %rsi
rolq $0x3, %rsi
xorq %rdx, %rsi
shrq $0x6, %r8
addq -0xc0(%rsp,%rax,8), %rcx
addq -0x78(%rsp,%rax,8), %rcx
xorq %rsi, %r8
addq %r8, %rcx
movq %rcx, -0x40(%rsp,%rax,8)
incq %rax
jmp 0x1372
movq (%rdi), %r9
movq 0x8(%rdi), %rsi
movq 0x10(%rdi), %rbx
movq 0x18(%rdi), %r8
movq 0x20(%rdi), %rcx
movq 0x28(%rdi), %r15
movq 0x30(%rdi), %r14
movq 0x38(%rdi), %r11
xorl %ebp, %ebp
leaq 0xc3a(%rip), %rax       # 0x2030
movq %rbx, -0x70(%rsp)
movq %r8, -0x68(%rsp)
movq %rcx, -0x60(%rsp)
movq %r15, -0x58(%rsp)
movq %r14, -0x50(%rsp)
movq %r11, -0x48(%rsp)
movq %rsi, -0x78(%rsp)
movq %r9, -0x80(%rsp)
movq %r14, %r13
movq %r15, %r14
movq %rcx, %r15
movq %rbx, %r12
cmpq $0x280, %rbp            # imm = 0x280
je 0x14b9
movq %r15, %rcx
rolq $0x32, %rcx
movq %r15, %rdx
rolq $0x2e, %rdx
movq %r15, %r10
rolq $0x17, %r10
xorq %rcx, %rdx
xorq %rdx, %r10
movq %r14, %rcx
xorq %r13, %rcx
andq %r15, %rcx
xorq %r13, %rcx
addq %rcx, %r11
addq %r10, %r11
addq (%rbp,%rax), %r11
addq -0x40(%rsp,%rbp), %r11
movq %r9, %r10
movq %r9, %rcx
movq %rsi, %rdx
movq %rsi, %rbx
xorq %r12, %rsi
andq %r9, %rsi
andq %r12, %rdx
xorq %rsi, %rdx
movq %r9, %rsi
rolq $0x24, %r9
rolq $0x1e, %r10
xorq %r9, %r10
rolq $0x19, %rcx
xorq %r10, %rcx
addq %rcx, %rdx
movq %r8, %rcx
addq %r11, %rcx
addq %r11, %rdx
addq $0x8, %rbp
movq %r12, %r8
movq %r13, %r11
movq %rdx, %r9
jmp 0x141e
addq -0x80(%rsp), %r9
movq %r9, (%rdi)
addq -0x78(%rsp), %rsi
movq %rsi, 0x8(%rdi)
addq -0x70(%rsp), %r12
movq %r12, 0x10(%rdi)
addq -0x68(%rsp), %r8
movq %r8, 0x18(%rdi)
addq -0x60(%rsp), %r15
movq %r15, 0x20(%rdi)
addq -0x58(%rsp), %r14
movq %r14, 0x28(%rdi)
addq -0x50(%rsp), %r13
movq %r13, 0x30(%rdi)
addq -0x48(%rsp), %r11
movq %r11, 0x38(%rdi)
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq