// File: /workspace/github_cpp_makefile_star2_O1/rupc[P]xor-secret-sharing-scheme/main.cpp
// Function: main
int main(int argc, char *argv[])
{
    srand (time(NULL));
    XORSecretShares xss(128);
    std::cout << "original secret" << "\n";
    std::string orig_secret = xss.generate_random_secret();
    std::cout << orig_secret << "\n\n";
    std::cout << "shadows" << "\n";
    auto shadows = xss.split(14);

    for (const auto &p : shadows) {
        std::cout << p << "\n";
    }

    std::cout << "\n";
    std::cout << "All shadows are XOR-ed" << "\n";

    auto key_size = xss.get_key_size();
    std::string xored_share = shadows[0];

    for (int i = 1; i < shadows.size(); i++) {
        switch (key_size) {
            case 64: {
                std::bitset<64> xored_share_64(xored_share);
                std::bitset<64> share_64(shadows[i]);
                xored_share = (xored_share_64^=share_64).to_string();
            }
                break;
            case 128: {
                std::bitset<128> xored_share_128(xored_share);
                std::bitset<128> share_128(shadows[i]);
                xored_share = (xored_share_128^=share_128).to_string();
            }
                break;
            case 256: {
                std::bitset<256> xored_share_256(xored_share);
                std::bitset<256> _share_256(shadows[i]);
                xored_share = (xored_share_256^=_share_256).to_string();
            }
                break;
            default: {
                std::bitset<64> xored_share_64(xored_share);
                std::bitset<64> _share_64(shadows[i]);
                xored_share = (xored_share_64^=_share_64).to_string();
            }
                break;
        }
        
    }

    std::cout << "Retrived Secret" << "\n";
    std::cout << xored_share << "\n";

    std::cout << "Original Secret" << "\n";
    std::cout << orig_secret << "\n";

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x20e0
movl %eax, %edi
callq 0x2100
leaq -0x128(%rbp), %rax
movl $0x80, -0x18(%rax)
movq %rax, -0x10(%rax)
movq %rbx, -0x8(%rax)
movb $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movq %rbx, 0x40(%rax)
movb $0x1, -0x14(%rax)
movq 0x3635(%rip), %rdi      # 0x5fd0
leaq 0x1668(%rip), %rsi      # 0x400a
movl $0xf, %edx
callq 0x2130
movq 0x361d(%rip), %rdi      # 0x5fd0
leaq 0x1661(%rip), %rsi      # 0x401b
movl $0x1, %edx
callq 0x2130
leaq -0xe0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x22fc
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movq 0x35e4(%rip), %rdi      # 0x5fd0
callq 0x2130
leaq 0x1622(%rip), %rsi      # 0x401a
movl $0x2, %edx
movq %rax, %rdi
callq 0x2130
movq 0x35c4(%rip), %rdi      # 0x5fd0
leaq 0x160a(%rip), %rsi      # 0x401d
movl $0x7, %edx
callq 0x2130
movq 0x35ac(%rip), %rdi      # 0x5fd0
leaq 0x15f0(%rip), %rsi      # 0x401b
movl $0x1, %edx
callq 0x2130
leaq -0x40(%rbp), %rdi
leaq -0x140(%rbp), %rsi
movl $0xe, %edx
callq 0x2542
movq -0x40(%rbp), %r15
movq -0x38(%rbp), %r12
cmpq %r12, %r15
je 0x2a8d
movq 0x3572(%rip), %rbx      # 0x5fd0
leaq 0x15b6(%rip), %r14      # 0x401b
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq %rbx, %rdi
callq 0x2130
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2130
addq $0x20, %r15
cmpq %r12, %r15
jne 0x2a65
movq 0x353c(%rip), %rdi      # 0x5fd0
leaq 0x1580(%rip), %rsi      # 0x401b
movl $0x1, %edx
callq 0x2130
movq 0x3524(%rip), %rdi      # 0x5fd0
leaq 0x1572(%rip), %rsi      # 0x4025
movl $0x16, %edx
callq 0x2130
movq 0x350c(%rip), %rdi      # 0x5fd0
leaq 0x1550(%rip), %rsi      # 0x401b
movl $0x1, %edx
callq 0x2130
movl -0x140(%rbp), %r13d
movq -0x40(%rbp), %rax
leaq -0x90(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %rdi
callq 0x30cc
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
cmpq $0x21, %rax
jb 0x2ca0
movl $0x1, %r12d
leaq -0xc0(%rbp), %rbx
leaq -0xa0(%rbp), %r14
cmpl $0x100, %r13d           # imm = 0x100
je 0x2bce
cmpl $0x80, %r13d
je 0x2b84
cmpl $0x40, %r13d
jne 0x2c2d
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2e46
movq %r12, %rsi
shlq $0x5, %rsi
addq -0x40(%rbp), %rsi
leaq -0x80(%rbp), %rdi
xorl %edx, %edx
callq 0x2e46
movq -0x80(%rbp), %rax
xorq %rax, -0x60(%rbp)
movq %rbx, %rdi
leaq -0x60(%rbp), %rsi
callq 0x3260
jmp 0x2c65
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2e94
movq %r12, %rsi
shlq $0x5, %rsi
addq -0x40(%rbp), %rsi
leaq -0x80(%rbp), %rdi
xorl %edx, %edx
callq 0x2e94
xorl %eax, %eax
movq -0x80(%rbp,%rax,8), %rcx
xorq %rcx, -0x60(%rbp,%rax,8)
incq %rax
cmpq $0x1, %rax
je 0x2baa
movq %rbx, %rdi
leaq -0x60(%rbp), %rsi
callq 0x3378
jmp 0x2c65
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2ee2
movq %r12, %rsi
shlq $0x5, %rsi
addq -0x40(%rbp), %rsi
leaq -0x60(%rbp), %rdi
xorl %edx, %edx
callq 0x2ee2
xorl %eax, %eax
movq -0x60(%rbp,%rax,8), %rcx
xorq %rcx, -0xc0(%rbp,%rax,8)
incq %rax
cmpq $0x4, %rax
jne 0x2bf3
leaq -0x80(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x34a2
movq %r14, %rdi
movq %r15, %rsi
callq 0x2150
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
jmp 0x2c7e
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2e46
movq %r12, %rsi
shlq $0x5, %rsi
addq -0x40(%rbp), %rsi
leaq -0x80(%rbp), %rdi
xorl %edx, %edx
callq 0x2e46
movq -0x80(%rbp), %rax
xorq %rax, -0x60(%rbp)
movq %rbx, %rdi
leaq -0x60(%rbp), %rsi
callq 0x3260
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2150
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x2c88
callq 0x20f0
incq %r12
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
sarq $0x5, %rax
cmpq %r12, %rax
ja 0x2b27
movq 0x3329(%rip), %rdi      # 0x5fd0
leaq 0x138e(%rip), %rsi      # 0x403c
movl $0xf, %edx
callq 0x2130
movq 0x3311(%rip), %rdi      # 0x5fd0
leaq 0x1355(%rip), %rsi      # 0x401b
movl $0x1, %edx
callq 0x2130
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq 0x32eb(%rip), %rdi      # 0x5fd0
callq 0x2130
leaq 0x132a(%rip), %rsi      # 0x401b
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
movq 0x32cb(%rip), %rdi      # 0x5fd0
leaq 0x1340(%rip), %rsi      # 0x404c
movl $0xf, %edx
callq 0x2130
movq 0x32b3(%rip), %rdi      # 0x5fd0
leaq 0x12f7(%rip), %rsi      # 0x401b
movl $0x1, %edx
callq 0x2130
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movq 0x328d(%rip), %rdi      # 0x5fd0
callq 0x2130
leaq 0x12cc(%rip), %rsi      # 0x401b
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
leaq -0x128(%rbp), %rbx
je 0x2d7b
callq 0x20f0
leaq -0x40(%rbp), %rdi
callq 0x300c
leaq -0xd0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2d99
callq 0x20f0
movq -0x138(%rbp), %rdi
cmpq %rbx, %rdi
je 0x2daa
callq 0x20f0
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2e05
jmp 0x2de3
jmp 0x2dc4
movq %rax, %rbx
jmp 0x2e26
jmp 0x2e05
jmp 0x2de8
jmp 0x2de8
jmp 0x2de8
jmp 0x2de8
jmp 0x2de8
jmp 0x2de8
jmp 0x2de8
jmp 0x2de8
jmp 0x2de8
jmp 0x2de8
jmp 0x2de8
jmp 0x2de8
movq %rax, %rbx
jmp 0x2e11
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x2e08
callq 0x20f0
jmp 0x2e08
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x300c
leaq -0xd0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2e26
callq 0x20f0
movq -0x138(%rbp), %rdi
leaq -0x128(%rbp), %rax
cmpq %rax, %rdi
je 0x2e3e
callq 0x20f0
movq %rbx, %rdi
callq 0x2180