// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
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 0x3210
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 0x323b
leaq 0x4e1a(%rip), %rsi      # 0x8082
leaq -0x338(%rbp), %rdi
movl $0x10, %edx
callq 0x2180
leaq -0x2c8(%rbp), %rdi
callq 0x2060
testb %al, %al
je 0x32f5
cmpq $0x0, 0x8(%rbx)
je 0x3340
leaq -0x540(%rbp), %r14
leaq -0x38(%rbp), %r13
movq $0x0, -0x50(%rbp)
leaq -0x48(%rbp), %r15
xorl %r12d, %r12d
movl $0x7d, %ecx
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2170
movq %r14, %rdi
movq %r15, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
cmpq %r13, %rdi
je 0x32e1
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
addq $0x7d, %r12
incq -0x50(%rbp)
addq $0x20, %r14
cmpq 0x8(%rbx), %r12
jb 0x32ae
jmp 0x3348
movq 0x7cd4(%rip), %rbx      # 0xafd0
leaq 0x4d8c(%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 0x7ca2(%rip), %rdi      # 0xafd0
callq 0x2030
movq %rax, %rdi
callq 0x20e0
jmp 0x377f
movq $0x0, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x372d
movq -0x50(%rbp), %rax
decq %rax
movq %rax, -0x118(%rbp)
leaq -0x1540(%rbp), %rbx
leaq -0x538(%rbp), %r12
xorl %r14d, %r14d
leaq -0x100(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x8(%r12), %rsi
movq (%r12), %rdx
addq %rsi, %rdx
leaq -0x110(%rbp), %r15
movq %r15, %rdi
callq 0x30c0
leaq -0x48(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x39a4
movq %rbx, %rdi
movq %r13, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x33ce
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x33f0
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x2160
cmpq %r14, -0x118(%rbp)
jne 0x347f
leaq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0xf0(%rbp), %r13
movq %r13, %rdi
callq 0x30c0
leaq -0x48(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
movl %r14d, %edx
movl $0x1, %ecx
callq 0x3a84
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x345f
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x3500
movq -0xe0(%rbp), %rsi
jmp 0x34f8
leaq -0xc0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %r13
movq %r13, %rdi
callq 0x30c0
leaq -0x48(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x3a84
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x34de
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x3500
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x2160
leaq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %r15
movq %r15, %rdi
callq 0x30c0
movq %r15, %rdi
leaq 0x4c10(%rip), %rsi      # 0x8138
callq 0x2280
leaq -0x138(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x3d12
movq (%rbx), %rcx
movq 0x8(%rbx), %r8
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2190
leaq -0x38(%rbp), %r15
movq %r15, -0x48(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x3576
movq %rdx, -0x48(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x38(%rbp)
jmp 0x357d
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbx, %rdi
leaq -0x48(%rbp), %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x35b5
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x138(%rbp), %rdi
leaq -0x128(%rbp), %rax
cmpq %rax, %rdi
je 0x35d7
movq -0x128(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x35f0
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x2160
leaq -0xa0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0xb0(%rbp), %r13
movq %r13, %rdi
callq 0x30c0
leaq -0x48(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x42f4
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x364a
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x366c
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2160
leaq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %r13
movq %r13, %rdi
callq 0x30c0
movq %r15, %rdi
movq %r13, %rsi
callq 0x43a8
movq %rbx, %rdi
movq %r15, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x36bf
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x36db
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2160
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
leaq -0x338(%rbp), %rdi
callq 0x21a0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
incq %r14
addq $0x20, %rbx
addq $0x20, %r12
cmpq %r14, -0x50(%rbp)
jne 0x3372
movq 0x789c(%rip), %rbx      # 0xafd0
leaq 0x4a0e(%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 0x786a(%rip), %rdi      # 0xafd0
callq 0x2030
movq %rax, %rdi
callq 0x20e0
leaq -0x338(%rbp), %rdi
callq 0x21d0
movq 0x7842(%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 0x37d7
movq (%r14), %rsi
incq %rsi
callq 0x2160
addq $-0x20, %r14
addq $0x20, %rbx
jne 0x37c3
movq $-0x200, %rbx           # imm = 0xFE00
leaq -0x350(%rbp), %r14
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x3803
movq (%r14), %rsi
incq %rsi
callq 0x2160
addq $-0x20, %r14
addq $0x20, %rbx
jne 0x37ef
addq $0x1518, %rsp           # imm = 0x1518
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x3943
jmp 0x3934
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x3937
movq -0xc0(%rbp), %rsi
jmp 0x3928
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x3937
movq -0xe0(%rbp), %rsi
jmp 0x3928
jmp 0x3934
jmp 0x3934
jmp 0x3934
movq %rax, %rbx
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x3937
movq -0x100(%rbp), %rsi
jmp 0x3928
jmp 0x3934
jmp 0x38b1
movq %rax, %rbx
jmp 0x38db
movq %rax, %rbx
movq -0x138(%rbp), %rdi
leaq -0x128(%rbp), %rax
cmpq %rax, %rdi
je 0x38db
movq -0x128(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x3937
movq -0x60(%rbp), %rsi
jmp 0x3928
jmp 0x3934
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
leaq -0xa0(%rbp), %rax
cmpq %rax, %rdi
je 0x3937
movq -0xa0(%rbp), %rsi
jmp 0x3928
jmp 0x3934
movq %rax, %rbx
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x3937
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x2160
jmp 0x3937
jmp 0x3934
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 0x3965
movq (%r15), %rsi
incq %rsi
callq 0x2160
addq $-0x20, %r15
addq $0x20, %r14
jne 0x3951
movq $-0x200, %r14           # imm = 0xFE00
leaq -0x350(%rbp), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x3991
movq (%r15), %rsi
incq %rsi
callq 0x2160
addq $-0x20, %r15
addq $0x20, %r14
jne 0x397d
movq %rbx, %rdi
callq 0x2240
nop