// File: /workspace/github_cpp_makefile_star2_O3/Chaircrusher[P]primeratiogen/Bjorklund.cpp
// Function: Bjorklund::iter()
void Bjorklund::iter(){
    //\Bjorklund algorithm
    //\do E[k,n]. k is number of one's in sequence, and n is the length of sequence.
    int divisor = lengthOfSeq - pulseAmt; //initial amount of zero's
    if(divisor < 0) throw out_of_range{"Divisor has to be greator than 0"};
    
    remainder.push_back(pulseAmt);
    //iteration
    int index = 0; //we start algorithm from first index.
    
    while(true){
        count.push_back(std::floor(divisor / remainder[index]));
        remainder.push_back(divisor % remainder[index]);
        divisor = remainder.at(index);
        index += 1; //move to next step.
        if(remainder[index] <= 1){
            break;
        }
    }
    count.push_back(divisor);
    buildSeq(index); //place one's and zero's
    reverse(sequence.begin(), sequence.end());
    
    //position correction. some of result of algorithm is one step rotated.
    int zeroCount =0;
    if(sequence.at(0) != 1){
        do{
            zeroCount ++;
        }while(sequence.at(zeroCount) == 0);
        std::rotate(sequence.begin(), sequence.begin() + zeroCount, sequence.end());
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x58(%rdi), %ebp
movl 0x5c(%rdi), %eax
subl %eax, %ebp
movl %ebp, 0xc(%rsp)
js 0x3669
movq %rdi, %rbx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x350b
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3517
leaq 0x5c(%rbx), %rdx
movq %rbx, %rdi
callq 0x39dc
leaq 0x18(%rbx), %r15
movq (%rbx), %rcx
movl (%rcx), %esi
xorl %r14d, %r14d
leaq 0x14(%rsp), %r12
leaq 0x10(%rsp), %r13
movl %ebp, %eax
cltd
idivl %esi
movl %eax, 0x14(%rsp)
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x354c
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%rbx)
jmp 0x355a
movq %r15, %rdi
movq %r12, %rdx
callq 0x3b18
movq (%rbx), %rcx
movl %ebp, %eax
cltd
idivl (%rcx,%r14,4)
movl %edx, 0x10(%rsp)
movq 0x8(%rbx), %rax
cmpq 0x10(%rbx), %rax
je 0x357b
movl %edx, (%rax)
addq $0x4, %rax
movq %rax, 0x8(%rbx)
jmp 0x3590
movq %rbx, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x3b18
movq (%rbx), %rcx
movq 0x8(%rbx), %rax
subq %rcx, %rax
sarq $0x2, %rax
cmpq %r14, %rax
jbe 0x3655
movl (%rcx,%r14,4), %ebp
movl %ebp, 0xc(%rsp)
movl 0x4(%rcx,%r14,4), %esi
incq %r14
cmpl $0x1, %esi
jg 0x352d
movq 0x20(%rbx), %rsi
cmpq 0x28(%rbx), %rsi
je 0x35cf
movl %ebp, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x20(%rbx)
jmp 0x35dc
leaq 0xc(%rsp), %rdx
movq %r15, %rdi
callq 0x39dc
movq %rbx, %rdi
movl %r14d, %esi
callq 0x376a
leaq 0x30(%rbx), %r14
movq 0x30(%rbx), %rdi
movq 0x40(%rbx), %rdx
movl 0x48(%rbx), %ecx
xorl %esi, %esi
callq 0x3bf3
movq %r14, %rdi
xorl %esi, %esi
callq 0x3928
testq %rdx, (%rax)
jne 0x3646
xorl %r15d, %r15d
incq %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3928
testq %rdx, (%rax)
je 0x360f
movl %r15d, %eax
shrl $0x6, %eax
movq 0x30(%rbx), %rdi
movq 0x40(%rbx), %r8
leaq (%rdi,%rax,8), %rdx
andl $0x3f, %r15d
movl 0x48(%rbx), %r9d
xorl %esi, %esi
movl %r15d, %ecx
callq 0x3c8a
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1abc(%rip), %rdi      # 0x5118
movq %r14, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2150
movl $0x10, %edi
callq 0x2090
movq %rax, %rbx
leaq 0x1a22(%rip), %rsi      # 0x509f
movq %rax, %rdi
callq 0x2040
movq 0x3944(%rip), %rsi      # 0x6fd0
movq 0x3935(%rip), %rdx      # 0x6fc8
movq %rbx, %rdi
callq 0x21e0
movq %rax, %r14
movq %rbx, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x21f0