// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %rdi, %r14
leaq -0x98(%rbp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x443f(%rip), %rsi      # 0x8163
leaq 0x4449(%rip), %rdx      # 0x8174
leaq -0xa8(%rbp), %rdi
callq 0x3140
leaq -0x78(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %rdi
callq 0x30a2
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x43f3(%rip), %rdx      # 0x8159
leaq -0x48(%rbp), %rdi
movq %rdx, %rsi
callq 0x3140
movq %r12, -0x118(%rbp)
movq %r14, -0x120(%rbp)
leaq -0xb8(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x43c7(%rip), %rdx      # 0x8159
leaq -0xc8(%rbp), %rdi
movq %rdx, %rsi
callq 0x3140
movq -0xa0(%rbp), %r15
movl $0x1, %r14d
subq %r15, %r14
movq -0x80(%rbp), %rax
movq %r14, %rcx
addq %rax, %rcx
je 0x40df
leaq -0x58(%rbp), %rbx
xorl %r12d, %r12d
leaq -0x68(%rbp), %r13
movq %r14, -0xf0(%rbp)
movq -0x88(%rbp), %rcx
cmpb $0x31, (%rcx,%r12)
jne 0x40cf
movq %r13, %rdi
leaq -0x88(%rbp), %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x2170
leaq -0xc8(%rbp), %rdi
movq %r13, %rsi
callq 0x21c0
movq -0x68(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3e1e
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
leaq 0x432a(%rip), %rcx      # 0x8159
xorl %r8d, %r8d
callq 0x2210
testq %r15, %r15
je 0x3eea
xorl %r14d, %r14d
movq -0xc8(%rbp), %rax
movb (%rax,%r14), %al
movq -0xa8(%rbp), %rcx
cmpb (%rcx,%r14), %al
jne 0x3e8d
movq %rbx, -0x68(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x30a2
movq -0x60(%rbp), %rsi
movl $0x1, %ecx
movq %r13, %rdi
xorl %edx, %edx
movl $0x30, %r8d
callq 0x2270
jmp 0x3ebd
movq %rbx, -0x68(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x30a2
movq -0x60(%rbp), %rsi
movl $0x1, %ecx
movq %r13, %rdi
xorl %edx, %edx
movl $0x31, %r8d
callq 0x2270
leaq -0x48(%rbp), %rdi
movq %r13, %rsi
callq 0x21c0
movq -0x68(%rbp), %rdi
cmpq %rbx, %rdi
je 0x3ede
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2160
incq %r14
cmpq %r14, %r15
jne 0x3e43
leaq -0x140(%rbp), %r14
movq %r14, %rdi
leaq -0x88(%rbp), %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0x2170
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq %r14, %rdi
callq 0x2090
leaq -0xd8(%rbp), %rsi
movq %rsi, -0xe8(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x3f45
movq %rdx, -0xe8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xd8(%rbp)
jmp 0x3f4b
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq -0xf0(%rbp), %r14
movq 0x8(%rax), %rdx
movq %rdx, -0xe0(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq (%r12,%r15), %rdx
leaq -0x110(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movq $-0x1, %rcx
callq 0x2170
movq -0xe8(%rbp), %rcx
movl $0xf, %edi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rcx
je 0x3fa9
movq -0xd8(%rbp), %rdi
movq -0xe0(%rbp), %r8
movq -0x110(%rbp), %rsi
movq -0x108(%rbp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0x3fe4
movl $0xf, %edi
leaq -0x100(%rbp), %r9
cmpq %r9, %rsi
je 0x3fdf
movq -0x100(%rbp), %rdi
cmpq %rdi, %rax
jbe 0x3ff2
leaq -0xe8(%rbp), %rdi
callq 0x2090
jmp 0x4002
leaq -0x110(%rbp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2190
movq %rbx, -0x68(%rbp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x401f
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0x4025
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, -0x60(%rbp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq -0x88(%rbp), %rdi
movq %r13, %rsi
callq 0x21c0
movq -0x68(%rbp), %rdi
cmpq %rbx, %rdi
je 0x4065
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x4087
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x40a9
movq -0xd8(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
je 0x40cb
movq -0x130(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x80(%rbp), %rax
incq %r12
leaq (%r14,%rax), %rcx
cmpq %rcx, %r12
jb 0x3dd3
movq -0x118(%rbp), %rax
movq 0x8(%rax), %rdx
addq $-0x10, %rdx
leaq -0x88(%rbp), %rsi
movq -0x120(%rbp), %r12
movq %r12, %rdi
movq $-0x1, %rcx
callq 0x2170
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
leaq -0x98(%rbp), %rbx
leaq -0x78(%rbp), %r14
leaq -0x38(%rbp), %r15
je 0x413c
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x4151
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x88(%rbp), %rdi
cmpq %r14, %rdi
je 0x4169
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xa8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x4184
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2160
movq %r12, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x423a
movq %rax, %r14
leaq -0x98(%rbp), %rbx
leaq -0x78(%rbp), %r15
leaq -0x38(%rbp), %r12
jmp 0x428a
movq %rax, %r14
jmp 0x429f
movq %rax, %r14
jmp 0x42b7
movq %rax, %r14
jmp 0x4218
movq %rax, %r14
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x41f6
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x2160
jmp 0x41f6
jmp 0x423a
movq %rax, %r14
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x4218
movq -0xd8(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
je 0x4259
movq -0x130(%rbp), %rsi
jmp 0x4251
jmp 0x423a
jmp 0x423a
jmp 0x423a
movq %rax, %r14
jmp 0x4259
jmp 0x4241
movq %rax, %r14
movq -0x68(%rbp), %rdi
cmpq %rbx, %rdi
je 0x4259
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2160
leaq -0x98(%rbp), %rbx
leaq -0x78(%rbp), %r15
leaq -0x38(%rbp), %r12
leaq -0xb8(%rbp), %rax
movq -0xc8(%rbp), %rdi
cmpq %rax, %rdi
je 0x428a
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x429f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0x42b7
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xa8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x42d2
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2160
movq %r14, %rdi
callq 0x2240