// File: /workspace/github_c_makefile_star2_O1/Seclabs-htc[P]slip39/trezor-crypto/sha2.c
// Function: sha512_Transform
void sha512_Transform(const sha2_word64* state_in, const sha2_word64* data, sha2_word64* state_out) {
	sha2_word64	a, b, c, d, e, f, g, h, s0, s1;
	sha2_word64	T1, T2, W512[16];
	int		j;

	/* Initialize registers with the prev. intermediate value */
	a = state_in[0];
	b = state_in[1];
	c = state_in[2];
	d = state_in[3];
	e = state_in[4];
	f = state_in[5];
	g = state_in[6];
	h = state_in[7];

	j = 0;
	do {
		/* Apply the SHA-512 compression function to update a..h with copy */
		T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + (W512[j] = *data++);
		T2 = Sigma0_512(a) + Maj(a, b, c);
		h = g;
		g = f;
		f = e;
		e = d + T1;
		d = c;
		c = b;
		b = a;
		a = T1 + T2;

		j++;
	} while (j < 16);

	do {
		/* Part of the message block expansion: */
		s0 = W512[(j+1)&0x0f];
		s0 = sigma0_512(s0);
		s1 = W512[(j+14)&0x0f];
		s1 =  sigma1_512(s1);

		/* Apply the SHA-512 compression function to update a..h */
		T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] +
		     (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0);
		T2 = Sigma0_512(a) + Maj(a, b, c);
		h = g;
		g = f;
		f = e;
		e = d + T1;
		d = c;
		c = b;
		b = a;
		a = T1 + T2;

		j++;
	} while (j < 80);

	/* Compute the current intermediate hash value */
	state_out[0] = state_in[0] + a;
	state_out[1] = state_in[1] + b;
	state_out[2] = state_in[2] + c;
	state_out[3] = state_in[3] + d;
	state_out[4] = state_in[4] + e;
	state_out[5] = state_in[5] + f;
	state_out[6] = state_in[6] + g;
	state_out[7] = state_in[7] + h;

	/* Clean up */
	a = b = c = d = e = f = g = h = T1 = T2 = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, -0x40(%rbp)
movq %rsi, %r8
movq (%rdi), %r13
movq 0x8(%rdi), %rax
movq 0x10(%rdi), %r11
movq 0x18(%rdi), %r14
movq 0x20(%rdi), %r12
movq 0x28(%rdi), %r9
movq 0x30(%rdi), %rdx
movq %rdi, -0x38(%rbp)
movq 0x38(%rdi), %r15
leaq -0xd0(%rbp), %rdi
movl $0x10, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq %rdx, %rcx
xorl %edi, %edi
leaq 0x2ce9(%rip), %rdx      # 0xc190
movq %r13, -0x30(%rbp)
movq %r13, %rbx
movq %r15, %rsi
movq %rcx, %r15
movq %r9, %rcx
movq %r12, %r9
movq %r14, %r12
movq %r11, %r14
movq %rax, %r11
movq %r9, %rax
rolq $0x32, %rax
movq %r9, %r10
rolq $0x2e, %r10
xorq %rax, %r10
movq %r9, %r13
rolq $0x17, %r13
xorq %r10, %r13
movq %rcx, %rax
xorq %r15, %rax
andq %r9, %rax
xorq %r15, %rax
addq %rsi, %rax
addq %r13, %rax
movq %rbx, %rsi
rolq $0x24, %rsi
movq %rbx, %r10
rolq $0x1e, %r10
xorq %rsi, %r10
movq %rbx, %rsi
rolq $0x19, %rsi
xorq %r10, %rsi
movq %r14, %r10
xorq %r11, %r10
andq %rbx, %r10
movq %r14, %r13
andq %r11, %r13
xorq %r10, %r13
addq (%rdi,%rdx), %rax
addq %rsi, %r13
addq (%r8,%rdi), %rax
addq %rax, %r12
addq %rax, %r13
addq $0x8, %rdi
movq %rbx, %rax
cmpq $0x80, %rdi
jne 0x94ab
movl $0x1e, %edi
movq %r15, -0x48(%rbp)
movq %rcx, %rsi
movq %r9, %rcx
leal -0xd(%rdi), %eax
andl $0xf, %eax
movq -0xd0(%rbp,%rax,8), %r8
movq %r8, %rax
rorq %rax
movq %r12, %r9
movq %r8, %r10
rolq $0x38, %r10
xorq %rax, %r10
shrq $0x7, %r8
movl %edi, %eax
andl $0xf, %eax
movq -0xd0(%rbp,%rax,8), %rax
movq %rax, %r12
rolq $0x2d, %r12
xorq %r10, %r8
movq %rax, %r10
rolq $0x3, %r10
xorq %r12, %r10
movq %r9, %r12
rolq $0x32, %r12
shrq $0x6, %rax
movq %r9, %r15
rolq $0x2e, %r15
xorq %r10, %rax
movq %r9, %rdx
rolq $0x17, %rdx
xorq %r12, %r15
xorq %r15, %rdx
movq %rsi, %r15
movq %rcx, %r10
xorq %rsi, %r10
andq %r9, %r10
xorq %rsi, %r10
addq -0x48(%rbp), %r10
movq %r13, %rsi
movq %r14, %r12
movq %r11, %r14
movq %rbx, %r11
addq %rdx, %r10
leal -0x5(%rdi), %edx
andl $0xf, %edx
addq -0xd0(%rbp,%rdx,8), %r8
leal -0xe(%rdi), %edx
leaq 0x2b9d(%rip), %rbx      # 0xc190
addq -0x70(%rbx,%rdi,8), %r10
andl $0xf, %edx
addq %rax, %r8
addq -0xd0(%rbp,%rdx,8), %r8
movq %r8, -0xd0(%rbp,%rdx,8)
addq %r10, %r8
movq %r13, %rax
rolq $0x24, %rax
movq %r13, %rdx
rolq $0x1e, %rdx
xorq %rax, %rdx
movq %r13, %rax
rolq $0x19, %rax
xorq %rdx, %rax
movq %r14, %rdx
xorq %r11, %rdx
andq %r13, %rdx
movq %r14, %r13
andq %r11, %r13
xorq %rdx, %r13
addq %rax, %r13
addq %r8, %r12
addq %r8, %r13
incq %rdi
movq %rsi, %rbx
cmpq $0x5e, %rdi
jne 0x9547
addq -0x30(%rbp), %r13
movq -0x40(%rbp), %rax
movq %r13, (%rax)
movq %rcx, %rdx
movq -0x38(%rbp), %rcx
addq 0x8(%rcx), %rsi
movq %rsi, 0x8(%rax)
addq 0x10(%rcx), %r11
movq %r11, 0x10(%rax)
addq 0x18(%rcx), %r14
movq %r14, 0x18(%rax)
addq 0x20(%rcx), %r12
movq %r12, 0x20(%rax)
addq 0x28(%rcx), %r9
movq %r9, 0x28(%rax)
addq 0x30(%rcx), %rdx
movq %rdx, 0x30(%rax)
addq 0x38(%rcx), %r15
movq %r15, 0x38(%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq