// File: robertomaldonado[P]HypercubeTopologyRouting/links.cpp
// Function: recursive_flip(std::vector<bool, std::allocator<bool>>, std::vector<bool, std::allocator<bool>>, std::vector<bool, std::allocator<bool>>)
void recursive_flip( vector<bool> vector_src, vector<bool> vector_dst, vector<bool> current_xor){
    int current;
    vector<bool> vector_original = vector_src;
        //000 to 011
        // 000, 001, 011 //xored is 010
        // 000, 010, 011 //xored is 000
    current = bin_vector_to_int( bits_for_node, vector_src);
    cout << "Currently at node:  " << current << endl;

    int a = bin_vector_to_int(bits_for_node, vector_src);
    int b = bin_vector_to_int(bits_for_node, vector_dst);
    int c = a^b;
    current_xor = int_to_bin_vector(bits_for_node, c);

    if( c == 0 ){
        cout << "Restart.."<<endl;
        a = bin_vector_to_int(bits_for_node, vector_src);
        vector_src = vector_original;
        vector_src = int_to_bin_vector(bits_for_node, 0);
        c = a^b;
        current_xor = int_to_bin_vector(bits_for_node, c);
    }

    for(int i = 0 ; i < current_xor.size() ; i++){

        if(current_xor[i]) { //If the bits need to be flipped
                // current = bin_vector_to_int( bits_for_node, vector_src);
                // cout << "..." << current << endl;
                // current = bin_vector_to_int( bits_for_node, vector_src);
                // cout << "Currently at node:  " << current << endl;

                // int a = bin_vector_to_int(bits_for_node, vector_src);
                // int b = bin_vector_to_int(bits_for_node, vector_dst);
                // int c = a^b;
                // current_xor = int_to_bin_vector(bits_for_node, c);

                vector_src[i] = !vector_src[i]; //Flip a bit
                current = bin_vector_to_int( bits_for_node, vector_src);

                cout << "Hop to node:  " << current << endl << endl;
                // recursive_flip(vector_src, vector_dst, current_xor);
                
        }
                // recursive_flip(vector_src, vector_dst, current_xor);     
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2a0, %rsp            # imm = 0x2A0
movq %rsi, %rax
movq %rdi, %rsi
movq %rsi, -0x1f0(%rbp)
movq %rax, -0x200(%rbp)
movq %rdx, -0x1f8(%rbp)
movq %rsi, -0x8(%rbp)
movq %rax, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x3c20
movq -0x1f0(%rbp), %rsi
movl 0xce54(%rip), %eax      # 0x1019c
movl %eax, -0x1e4(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3c20
jmp 0x3359
movl -0x1e4(%rbp), %edi
leaq -0x70(%rbp), %rsi
callq 0x8d30
movl %eax, -0x204(%rbp)
jmp 0x3370
movl -0x204(%rbp), %eax
movl %eax, -0x1c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3db0
movq 0xcc3f(%rip), %rdi      # 0xffc8
leaq 0x7d42(%rip), %rsi      # 0xb0d2
callq 0x21a0
movq %rax, -0x210(%rbp)
jmp 0x339e
movq -0x210(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x2270
movq %rax, -0x218(%rbp)
jmp 0x33b6
movq -0x218(%rbp), %rdi
movq 0xcbf4(%rip), %rsi      # 0xffb8
callq 0x21d0
jmp 0x33cb
movq -0x1f0(%rbp), %rsi
movl 0xcdc4(%rip), %eax      # 0x1019c
movl %eax, -0x21c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3c20
jmp 0x33ec
movl -0x21c(%rbp), %edi
leaq -0xa8(%rbp), %rsi
callq 0x8d30
movl %eax, -0x220(%rbp)
jmp 0x3406
leaq -0xa8(%rbp), %rdi
callq 0x3db0
movl -0x220(%rbp), %eax
movq -0x200(%rbp), %rsi
movl %eax, -0x80(%rbp)
movl 0xcd74(%rip), %eax      # 0x1019c
movl %eax, -0x224(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x3c20
jmp 0x343c
movl -0x224(%rbp), %edi
leaq -0xd8(%rbp), %rsi
callq 0x8d30
movl %eax, -0x228(%rbp)
jmp 0x3456
leaq -0xd8(%rbp), %rdi
callq 0x3db0
movl -0x228(%rbp), %eax
movl %eax, -0xac(%rbp)
movl -0x80(%rbp), %eax
movl -0xac(%rbp), %ecx
xorl %ecx, %eax
movl %eax, -0xdc(%rbp)
movl 0xcd17(%rip), %esi      # 0x1019c
movl -0xdc(%rbp), %edx
leaq -0x108(%rbp), %rdi
callq 0x8de0
jmp 0x3499
movq -0x1f8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x42f0
leaq -0x108(%rbp), %rdi
callq 0x3db0
cmpl $0x0, -0xdc(%rbp)
jne 0x3665
movq 0xcafc(%rip), %rdi      # 0xffc8
leaq 0x7c14(%rip), %rsi      # 0xb0e7
callq 0x21a0
movq %rax, -0x230(%rbp)
jmp 0x34e1
movq -0x230(%rbp), %rdi
movq 0xcac9(%rip), %rsi      # 0xffb8
callq 0x21d0
jmp 0x34f6
movq -0x1f0(%rbp), %rsi
movl 0xcc99(%rip), %eax      # 0x1019c
movl %eax, -0x234(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x3c20
jmp 0x3517
movl -0x234(%rbp), %edi
leaq -0x130(%rbp), %rsi
callq 0x8d30
movl %eax, -0x238(%rbp)
jmp 0x3531
movl -0x238(%rbp), %eax
movl %eax, -0x80(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x3db0
movq -0x1f0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x4360
jmp 0x3558
movl 0xcc3e(%rip), %esi      # 0x1019c
leaq -0x158(%rbp), %rdi
xorl %edx, %edx
callq 0x8de0
jmp 0x356e
movq -0x1f0(%rbp), %rdi
leaq -0x158(%rbp), %rsi
movq %rsi, -0x240(%rbp)
callq 0x42f0
movq -0x240(%rbp), %rdi
callq 0x3db0
movl -0x80(%rbp), %eax
movl -0xac(%rbp), %ecx
xorl %ecx, %eax
movl %eax, -0xdc(%rbp)
movl 0xcbf1(%rip), %esi      # 0x1019c
movl -0xdc(%rbp), %edx
leaq -0x180(%rbp), %rdi
callq 0x8de0
jmp 0x35bf
movq -0x1f8(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x42f0
leaq -0x180(%rbp), %rdi
callq 0x3db0
jmp 0x3665
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x3893
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3db0
jmp 0x3893
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x3db0
jmp 0x3893
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x3db0
jmp 0x3893
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x3db0
jmp 0x3893
movl $0x0, -0x184(%rbp)
movq -0x1f8(%rbp), %rdi
movslq -0x184(%rbp), %rax
movq %rax, -0x248(%rbp)
callq 0x3ac0
movq %rax, %rcx
movq -0x248(%rbp), %rax
cmpq %rcx, %rax
jae 0x3881
movq -0x1f8(%rbp), %rdi
movslq -0x184(%rbp), %rsi
callq 0x3b40
movq %rdx, -0x258(%rbp)
movq %rax, -0x250(%rbp)
jmp 0x36bf
movq -0x258(%rbp), %rax
movq -0x250(%rbp), %rcx
movq %rcx, -0x198(%rbp)
movq %rax, -0x190(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x3ba0
testb $0x1, %al
jne 0x36f0
jmp 0x386b
movq -0x1f0(%rbp), %rdi
movslq -0x184(%rbp), %rsi
callq 0x3b40
movq %rdx, -0x268(%rbp)
movq %rax, -0x260(%rbp)
jmp 0x3713
movq -0x268(%rbp), %rax
movq -0x260(%rbp), %rcx
movq %rcx, -0x1a8(%rbp)
movq %rax, -0x1a0(%rbp)
leaq -0x1a8(%rbp), %rdi
callq 0x3ba0
movq -0x1f0(%rbp), %rdi
xorb $0x1, %al
movb %al, -0x279(%rbp)
movslq -0x184(%rbp), %rsi
callq 0x3b40
movq %rdx, -0x278(%rbp)
movq %rax, -0x270(%rbp)
jmp 0x3766
movb -0x279(%rbp), %al
movq -0x278(%rbp), %rcx
movq -0x270(%rbp), %rdx
movq %rdx, -0x1b8(%rbp)
movq %rcx, -0x1b0(%rbp)
movzbl %al, %esi
andl $0x1, %esi
leaq -0x1b8(%rbp), %rdi
callq 0x3bd0
movq -0x1f0(%rbp), %rsi
movl 0xc9f5(%rip), %eax      # 0x1019c
movl %eax, -0x280(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x3c20
jmp 0x37bb
movl -0x280(%rbp), %edi
leaq -0x1e0(%rbp), %rsi
callq 0x8d30
movl %eax, -0x284(%rbp)
jmp 0x37d5
movl -0x284(%rbp), %eax
movl %eax, -0x1c(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x3db0
movq 0xc7d7(%rip), %rdi      # 0xffc8
leaq 0x78f9(%rip), %rsi      # 0xb0f1
callq 0x21a0
movq %rax, -0x290(%rbp)
jmp 0x3806
movq -0x290(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x2270
movq %rax, -0x298(%rbp)
jmp 0x381e
movq -0x298(%rbp), %rdi
movq 0xc78c(%rip), %rsi      # 0xffb8
callq 0x21d0
movq %rax, -0x2a0(%rbp)
jmp 0x383a
movq -0x2a0(%rbp), %rdi
movq 0xc770(%rip), %rsi      # 0xffb8
callq 0x21d0
jmp 0x384f
jmp 0x386b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x3db0
jmp 0x3893
jmp 0x386d
movl -0x184(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x184(%rbp)
jmp 0x366f
leaq -0x48(%rbp), %rdi
callq 0x3db0
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x3db0
movq -0x78(%rbp), %rdi
callq 0x2290
nopw %cs:(%rax,%rax)