// File: /workspace/github_c_makefile_star2_O0/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:
movq %rdi, -0x8(%rsp)
movl $0x0, -0xc(%rsp)
cmpl $0x14, -0xc(%rsp)
jge 0x2ae9
movq -0x8(%rsp), %rax
movq %rax, -0x40(%rsp)
movl -0xc(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x40(%rsp), %rax
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
sarl $0x4, %eax
movb %al, %cl
movslq -0xc(%rsp), %rax
movb %cl, -0x28(%rsp,%rax)
movq -0x8(%rsp), %rax
movq %rax, -0x38(%rsp)
movl -0xc(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x38(%rsp), %rax
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
andl $0xf, %eax
movb %al, %cl
movl -0xc(%rsp), %eax
addl $0x1, %eax
cltq
movb %cl, -0x28(%rsp,%rax)
movl -0xc(%rsp), %eax
addl $0x2, %eax
movl %eax, -0xc(%rsp)
jmp 0x2a6d
movl $0x0, -0xc(%rsp)
movb -0x27(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x34cf(%rip), %rax      # 0x5fd0
movb %dl, (%rax,%rcx,8)
movb -0x25(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x34bc(%rip), %rax      # 0x5fd0
movb %dl, 0x1(%rax,%rcx,8)
movb -0x24(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x34a8(%rip), %rax      # 0x5fd0
movb %dl, 0x2(%rax,%rcx,8)
movb -0x22(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x3494(%rip), %rax      # 0x5fd0
movb %dl, 0x3(%rax,%rcx,8)
movb -0x1b(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x3480(%rip), %rax      # 0x5fd0
movb %dl, 0x4(%rax,%rcx,8)
movb -0x1a(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x346c(%rip), %rax      # 0x5fd0
movb %dl, 0x5(%rax,%rcx,8)
movb -0x19(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x3458(%rip), %rax      # 0x5fd0
movb %dl, 0x6(%rax,%rcx,8)
movb -0x18(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x3444(%rip), %rax      # 0x5fd0
movb %dl, 0x7(%rax,%rcx,8)
movb -0x23(%rsp), %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x342b(%rip), %rax      # 0x5fd0
movb %dl, (%rax,%rcx,8)
movzbl -0x21(%rsp), %eax
movslq -0xc(%rsp), %rdx
movq 0x343f(%rip), %rcx      # 0x5ff8
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x33fe(%rip), %rax      # 0x5fd0
movb %dl, 0x1(%rax,%rcx,8)
movb -0x20(%rsp), %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x33e5(%rip), %rax      # 0x5fd0
movb %dl, 0x2(%rax,%rcx,8)
movb -0x1e(%rsp), %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x33cc(%rip), %rax      # 0x5fd0
movb %dl, 0x3(%rax,%rcx,8)
movb -0x17(%rsp), %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x33b3(%rip), %rax      # 0x5fd0
movb %dl, 0x4(%rax,%rcx,8)
movb -0x16(%rsp), %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x339a(%rip), %rax      # 0x5fd0
movb %dl, 0x5(%rax,%rcx,8)
movzbl -0x15(%rsp), %eax
movslq -0xc(%rsp), %rdx
movq 0x3375(%rip), %rcx      # 0x5fc0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x336c(%rip), %rax      # 0x5fd0
movb %dl, 0x6(%rax,%rcx,8)
movzbl -0x27(%rsp), %eax
movzbl -0x28(%rsp), %ecx
movl %ecx, %edx
movq 0x3375(%rip), %rcx      # 0x5ff0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x333c(%rip), %rax      # 0x5fd0
movb %dl, 0x7(%rax,%rcx,8)
cmpl $0x22, -0xc(%rsp)
jne 0x2ca4
jmp 0x2e29
movzbl -0x24(%rsp), %eax
movzbl -0x18(%rsp), %ecx
movl %ecx, %edx
movq 0x3339(%rip), %rcx      # 0x5ff0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x29(%rsp)
movzbl -0x23(%rsp), %eax
movzbl -0x29(%rsp), %ecx
movl %ecx, %edx
movq 0x331c(%rip), %rcx      # 0x5ff0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x2c(%rsp)
movb -0x22(%rsp), %al
movb %al, -0x2b(%rsp)
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x32d9(%rip), %rax      # 0x5fd0
movb 0x1(%rax,%rcx,8), %al
movb %al, -0x2a(%rsp)
movb -0x1c(%rsp), %al
movb %al, -0x24(%rsp)
movb -0x1b(%rsp), %al
movb %al, -0x23(%rsp)
movb -0x1a(%rsp), %al
movb %al, -0x22(%rsp)
movb -0x19(%rsp), %al
movb %al, -0x21(%rsp)
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x32a0(%rip), %rax      # 0x5fd0
movb 0x7(%rax,%rcx,8), %al
movb %al, -0x1c(%rsp)
movb -0x26(%rsp), %al
movb %al, -0x1b(%rsp)
movb -0x25(%rsp), %al
movb %al, -0x1a(%rsp)
movzbl -0x28(%rsp), %eax
movl -0xc(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rdx
movq 0x3262(%rip), %rcx      # 0x5fc0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x19(%rsp)
movzbl -0x20(%rsp), %eax
movl -0xc(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rdx
movq 0x3252(%rip), %rcx      # 0x5fd0
movzbl 0x7(%rcx,%rdx,8), %ecx
movl %ecx, %edx
movq 0x3264(%rip), %rcx      # 0x5ff0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x28(%rsp)
movb -0x1f(%rsp), %al
movb %al, -0x27(%rsp)
movb -0x1e(%rsp), %al
movb %al, -0x26(%rsp)
movzbl -0x1d(%rsp), %eax
movl -0xc(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rdx
movq 0x323c(%rip), %rcx      # 0x5ff8
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x25(%rsp)
movb -0x18(%rsp), %al
movb %al, -0x20(%rsp)
movb -0x17(%rsp), %al
movb %al, -0x1f(%rsp)
movb -0x16(%rsp), %al
movb %al, -0x1e(%rsp)
movzbl -0x15(%rsp), %eax
movslq -0xc(%rsp), %rdx
movq 0x31d1(%rip), %rcx      # 0x5fc0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x1d(%rsp)
movb -0x2c(%rsp), %al
movb %al, -0x18(%rsp)
movb -0x2b(%rsp), %al
movb %al, -0x17(%rsp)
movb -0x2a(%rsp), %al
movb %al, -0x16(%rsp)
movb -0x29(%rsp), %al
movb %al, -0x15(%rsp)
movl -0xc(%rsp), %eax
addl $0x2, %eax
movl %eax, -0xc(%rsp)
jmp 0x2af1
retq
nopw (%rax,%rax)