// File: 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
subq $0x1fd0, %rsp           # imm = 0x1FD0
movq %rsi, -0x1fa8(%rbp)
movq %rdi, -0x1f98(%rbp)
movq %rdi, %rax
movq %rax, -0x1fa0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x1f75(%rbp)
leaq -0x1f76(%rbp), %rdi
movq %rdi, -0x1f90(%rbp)
callq 0x33a0
movq -0x1f98(%rbp), %rdi
movq -0x1f90(%rbp), %rdx
leaq 0x261f(%rip), %rsi      # 0xa159
callq 0x4340
jmp 0x7b41
leaq -0x1f76(%rbp), %rdi
callq 0x3240
movq -0x1fa8(%rbp), %rdi
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
callq 0x3170
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x24(%rbp), %eax
ja 0x7c62
movl -0x18(%rbp), %esi
movl $0x2, %edi
callq 0x9290
movsd %xmm0, -0x1fb0(%rbp)
jmp 0x7b94
movsd -0x1fb0(%rbp), %xmm0
movl -0x14(%rbp), %eax
incl %eax
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm0
jne 0x7c10
jp 0x7c10
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
movl $0x0, -0x1f70(%rbp,%rax,4)
jmp 0x7c54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1f80(%rbp)
movl %eax, -0x1f84(%rbp)
leaq -0x1f76(%rbp), %rdi
callq 0x3240
jmp 0x7e77
movq -0x1f98(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1f80(%rbp)
movl %eax, -0x1f84(%rbp)
callq 0x3140
jmp 0x7e77
movq -0x1fa8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x3430
movq %rax, -0x1fb8(%rbp)
jmp 0x7c2a
movq -0x1fb8(%rbp), %rax
movsbl (%rax), %edx
xorl %ecx, %ecx
movl $0x1, %eax
cmpl $0x31, %edx
cmovel %eax, %ecx
movl -0x14(%rbp), %eax
movl %ecx, -0x1f70(%rbp,%rax,4)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x7b71
movl -0x18(%rbp), %ecx
movl -0x24(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
decl %eax
movl %eax, -0x18(%rbp)
movl -0x24(%rbp), %edi
callq 0x9210
movb %al, -0x1fb9(%rbp)
jmp 0x7c85
movb -0x1fb9(%rbp), %al
testb $0x1, %al
jne 0x7c91
jmp 0x7c9a
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
ja 0x7d96
movl -0x14(%rbp), %esi
movl $0x2, %edi
callq 0x9290
movsd %xmm0, -0x1fc8(%rbp)
jmp 0x7cc4
movsd -0x1fc8(%rbp), %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x1f74(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x7d60
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %ecx
movl -0x28(%rbp), %edx
addl -0x1c(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x1fc9(%rbp)
jae 0x7d19
movl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
setb %al
movb %al, -0x1fc9(%rbp)
movb -0x1fc9(%rbp), %al
testb $0x1, %al
jne 0x7d25
jmp 0x7d55
movl -0x20(%rbp), %eax
movl -0x28(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x7d48
movl -0x20(%rbp), %eax
movl -0x1f70(%rbp,%rax,4), %eax
addl -0x1f74(%rbp), %eax
movl %eax, -0x1f74(%rbp)
jmp 0x7d4a
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x7cf5
movl -0x28(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x7ce7
movl -0x1f74(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x7d86
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl $0x1, -0x1f70(%rbp,%rax,4)
jmp 0x7d88
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x7ca1
movl $0x0, -0x1f74(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x24(%rbp), %eax
jae 0x7df2
movq -0x1f98(%rbp), %rdi
movl -0x14(%rbp), %eax
movl -0x1f70(%rbp,%rax,4), %ecx
movl -0x1f74(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x1f74(%rbp)
movl -0x14(%rbp), %eax
movl -0x1f70(%rbp,%rax,4), %eax
addl $0x30, %eax
movsbl %al, %esi
callq 0x3150
jmp 0x7de5
jmp 0x7de7
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x7da7
movl -0x1f74(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x7e28
movq -0x1f98(%rbp), %rdi
movl -0x24(%rbp), %eax
movl $0x0, -0x1f70(%rbp,%rax,4)
movl $0x30, %esi
callq 0x3150
jmp 0x7e26
jmp 0x7e4b
movq -0x1f98(%rbp), %rdi
movl -0x24(%rbp), %eax
movl $0x1, -0x1f70(%rbp,%rax,4)
movl $0x31, %esi
callq 0x3150
jmp 0x7e49
jmp 0x7e4b
movb $0x1, -0x1f75(%rbp)
testb $0x1, -0x1f75(%rbp)
jne 0x7e67
movq -0x1f98(%rbp), %rdi
callq 0x3140
movq -0x1fa0(%rbp), %rax
addq $0x1fd0, %rsp           # imm = 0x1FD0
popq %rbp
retq
movq -0x1f80(%rbp), %rdi
callq 0x3390
nopw %cs:(%rax,%rax)