// File: carellano8[P]Proyecto-Redes-I-2017/crc16.cpp
// Function: crc16::enviar(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void crc16::enviar(string msj){
    size_t i,n;
    string bufferMsj[MAXMSJ/MAXT];
    binario bufferB[MAXMSJ/MAXT*8];
    ofstream archivo("canalcrc.txt");

    if(archivo.is_open()){
        i=0;n=0;
        while(i<msj.size()){
            bufferMsj[n]=msj.substr(i,MAXT);
            i+=MAXT;n++;
        }

        for (i = 0; i < n; ++i){
            bufferB[i]=msjTobin(bufferMsj[i]);
            if(i==n-1){
                bufferB[i]=insertarCabecera(bufferB[i],i,1);// Inserta el bit de fin de trasmision demensaje
            }else{
                bufferB[i]=insertarCabecera(bufferB[i],i,0);
            }
            bufferB[i]=bufferB[i]+crc(bufferB[i]+"0000000000000000");
            bufferB[i]=relleno_Bit(bufferB[i]);
            bufferB[i]=insercion_banderas(bufferB[i]);
            //cout<<"Tamano: "<<bufferB[i].size()<<endl;
            archivo/*<<"Trama: "*/<<bufferB[i]<<endl;
        }
        cout<<"tramas Enviadas "<<endl;
        archivo.close();
    }else{

            cout<<"Se ha detectado algun un error"<<endl;
        }
    

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x16d0, %rsp           # imm = 0x16D0
movq %rdi, -0x1608(%rbp)
movq %rdi, -0x8(%rbp)
leaq -0x220(%rbp), %rax
movq %rax, %rcx
addq $0x200, %rcx            # imm = 0x200
movq %rcx, -0x1600(%rbp)
movq %rax, -0x15f8(%rbp)
movq -0x15f8(%rbp), %rdi
movq %rdi, -0x1610(%rbp)
callq 0x32d0
movq -0x1610(%rbp), %rax
movq -0x1600(%rbp), %rcx
addq $0x20, %rax
cmpq %rcx, %rax
movq %rax, -0x15f8(%rbp)
jne 0x46c5
leaq -0x1220(%rbp), %rax
movq %rax, %rcx
addq $0x1000, %rcx           # imm = 0x1000
movq %rcx, -0x1620(%rbp)
movq %rax, -0x1618(%rbp)
movq -0x1618(%rbp), %rdi
movq %rdi, -0x1628(%rbp)
callq 0x32d0
movq -0x1628(%rbp), %rax
movq -0x1620(%rbp), %rcx
addq $0x20, %rax
cmpq %rcx, %rax
movq %rax, -0x1618(%rbp)
jne 0x4715
leaq 0x5935(%rip), %rsi      # 0xa082
leaq -0x1420(%rbp), %rdi
movl $0x10, %edx
callq 0x3250
jmp 0x4760
leaq -0x1420(%rbp), %rdi
callq 0x3190
movb %al, -0x1629(%rbp)
jmp 0x4774
movb -0x1629(%rbp), %al
testb $0x1, %al
jne 0x4783
jmp 0x4cca
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x1608(%rbp), %rdi
movq -0x10(%rbp), %rax
movq %rax, -0x1638(%rbp)
callq 0x3170
movq %rax, %rcx
movq -0x1638(%rbp), %rax
cmpq %rcx, %rax
jae 0x4850
movq -0x1608(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x1450(%rbp), %rdi
movl $0x7d, %ecx
callq 0x3200
jmp 0x47db
movq -0x18(%rbp), %rax
leaq -0x220(%rbp), %rdi
shlq $0x5, %rax
addq %rax, %rdi
leaq -0x1450(%rbp), %rsi
callq 0x3290
leaq -0x1450(%rbp), %rdi
callq 0x3140
movq -0x10(%rbp), %rax
addq $0x7d, %rax
movq %rax, -0x10(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x4793
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1428(%rbp)
movl %eax, -0x142c(%rbp)
jmp 0x4db6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1428(%rbp)
movl %eax, -0x142c(%rbp)
jmp 0x4daa
movq $0x0, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x4c89
movq -0x10(%rbp), %rax
shlq $0x5, %rax
leaq -0x220(%rbp,%rax), %rsi
leaq -0x1490(%rbp), %rdi
callq 0x30e0
jmp 0x4884
leaq -0x1470(%rbp), %rdi
leaq -0x1490(%rbp), %rsi
callq 0x4e60
jmp 0x4899
movq -0x10(%rbp), %rax
leaq -0x1220(%rbp), %rdi
shlq $0x5, %rax
addq %rax, %rdi
leaq -0x1470(%rbp), %rsi
callq 0x3290
leaq -0x1470(%rbp), %rdi
callq 0x3140
leaq -0x1490(%rbp), %rdi
callq 0x3140
movq -0x10(%rbp), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x49a0
movq -0x10(%rbp), %rax
shlq $0x5, %rax
leaq -0x1220(%rbp,%rax), %rsi
leaq -0x14d0(%rbp), %rdi
callq 0x30e0
jmp 0x4902
movl -0x10(%rbp), %edx
leaq -0x14b0(%rbp), %rdi
leaq -0x14d0(%rbp), %rsi
movl $0x1, %ecx
callq 0x4fc0
jmp 0x491f
movq -0x10(%rbp), %rax
leaq -0x1220(%rbp), %rdi
shlq $0x5, %rax
addq %rax, %rdi
leaq -0x14b0(%rbp), %rsi
callq 0x3290
leaq -0x14b0(%rbp), %rdi
callq 0x3140
leaq -0x14d0(%rbp), %rdi
callq 0x3140
jmp 0x4a33
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1428(%rbp)
movl %eax, -0x142c(%rbp)
leaq -0x1490(%rbp), %rdi
callq 0x3140
jmp 0x4daa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1428(%rbp)
movl %eax, -0x142c(%rbp)
leaq -0x14d0(%rbp), %rdi
callq 0x3140
jmp 0x4daa
movq -0x10(%rbp), %rax
shlq $0x5, %rax
leaq -0x1220(%rbp,%rax), %rsi
leaq -0x1510(%rbp), %rdi
callq 0x30e0
jmp 0x49be
movl -0x10(%rbp), %edx
leaq -0x14f0(%rbp), %rdi
leaq -0x1510(%rbp), %rsi
xorl %ecx, %ecx
callq 0x4fc0
jmp 0x49d8
movq -0x10(%rbp), %rax
leaq -0x1220(%rbp), %rdi
shlq $0x5, %rax
addq %rax, %rdi
leaq -0x14f0(%rbp), %rsi
callq 0x3290
leaq -0x14f0(%rbp), %rdi
callq 0x3140
leaq -0x1510(%rbp), %rdi
callq 0x3140
jmp 0x4a33
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1428(%rbp)
movl %eax, -0x142c(%rbp)
leaq -0x1510(%rbp), %rdi
callq 0x3140
jmp 0x4daa
movq -0x10(%rbp), %rax
shlq $0x5, %rax
leaq -0x1220(%rbp,%rax), %rsi
movq %rsi, -0x1640(%rbp)
leaq 0x56e7(%rip), %rdx      # 0xa138
leaq -0x1570(%rbp), %rdi
callq 0x64b0
jmp 0x4a5f
leaq -0x1550(%rbp), %rdi
leaq -0x1570(%rbp), %rsi
callq 0x5150
jmp 0x4a74
movq -0x1640(%rbp), %rsi
leaq -0x1530(%rbp), %rdi
leaq -0x1550(%rbp), %rdx
callq 0x6460
jmp 0x4a90
movq -0x10(%rbp), %rax
shlq $0x5, %rax
leaq -0x1220(%rbp,%rax), %rdi
leaq -0x1530(%rbp), %rsi
movq %rsi, -0x1648(%rbp)
callq 0x3290
movq -0x1648(%rbp), %rdi
callq 0x3140
leaq -0x1550(%rbp), %rdi
callq 0x3140
leaq -0x1570(%rbp), %rdi
callq 0x3140
movq -0x10(%rbp), %rax
shlq $0x5, %rax
leaq -0x1220(%rbp,%rax), %rsi
leaq -0x15b0(%rbp), %rdi
callq 0x30e0
jmp 0x4af5
leaq -0x1590(%rbp), %rdi
leaq -0x15b0(%rbp), %rsi
callq 0x5650
jmp 0x4b0a
movq -0x10(%rbp), %rax
shlq $0x5, %rax
leaq -0x1220(%rbp,%rax), %rdi
leaq -0x1590(%rbp), %rsi
movq %rsi, -0x1650(%rbp)
callq 0x3290
movq -0x1650(%rbp), %rdi
callq 0x3140
leaq -0x15b0(%rbp), %rdi
callq 0x3140
movq -0x10(%rbp), %rax
shlq $0x5, %rax
leaq -0x1220(%rbp,%rax), %rsi
leaq -0x15f0(%rbp), %rdi
callq 0x30e0
jmp 0x4b63
leaq -0x15d0(%rbp), %rdi
leaq -0x15f0(%rbp), %rsi
callq 0x57b0
jmp 0x4b78
movq -0x10(%rbp), %rax
shlq $0x5, %rax
leaq -0x1220(%rbp,%rax), %rdi
leaq -0x15d0(%rbp), %rsi
movq %rsi, -0x1660(%rbp)
callq 0x3290
movq -0x1660(%rbp), %rdi
callq 0x3140
leaq -0x15f0(%rbp), %rdi
callq 0x3140
movq -0x10(%rbp), %rax
shlq $0x5, %rax
leaq -0x1220(%rbp,%rax), %rsi
leaq -0x1420(%rbp), %rdi
callq 0x31d0
movq %rax, -0x1658(%rbp)
jmp 0x4bd8
movq -0x1658(%rbp), %rdi
movq 0x83da(%rip), %rsi      # 0xcfc0
callq 0x3210
jmp 0x4bed
jmp 0x4bef
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x4858
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1428(%rbp)
movl %eax, -0x142c(%rbp)
jmp 0x4c32
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1428(%rbp)
movl %eax, -0x142c(%rbp)
leaq -0x1550(%rbp), %rdi
callq 0x3140
leaq -0x1570(%rbp), %rdi
callq 0x3140
jmp 0x4daa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1428(%rbp)
movl %eax, -0x142c(%rbp)
leaq -0x15b0(%rbp), %rdi
callq 0x3140
jmp 0x4daa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1428(%rbp)
movl %eax, -0x142c(%rbp)
leaq -0x15f0(%rbp), %rdi
callq 0x3140
jmp 0x4daa
movq 0x8340(%rip), %rdi      # 0xcfd0
leaq 0x54b2(%rip), %rsi      # 0xa149
callq 0x31f0
movq %rax, -0x1668(%rbp)
jmp 0x4ca5
movq -0x1668(%rbp), %rdi
movq 0x830d(%rip), %rsi      # 0xcfc0
callq 0x3210
jmp 0x4cba
leaq -0x1420(%rbp), %rdi
callq 0x32e0
jmp 0x4cc8
jmp 0x4cfd
movq 0x82ff(%rip), %rdi      # 0xcfd0
leaq 0x53b7(%rip), %rsi      # 0xa08f
callq 0x31f0
movq %rax, -0x1670(%rbp)
jmp 0x4ce6
movq -0x1670(%rbp), %rdi
movq 0x82cc(%rip), %rsi      # 0xcfc0
callq 0x3210
jmp 0x4cfb
jmp 0x4cfd
leaq -0x1420(%rbp), %rdi
callq 0x3300
leaq -0x1220(%rbp), %rax
movq %rax, -0x1680(%rbp)
addq $0x1000, %rax           # imm = 0x1000
movq %rax, -0x1678(%rbp)
movq -0x1678(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x1688(%rbp)
callq 0x3140
movq -0x1680(%rbp), %rcx
movq -0x1688(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1678(%rbp)
jne 0x4d24
leaq -0x220(%rbp), %rax
movq %rax, -0x1698(%rbp)
addq $0x200, %rax            # imm = 0x200
movq %rax, -0x1690(%rbp)
movq -0x1690(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x16a0(%rbp)
callq 0x3140
movq -0x1698(%rbp), %rcx
movq -0x16a0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1690(%rbp)
jne 0x4d70
addq $0x16d0, %rsp           # imm = 0x16D0
popq %rbp
retq
leaq -0x1420(%rbp), %rdi
callq 0x3300
leaq -0x1220(%rbp), %rax
movq %rax, -0x16b0(%rbp)
addq $0x1000, %rax           # imm = 0x1000
movq %rax, -0x16a8(%rbp)
movq -0x16a8(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x16b8(%rbp)
callq 0x3140
movq -0x16b0(%rbp), %rcx
movq -0x16b8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x16a8(%rbp)
jne 0x4dd1
leaq -0x220(%rbp), %rax
movq %rax, -0x16c8(%rbp)
addq $0x200, %rax            # imm = 0x200
movq %rax, -0x16c0(%rbp)
movq -0x16c0(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x16d0(%rbp)
callq 0x3140
movq -0x16c8(%rbp), %rcx
movq -0x16d0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x16c0(%rbp)
jne 0x4e1d
jmp 0x4e50
movq -0x1428(%rbp), %rdi
callq 0x3390
nopl (%rax)