// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x10
popq %rax
leaq (%rax,%rbp), %rcx
addq $-0x540, %rcx           # imm = 0xFAC0
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x210, %rax            # imm = 0x210
jne 0x2d0e
pushq $0x10
popq %rax
leaq (%rax,%rbp), %rcx
addq $-0x1540, %rcx          # imm = 0xEAC0
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x1010, %rax           # imm = 0x1010
jne 0x2d34
leaq 0x3324(%rip), %rsi      # 0x6082
leaq -0x340(%rbp), %rdi
pushq $0x10
popq %rdx
callq 0x2180
leaq -0x2d0(%rbp), %rdi
callq 0x2050
testb %al, %al
je 0x2dd0
pushq $-0x1
popq %rax
movq %rax, -0x30(%rbp)
leaq -0x540(%rbp), %r15
xorl %r12d, %r12d
leaq -0x140(%rbp), %r13
pushq $0x7d
popq %rbx
cmpq 0x8(%r14), %r12
jae 0x2df0
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x2160
movq %r15, %rdi
movq %r13, %rsi
callq 0x21a0
movq %r13, %rdi
callq 0x20a0
addq $0x7d, %r12
incq -0x30(%rbp)
addq $0x20, %r15
jmp 0x2d98
movq 0x61f9(%rip), %rdi      # 0x8fd0
leaq 0x32b1(%rip), %rsi      # 0x608f
callq 0x2150
movq %rax, %rdi
callq 0x20b0
jmp 0x2fef
movq -0x30(%rbp), %rax
incq %rax
movq %rax, -0x40(%rbp)
leaq -0x540(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x1540(%rbp), %r15
xorl %r12d, %r12d
leaq -0x140(%rbp), %r13
cmpq %r12, -0x40(%rbp)
je 0x2fc8
leaq -0x120(%rbp), %r14
movq %r14, %rdi
movq -0x38(%rbp), %rsi
callq 0x21c0
movq %r13, %rdi
movq %r14, %rsi
callq 0x3110
movq %r15, %rdi
movq %r13, %rsi
callq 0x21a0
movq %r13, %rdi
callq 0x20a0
movq %r14, %rdi
callq 0x20a0
cmpq %r12, -0x30(%rbp)
jne 0x2e9c
leaq -0x100(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x21c0
movq %r13, %rdi
movq %r14, %rsi
movq -0x30(%rbp), %rdx
pushq $0x1
popq %rcx
callq 0x31aa
movq %r15, %rdi
movq %r13, %rsi
callq 0x21a0
movq %r13, %rdi
callq 0x20a0
movq %r14, %rdi
jmp 0x2ed4
leaq -0xe0(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21c0
movq %r13, %rdi
movq %rbx, %rsi
movl %r12d, %edx
xorl %ecx, %ecx
callq 0x31aa
movq %r15, %rdi
movq %r13, %rsi
callq 0x21a0
movq %r13, %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x20a0
leaq -0x60(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
leaq 0x324e(%rip), %rdx      # 0x6138
callq 0x3d74
leaq -0xc0(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32ac
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x3d46
movq %r15, %rdi
movq %r13, %rsi
callq 0x21a0
movq %r13, %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x20a0
leaq -0x60(%rbp), %rdi
callq 0x20a0
leaq -0xa0(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21c0
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3564
movq %r15, %rdi
movq %r13, %rsi
callq 0x21a0
movq %r13, %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x20a0
leaq -0x80(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21c0
movq %r13, %rdi
movq %rbx, %rsi
callq 0x35fa
movq %r15, %rdi
movq %r13, %rsi
callq 0x21a0
movq %r13, %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x20a0
leaq -0x340(%rbp), %rdi
movq %r15, %rsi
callq 0x2130
movq %rax, %rdi
callq 0x20b0
incq %r12
addq $0x20, -0x38(%rbp)
addq $0x20, %r15
jmp 0x2e17
movq 0x6001(%rip), %rdi      # 0x8fd0
leaq 0x3173(%rip), %rsi      # 0x6149
callq 0x2150
movq %rax, %rdi
callq 0x20b0
leaq -0x340(%rbp), %rdi
callq 0x21d0
leaq -0x340(%rbp), %rdi
callq 0x21e0
movl $0xfe0, %ebx            # imm = 0xFE0
leaq (%rbx,%rbp), %rdi
addq $-0x1540, %rdi          # imm = 0xEAC0
callq 0x20a0
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x3000
movl $0x1e0, %ebx            # imm = 0x1E0
leaq (%rbx,%rbp), %rdi
addq $-0x540, %rdi           # imm = 0xFAC0
callq 0x20a0
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x301f
addq $0x1518, %rsp           # imm = 0x1518
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x30c7
jmp 0x30b8
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
jmp 0x30ad
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
jmp 0x30ad
jmp 0x30b8
jmp 0x30b8
jmp 0x30b8
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
jmp 0x30ad
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
jmp 0x30ad
jmp 0x30b8
movq %rax, %rbx
jmp 0x309b
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x20a0
leaq -0x60(%rbp), %rdi
jmp 0x30ad
jmp 0x30b8
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x20a0
jmp 0x30bb
jmp 0x30b8
jmp 0x30b8
movq %rax, %rbx
leaq -0x340(%rbp), %rdi
callq 0x21e0
movl $0xfe0, %r14d           # imm = 0xFE0
leaq (%r14,%rbp), %rdi
addq $-0x1540, %rdi          # imm = 0xEAC0
callq 0x20a0
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x30cd
movl $0x1e0, %r14d           # imm = 0x1E0
leaq (%r14,%rbp), %rdi
addq $-0x540, %rdi           # imm = 0xFAC0
callq 0x20a0
addq $-0x20, %r14
cmpq $-0x20, %r14
jne 0x30ed
movq %rbx, %rdi
callq 0x2230
nop