// File: /workspace/github_c_makefile_star2_O2/mjosaarinen[P]brutus/crypto_aead/twine80n6t4clocv2/ref/twine.c
// Function: Keyschedule80
void Keyschedule80(const uint8 sk[80/8])
{
	int	i;
	uint8	tmp[80/4];
	uint8	wk[4];
        
	//Copy the key 
#if 1
	for(i=0; i<(80/4); i+=2)
	{
		tmp[i] = sk[i/2] >> 4;
		tmp[i+1] = sk[i/2] & 0x0f;
	}
#else
	tmp[0] = sk[0] >> 4;
	tmp[1] = sk[0] & 0x0f;
	tmp[2] = sk[1] >> 4;
	tmp[3] = sk[1] & 0x0f;
	tmp[4] = sk[2] >> 4;
	tmp[5] = sk[2] & 0x0f;
	tmp[6] = sk[3] >> 4;
	tmp[7] = sk[3] & 0x0f;
	tmp[8] = sk[4] >> 4;
	tmp[9] = sk[4] & 0x0f;
	tmp[10] = sk[5] >> 4;
	tmp[11] = sk[5] & 0x0f;
	tmp[12] = sk[6] >> 4;
	tmp[13] = sk[6] & 0x0f;
	tmp[14] = sk[7] >> 4;
	tmp[15] = sk[7] & 0x0f;
	tmp[16] = sk[8] >> 4;
	tmp[17] = sk[8] & 0x0f;
	tmp[18] = sk[9] >> 4;
	tmp[19] = sk[9] & 0x0f;
#endif
        
	//Extended key (ek) generation
	for(i=0; ; i+=2)
	{
		//ek for two rounds 
		ek[i][0] = tmp[1];
		ek[i][1] = tmp[3];
		ek[i][2] = tmp[4];
		ek[i][3] = tmp[6];
		ek[i][4] = tmp[13];
		ek[i][5] = tmp[14];
		ek[i][6] = tmp[15];
		ek[i][7] = tmp[16];

		ek[i+1][0] = tmp[5];
		ek[i+1][1] = tmp[7] ^ CON_H[i];
		ek[i+1][2] = tmp[8];
		ek[i+1][3] = tmp[10];
		ek[i+1][4] = tmp[17];
		ek[i+1][5] = tmp[18];
		ek[i+1][6] = tmp[19] ^ CON_L[i];
		ek[i+1][7] = tmp[1] ^ S[tmp[0]];
	
		//to the last two rounds 
		if(i == (ROUND-2))
			break;

		//rotations for two rounds 
		wk[3] = tmp[4] ^ S[tmp[16]];
		wk[0] = tmp[5] ^ S[wk[3]];
		wk[1] = tmp[6];
		wk[2] = ek[i+1][1];

		tmp[4] = tmp[12];
		tmp[5] = tmp[13];
		tmp[6] = tmp[14];
		tmp[7] = tmp[15];

		tmp[12] = ek[i+1][7];
		tmp[13] = tmp[2];
		tmp[14] = tmp[3];
		tmp[15] = tmp[0] ^ CON_L[i+1];

		tmp[0] = tmp[8] ^ S[ek[i+1][7]];
		tmp[1] = tmp[9];
		tmp[2] = tmp[10];
		tmp[3] = tmp[11] ^ CON_H[i+1];

		tmp[8] = tmp[16];
		tmp[9] = tmp[17];
		tmp[10] = tmp[18];
		tmp[11] = tmp[19] ^ CON_L[i];

		tmp[16] = wk[0];
		tmp[17] = wk[1];
		tmp[18] = wk[2];
		tmp[19] = wk[3];
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
xorl %eax, %eax
cmpq $0x14, %rax
jae 0x1ed5
movb (%rdi), %cl
movl %ecx, %edx
shrb $0x4, %dl
movb %dl, -0x18(%rsp,%rax)
andb $0xf, %cl
movb %cl, -0x17(%rsp,%rax)
addq $0x2, %rax
incq %rdi
jmp 0x1eb4
movb -0x18(%rsp), %al
movb %al, -0x1f(%rsp)
movb -0x17(%rsp), %al
movb %al, -0x1c(%rsp)
movb -0x15(%rsp), %al
movb %al, -0x21(%rsp)
movb -0x14(%rsp), %bl
movb -0x12(%rsp), %al
movb %al, -0x20(%rsp)
movb -0xb(%rsp), %al
movb %al, -0x1e(%rsp)
movb -0xa(%rsp), %dl
movb -0x9(%rsp), %al
movb %al, -0x1b(%rsp)
movb -0x8(%rsp), %bpl
movb -0x13(%rsp), %r13b
movb -0x11(%rsp), %dil
movb -0x10(%rsp), %r8b
movb -0xe(%rsp), %al
movb %al, -0x22(%rsp)
movb -0x7(%rsp), %al
movb %al, -0x23(%rsp)
movb -0x6(%rsp), %r12b
movb -0x5(%rsp), %r10b
movb -0xc(%rsp), %cl
movabsq $0x1, %r14
movq 0x3080(%rip), %r15      # 0x4fd0
movb -0x16(%rsp), %r9b
movb -0xf(%rsp), %r11b
movb -0xd(%rsp), %al
movb %al, -0x1d(%rsp)
movb %cl, -0x19(%rsp)
movb -0x1c(%rsp), %cl
movb %cl, -0x8(%r15,%r14,8)
movzbl -0x1f(%rsp), %eax
movq 0x3075(%rip), %rsi      # 0x4ff0
xorb (%rsi,%rax), %cl
movl %edx, %esi
movl %r12d, %eax
movb %r9b, -0x1a(%rsp)
movl %r11d, %edx
movb -0x21(%rsp), %r9b
movb %r9b, -0x7(%r15,%r14,8)
movb %bl, -0x6(%r15,%r14,8)
movb -0x20(%rsp), %r9b
movb %r9b, -0x5(%r15,%r14,8)
movb -0x1e(%rsp), %r9b
movb %r9b, -0x4(%r15,%r14,8)
movb %sil, -0x3(%r15,%r14,8)
movb -0x1b(%rsp), %r11b
movb %r11b, -0x2(%r15,%r14,8)
movb %bpl, -0x1(%r15,%r14,8)
movb %r13b, (%r15,%r14,8)
movl %edi, %r12d
movq 0x3028(%rip), %r9       # 0x4ff8
xorb -0x1(%r9,%r14), %r12b
movb %r12b, 0x1(%r15,%r14,8)
movb %r8b, 0x2(%r15,%r14,8)
movb -0x22(%rsp), %r9b
movb %r9b, 0x3(%r15,%r14,8)
movb -0x23(%rsp), %r9b
movb %r9b, 0x4(%r15,%r14,8)
movb %al, 0x5(%r15,%r14,8)
movq 0x2fc1(%rip), %r9       # 0x4fc0
xorb -0x1(%r9,%r14), %r10b
movb %r10b, 0x6(%r15,%r14,8)
movb %cl, 0x7(%r15,%r14,8)
cmpq $0x23, %r14
je 0x20c0
movzbl %bpl, %r9d
movb %dl, -0x1c(%rsp)
movl %ebp, %edi
movq 0x2fc7(%rip), %rbp      # 0x4ff0
xorb (%rbp,%r9), %bl
movl %r11d, %edx
movb -0x1f(%rsp), %r9b
movq 0x2f83(%rip), %r11      # 0x4fc0
xorb (%r11,%r14), %r9b
movzbl %cl, %r11d
xorb (%rbp,%r11), %r8b
movzbl %bl, %r11d
movb %r9b, -0x1b(%rsp)
movb %r8b, -0x1f(%rsp)
movl %edi, %r8d
xorb (%rbp,%r11), %r13b
movb -0x21(%rsp), %bpl
movb -0x1d(%rsp), %r9b
movq 0x2f87(%rip), %r11      # 0x4ff8
xorb (%r11,%r14), %r9b
addq $0x2, %r14
movb %r9b, -0x21(%rsp)
movb %r10b, -0x1d(%rsp)
movb -0x23(%rsp), %r11b
movb -0x22(%rsp), %r9b
movl %ebx, %r10d
movb -0x20(%rsp), %dil
movb %dil, -0x23(%rsp)
movl %edx, %edi
movl %ebp, %edx
movb %al, -0x22(%rsp)
movl %r13d, %ebp
movb -0x1e(%rsp), %r13b
movb -0x1a(%rsp), %al
movb %al, -0x1e(%rsp)
movb %sil, -0x20(%rsp)
movb -0x19(%rsp), %bl
jmp 0x1f62
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq