// File: /workspace/github_c_makefile_star2_O0/mjosaarinen[P]brutus/crypto_aead/twine80n6t4clocv2/ref/twine.c
// Function: Keyschedule128
void Keyschedule128(const uint8 sk[128/4])
{
	int	i;
	uint8	tmp[128/4];
	uint8	wk[5];

	//Copy the key 
#if 1
	for(i=0; i<(128/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;
	tmp[20] = sk[10] >> 4;
	tmp[21] = sk[10] & 0x0f;
	tmp[22] = sk[11] >> 4;
	tmp[23] = sk[11] & 0x0f;
	tmp[24] = sk[12] >> 4;
	tmp[25] = sk[12] & 0x0f;
	tmp[26] = sk[13] >> 4;
	tmp[27] = sk[13] & 0x0f;
	tmp[28] = sk[14] >> 4;
	tmp[29] = sk[14] & 0x0f;
	tmp[30] = sk[15] >> 4;
	tmp[31] = sk[15] & 0x0f;
#endif
        
	//Extended key (ek) generation
	for(i=0; ; i+=2)
	{
		//ek for two rounds
		ek[i][0] = tmp[2];
		ek[i][1] = tmp[3];
		ek[i][2] = tmp[12];
		ek[i][3] = tmp[15];
		ek[i][4] = tmp[17];
		ek[i][5] = tmp[18];
		ek[i][6] = tmp[28];
		ek[i][7] = tmp[31];

		ek[i+1][0] = tmp[6];
		ek[i+1][1] = tmp[7] ^ CON_H[i];
		ek[i+1][2] = tmp[16];
		ek[i+1][3] = tmp[19] ^ CON_L[i];
		ek[i+1][4] = tmp[21];
		ek[i+1][5] = tmp[22];
		ek[i+1][6] = tmp[1] ^ S[tmp[0]];
		ek[i+1][7] = 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] = tmp[7] ^ CON_H[i];

		tmp[4] = tmp[12];
		tmp[5] = tmp[13];
		tmp[6] = tmp[14];
		tmp[7] = tmp[15];

		tmp[12] = tmp[20];
		tmp[13] = tmp[21];
		tmp[14] = tmp[22];
		tmp[15] = tmp[23] ^ S[tmp[30]] ^ CON_L[i+1];

		wk[4] = tmp[20];
		tmp[20] = tmp[28];
		tmp[21] = tmp[29];
		tmp[22] = tmp[30];
		tmp[23] = tmp[31];

		tmp[28] = wk[0];
		tmp[29] = wk[1];
		tmp[30] = wk[2];
		tmp[31] = wk[3];


		wk[3] = tmp[0];
		wk[0] = ek[i+1][6];
		wk[1] = tmp[2];
		wk[2] = tmp[3];

		tmp[0] = tmp[8] ^ S[wk[4]];
		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] = tmp[24];
		tmp[17] = tmp[25];
		tmp[18] = tmp[26];
		tmp[19] = tmp[27] ^ S[wk[2]];

		tmp[24] = wk[0];
		tmp[25] = wk[1];
		tmp[26] = wk[2];
		tmp[27] = wk[3];
	}
}

