// File: /workspace/github_c_makefile_star2_O2/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
movq %rdi, 0x8(%rsp)
pushq $0x1
popq %r14
movl $0x100, %esi            # imm = 0x100
leaq 0x40(%rsp), %rdi
callq 0x5fcc
xorl %eax, %eax
cmpq $0x80, %rax
je 0x61c5
andb $0x1f, 0x41(%rsp,%rax,2)
incq %rax
jmp 0x61b3
movw $0x1, 0x240(%rsp)
movq %r14, %rax
cmpq $0x80, %rax
je 0x61e8
andw $0x0, 0x240(%rsp,%rax,2)
incq %rax
jmp 0x61d2
xorl %eax, %eax
cmpq $0x80, %rax
je 0x6204
movzwl 0x40(%rsp,%rax,2), %ecx
movw %cx, 0x340(%rsp,%rax,2)
incq %rax
jmp 0x61ea
pushq $0x7f
popq %rbx
leaq 0x340(%rsp), %rsi
subq $0x1, %rbx
jb 0x622e
leaq 0x100(%rsi), %r15
movq %r15, %rdi
leaq 0x40(%rsp), %rdx
callq 0x529b
movq %r15, %rsi
jmp 0x620f
movl $0x8100, %r15d          # imm = 0x8100
leaq 0x240(%rsp), %rbx
movq %rbx, 0x10(%rsp)
leaq 0x242(%rsp), %r12
movq %r14, %rbp
xorl %r13d, %r13d
cmpq $0x80, %r13
je 0x6380
movq %r13, %rax
shlq $0x8, %rax
addq %rsp, %rax
addq $0x240, %rax            # imm = 0x240
movq %rax, 0x30(%rsp)
leaq (%rax,%r13,2), %r14
movq %r12, 0x28(%rsp)
movq %rbp, 0x20(%rsp)
cmpq $0x80, %rbp
je 0x62b6
movzwl (%r14), %edi
callq 0x4eb0
xorl %ecx, %ecx
cmpq %rcx, %r15
je 0x62ad
movzwl (%r12,%rcx), %edx
andw %ax, %dx
xorw %dx, (%rbx,%rcx)
addq $0x100, %rcx            # imm = 0x100
jmp 0x6293
incq %rbp
addq $0x2, %r12
jmp 0x627f
movzwl (%r14), %eax
testw %ax, %ax
je 0x639f
leaq 0x1(%r13), %rcx
movq %rcx, 0x18(%rsp)
movzwl %ax, %edi
callq 0x5293
movzwl %ax, %ebp
xorl %r14d, %r14d
cmpq %r14, %r15
je 0x62f9
movzwl (%rbx,%r14), %edi
movl %ebp, %esi
callq 0x4ebc
movw %ax, (%rbx,%r14)
addq $0x100, %r14            # imm = 0x100
jmp 0x62da
movq 0x10(%rsp), %r14
xorl %r12d, %r12d
movq %r13, 0x38(%rsp)
cmpq $0x80, %r12
je 0x634e
cmpq %r13, %r12
jne 0x6322
incq %r12
addq $0x2, %r14
movq 0x38(%rsp), %r13
jmp 0x6306
movq 0x30(%rsp), %rax
movzwl (%rax,%r12,2), %ebp
xorl %r13d, %r13d
cmpq %r13, %r15
je 0x6314
movzwl (%rbx,%r13), %edi
movl %ebp, %esi
callq 0x4ebc
xorw %ax, (%r14,%r13)
addq $0x100, %r13            # imm = 0x100
jmp 0x632f
movq 0x20(%rsp), %rbp
incq %rbp
movl $0x102, %eax            # imm = 0x102
addq %rax, %rbx
movq 0x28(%rsp), %r12
addq %rax, %r12
addq $-0x100, %r15
addq $0x100, 0x10(%rsp)      # imm = 0x100
movq 0x18(%rsp), %r13
jmp 0x624f
xorl %eax, %eax
cmpq $0x80, %rax
je 0x639f
movzwl 0x8240(%rsp,%rax,2), %ecx
movw %cx, 0x140(%rsp,%rax,2)
incq %rax
jmp 0x6382
cmpq $0x80, %r13
pushq $0x1
popq %r14
jne 0x61a2
movl $0x400, %ebx            # imm = 0x400
cmpq $0x500, %rbx            # imm = 0x500
je 0x63da
movq 0x8(%rsp), %rax
leaq (%rax,%rbx), %rdi
movzwl -0x2c0(%rsp,%rbx), %esi
callq 0x65bc
addq $0x2, %rbx
jmp 0x63b5
movl $0x400, %esi            # imm = 0x400
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x5fcc
addq $0x500, %rbx            # imm = 0x500
movq %rbx, %rdi
callq 0x3b3c
xorl %eax, %eax
addq $0x8348, %rsp           # imm = 0x8348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop