// File: /workspace/github_c_makefile_star2_O1/Seclabs-htc[P]slip39/trezor-crypto/sha2.c
// Function: sha1_Transform
void sha1_Transform(const sha2_word32* state_in, const sha2_word32* data, sha2_word32* state_out) {
	sha2_word32	a, b, c, d, e;
	sha2_word32	T1;
	sha2_word32	W1[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];
	j = 0;
	do {
		T1 = ROTL32(5, a) + Ch(b, c, d) + e + K1_0_TO_19 + (W1[j] = *data++);
		e = d;
		d = c;
		c = ROTL32(30, b);
		b = a;
		a = T1;
		j++;
	} while (j < 16);

	do {
		T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
		T1 = ROTL32(5, a) + Ch(b,c,d) + e + K1_0_TO_19 + (W1[j&0x0f] = ROTL32(1, T1));
		e = d;
		d = c;
		c = ROTL32(30, b);
		b = a;
		a = T1;
		j++;
	} while (j < 20);

	do {
		T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
		T1 = ROTL32(5, a) + Parity(b,c,d) + e + K1_20_TO_39 + (W1[j&0x0f] = ROTL32(1, T1));
		e = d;
		d = c;
		c = ROTL32(30, b);
		b = a;
		a = T1;
		j++;
	} while (j < 40);

	do {
		T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
		T1 = ROTL32(5, a) + Maj(b,c,d) + e + K1_40_TO_59 + (W1[j&0x0f] = ROTL32(1, T1));
		e = d;
		d = c;
		c = ROTL32(30, b);
		b = a;
		a = T1;
		j++;
	} while (j < 60);

	do {
		T1 = W1[(j+13)&0x0f] ^ W1[(j+8)&0x0f] ^ W1[(j+2)&0x0f] ^ W1[j&0x0f];
		T1 = ROTL32(5, a) + Parity(b,c,d) + e + K1_60_TO_79 + (W1[j&0x0f] = ROTL32(1, T1));
		e = d;
		d = c;
		c = ROTL32(30, b);
		b = a;
		a = T1;
		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;

	/* Clean up */
	a = b = c = d = e = T1 = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl (%rdi), %r8d
movl 0x4(%rdi), %r10d
movl 0x8(%rdi), %r9d
movl 0xc(%rdi), %ecx
movl 0x10(%rdi), %eax
movups (%rsi), %xmm0
movups 0x10(%rsi), %xmm1
movups 0x20(%rsi), %xmm2
movups 0x30(%rsi), %xmm3
movaps %xmm3, -0x30(%rbp)
movaps %xmm2, -0x40(%rbp)
movaps %xmm1, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
xorl %ebx, %ebx
movl %r8d, %r11d
movl %eax, %r14d
movl %ecx, %eax
movl %r9d, %ecx
movl %r10d, %r9d
movl %r11d, %r10d
roll $0x5, %r11d
addl %r14d, %r11d
movl %ecx, %r14d
xorl %eax, %r14d
andl %r9d, %r14d
xorl %eax, %r14d
addl %r11d, %r14d
movl (%rsi,%rbx,4), %r11d
addl %r14d, %r11d
addl $0x5a827999, %r11d      # imm = 0x5A827999
roll $0x1e, %r9d
incq %rbx
cmpq $0x10, %rbx
jne 0x8853
xorl %esi, %esi
movl %eax, %ebx
movl %ecx, %eax
movl %r9d, %ecx
movl %r10d, %r9d
leal 0x1d(%rsi), %r10d
andl $0xf, %r10d
movq %rsi, %r14
xorq $0x8, %r14
movl -0x60(%rbp,%r14,4), %r14d
xorl -0x60(%rbp,%r10,4), %r14d
xorl -0x58(%rbp,%rsi,4), %r14d
movl %r11d, %r10d
xorl -0x60(%rbp,%rsi,4), %r14d
roll $0x5, %r11d
addl %ebx, %r11d
movl %ecx, %ebx
xorl %eax, %ebx
andl %r9d, %ebx
xorl %eax, %ebx
addl %r11d, %ebx
roll %r14d
movl %r14d, -0x60(%rbp,%rsi,4)
leal (%r14,%rbx), %r11d
addl $0x5a827999, %r11d      # imm = 0x5A827999
roll $0x1e, %r9d
incq %rsi
cmpq $0x4, %rsi
jne 0x8894
movl $0x14, %esi
movl %eax, %ebx
movl %ecx, %eax
movl %r9d, %ecx
movl %r10d, %r9d
movl %r11d, %r10d
leal 0xd(%rsi), %r14d
andl $0xf, %r14d
movl %esi, %r11d
andl $0xf, %r11d
movl %r11d, %r15d
xorl $0x8, %r15d
movl -0x60(%rbp,%r15,4), %r15d
xorl -0x60(%rbp,%r14,4), %r15d
leal 0x2(%rsi), %r14d
andl $0xf, %r14d
xorl -0x60(%rbp,%r14,4), %r15d
xorl -0x60(%rbp,%r11,4), %r15d
movl %r10d, %r14d
roll $0x5, %r14d
movl %ecx, %r12d
xorl %r9d, %r12d
xorl %eax, %r12d
addl %r14d, %r12d
addl %ebx, %r12d
roll %r15d
movl %r15d, -0x60(%rbp,%r11,4)
leal (%r15,%r12), %r11d
addl $0x6ed9eba1, %r11d      # imm = 0x6ED9EBA1
roll $0x1e, %r9d
incl %esi
cmpl $0x28, %esi
jne 0x88fc
movl $0x28, %esi
movl %eax, %r15d
movl %ecx, %eax
movl %r9d, %ecx
movl %r10d, %r9d
leal 0xd(%rsi), %r10d
andl $0xf, %r10d
movl %esi, %ebx
andl $0xf, %ebx
movl %ebx, %r14d
xorl $0x8, %r14d
movl -0x60(%rbp,%r14,4), %r14d
xorl -0x60(%rbp,%r10,4), %r14d
leal 0x2(%rsi), %r10d
andl $0xf, %r10d
xorl -0x60(%rbp,%r10,4), %r14d
xorl -0x60(%rbp,%rbx,4), %r14d
movl %r11d, %r10d
roll $0x5, %r11d
addl %r15d, %r11d
movl %eax, %r15d
xorl %ecx, %r15d
andl %r9d, %r15d
movl %eax, %r12d
andl %ecx, %r12d
xorl %r15d, %r12d
addl %r11d, %r12d
roll %r14d
movl %r14d, -0x60(%rbp,%rbx,4)
leal (%r14,%r12), %r11d
addl $0x8f1bbcdc, %r11d      # imm = 0x8F1BBCDC
roll $0x1e, %r9d
incl %esi
cmpl $0x3c, %esi
jne 0x8974
movl $0x3c, %esi
movl %eax, %ebx
movl %ecx, %eax
movl %r9d, %ecx
movl %r10d, %r9d
movl %r11d, %r10d
leal 0xd(%rsi), %r14d
andl $0xf, %r14d
movl %esi, %r11d
andl $0xf, %r11d
movl %r11d, %r15d
xorl $0x8, %r15d
movl -0x60(%rbp,%r15,4), %r15d
xorl -0x60(%rbp,%r14,4), %r15d
leal 0x2(%rsi), %r14d
andl $0xf, %r14d
xorl -0x60(%rbp,%r14,4), %r15d
xorl -0x60(%rbp,%r11,4), %r15d
movl %r10d, %r14d
roll $0x5, %r14d
movl %ecx, %r12d
xorl %r9d, %r12d
xorl %eax, %r12d
addl %r14d, %r12d
addl %ebx, %r12d
roll %r15d
movl %r15d, -0x60(%rbp,%r11,4)
leal (%r15,%r12), %r11d
addl $0xca62c1d6, %r11d      # imm = 0xCA62C1D6
roll $0x1e, %r9d
incl %esi
cmpl $0x50, %esi
jne 0x89f1
addl %r8d, %r11d
movl %r11d, (%rdx)
addl 0x4(%rdi), %r10d
movl %r10d, 0x4(%rdx)
addl 0x8(%rdi), %r9d
movl %r9d, 0x8(%rdx)
addl 0xc(%rdi), %ecx
movl %ecx, 0xc(%rdx)
addl 0x10(%rdi), %eax
movl %eax, 0x10(%rdx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq