// File: /workspace/github_c_makefile_star2_O1/Seclabs-htc[P]slip39/trezor-crypto/sha2.c
// Function: sha256_Transform
void sha256_Transform(const sha2_word32* state_in, const sha2_word32* data, sha2_word32* state_out) {
	sha2_word32	a, b, c, d, e, f, g, h, s0, s1;
	sha2_word32	T1, T2, W256[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-256 compression function to update a..h with copy */
		T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + (W256[j] = *data++);
		T2 = Sigma0_256(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 = W256[(j+1)&0x0f];
		s0 = sigma0_256(s0);
		s1 = W256[(j+14)&0x0f];	
		s1 = sigma1_256(s1);

		/* Apply the SHA-256 compression function to update a..h */
		T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + 
		     (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0);
		T2 = Sigma0_256(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 < 64);

	/* 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
movq %rdx, -0x40(%rbp)
movl (%rdi), %r12d
movl 0x4(%rdi), %ebx
movl 0x8(%rdi), %r8d
movl 0xc(%rdi), %r10d
movl 0x10(%rdi), %r14d
movl 0x14(%rdi), %eax
movl 0x18(%rdi), %r11d
movq %rdi, -0x38(%rbp)
movl 0x1c(%rdi), %edi
movups (%rsi), %xmm0
movups 0x10(%rsi), %xmm1
movups 0x20(%rsi), %xmm2
movups 0x30(%rsi), %xmm3
movaps %xmm3, -0x50(%rbp)
movaps %xmm2, -0x60(%rbp)
movaps %xmm1, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
xorl %r13d, %r13d
leaq 0x31ee(%rip), %rdx      # 0xc090
movl %r12d, -0x2c(%rbp)
movl %r12d, %r9d
movl %edi, %ecx
movl %r11d, %edi
movl %eax, %r11d
movl %r14d, %eax
movl %r10d, %r14d
movl %r8d, %r10d
movl %ebx, %r8d
movl %eax, %ebx
roll $0x1a, %ebx
movl %eax, %r15d
roll $0x15, %r15d
xorl %ebx, %r15d
movl %eax, %r12d
roll $0x7, %r12d
xorl %r15d, %r12d
movl %r11d, %ebx
xorl %edi, %ebx
andl %eax, %ebx
xorl %edi, %ebx
addl %ecx, %ebx
addl %r12d, %ebx
movl %r9d, %ecx
roll $0x1e, %ecx
movl %r9d, %r15d
roll $0x13, %r15d
xorl %ecx, %r15d
movl %r9d, %ecx
roll $0xa, %ecx
xorl %r15d, %ecx
movl %r10d, %r15d
xorl %r8d, %r15d
andl %r9d, %r15d
movl %r10d, %r12d
andl %r8d, %r12d
xorl %r15d, %r12d
addl (%r13,%rdx), %ebx
addl %ecx, %r12d
addl (%rsi,%r13), %ebx
addl %ebx, %r14d
addl %ebx, %r12d
addq $0x4, %r13
movl %r9d, %ebx
cmpq $0x40, %r13
jne 0x8ea6
movl $0x1e, %esi
movl %edi, -0x30(%rbp)
movl %r11d, %edi
movl %eax, %r15d
leal -0xd(%rsi), %ecx
andl $0xf, %ecx
movl -0x80(%rbp,%rcx,4), %r13d
movl %r13d, %ecx
roll $0x19, %ecx
movl %r14d, %eax
movl %r13d, %r14d
roll $0xe, %r14d
xorl %ecx, %r14d
shrl $0x3, %r13d
movl %esi, %ecx
andl $0xf, %ecx
movl -0x80(%rbp,%rcx,4), %ebx
movl %ebx, %ecx
roll $0xf, %ecx
xorl %r14d, %r13d
movl %ebx, %r14d
roll $0xd, %r14d
xorl %ecx, %r14d
movl %eax, %ecx
roll $0x1a, %ecx
shrl $0xa, %ebx
movl %eax, %r11d
roll $0x15, %r11d
xorl %r14d, %ebx
movl %eax, %edx
roll $0x7, %edx
xorl %ecx, %r11d
xorl %r11d, %edx
movl %r15d, %r11d
movl %r15d, %ecx
xorl %edi, %ecx
andl %eax, %ecx
xorl %edi, %ecx
addl -0x30(%rbp), %ecx
movl %r12d, %r15d
movl %r10d, %r14d
movl %r8d, %r10d
movl %r9d, %r8d
addl %edx, %ecx
leal -0x5(%rsi), %edx
andl $0xf, %edx
addl -0x80(%rbp,%rdx,4), %r13d
leal -0xe(%rsi), %edx
leaq 0x30c4(%rip), %r9       # 0xc090
addl -0x38(%r9,%rsi,4), %ecx
andl $0xf, %edx
addl %ebx, %r13d
addl -0x80(%rbp,%rdx,4), %r13d
movl %r13d, -0x80(%rbp,%rdx,4)
addl %ecx, %r13d
movl %r12d, %ecx
roll $0x1e, %ecx
movl %r12d, %edx
roll $0x13, %edx
xorl %ecx, %edx
movl %r12d, %ecx
roll $0xa, %ecx
xorl %edx, %ecx
movl %r10d, %edx
xorl %r8d, %edx
andl %r12d, %edx
movl %r10d, %r12d
andl %r8d, %r12d
xorl %edx, %r12d
addl %ecx, %r12d
addl %r13d, %r14d
addl %r13d, %r12d
incq %rsi
movl %r15d, %r9d
cmpq $0x4e, %rsi
jne 0x8f37
addl -0x2c(%rbp), %r12d
movq -0x40(%rbp), %rcx
movl %r12d, (%rcx)
movq -0x38(%rbp), %rdx
addl 0x4(%rdx), %r15d
movl %r15d, 0x4(%rcx)
addl 0x8(%rdx), %r8d
movl %r8d, 0x8(%rcx)
addl 0xc(%rdx), %r10d
movl %r10d, 0xc(%rcx)
addl 0x10(%rdx), %r14d
movl %r14d, 0x10(%rcx)
addl 0x14(%rdx), %eax
movl %eax, 0x14(%rcx)
addl 0x18(%rdx), %r11d
movl %r11d, 0x18(%rcx)
addl 0x1c(%rdx), %edi
movl %edi, 0x1c(%rcx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq