// File: /workspace/github_cpp_makefile_star2_O1/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 0x4425(%rip), %rsi      # 0x8163
leaq 0x442f(%rip), %rdx      # 0x8174
leaq -0xa8(%rbp), %rdi
callq 0x315a
leaq -0x78(%rbp), %r15
movq %r15, -0x10(%r15)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %rdi
callq 0x30c0
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x43d9(%rip), %rdx      # 0x8159
leaq -0x48(%rbp), %rdi
movq %rdx, %rsi
callq 0x315a
movq %r12, -0x118(%rbp)
movq %r14, -0x120(%rbp)
leaq -0xb8(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x43ad(%rip), %rdx      # 0x8159
leaq -0xc8(%rbp), %rdi
movq %rdx, %rsi
callq 0x315a
movq -0xa0(%rbp), %r15
movl $0x1, %r14d
subq %r15, %r14
movq -0x80(%rbp), %rax
addq %r14, %rax
je 0x40f9
leaq -0x58(%rbp), %rbx
xorl %r12d, %r12d
leaq -0x68(%rbp), %r13
movq %r14, -0x110(%rbp)
movq -0x88(%rbp), %rax
cmpb $0x31, (%rax,%r12)
jne 0x40e6
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 0x3e35
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
leaq 0x4313(%rip), %rcx      # 0x8159
xorl %r8d, %r8d
callq 0x2210
testq %r15, %r15
je 0x3f01
xorl %r14d, %r14d
movq -0xc8(%rbp), %rax
movb (%rax,%r14), %al
movq -0xa8(%rbp), %rcx
cmpb (%rcx,%r14), %al
jne 0x3ea4
movq %rbx, -0x68(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x30c0
movq -0x60(%rbp), %rsi
movl $0x1, %ecx
movq %r13, %rdi
xorl %edx, %edx
movl $0x30, %r8d
callq 0x2270
jmp 0x3ed4
movq %rbx, -0x68(%rbp)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x30c0
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 0x3ef5
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2160
incq %r14
cmpq %r14, %r15
jne 0x3e5a
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 0x3f5c
movq %rdx, -0xe8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0xd8(%rbp)
jmp 0x3f62
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq -0x110(%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 -0x108(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movq $-0x1, %rcx
callq 0x2170
movq -0xe8(%rbp), %rcx
movl $0xf, %esi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rcx
je 0x3fc0
movq -0xd8(%rbp), %rsi
movq -0xe0(%rbp), %r8
movq -0x100(%rbp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x3ff8
movl $0xf, %esi
leaq -0xf8(%rbp), %rdi
cmpq %rdi, -0x108(%rbp)
je 0x3ff3
movq -0xf8(%rbp), %rsi
cmpq %rsi, %rax
jbe 0x400d
movq -0x108(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x2090
jmp 0x401d
leaq -0x108(%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 0x403a
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0x4040
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 0x4080
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x40a2
movq -0xf8(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x40c4
movq -0xd8(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
je 0x40e6
movq -0x130(%rbp), %rsi
incq %rsi
callq 0x2160
incq %r12
movq -0x80(%rbp), %rax
addq %r14, %rax
cmpq %rax, %r12
jb 0x3dea
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 0x4156
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x416b
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x88(%rbp), %rdi
cmpq %r14, %rdi
je 0x4183
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xa8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x419e
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 0x4254
movq %rax, %r14
leaq -0x98(%rbp), %rbx
leaq -0x78(%rbp), %r15
leaq -0x38(%rbp), %r12
jmp 0x42a4
movq %rax, %r14
jmp 0x42b9
movq %rax, %r14
jmp 0x42d1
movq %rax, %r14
jmp 0x4232
movq %rax, %r14
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x4210
movq -0xf8(%rbp), %rsi
incq %rsi
callq 0x2160
jmp 0x4210
jmp 0x4254
movq %rax, %r14
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x4232
movq -0xd8(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
je 0x4273
movq -0x130(%rbp), %rsi
jmp 0x426b
jmp 0x4254
jmp 0x4254
jmp 0x4254
movq %rax, %r14
jmp 0x4273
jmp 0x425b
movq %rax, %r14
movq -0x68(%rbp), %rdi
cmpq %rbx, %rdi
je 0x4273
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 0x42a4
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x42b9
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x88(%rbp), %rdi
cmpq %r15, %rdi
je 0x42d1
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xa8(%rbp), %rdi
cmpq %rbx, %rdi
je 0x42ec
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2160
movq %r14, %rdi
callq 0x2240