// File: /workspace/github_c_makefile_star2_O3/janmojzis[P]mcencrypt/sk_gen.c
// Function: sk_gen
int sk_gen(unsigned char *sk)
{
	int i;

	gf g[ SYS_T ]; /* // irreducible polynomial */
	gf a[ SYS_T ]; /* // random element in GF(2^mt) */
	
	while (1)
	{
		randombytes((unsigned char *) a, sizeof(a)); 

		for (i = 0; i < SYS_T; i++) a[i] &= GFMASK;

		if ( irr_gen(g, a) == 0 ) break;
	}

	for (i = 0; i < SYS_T; i++) 
		store2( sk + SYS_N/8 + i*2, g[i] );

	randombytes(sk, SYS_N/8);

	controlbits(sk + SYS_N/8 + IRR_BYTES);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8348, %rsp           # imm = 0x8348
leaq 0x242(%rsp), %r15
leaq 0x40(%rsp), %r12
movq %rdi, 0x20(%rsp)
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
callq 0x6930
xorl %eax, %eax
movaps 0x2277(%rip), %xmm1     # 0x8db0
movaps 0x40(%rsp,%rax,2), %xmm0
andps %xmm1, %xmm0
movaps %xmm0, 0x40(%rsp,%rax,2)
addq $0x8, %rax
cmpq $0x80, %rax
jne 0x6b39
movw $0x1, 0x240(%rsp)
movl $0xfe, %edx
movq %r15, %rdi
xorl %esi, %esi
callq 0x1070
movl $0x100, %edx            # imm = 0x100
leaq 0x340(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x10a0
movl $0x7f, %ebx
movq %r14, %rsi
leaq 0x100(%rsi), %r13
movq %r13, %rdi
movq %r12, %rdx
callq 0x5a02
movq %r13, %rsi
decq %rbx
jne 0x6b8b
movl $0x1, %r13d
movl $0x8100, %r14d          # imm = 0x8100
leaq 0x240(%rsp), %r12
movq %r12, 0x18(%rsp)
movq %r15, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x8(%rsp)
cmpq $0x7e, %rax
ja 0x6c24
movq 0x8(%rsp), %rcx
movq %rcx, %rax
shlq $0x8, %rax
addq %rsp, %rax
addq $0x240, %rax            # imm = 0x240
leaq (%rax,%rcx,2), %rbx
movq 0x10(%rsp), %r15
movq %r13, %rbp
movzwl (%rbx), %edi
callq 0x52a8
xorl %ecx, %ecx
movzwl (%r15,%rcx), %edx
andw %ax, %dx
xorw %dx, (%r12,%rcx)
addq $0x100, %rcx            # imm = 0x100
cmpq %rcx, %r14
jne 0x6bfb
incq %rbp
addq $0x2, %r15
cmpq $0x80, %rbp
jne 0x6bf1
movq 0x8(%rsp), %rcx
movq %rcx, %rax
shlq $0x8, %rax
addq %rsp, %rax
addq $0x240, %rax            # imm = 0x240
movq %rax, 0x38(%rsp)
movzwl (%rax,%rcx,2), %eax
testw %ax, %ax
je 0x6d07
movq %r13, 0x30(%rsp)
incq %rcx
movq %rcx, 0x28(%rsp)
movzwl %ax, %edi
callq 0x59f8
movzwl %ax, %ebp
xorl %ebx, %ebx
movzwl (%r12,%rbx), %edi
movl %ebp, %esi
callq 0x52b4
movw %ax, (%r12,%rbx)
addq $0x100, %rbx            # imm = 0x100
cmpq %rbx, %r14
jne 0x6c65
movq 0x18(%rsp), %rbx
xorl %r15d, %r15d
cmpq 0x8(%rsp), %r15
je 0x6cbb
movq 0x38(%rsp), %rax
movzwl (%rax,%r15,2), %ebp
xorl %r13d, %r13d
movzwl (%r12,%r13), %edi
movl %ebp, %esi
callq 0x52b4
xorw %ax, (%rbx,%r13)
addq $0x100, %r13            # imm = 0x100
cmpq %r13, %r14
jne 0x6c9e
incq %r15
addq $0x2, %rbx
cmpq $0x80, %r15
jne 0x6c8a
movq 0x30(%rsp), %r13
incq %r13
addq $-0x100, %r14
movl $0x102, %eax            # imm = 0x102
addq %rax, %r12
addq %rax, 0x10(%rsp)
addq $0x100, 0x18(%rsp)      # imm = 0x100
movq 0x28(%rsp), %rcx
movq %rcx, %rax
cmpq $0x80, %rcx
jne 0x6bc5
jmp 0x6d19
leaq 0x242(%rsp), %r15
leaq 0x40(%rsp), %r12
jmp 0x6b23
leaq 0x8240(%rsp), %rsi
leaq 0x140(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x10a0
movl $0x400, %ebx            # imm = 0x400
movq 0x20(%rsp), %r14
leaq (%r14,%rbx), %rdi
movzwl -0x2c0(%rsp,%rbx), %esi
callq 0x6f24
addq $0x2, %rbx
cmpq $0x500, %rbx            # imm = 0x500
jne 0x6d3d
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
callq 0x6930
addq $0x500, %r14            # imm = 0x500
movq %r14, %rdi
callq 0x3bc0
xorl %eax, %eax
addq $0x8348, %rsp           # imm = 0x8348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop