// File: /workspace/github_c_makefile_star2_O1/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, 0x20(%rsp)
leaq 0x242(%rsp), %r14
leaq 0x40(%rsp), %r13
movl $0x100, %esi            # imm = 0x100
movq %r13, %rdi
callq 0x6524
xorl %eax, %eax
andb $0x1f, 0x41(%rsp,%rax,2)
incq %rax
cmpq $0x80, %rax
jne 0x676a
movw $0x1, 0x240(%rsp)
movl $0xfe, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1070
movl $0x100, %edx            # imm = 0x100
leaq 0x340(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x10a0
movl $0x7f, %ebx
movq %r15, %rsi
leaq 0x100(%rsi), %r12
movq %r12, %rdi
movq %r13, %rdx
callq 0x56ed
movq %r12, %rsi
decq %rbx
jne 0x67b3
movl $0x8100, %r15d          # imm = 0x8100
leaq 0x240(%rsp), %r13
movq %r13, 0x18(%rsp)
movq %r14, 0x10(%rsp)
movl $0x1, %r14d
xorl %eax, %eax
movq %rax, 0x8(%rsp)
cmpq $0x7e, %rax
ja 0x684d
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), %r12
movq %r14, %rbp
movzwl (%rbx), %edi
callq 0x4f58
xorl %ecx, %ecx
movzwl (%r12,%rcx), %edx
andw %ax, %dx
xorw %dx, (%r13,%rcx)
addq $0x100, %rcx            # imm = 0x100
cmpq %rcx, %r15
jne 0x6823
incq %rbp
addq $0x2, %r12
cmpq $0x80, %rbp
jne 0x6819
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 0x674e
movq %r14, 0x30(%rsp)
incq %rcx
movq %rcx, 0x28(%rsp)
movw %ax, 0x6(%rsp)
movzwl %ax, %edi
callq 0x56e3
movzwl %ax, %r12d
xorl %ebx, %ebx
movzwl (%r13,%rbx), %edi
movl %r12d, %esi
callq 0x4f64
movw %ax, (%r13,%rbx)
addq $0x100, %rbx            # imm = 0x100
cmpq %rbx, %r15
jne 0x6894
movq 0x18(%rsp), %rbx
xorl %ebp, %ebp
cmpq 0x8(%rsp), %rbp
je 0x68ee
movq 0x38(%rsp), %rax
movzwl (%rax,%rbp,2), %r12d
xorl %r14d, %r14d
movzwl (%r13,%r14), %edi
movl %r12d, %esi
callq 0x4f64
xorw %ax, (%rbx,%r14)
addq $0x100, %r14            # imm = 0x100
cmpq %r14, %r15
jne 0x68cf
incq %rbp
addq $0x2, %rbx
cmpq $0x80, %rbp
jne 0x68bb
movq 0x30(%rsp), %r14
incq %r14
addq $-0x100, %r15
movl $0x102, %eax            # imm = 0x102
addq %rax, %r13
addq %rax, 0x10(%rsp)
addq $0x100, 0x18(%rsp)      # imm = 0x100
movq 0x28(%rsp), %rcx
movq %rcx, %rax
cmpq $0x80, %rcx
jne 0x67ed
movl $0x100, %edx            # imm = 0x100
leaq 0x140(%rsp), %rdi
leaq 0x8240(%rsp), %rsi
callq 0x10a0
cmpw $0x0, 0x6(%rsp)
leaq 0x242(%rsp), %r14
leaq 0x40(%rsp), %r13
je 0x675b
movl $0x400, %ebx            # imm = 0x400
movq 0x20(%rsp), %r14
leaq (%r14,%rbx), %rdi
movzwl -0x2c0(%rsp,%rbx), %esi
callq 0x6b5c
addq $0x2, %rbx
cmpq $0x500, %rbx            # imm = 0x500
jne 0x6975
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdi
callq 0x6524
addq $0x500, %r14            # imm = 0x500
movq %r14, %rdi
callq 0x3bc4
xorl %eax, %eax
addq $0x8348, %rsp           # imm = 0x8348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop