// File: /workspace/github_cpp_makefile_star2_O3/carellano8[P]Proyecto-Redes-I-2017/hamming.cpp
// Function: hamming::codificadorHamming(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
binario hamming::codificadorHamming(binario bin){
    unsigned int i,j,k,m,n,p;
    int b[MAXMSJ],acum;
    binario s="";
    k=0;j=0;i=0;n=bin.size();//inicializacion
    
    while(k<=n){
        if(pow(2,j)==(i+1)){//si es potencia de 2 se omite el vector se rellena con 0
            j++;
            b[i]=0;
            }
        else{
            b[i]=(bin[k]=='1')?1:0;
            k++;
            }
        i++;
        }
    n+=j;
    j--;
    //~ cout<<j<<" "<<n<<endl;
    if(potencia2(n)){n--;}
    for(i=0;i<=j;i++){

        p=pow(2,i);
        k=p-1;acum=0;
        while(k<n){

                for(m=k;m<p+k&&m<n;m++){
                    if(m!=p-1){
                        acum+=b[m];

                    }
                    //~ cout<<m<<" ";
                }
                //~ cout<<endl;
                k=p+m;
            }
            //~ cout<<endl;
        if(acum%2!=0){
            b[p-1]=1;
            }
    }
    acum=0;
    for (i = 0; i < n; i++){
        acum+=b[i];
        s+=(b[i]+'0');
    }
    //~ cout<<s<<" "<<j<<endl;
    if(acum%2==0){
        b[n]=0;
        s+='0';
    }
    else{
        b[n]=1;
        s+='1';
        }
    //~ n++;

    //~ cout<<"Tamano: "<<n<<" | Bits de paridad: "<<j<<endl<<"Binario: ";
    //~ for(i = 0; i <n ; i++){
        //~ cout<<b[i];
    //~ }
    //~ cout<<endl;

    return s;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f58, %rsp           # imm = 0x1F58
movq %rsi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, -0x38(%rbp)
movq %rax, (%rdi)
leaq 0x241c(%rip), %rdx      # 0x8159
movq %rdi, -0x30(%rbp)
movq %rdx, %rsi
callq 0x3140
movq %rbx, -0x40(%rbp)
movl 0x8(%rbx), %r12d
xorl %r15d, %r15d
movl $0x1, %ebx
xorl %r13d, %r13d
leal -0x1(%rbx), %r14d
movl %r13d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
callq 0x2140
movl %ebx, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm0
movl %r14d, %eax
jne 0x5d95
jp 0x5d95
incl %r13d
movl $0x0, -0x1f80(%rbp,%rax,4)
jmp 0x5db3
movl %r15d, %ecx
movq -0x40(%rbp), %rdx
movq (%rdx), %rdx
xorl %esi, %esi
cmpb $0x31, (%rdx,%rcx)
sete %sil
movl %esi, -0x1f80(%rbp,%rax,4)
incl %r15d
incl %ebx
cmpl %r12d, %r15d
jbe 0x5d5c
addl %r13d, %r12d
testl %r12d, %r12d
jle 0x5df4
movl $0x1, %ebx
movl $0x1, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
callq 0x2140
xorl %eax, %eax
cmpl %r12d, %r14d
sete %cl
je 0x5def
incl %ebx
cvttsd2si %xmm0, %r14d
cmpl %r14d, %r12d
jge 0x5dcd
movb %cl, %al
subl %eax, %r12d
decl %r13d
xorl %r14d, %r14d
movl %r14d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
callq 0x2140
cvttsd2si %xmm0, %rax
leal -0x1(%rax), %edi
cmpl %r12d, %edi
jae 0x5e63
movl %edi, %ecx
xorl %edx, %edx
leal (%rdi,%rax), %r8d
cmpl %r12d, %r8d
movl %r12d, %esi
cmovbl %r8d, %esi
cmpl %esi, %edi
jae 0x5e4b
movl %edi, %edi
movl %esi, %r8d
cmpq %rdi, %rcx
je 0x5e3e
addl -0x1f80(%rbp,%rdi,4), %edx
incq %rdi
cmpq %rdi, %r8
jne 0x5e32
addl %eax, %esi
movl %esi, %r8d
movl %r8d, %edi
cmpl %r12d, %r8d
jb 0x5e1b
testb $0x1, %dl
je 0x5e63
movl $0x1, -0x1f80(%rbp,%rcx,4)
incl %r14d
cmpl %r13d, %r14d
jbe 0x5dfa
testl %r12d, %r12d
je 0x5ea7
movl %r12d, %r14d
xorl %r15d, %r15d
xorl %ebx, %ebx
movq -0x30(%rbp), %r13
movl -0x1f80(%rbp,%r15,4), %r12d
leal 0x30(%r12), %eax
movsbl %al, %esi
movq %r13, %rdi
callq 0x2120
addl %r12d, %ebx
incq %r15
cmpq %r15, %r14
jne 0x5e7c
andb $0x1, %bl
orb $0x30, %bl
jmp 0x5ead
movb $0x30, %bl
movq -0x30(%rbp), %r13
movzbl %bl, %esi
movq %r13, %rdi
callq 0x2120
movq %r13, %rax
addq $0x1f58, %rsp           # imm = 0x1F58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5ed1
jmp 0x5ed1
movq %rax, %r14
movq -0x30(%rbp), %rax
movq (%rax), %rdi
cmpq -0x38(%rbp), %rdi
je 0x5ef0
movq -0x38(%rbp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x2160
movq %r14, %rdi
callq 0x2240