// File: sellibitze[P]secretshare-cxx/main.cpp
// Function: main
int main(int argc, char* argv[])
{
	try {
		int k = 0;
		int n = 0;
		mode m = mode::dontknow;
		if (argc >= 2) {
			if (strcmp(argv[1], "e") == 0) m = mode::encode; else
			if (strcmp(argv[1], "d") == 0) m = mode::decode;
		}
		if (m == mode::encode) {
			if (argc < 4) {
				cerr << "Missing two encoding parameters\n";
				return EXIT_FAILURE;
			}
			k = atoi(argv[2]);
			n = atoi(argv[3]);
			if (k < 1 || k > 255) {
				cerr << "K needs to be within 1...255\n";
				return EXIT_FAILURE;
			}
			if (n < k || n > 255) {
				cerr << "N needs to be within K...255\n";
				return EXIT_FAILURE;
			}
		}
		switch (m) {
			case mode::encode:
				do_encode(k, n);
				break;
			case mode::decode:
				do_decode();
				break;
			case mode::dontknow:
				cout << "\n"
"This program sss is an implementation of Shamir's secret sharing scheme.\n"
"\n"
"Usage: sss <mode> [K N]\n"
"\n"
"Encoding (reading secret data from STDIN and writing N shares to STDOUT of\n"
"which K shares are necessary to decode the secret again):\n"
"   secretshare e K N\n"
"\n"
"Decoding (reading shares from STDIN and writing decoded secret to STDOUT)\n"
"   secretshare d\n" << endl;
				return argc==1 ? EXIT_SUCCESS : EXIT_FAILURE;
		}
		return EXIT_SUCCESS;
	} catch (exception const& x) {
		cerr << "Exception: " << x.what() << endl;
		return EXIT_FAILURE;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x2, -0x8(%rbp)
jl 0x43f7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x5122(%rip), %rsi      # 0x94e2
callq 0x22d0
cmpl $0x0, %eax
jne 0x43d3
movl $0x1, -0x1c(%rbp)
jmp 0x43f5
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x50e4(%rip), %rsi      # 0x94c6
callq 0x22d0
cmpl $0x0, %eax
jne 0x43f3
movl $0x2, -0x1c(%rbp)
jmp 0x43f5
jmp 0x43f7
cmpl $0x1, -0x1c(%rbp)
jne 0x4534
cmpl $0x4, -0x8(%rbp)
jge 0x44b0
movq 0x9bd6(%rip), %rdi      # 0xdfe8
leaq 0x4d72(%rip), %rsi      # 0x918b
callq 0x21a0
jmp 0x4420
movl $0x1, -0x4(%rbp)
jmp 0x45ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x45d3
movq -0x28(%rbp), %rdi
callq 0x2070
movq %rax, -0x38(%rbp)
movq 0x9b8c(%rip), %rdi      # 0xdfe8
leaq 0x4ee0(%rip), %rsi      # 0x9343
callq 0x21a0
movq %rax, -0x40(%rbp)
jmp 0x446e
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0x40(%rbp), %rdi
movq %rax, %rsi
callq 0x21a0
movq %rax, -0x48(%rbp)
jmp 0x448d
movq -0x48(%rbp), %rdi
movq 0x9af0(%rip), %rsi      # 0xdf88
callq 0x21f0
jmp 0x449f
movl $0x1, -0x4(%rbp)
callq 0x2340
jmp 0x45ca
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2310
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2310
movl %eax, -0x18(%rbp)
cmpl $0x1, -0x14(%rbp)
jl 0x44df
cmpl $0xff, -0x14(%rbp)
jle 0x4500
movq 0x9b02(%rip), %rdi      # 0xdfe8
leaq 0x4cbf(%rip), %rsi      # 0x91ac
callq 0x21a0
jmp 0x44f4
movl $0x1, -0x4(%rbp)
jmp 0x45ca
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jl 0x4511
cmpl $0xff, -0x18(%rbp)
jle 0x4532
movq 0x9ad0(%rip), %rdi      # 0xdfe8
leaq 0x4cab(%rip), %rsi      # 0x91ca
callq 0x21a0
jmp 0x4526
movl $0x1, -0x4(%rbp)
jmp 0x45ca
jmp 0x4534
movl -0x1c(%rbp), %eax
movl %eax, -0x4c(%rbp)
testl %eax, %eax
je 0x456c
jmp 0x4540
movl -0x4c(%rbp), %eax
subl $0x1, %eax
je 0x4554
jmp 0x454a
movl -0x4c(%rbp), %eax
subl $0x2, %eax
je 0x4563
jmp 0x45ac
movl -0x14(%rbp), %edi
movl -0x18(%rbp), %esi
callq 0x45f0
jmp 0x4561
jmp 0x45ac
callq 0x4760
jmp 0x456a
jmp 0x45ac
movq 0x9a45(%rip), %rdi      # 0xdfb8
leaq 0x4c6e(%rip), %rsi      # 0x91e8
callq 0x21a0
movq %rax, -0x58(%rbp)
jmp 0x4585
movq -0x58(%rbp), %rdi
movq 0x99f8(%rip), %rsi      # 0xdf88
callq 0x21f0
jmp 0x4597
movl -0x8(%rbp), %edx
movl $0x1, %eax
xorl %ecx, %ecx
cmpl $0x1, %edx
cmovel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x45ca
movl $0x0, -0x4(%rbp)
jmp 0x45ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x2340
jmp 0x45c8
jmp 0x45d3
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x2370
movq %rax, %rdi
callq 0x2ec0
nopw %cs:(%rax,%rax)