// File: 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
subq $0x210, %rsp            # imm = 0x210
movq %rsi, -0x1d0(%rbp)
movq %rdi, -0x1c8(%rbp)
movq %rdi, %rax
movq %rax, -0x1c0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x33a0
movq -0x1b8(%rbp), %rdx
leaq 0x4fca(%rip), %rsi      # 0xa163
leaq -0x30(%rbp), %rdi
callq 0x4340
jmp 0x51a4
leaq -0x31(%rbp), %rdi
callq 0x3240
movq -0x1d0(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x30e0
jmp 0x51bf
leaq -0x89(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x33a0
movq -0x1d8(%rbp), %rdx
leaq 0x4f79(%rip), %rsi      # 0xa159
leaq -0x88(%rbp), %rdi
callq 0x4340
jmp 0x51ee
leaq -0x89(%rbp), %rdi
callq 0x3240
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x33a0
movq -0x1e0(%rbp), %rdx
leaq 0x4f3e(%rip), %rsi      # 0xa159
leaq -0xb0(%rbp), %rdi
callq 0x4340
jmp 0x5229
leaq -0xb1(%rbp), %rdi
callq 0x3240
leaq -0x30(%rbp), %rdi
callq 0x3170
movq %rax, -0xc8(%rbp)
movq $0x0, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x1e8(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3170
movq %rax, %rcx
movq -0x1e8(%rbp), %rax
subq -0xc8(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x55b6
movq -0xc0(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x3430
movq %rax, -0x1f0(%rbp)
jmp 0x529e
movq -0x1f0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x31, %eax
jne 0x559d
movq -0xc0(%rbp), %rdx
movq -0xc8(%rbp), %rcx
leaq -0xe8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x3200
jmp 0x52d1
leaq -0xb0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
movq %rsi, -0x1f8(%rbp)
callq 0x3290
movq -0x1f8(%rbp), %rdi
callq 0x3140
leaq 0x4e5b(%rip), %rsi      # 0xa159
leaq -0x88(%rbp), %rdi
callq 0x32c0
jmp 0x530c
movq $0x0, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
cmpq -0xc8(%rbp), %rax
jae 0x548e
movq -0xf0(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x3430
movq %rax, -0x200(%rbp)
jmp 0x5347
movq -0x200(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x20c(%rbp)
movq -0xf0(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x3430
movq %rax, -0x208(%rbp)
jmp 0x5370
movl -0x20c(%rbp), %eax
movq -0x208(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x543c
leaq -0x110(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movl $0x30, %edx
callq 0x6560
jmp 0x53a2
leaq -0x88(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x3290
leaq -0x110(%rbp), %rdi
callq 0x3140
jmp 0x5475
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x3240
jmp 0x5646
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x563d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x89(%rbp), %rdi
callq 0x3240
jmp 0x5634
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xb1(%rbp), %rdi
callq 0x3240
jmp 0x5628
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x561c
leaq -0x130(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movl $0x31, %edx
callq 0x6560
jmp 0x5456
leaq -0x88(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x3290
leaq -0x130(%rbp), %rdi
callq 0x3140
jmp 0x5477
movq -0xf0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xf0(%rbp)
jmp 0x5317
movq -0xc0(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x190(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x3200
jmp 0x54ab
leaq -0x170(%rbp), %rdi
leaq -0x190(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x66b0
jmp 0x54c7
movq -0xc0(%rbp), %rdx
movq -0xc8(%rbp), %rax
addq %rax, %rdx
leaq -0x1b0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movq $-0x1, %rcx
callq 0x3200
jmp 0x54f1
leaq -0x150(%rbp), %rdi
leaq -0x170(%rbp), %rsi
leaq -0x1b0(%rbp), %rdx
callq 0x65e0
jmp 0x550d
leaq -0x68(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x3290
leaq -0x150(%rbp), %rdi
callq 0x3140
leaq -0x1b0(%rbp), %rdi
callq 0x3140
leaq -0x170(%rbp), %rdi
callq 0x3140
leaq -0x190(%rbp), %rdi
callq 0x3140
jmp 0x559d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x558f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5583
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x3140
leaq -0x170(%rbp), %rdi
callq 0x3140
leaq -0x190(%rbp), %rdi
callq 0x3140
jmp 0x561c
jmp 0x559f
movq -0xc0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc0(%rbp)
jmp 0x5250
movq -0x1d0(%rbp), %rdi
callq 0x3170
movq -0x1c8(%rbp), %rdi
movq %rax, %rdx
addq $-0x10, %rdx
leaq -0x68(%rbp), %rsi
movq $-0x1, %rcx
callq 0x3200
jmp 0x55e2
leaq -0xb0(%rbp), %rdi
callq 0x3140
leaq -0x88(%rbp), %rdi
callq 0x3140
leaq -0x68(%rbp), %rdi
callq 0x3140
leaq -0x30(%rbp), %rdi
callq 0x3140
movq -0x1c0(%rbp), %rax
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq
leaq -0xb0(%rbp), %rdi
callq 0x3140
leaq -0x88(%rbp), %rdi
callq 0x3140
leaq -0x68(%rbp), %rdi
callq 0x3140
leaq -0x30(%rbp), %rdi
callq 0x3140
movq -0x40(%rbp), %rdi
callq 0x3390
nop