// File: /workspace/github_cpp_makefile_star2_O2/carellano8[P]Proyecto-Redes-I-2017/crc16.cpp
// Function: crc16::crc(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
binario crc16::crc(binario bin_in){
        //Polinomio genrador x16+x15+x2+1
        binario crc16="11000000000000101";//polinomio generador
        binario bin_out=bin_in, resto="", aux="";//copia de la trama inicial los r bit 0 del grado del polinomio
        //resto de la divicion xor, auxiliar
        size_t i,crcLong=crc16.size();//variable de for y longitud de el polinomio

        for (i = 0; i <bin_out.size()-crcLong+1 ; i++)
        {
            if (bin_out[i]=='1')
            {
                aux=bin_out.substr(i,crcLong);
                // cout<<"aux "<<aux<<endl;
                resto="";
                for (size_t j = 0; j < crcLong; j++) {
                           if(aux[j]==crc16[j]){
                             resto=resto+'0';
                           }
                           else{
                             resto=resto+'1';
                           }
                }
                bin_out=bin_out.substr(0,i)+resto+bin_out.substr(i+crcLong);
            // cout<<"bin "<<bin_out<<endl;
            }

        }
      
        return bin_out.substr(bin_in.size()-16);
        }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x2e96(%rip), %rsi      # 0x6163
leaq -0xa0(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x2c1a
leaq -0x50(%rbp), %rdi
movq %r14, %rsi
callq 0x21c0
leaq 0x2e69(%rip), %rsi      # 0x6159
leaq -0xe0(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0x2c1a
movq %r14, -0x58(%rbp)
movq %rbx, -0x60(%rbp)
leaq 0x2e4a(%rip), %rsi      # 0x6159
leaq -0x80(%rbp), %rdi
leaq -0x140(%rbp), %rdx
callq 0x2c1a
movq -0x98(%rbp), %r15
xorl %r12d, %r12d
leaq -0x140(%rbp), %r13
leaq -0x50(%rbp), %rbx
leaq -0xe0(%rbp), %r14
movq -0x48(%rbp), %rax
subq %r15, %rax
incq %rax
cmpq %rax, %r12
jae 0x3485
movq -0x50(%rbp), %rax
cmpb $0x31, (%rax,%r12)
jne 0x347d
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x2160
movq %r12, -0x30(%rbp)
leaq -0x80(%rbp), %rdi
movq %r13, %rsi
callq 0x21a0
movq %r13, %rdi
callq 0x20a0
movq %r14, %rdi
leaq 0x2dc9(%rip), %rsi      # 0x6159
callq 0x2270
xorl %ebx, %ebx
cmpq %rbx, %r15
je 0x33e5
movq -0x80(%rbp), %rax
movb (%rax,%rbx), %al
movq -0xa0(%rbp), %rcx
cmpb (%rcx,%rbx), %al
jne 0x33bf
movq %r13, %rdi
movq %r14, %rsi
pushq $0x30
popq %rdx
callq 0x3db9
jmp 0x33cd
movq %r13, %rdi
movq %r14, %rsi
pushq $0x31
popq %rdx
callq 0x3db9
movq %r14, %rdi
movq %r13, %rsi
callq 0x21a0
movq %r13, %rdi
callq 0x20a0
incq %rbx
jmp 0x3397
leaq -0x100(%rbp), %r12
movq %r12, %rdi
leaq -0x50(%rbp), %rbx
movq %rbx, %rsi
xorl %edx, %edx
movq -0x30(%rbp), %rcx
callq 0x2160
leaq -0x120(%rbp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x3e65
movq -0x30(%rbp), %rax
leaq (%rax,%r15), %rdx
leaq -0xc0(%rbp), %rdi
movq %rbx, %rsi
pushq $-0x1
popq %rcx
callq 0x2160
movq %r13, %rdi
leaq -0x120(%rbp), %r12
movq %r12, %rsi
leaq -0xc0(%rbp), %rdx
callq 0x3df4
movq %rbx, %rdi
movq %r13, %rsi
callq 0x21a0
movq %r13, %rdi
callq 0x20a0
leaq -0xc0(%rbp), %rdi
callq 0x20a0
movq %r12, %rdi
callq 0x20a0
leaq -0x100(%rbp), %rdi
callq 0x20a0
movq -0x30(%rbp), %r12
incq %r12
jmp 0x333b
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rdx
addq $-0x10, %rdx
leaq -0x50(%rbp), %rsi
pushq $-0x1
popq %rcx
movq -0x60(%rbp), %rbx
movq %rbx, %rdi
callq 0x2160
leaq -0x80(%rbp), %rdi
callq 0x20a0
leaq -0xe0(%rbp), %rdi
callq 0x20a0
leaq -0x50(%rbp), %rdi
callq 0x20a0
leaq -0xa0(%rbp), %rdi
callq 0x20a0
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x352f
movq %rax, %rbx
jmp 0x353b
movq %rax, %rbx
jmp 0x3547
movq %rax, %rbx
jmp 0x3550
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x20a0
jmp 0x3508
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0x20a0
jmp 0x3519
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0x20a0
jmp 0x3532
jmp 0x352f
jmp 0x352f
jmp 0x352f
jmp 0x352f
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x20a0
leaq -0xe0(%rbp), %rdi
callq 0x20a0
leaq -0x50(%rbp), %rdi
callq 0x20a0
leaq -0xa0(%rbp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x2230