// File: /workspace/github_cpp_makefile_star2_O3/carellano8[P]Proyecto-Redes-I-2017/hamming.cpp
// Function: hamming::enviar(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void hamming::enviar(string msj){
    size_t i,n;
    string bufferMsj[MAXMSJ/MAXT];
    binario bufferB[MAXMSJ/MAXT*8];
    i=0;n=0;
	ofstream archivo("canalh.txt");

    if(archivo.is_open()){
	    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]=codificadorHamming(bufferB[i]);
	        bufferB[i]=relleno_Bit(bufferB[i]);
	        bufferB[i]=insercion_banderas(bufferB[i]);
	        archivo/*<<"Trama Hamming: "*/<<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 $0x14f8, %rsp           # imm = 0x14F8
movq %rdi, %r14
movl $0x10, %eax
leaq (%rax,%rbp), %rcx
addq $-0x520, %rcx           # imm = 0xFAE0
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x210, %rax            # imm = 0x210
jne 0x52e0
movl $0x10, %eax
leaq (%rax,%rbp), %rcx
addq $-0x1520, %rcx          # imm = 0xEAE0
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x1010, %rax           # imm = 0x1010
jne 0x530b
leaq 0x2d84(%rip), %rsi      # 0x80bc
leaq -0x318(%rbp), %rdi
movl $0x10, %edx
callq 0x2180
leaq -0x2a8(%rbp), %rdi
callq 0x2060
testb %al, %al
je 0x5776
cmpq $0x0, 0x8(%r14)
je 0x5722
movq $-0x1, %rbx
leaq -0x520(%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 0x53b4
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
addq $0x7d, %r12
incq %rbx
addq $0x20, %r15
cmpq 0x8(%r14), %r12
jb 0x537d
cmpq $-0x1, %rbx
je 0x5722
leaq 0x1(%rbx), %rax
movq %rax, -0x110(%rbp)
leaq -0x1520(%rbp), %r14
leaq -0x518(%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 0x59a8
leaq -0x38(%rbp), %r12
movq %r14, %rdi
movq %r13, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
cmpq %r12, %rdi
je 0x544c
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x546e
movq -0xf8(%rbp), %rsi
incq %rsi
callq 0x2160
cmpq %r15, %rbx
jne 0x54f8
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 0x5a88
movq %r14, %rdi
movq %r12, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x54d8
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x5579
movq -0xd8(%rbp), %rsi
jmp 0x5571
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 0x5a88
movq %r14, %rdi
movq %r12, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x5557
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x5579
movq -0xb8(%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
movq %r12, %rdi
movq %r13, %rsi
callq 0x5d14
movq %r14, %rdi
movq %r12, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x55cf
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x55f1
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 0x5ef8
movq %r14, %rdi
movq %r12, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x5644
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x5660
movq -0x78(%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), %r13
movq %r13, %rdi
callq 0x30a2
movq %r12, %rdi
movq %r13, %rsi
callq 0x5fac
movq %r14, %rdi
movq %r12, %rsi
callq 0x21c0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x56ad
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x2160
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x56c6
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2160
movq (%r14), %rsi
movq 0x8(%r14), %rdx
leaq -0x318(%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 0x53eb
movq 0x58a7(%rip), %rbx      # 0xafd0
leaq 0x2a19(%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 0x5875(%rip), %rdi      # 0xafd0
callq 0x2030
movq %rax, %rdi
callq 0x20e0
leaq -0x318(%rbp), %rdi
callq 0x21d0
jmp 0x57bc
movq 0x5853(%rip), %rbx      # 0xafd0
leaq 0x290b(%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 0x5821(%rip), %rdi      # 0xafd0
callq 0x2030
movq %rax, %rdi
callq 0x20e0
movq 0x5805(%rip), %rax      # 0xafc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x310(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x318(%rbp,%rcx)
callq 0x2110
leaq -0x220(%rbp), %rdi
callq 0x20a0
movq $-0x1000, %rbx          # imm = 0xF000
leaq -0x530(%rbp), %r14
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x5814
movq (%r14), %rsi
incq %rsi
callq 0x2160
addq $-0x20, %r14
addq $0x20, %rbx
jne 0x5800
movq $-0x200, %rbx           # imm = 0xFE00
leaq -0x330(%rbp), %r14
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x5840
movq (%r14), %rsi
incq %rsi
callq 0x2160
addq $-0x20, %r14
addq $0x20, %rbx
jne 0x582c
addq $0x14f8, %rsp           # imm = 0x14F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x5947
jmp 0x5938
jmp 0x5938
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
cmpq %rax, %rdi
je 0x593b
movq -0xb8(%rbp), %rsi
jmp 0x592c
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x593b
movq -0xd8(%rbp), %rsi
jmp 0x592c
jmp 0x5938
jmp 0x5938
movq %rax, %rbx
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x593b
movq -0xf8(%rbp), %rsi
jmp 0x592c
jmp 0x5938
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x593b
movq -0x98(%rbp), %rsi
jmp 0x592c
jmp 0x5938
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x593b
movq -0x78(%rbp), %rsi
jmp 0x592c
jmp 0x5938
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x593b
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2160
jmp 0x593b
jmp 0x5938
movq %rax, %rbx
leaq -0x318(%rbp), %rdi
callq 0x21e0
movq $-0x1000, %r14          # imm = 0xF000
leaq -0x530(%rbp), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x5969
movq (%r15), %rsi
incq %rsi
callq 0x2160
addq $-0x20, %r15
addq $0x20, %r14
jne 0x5955
movq $-0x200, %r14           # imm = 0xFE00
leaq -0x330(%rbp), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x5995
movq (%r15), %rsi
incq %rsi
callq 0x2160
addq $-0x20, %r15
addq $0x20, %r14
jne 0x5981
movq %rbx, %rdi
callq 0x2240
nop