// Assembly:
movq %rdi, -0x8(%rsp)
movl $0x0, -0xc(%rsp)
cmpl $0x20, -0xc(%rsp)
jge 0x2eb9
movq -0x8(%rsp), %rax
movq %rax, -0x50(%rsp)
movl -0xc(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x50(%rsp), %rax
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
sarl $0x4, %eax
movb %al, %cl
movslq -0xc(%rsp), %rax
movb %cl, -0x38(%rsp,%rax)
movq -0x8(%rsp), %rax
movq %rax, -0x48(%rsp)
movl -0xc(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0x48(%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, -0x38(%rsp,%rax)
movl -0xc(%rsp), %eax
addl $0x2, %eax
movl %eax, -0xc(%rsp)
jmp 0x2e3d
movl $0x0, -0xc(%rsp)
movb -0x36(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x30ff(%rip), %rax      # 0x5fd0
movb %dl, (%rax,%rcx,8)
movb -0x35(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x30ec(%rip), %rax      # 0x5fd0
movb %dl, 0x1(%rax,%rcx,8)
movb -0x2c(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x30d8(%rip), %rax      # 0x5fd0
movb %dl, 0x2(%rax,%rcx,8)
movb -0x29(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x30c4(%rip), %rax      # 0x5fd0
movb %dl, 0x3(%rax,%rcx,8)
movb -0x27(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x30b0(%rip), %rax      # 0x5fd0
movb %dl, 0x4(%rax,%rcx,8)
movb -0x26(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x309c(%rip), %rax      # 0x5fd0
movb %dl, 0x5(%rax,%rcx,8)
movb -0x1c(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x3088(%rip), %rax      # 0x5fd0
movb %dl, 0x6(%rax,%rcx,8)
movb -0x19(%rsp), %dl
movslq -0xc(%rsp), %rcx
movq 0x3074(%rip), %rax      # 0x5fd0
movb %dl, 0x7(%rax,%rcx,8)
movb -0x32(%rsp), %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x305b(%rip), %rax      # 0x5fd0
movb %dl, (%rax,%rcx,8)
movzbl -0x31(%rsp), %eax
movslq -0xc(%rsp), %rdx
movq 0x306f(%rip), %rcx      # 0x5ff8
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x302e(%rip), %rax      # 0x5fd0
movb %dl, 0x1(%rax,%rcx,8)
movb -0x28(%rsp), %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x3015(%rip), %rax      # 0x5fd0
movb %dl, 0x2(%rax,%rcx,8)
movzbl -0x25(%rsp), %eax
movslq -0xc(%rsp), %rdx
movq 0x2ff0(%rip), %rcx      # 0x5fc0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x2fe7(%rip), %rax      # 0x5fd0
movb %dl, 0x3(%rax,%rcx,8)
movb -0x23(%rsp), %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x2fce(%rip), %rax      # 0x5fd0
movb %dl, 0x4(%rax,%rcx,8)
movb -0x22(%rsp), %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x2fb5(%rip), %rax      # 0x5fd0
movb %dl, 0x5(%rax,%rcx,8)
movzbl -0x37(%rsp), %eax
movzbl -0x38(%rsp), %ecx
movl %ecx, %edx
movq 0x2fbe(%rip), %rcx      # 0x5ff0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x2f85(%rip), %rax      # 0x5fd0
movb %dl, 0x6(%rax,%rcx,8)
movb -0x38(%rsp), %dl
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x2f6c(%rip), %rax      # 0x5fd0
movb %dl, 0x7(%rax,%rcx,8)
cmpl $0x22, -0xc(%rsp)
jne 0x3074
jmp 0x329b
movzbl -0x34(%rsp), %eax
movzbl -0x28(%rsp), %ecx
movl %ecx, %edx
movq 0x2f69(%rip), %rcx      # 0x5ff0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x3a(%rsp)
movzbl -0x33(%rsp), %eax
movzbl -0x3a(%rsp), %ecx
movl %ecx, %edx
movq 0x2f4c(%rip), %rcx      # 0x5ff0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x3d(%rsp)
movb -0x32(%rsp), %al
movb %al, -0x3c(%rsp)
movzbl -0x31(%rsp), %eax
movslq -0xc(%rsp), %rdx
movq 0x2f31(%rip), %rcx      # 0x5ff8
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x3b(%rsp)
movb -0x2c(%rsp), %al
movb %al, -0x34(%rsp)
movb -0x2b(%rsp), %al
movb %al, -0x33(%rsp)
movb -0x2a(%rsp), %al
movb %al, -0x32(%rsp)
movb -0x29(%rsp), %al
movb %al, -0x31(%rsp)
movb -0x24(%rsp), %al
movb %al, -0x2c(%rsp)
movb -0x23(%rsp), %al
movb %al, -0x2b(%rsp)
movb -0x22(%rsp), %al
movb %al, -0x2a(%rsp)
movzbl -0x21(%rsp), %eax
movzbl -0x1a(%rsp), %ecx
movl %ecx, %edx
movq 0x2ed4(%rip), %rcx      # 0x5ff0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movl -0xc(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rdx
movq 0x2e8d(%rip), %rcx      # 0x5fc0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x29(%rsp)
movb -0x24(%rsp), %al
movb %al, -0x39(%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)
movb -0x3d(%rsp), %al
movb %al, -0x1c(%rsp)
movb -0x3c(%rsp), %al
movb %al, -0x1b(%rsp)
movb -0x3b(%rsp), %al
movb %al, -0x1a(%rsp)
movb -0x3a(%rsp), %al
movb %al, -0x19(%rsp)
movb -0x38(%rsp), %al
movb %al, -0x3a(%rsp)
movl -0xc(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
movq 0x2e32(%rip), %rax      # 0x5fd0
movb 0x6(%rax,%rcx,8), %al
movb %al, -0x3d(%rsp)
movb -0x36(%rsp), %al
movb %al, -0x3c(%rsp)
movb -0x35(%rsp), %al
movb %al, -0x3b(%rsp)
movzbl -0x30(%rsp), %eax
movzbl -0x39(%rsp), %ecx
movl %ecx, %edx
movq 0x2e27(%rip), %rcx      # 0x5ff0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x38(%rsp)
movb -0x2f(%rsp), %al
movb %al, -0x37(%rsp)
movb -0x2e(%rsp), %al
movb %al, -0x36(%rsp)
movzbl -0x2d(%rsp), %eax
movl -0xc(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rdx
movq 0x2dff(%rip), %rcx      # 0x5ff8
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x35(%rsp)
movb -0x28(%rsp), %al
movb %al, -0x30(%rsp)
movb -0x27(%rsp), %al
movb %al, -0x2f(%rsp)
movb -0x26(%rsp), %al
movb %al, -0x2e(%rsp)
movzbl -0x25(%rsp), %eax
movslq -0xc(%rsp), %rdx
movq 0x2d94(%rip), %rcx      # 0x5fc0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x2d(%rsp)
movb -0x20(%rsp), %al
movb %al, -0x28(%rsp)
movb -0x1f(%rsp), %al
movb %al, -0x27(%rsp)
movb -0x1e(%rsp), %al
movb %al, -0x26(%rsp)
movzbl -0x1d(%rsp), %eax
movzbl -0x3b(%rsp), %ecx
movl %ecx, %edx
movq 0x2d8f(%rip), %rcx      # 0x5ff0
movzbl (%rcx,%rdx), %ecx
xorl %ecx, %eax
movb %al, -0x25(%rsp)
movb -0x3d(%rsp), %al
movb %al, -0x20(%rsp)
movb -0x3c(%rsp), %al
movb %al, -0x1f(%rsp)
movb -0x3b(%rsp), %al
movb %al, -0x1e(%rsp)
movb -0x3a(%rsp), %al
movb %al, -0x1d(%rsp)
movl -0xc(%rsp), %eax
addl $0x2, %eax
movl %eax, -0xc(%rsp)
jmp 0x2ec1
retq
nopl (%rax)