// File: sellibitze[P]secretshare-cxx/main.cpp
// Function: (anonymous namespace)::secret_share(slice<unsigned char const>, unsigned int, unsigned int)
vector<share> secret_share(slice<const octet> const secret, unsigned k, unsigned n)
{
	auto const blocksize = secret.size();
	if (k == 0 || k > 255 || n > 255 || k > n)
		throw runtime_error("Illegal K/N parameters");
	vector<octet> poly (k);
	vector<share> result (n, share(blocksize));
	for (size_t byteidx=0; byteidx<blocksize; ++byteidx) {
		get_random(all_of(poly).slice_from(1));
		poly[0] = secret[byteidx];
		for (unsigned shareidx=0; shareidx<n; ++shareidx) {
			auto& s = result[shareidx];
			s.xcoord = shareidx + 1;
			s.data[byteidx] = poly_evaluate(poly, s.xcoord);
		}
	}
	return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0xd8(%rbp)
movq %rdi, %rax
movq %rax, -0xd0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x10(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x2af0
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x49ac
cmpl $0xff, -0x1c(%rbp)
ja 0x49ac
cmpl $0xff, -0x20(%rbp)
ja 0x49ac
movl -0x1c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jbe 0x4a08
movl $0x10, %edi
callq 0x20b0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xe0(%rbp)
leaq 0x49bb(%rip), %rsi      # 0x9385
callq 0x2060
jmp 0x49d1
movq -0xe0(%rbp), %rdi
movq 0x9611(%rip), %rsi      # 0xdff0
movq 0x95c2(%rip), %rdx      # 0xdfa8
callq 0x2360
movq -0xe0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
callq 0x2160
jmp 0x4ce8
movl -0x1c(%rbp), %eax
movq %rax, -0xf0(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x2e00
movq -0xf0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
leaq -0x50(%rbp), %rdi
callq 0x7170
jmp 0x4a3b
leaq -0x51(%rbp), %rdi
callq 0x3010
movb $0x0, -0x52(%rbp)
movl -0x20(%rbp), %eax
movq %rax, -0xf8(%rbp)
movq -0x28(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x50a0
jmp 0x4a61
leaq -0x79(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x5120
movq -0xd8(%rbp), %rdi
movq -0xf8(%rbp), %rsi
movq -0x100(%rbp), %rcx
leaq -0x78(%rbp), %rdx
callq 0x5140
jmp 0x4a91
leaq -0x79(%rbp), %rdi
callq 0x51c0
leaq -0x78(%rbp), %rdi
callq 0x51e0
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x4cb0
leaq -0x50(%rbp), %rdi
callq 0x71e0
movq %rdx, -0x110(%rbp)
movq %rax, -0x108(%rbp)
jmp 0x4ad8
movq -0x110(%rbp), %rax
movq -0x108(%rbp), %rcx
movq %rcx, -0xa8(%rbp)
movq %rax, -0xa0(%rbp)
leaq -0xa8(%rbp), %rdi
movl $0x1, %esi
callq 0x7210
movq %rdx, -0x120(%rbp)
movq %rax, -0x118(%rbp)
jmp 0x4b15
movq -0x120(%rbp), %rax
movq -0x118(%rbp), %rcx
movq %rcx, -0x98(%rbp)
movq %rax, -0x90(%rbp)
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x4120
jmp 0x4b46
movq -0x88(%rbp), %rsi
leaq -0x18(%rbp), %rdi
callq 0x7280
movq %rax, -0x128(%rbp)
jmp 0x4b5f
movq -0x128(%rbp), %rax
movb (%rax), %al
movb %al, -0x129(%rbp)
leaq -0x50(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x72e0
movb -0x129(%rbp), %cl
movb %cl, (%rax)
movl $0x0, -0xac(%rbp)
movl -0xac(%rbp), %eax
cmpl -0x20(%rbp), %eax
jae 0x4c97
movq -0xd8(%rbp), %rdi
movl -0xac(%rbp), %eax
movl %eax, %esi
callq 0x5200
movq %rax, -0xb8(%rbp)
movb -0xac(%rbp), %cl
incb %cl
movq -0xb8(%rbp), %rax
movb %cl, (%rax)
leaq -0xc8(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x7120
jmp 0x4bda
movq -0xb8(%rbp), %rax
movzbl (%rax), %edx
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x3db0
movb %al, -0x12a(%rbp)
jmp 0x4bff
movq -0xb8(%rbp), %rdi
addq $0x8, %rdi
movq -0x88(%rbp), %rsi
callq 0x72e0
movb -0x12a(%rbp), %cl
movb %cl, (%rax)
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x4b8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x51(%rbp), %rdi
callq 0x3010
jmp 0x4ce8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x4cdf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x79(%rbp), %rdi
callq 0x51c0
leaq -0x78(%rbp), %rdi
callq 0x51e0
jmp 0x4cdf
movq -0xd8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
callq 0x5040
jmp 0x4cdf
jmp 0x4c99
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x4aae
movb $0x1, -0x52(%rbp)
testb $0x1, -0x52(%rbp)
jne 0x4cc6
movq -0xd8(%rbp), %rdi
callq 0x5040
leaq -0x50(%rbp), %rdi
callq 0x2d50
movq -0xd0(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x2d50
movq -0x30(%rbp), %rdi
callq 0x2370
nopw %cs:(%rax,%rax)