// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1518, %rsp           # imm = 0x1518
movq %rdi, %r14
movl $0x10, %eax
leaq (%rax,%rbp), %rcx
addq $-0x540, %rcx           # imm = 0xFAC0
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x210, %rax            # imm = 0x210
jne 0x31fc
movl $0x10, %eax
leaq (%rax,%rbp), %rcx
addq $-0x1540, %rcx          # imm = 0xEAC0
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x1010, %rax           # imm = 0x1010
jne 0x3227
leaq 0x4e2e(%rip), %rsi      # 0x8082
leaq -0x338(%rbp), %rdi
movl $0x10, %edx
callq 0x2180
leaq -0x2c8(%rbp), %rdi
callq 0x2060
testb %al, %al
je 0x3721
cmpq $0x0, 0x8(%r14)
je 0x36cd
movq $-0x1, %rbx
leaq -0x540(%rbp), %r15
xorl %r12d, %r12d
leaq -0x48(%rbp), %r13
movl $0x7d, %ecx
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2170
movq %r15, %rdi
movq %r13, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x32d0
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
addq $0x7d, %r12
incq %rbx
addq $0x20, %r15
cmpq 0x8(%r14), %r12
jb 0x3299
cmpq $-0x1, %rbx
je 0x36cd
leaq 0x1(%rbx), %rax
movq %rax, -0x110(%rbp)
leaq -0x1540(%rbp), %r14
leaq -0x538(%rbp), %rcx
xorl %r15d, %r15d
leaq -0xf8(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x8(%rcx), %rsi
movq %rcx, -0x118(%rbp)
movq (%rcx), %rdx
addq %rsi, %rdx
leaq -0x108(%rbp), %r12
movq %r12, %rdi
callq 0x30a2
leaq -0x48(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x398c
leaq -0x38(%rbp), %r12
movq %r14, %rdi
movq %r13, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x3368
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x338a
movq -0xf8(%rbp), %rsi
incq %rsi
callq 0x2160
cmpq %r15, %rbx
jne 0x3414
leaq -0xd8(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0xe8(%rbp), %r13
movq %r13, %rdi
callq 0x30a2
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
movl %ebx, %edx
movl $0x1, %ecx
callq 0x3a6c
movq %r14, %rdi
movq %r12, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x33f4
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x3495
movq -0xd8(%rbp), %rsi
jmp 0x348d
leaq -0xb8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0xc8(%rbp), %r13
movq %r13, %rdi
callq 0x30a2
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x3a6c
movq %r14, %rdi
movq %r12, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3473
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x3495
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2160
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %r12
movq %r12, %rdi
callq 0x30a2
movq %r12, %rdi
leaq 0x4c7b(%rip), %rsi      # 0x8138
callq 0x2280
leaq -0x138(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x3cf8
movq (%r14), %rcx
movq 0x8(%r14), %r8
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2190
leaq -0x38(%rbp), %r12
movq %r12, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x350b
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x3513
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
leaq -0x48(%rbp), %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x354b
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x138(%rbp), %rdi
leaq -0x128(%rbp), %rax
cmpq %rax, %rdi
je 0x356d
movq -0x128(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x3586
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2160
leaq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %r13
movq %r13, %rdi
callq 0x30a2
leaq -0x48(%rbp), %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x42da
movq %r14, %rdi
movq %r12, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x35e0
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x3602
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2160
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %r13
movq %r13, %rdi
callq 0x30a2
movq %r12, %rdi
movq %r13, %rsi
callq 0x438e
movq %r14, %rdi
movq %r12, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3655
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x3671
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2160
movq (%r14), %rsi
movq 0x8(%r14), %rdx
leaq -0x338(%rbp), %rdi
callq 0x21a0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
incq %r15
addq $0x20, %r14
movq -0x118(%rbp), %rcx
addq $0x20, %rcx
cmpq %r15, -0x110(%rbp)
jne 0x3307
movq 0x78fc(%rip), %rbx      # 0xafd0
leaq 0x4a6e(%rip), %rsi      # 0x8149
movl $0x10, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq 0x78ca(%rip), %rdi      # 0xafd0
callq 0x2030
movq %rax, %rdi
callq 0x20e0
leaq -0x338(%rbp), %rdi
callq 0x21d0
jmp 0x3767
movq 0x78a8(%rip), %rbx      # 0xafd0
leaq 0x4960(%rip), %rsi      # 0x808f
movl $0x1e, %edx
movq %rbx, %rdi
callq 0x21a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq 0x7876(%rip), %rdi      # 0xafd0
callq 0x2030
movq %rax, %rdi
callq 0x20e0
movq 0x785a(%rip), %rax      # 0xafc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x330(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x338(%rbp,%rcx)
callq 0x2110
leaq -0x240(%rbp), %rdi
callq 0x20a0
movq $-0x1000, %rbx          # imm = 0xF000
leaq -0x550(%rbp), %r14
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x37bf
movq (%r14), %rsi
incq %rsi
callq 0x2160
addq $-0x20, %r14
addq $0x20, %rbx
jne 0x37ab
movq $-0x200, %rbx           # imm = 0xFE00
leaq -0x350(%rbp), %r14
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x37eb
movq (%r14), %rsi
incq %rsi
callq 0x2160
addq $-0x20, %r14
addq $0x20, %rbx
jne 0x37d7
addq $0x1518, %rsp           # imm = 0x1518
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x392b
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x391f
movq -0xb8(%rbp), %rsi
jmp 0x3910
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x391f
movq -0xd8(%rbp), %rsi
jmp 0x3910
jmp 0x391c
jmp 0x391c
jmp 0x391c
jmp 0x391c
movq %rax, %rbx
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x391f
movq -0xf8(%rbp), %rsi
jmp 0x3910
jmp 0x391c
jmp 0x3899
movq %rax, %rbx
jmp 0x38c3
movq %rax, %rbx
movq -0x138(%rbp), %rdi
leaq -0x128(%rbp), %rax
cmpq %rax, %rdi
je 0x38c3
movq -0x128(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x391f
movq -0x58(%rbp), %rsi
jmp 0x3910
jmp 0x391c
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x391f
movq -0x98(%rbp), %rsi
jmp 0x3910
jmp 0x391c
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x391f
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2160
jmp 0x391f
jmp 0x391c
movq %rax, %rbx
leaq -0x338(%rbp), %rdi
callq 0x21e0
movq $-0x1000, %r14          # imm = 0xF000
leaq -0x550(%rbp), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x394d
movq (%r15), %rsi
incq %rsi
callq 0x2160
addq $-0x20, %r15
addq $0x20, %r14
jne 0x3939
movq $-0x200, %r14           # imm = 0xFE00
leaq -0x350(%rbp), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x3979
movq (%r15), %rsi
incq %rsi
callq 0x2160
addq $-0x20, %r15
addq $0x20, %r14
jne 0x3965
movq %rbx, %rdi
callq 0x2240
nop