// File: /workspace/github_cpp_makefile_star2_O3/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 0x3634(%rip), %rdi      # 0x5fd0
leaq 0x1667(%rip), %rsi      # 0x400a
movl $0xf, %edx
callq 0x2130
movq 0x361c(%rip), %rdi      # 0x5fd0
leaq 0x1660(%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 0x35e3(%rip), %rdi      # 0x5fd0
callq 0x2130
leaq 0x1621(%rip), %rsi      # 0x401a
movl $0x2, %edx
movq %rax, %rdi
callq 0x2130
movq 0x35c3(%rip), %rdi      # 0x5fd0
leaq 0x1609(%rip), %rsi      # 0x401d
movl $0x7, %edx
callq 0x2130
movq 0x35ab(%rip), %rdi      # 0x5fd0
leaq 0x15ef(%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 0x2a8e
movq 0x3571(%rip), %rbx      # 0x5fd0
leaq 0x15b5(%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 0x2a66
movq 0x353b(%rip), %rdi      # 0x5fd0
leaq 0x157f(%rip), %rsi      # 0x401b
movl $0x1, %edx
callq 0x2130
movq 0x3523(%rip), %rdi      # 0x5fd0
leaq 0x1571(%rip), %rsi      # 0x4025
movl $0x16, %edx
callq 0x2130
movq 0x350b(%rip), %rdi      # 0x5fd0
leaq 0x154f(%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 0x30d4
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
cmpq $0x21, %rax
jb 0x2c9c
movl $0x1, %r12d
leaq -0xc0(%rbp), %rbx
leaq -0xa0(%rbp), %r14
cmpl $0x100, %r13d           # imm = 0x100
je 0x2bca
cmpl $0x80, %r13d
je 0x2b85
cmpl $0x40, %r13d
jne 0x2c29
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2e42
movq %r12, %rsi
shlq $0x5, %rsi
addq -0x40(%rbp), %rsi
leaq -0x80(%rbp), %rdi
xorl %edx, %edx
callq 0x2e42
movq -0x80(%rbp), %rax
xorq %rax, -0x60(%rbp)
movq %rbx, %rdi
leaq -0x60(%rbp), %rsi
callq 0x3272
jmp 0x2c61
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2e90
movq %r12, %rsi
shlq $0x5, %rsi
addq -0x40(%rbp), %rsi
leaq -0x80(%rbp), %rdi
xorl %edx, %edx
callq 0x2e90
movq -0x80(%rbp), %rax
xorq %rax, -0x60(%rbp)
movq -0x78(%rbp), %rax
xorq %rax, -0x58(%rbp)
movq %rbx, %rdi
leaq -0x60(%rbp), %rsi
callq 0x3392
jmp 0x2c61
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2ede
movq %r12, %rsi
shlq $0x5, %rsi
addq -0x40(%rbp), %rsi
leaq -0x60(%rbp), %rdi
xorl %edx, %edx
callq 0x2ede
xorl %eax, %eax
movq -0x60(%rbp,%rax,8), %rcx
xorq %rcx, -0xc0(%rbp,%rax,8)
incq %rax
cmpq $0x4, %rax
jne 0x2bef
leaq -0x80(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x34c4
movq %r14, %rdi
movq %r15, %rsi
callq 0x2150
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
jmp 0x2c7a
leaq -0x60(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x2e42
movq %r12, %rsi
shlq $0x5, %rsi
addq -0x40(%rbp), %rsi
leaq -0x80(%rbp), %rdi
xorl %edx, %edx
callq 0x2e42
movq -0x80(%rbp), %rax
xorq %rax, -0x60(%rbp)
movq %rbx, %rdi
leaq -0x60(%rbp), %rsi
callq 0x3272
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2150
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x2c84
callq 0x20f0
incq %r12
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
sarq $0x5, %rax
cmpq %r12, %rax
ja 0x2b28
movq 0x332d(%rip), %rdi      # 0x5fd0
leaq 0x1392(%rip), %rsi      # 0x403c
movl $0xf, %edx
callq 0x2130
movq 0x3315(%rip), %rdi      # 0x5fd0
leaq 0x1359(%rip), %rsi      # 0x401b
movl $0x1, %edx
callq 0x2130
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq 0x32ef(%rip), %rdi      # 0x5fd0
callq 0x2130
leaq 0x132e(%rip), %rsi      # 0x401b
movl $0x1, %edx
movq %rax, %rdi
callq 0x2130
movq 0x32cf(%rip), %rdi      # 0x5fd0
leaq 0x1344(%rip), %rsi      # 0x404c
movl $0xf, %edx
callq 0x2130
movq 0x32b7(%rip), %rdi      # 0x5fd0
leaq 0x12fb(%rip), %rsi      # 0x401b
movl $0x1, %edx
callq 0x2130
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movq 0x3291(%rip), %rdi      # 0x5fd0
callq 0x2130
leaq 0x12d0(%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 0x2d77
callq 0x20f0
leaq -0x40(%rbp), %rdi
callq 0x300a
leaq -0xd0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2d95
callq 0x20f0
movq -0x138(%rbp), %rdi
cmpq %rbx, %rdi
je 0x2da6
callq 0x20f0
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2e01
jmp 0x2ddf
jmp 0x2dc0
movq %rax, %rbx
jmp 0x2e22
jmp 0x2e01
jmp 0x2de4
jmp 0x2de4
jmp 0x2de4
jmp 0x2de4
jmp 0x2de4
jmp 0x2de4
jmp 0x2de4
jmp 0x2de4
jmp 0x2de4
jmp 0x2de4
jmp 0x2de4
jmp 0x2de4
movq %rax, %rbx
jmp 0x2e0d
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x2e04
callq 0x20f0
jmp 0x2e04
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x300a
leaq -0xd0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2e22
callq 0x20f0
movq -0x138(%rbp), %rdi
leaq -0x128(%rbp), %rax
cmpq %rax, %rdi
je 0x2e3a
callq 0x20f0
movq %rbx, %rdi
callq 0x2180