// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/net.cc
// Function: try_unit_cell_vector_assign(int, int, int, XYZ, std::vector<int, std::allocator<int>>*, std::vector<int, std::allocator<int>>*, std::vector<int, std::allocator<int>>*, std::vector<XYZ, std::allocator<XYZ>>*, std::vector<int, std::allocator<int>>*, std::vector<XYZ, std::allocator<XYZ>>*, int)
bool try_unit_cell_vector_assign(int a, int b, int c, XYZ xyz, vector<int> *loops_a, vector<int> *loops_b, vector<int> *loops_c, vector<XYZ> *loops_xyz, vector<int> *unit_cell_vector_IDs, vector<XYZ> *unit_cell_vectors, int num_uc_vectors_required) {
  bool verbose = false;
  int num_uc_vectors_assigned = unit_cell_vectors->size();
  for(int uc=0; uc<3 && num_uc_vectors_assigned<num_uc_vectors_required; uc++) {
    //is this unit cell vector assigned already?
    bool this_uc_assigned = false;
    for(int i=0; i<num_uc_vectors_assigned && !this_uc_assigned; i++) {
      if(unit_cell_vector_IDs->at(i)==uc) this_uc_assigned = true;
    }
    if(!this_uc_assigned) {
      //if not assigned already, can we assign it based on this loop alone?
      if(
(uc==0 && a!=0 && b==0 && c==0) ||
(uc==1 && a==0 && b!=0 && c==0) ||
(uc==2 && a==0 && b==0 && c!=0)
      ) {
        XYZ vec(0,0,0);
        if(uc==0) vec=xyz.scale(1.0/a); else if(uc==1) vec=xyz.scale(1.0/b); else vec=xyz.scale(1.0/c);
if(verbose) printf("DEBUG: we can assign unit cell vector %c as %.3f %.3f %.3f\n", 'a'+uc, vec.x, vec.y, vec.z);
        unit_cell_vector_IDs->push_back(uc);
        unit_cell_vectors->push_back(vec);
        this_uc_assigned = true;
        num_uc_vectors_assigned++;
      } else {
        //we could not assign it based on this loop alone - but we might be able to based on other loops ...
        int num_loops = loops_xyz->size();
        for(int i=0; i<num_loops && !this_uc_assigned; i++) {
          XYZ other_xyz = loops_xyz->at(i);
          int other_a = loops_a->at(i);
          int other_b = loops_b->at(i);
          int other_c = loops_c->at(i);
if(verbose) printf("DEBUG: comparing to previous loop (%d %d %d) %.3f %.3f %.3f to try and isolate vector %c\n", other_a, other_b, other_c, other_xyz.x, other_xyz.y, other_xyz.z, 'a'+uc);
          //can we isolate this unit cell vector with a linear combination of these two loops?
          //bool can_isolate = true;
          if(
(uc!=0 && a!=0 && other_a==0) ||
(uc!=1 && b!=0 && other_b==0) ||
(uc!=2 && c!=0 && other_c==0)
          ) {
if(verbose) printf("DEBUG: cannot isolate vector %c because some other unit cell vector cannot be reduced to zero\n", 'a'+uc);
          } else if(
(uc==0 && a==0 && other_a==0) ||
(uc==1 && b==0 && other_b==0) ||
(uc==2 && c==0 && other_c==0)
          ) {
if(verbose) printf("DEBUG: cannot isolate vector %c because both coefficients of this vector are zero\n", 'a'+uc);
          } else { //there is another way it might not be possible - if the ratios of the two other unit cell vector coefficients are not equal
if(verbose) printf("DEBUG: may be able to isolate vector %c\n", 'a'+uc);
            vector<double> amounts_of_other_loop_to_subtract;
            vector<double> amount_of_other_loop_that_would_reduce_uc_to_zero;
            if(!(a==0 && other_a==0)) {double r = ((double)(a))/other_a; if(uc!=0) amounts_of_other_loop_to_subtract.push_back(r); else amount_of_other_loop_that_would_reduce_uc_to_zero.push_back(r);}
            if(!(b==0 && other_b==0)) {double r = ((double)(b))/other_b; if(uc!=1) amounts_of_other_loop_to_subtract.push_back(r); else amount_of_other_loop_that_would_reduce_uc_to_zero.push_back(r);}
            if(!(c==0 && other_c==0)) {double r = ((double)(c))/other_c; if(uc!=2) amounts_of_other_loop_to_subtract.push_back(r); else amount_of_other_loop_that_would_reduce_uc_to_zero.push_back(r);}
            int num_amounts = amounts_of_other_loop_to_subtract.size();
            if(num_amounts==0) {
              printf("ERROR: detected that unit cell vector has already been determined in determination routine\n");
              exit(EXIT_FAILURE);
            } else if(num_amounts>2) {
              printf("ERROR: pushed too many solutions to unit cell vector determination routine\n");
              exit(EXIT_FAILURE);
            } else {
              bool can_isolate = true;
              if(num_amounts==2) {
                if(fabs(amounts_of_other_loop_to_subtract.at(0)-amounts_of_other_loop_to_subtract.at(1))>DISTANCE_TOLERANCE) {
                  can_isolate = false;
if(verbose) printf("DEBUG: cannot isolate vector %c because no linear combination will isolate this vector\n", 'a'+uc);
                }
              }
              if(can_isolate) { //we should be able to isolate it - but are we reducing to zero?
                double ratio = amounts_of_other_loop_to_subtract.at(0);
                bool can_isolate_nonzero = true;
                if(amount_of_other_loop_that_would_reduce_uc_to_zero.size()!=0) {
                  if(fabs(ratio-amount_of_other_loop_that_would_reduce_uc_to_zero.at(0))<DISTANCE_TOLERANCE) {
                    can_isolate_nonzero = false;
if(verbose) printf("DEBUG: cannot isolate vector %c because this linear combination reveals that the two vectors are multiples of each other\n", 'a'+uc);
                  }
                }
                if(can_isolate_nonzero) {
                  XYZ pre_scale_vector = xyz-(other_xyz.scale(ratio));
if(verbose) printf("DEBUG: this loop %.3f %.3f %.3f, minus %.3f times other loop %.3f %.3f %.3f, gives isolated %c loop %.3f %.3f %.3f\n", xyz.x, xyz.y, xyz.z, ratio, other_xyz.x, other_xyz.y, other_xyz.z, 'a'+uc, pre_scale_vector.x, pre_scale_vector.y, pre_scale_vector.z);
                  XYZ vec(0,0,0);
                  if(uc==0) vec=pre_scale_vector.scale(1.0/(a-(other_a*ratio))); else if(uc==1) vec=pre_scale_vector.scale(1.0/(b-(other_b*ratio))); else vec=pre_scale_vector.scale(1.0/(c-(other_c*ratio)));
if(verbose) printf("DEBUG: we can assign unit cell vector %c as %.3f %.3f %.3f based on a linear combination with a previous loop\n", 'a'+uc, vec.x, vec.y, vec.z);
                  unit_cell_vector_IDs->push_back(uc);
                  unit_cell_vectors->push_back(vec);
                  this_uc_assigned = true;
                  num_uc_vectors_assigned++;
                  //also push this new loop so we can refer to it for subsequent linear combinations - only if it is unique!
                  int new_a=0, new_b=0, new_c=0;
                  if(uc==0) new_a=1; else if(uc==1) new_b=1; else new_c=1;
                  if(loop_is_unique(new_a, new_b, new_c, loops_a, loops_b, loops_c)) {
if(verbose) printf("DEBUG: pushing the newly defined, unique loop\n");
                    loops_a->push_back(new_a);
                    loops_b->push_back(new_b);
                    loops_c->push_back(new_c);
                    loops_xyz->push_back(vec);
                    num_loops++;
                  }
                }
              }
            }
          } 
        }
      }
    }
  }
  return (num_uc_vectors_assigned==num_uc_vectors_required);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %r9, 0x50(%rsp)
movq %r8, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movl %edx, %ecx
movq 0x1a8(%rsp), %rdx
movq 0x1a0(%rsp), %r15
movq 0x8(%rdx), %rax
subq (%rdx), %rax
pushq $0x18
popq %r8
cqto
idivq %r8
movq %rax, %rbx
movl %ecx, %eax
orl %esi, %eax
movl %eax, 0x7c(%rsp)
movl %esi, %eax
cvtsi2sd %edi, %xmm0
movl %esi, 0x14(%rsp)
cvtsi2sd %esi, %xmm1
movl %ecx, 0xc(%rsp)
cvtsi2sd %ecx, %xmm2
movl %edi, 0x10(%rsp)
orl %edi, %eax
movl %eax, 0x78(%rsp)
movsd 0x8498d(%rip), %xmm3    # 0xfc058
movapd %xmm3, %xmm4
movsd %xmm1, 0x120(%rsp)
divsd %xmm1, %xmm4
movsd %xmm4, 0x140(%rsp)
movapd %xmm3, %xmm1
movsd %xmm0, 0x128(%rsp)
divsd %xmm0, %xmm1
movsd %xmm1, 0x138(%rsp)
movsd %xmm2, 0x118(%rsp)
divsd %xmm2, %xmm3
movsd %xmm3, 0x130(%rsp)
xorl %ecx, %ecx
pushq $0x1
popq %rbp
movl %ecx, 0x8(%rsp)
cmpl $0x2, %ecx
jg 0x77da3
cmpl 0x1b0(%rsp), %ebx
jge 0x77da3
movq %rbx, 0x18(%rsp)
movslq %ebx, %r14
xorl %ebx, %ebx
xorl %r13d, %r13d
cmpq %r14, %rbx
jge 0x7776a
testb $0x1, %r13b
jne 0x7776a
movq %r15, %rdi
movq %rbx, %rsi
callq 0xac00
movl 0x8(%rsp), %ecx
cmpl %ecx, (%rax)
movzbl %r13b, %r13d
cmovel %ebp, %r13d
incq %rbx
jmp 0x77741
testb $0x1, %r13b
je 0x7777a
movq 0x18(%rsp), %rbx
jmp 0x7786b
cmpl $0x0, 0x10(%rsp)
movq 0x18(%rsp), %rbx
je 0x7778e
movl 0x7c(%rsp), %eax
orl %ecx, %eax
je 0x777c7
cmpl $0x0, 0xc(%rsp)
jne 0x777a8
cmpl $0x0, 0x14(%rsp)
je 0x777a8
cmpl $0x0, 0x10(%rsp)
jne 0x777a8
cmpl $0x1, %ecx
je 0x777c7
cmpl $0x0, 0xc(%rsp)
je 0x77876
cmpl $0x0, 0x78(%rsp)
jne 0x77876
cmpl $0x2, %ecx
jne 0x77876
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
leaq 0x80(%rsp), %rdi
callq 0x6402e
movl 0x8(%rsp), %eax
cmpl $0x1, %eax
je 0x77805
testl %eax, %eax
leaq 0x20(%rsp), %rdi
leaq 0x180(%rsp), %rsi
jne 0x7781d
movsd 0x138(%rsp), %xmm0
jmp 0x77826
leaq 0x20(%rsp), %rdi
leaq 0x180(%rsp), %rsi
movsd 0x140(%rsp), %xmm0
jmp 0x77826
movsd 0x130(%rsp), %xmm0
callq 0x640ba
movq 0x30(%rsp), %rax
movq %rax, 0x90(%rsp)
movupd 0x20(%rsp), %xmm0
movapd %xmm0, 0x80(%rsp)
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0x9434
movq 0x1a8(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x4beaa
incl %ebx
movl 0x8(%rsp), %ecx
incl %ecx
jmp 0x7771a
movq 0x198(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movq %rax, 0x58(%rsp)
xorl %r14d, %r14d
movslq 0x58(%rsp), %rax
cmpq %rax, %r14
jge 0x77770
testb $0x1, %r13b
jne 0x77770
cmpl $0x0, 0x10(%rsp)
setne %bpl
movq 0x198(%rsp), %rdi
movq %r14, %rsi
callq 0x4b6d6
movupd (%rax), %xmm0
movapd %xmm0, 0x80(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x90(%rsp)
movq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0xac00
movl (%rax), %r12d
movq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0xac00
movl (%rax), %ebx
movq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0xac00
movl 0x8(%rsp), %ecx
testl %ecx, %ecx
setne %dl
andb %bpl, %dl
testl %r12d, %r12d
sete %sil
testb %sil, %dl
jne 0x7797f
cmpl $0x0, 0x14(%rsp)
setne %dl
cmpl $0x1, %ecx
setne %sil
andb %dl, %sil
testl %ebx, %ebx
sete %dl
testb %dl, %sil
jne 0x7797f
movl (%rax), %esi
cmpl $0x0, 0xc(%rsp)
setne %al
cmpl $0x2, %ecx
setne %dl
andb %al, %dl
testl %esi, %esi
sete %al
testb %al, %dl
jne 0x7797f
movl %ecx, %eax
orl 0x10(%rsp), %eax
orl %r12d, %eax
je 0x7797f
movl %ecx, %eax
xorl $0x1, %eax
orl 0x14(%rsp), %eax
orl %ebx, %eax
je 0x7797f
movl %ecx, %eax
xorl $0x2, %eax
orl 0xc(%rsp), %eax
orl %esi, %eax
jne 0x7798a
pushq $0x1
popq %rbp
incq %r14
jmp 0x77895
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movapd %xmm0, 0xb0(%rsp)
andq $0x0, 0xc0(%rsp)
movl 0x10(%rsp), %eax
orl %r12d, %eax
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x110(%rsp)
je 0x77a02
movl %esi, %ebp
movsd 0x128(%rsp), %xmm0
divsd 0x110(%rsp), %xmm0
movsd %xmm0, 0xc8(%rsp)
testl %ecx, %ecx
leaq 0x20(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmoveq %rax, %rdi
leaq 0xc8(%rsp), %rsi
callq 0xac88
movl %ebp, %esi
movl 0x14(%rsp), %eax
orl %ebx, %eax
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x108(%rsp)
leaq 0x20(%rsp), %rdi
pushq $0x1
popq %rbp
je 0x77a61
movl %esi, %ebx
movsd 0x120(%rsp), %xmm0
divsd 0x108(%rsp), %xmm0
cmpl $0x1, 0x8(%rsp)
movsd %xmm0, 0xc8(%rsp)
leaq 0xb0(%rsp), %rax
cmoveq %rax, %rdi
leaq 0xc8(%rsp), %rsi
callq 0xac88
leaq 0x20(%rsp), %rdi
movl %ebx, %esi
movl 0xc(%rsp), %eax
orl %esi, %eax
cvtsi2sd %esi, %xmm0
movsd %xmm0, 0x100(%rsp)
je 0x77ab4
movsd 0x118(%rsp), %xmm0
divsd 0x100(%rsp), %xmm0
cmpl $0x2, 0x8(%rsp)
movsd %xmm0, 0xc8(%rsp)
leaq 0xb0(%rsp), %rax
cmoveq %rax, %rdi
leaq 0xc8(%rsp), %rsi
callq 0xac88
leaq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
shrq $0x3, %rax
testl %eax, %eax
je 0x77dbf
cmpl $0x3, %eax
jge 0x77dc8
cmpl $0x2, %eax
jne 0x77b20
xorl %esi, %esi
movq %rdi, %rbx
callq 0xaa50
movsd (%rax), %xmm0
movapd %xmm0, 0xa0(%rsp)
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xaa50
movapd 0xa0(%rsp), %xmm0
subsd (%rax), %xmm0
andpd 0x84591(%rip), %xmm0    # 0xfc0a0
ucomisd 0x89bb1(%rip), %xmm0    # 0x1016c8
movq %rbx, %rdi
ja 0x77d87
xorl %esi, %esi
callq 0xaa50
movsd (%rax), %xmm0
movq 0xb8(%rsp), %rax
cmpq 0xb0(%rsp), %rax
movsd %xmm0, 0xa0(%rsp)
je 0x77b80
leaq 0xb0(%rsp), %rdi
xorl %esi, %esi
callq 0xaa50
movsd 0xa0(%rsp), %xmm0
movapd %xmm0, %xmm2
subsd (%rax), %xmm2
andpd 0x84532(%rip), %xmm2    # 0xfc0a0
movsd 0x89b52(%rip), %xmm1    # 0x1016c8
ucomisd %xmm2, %xmm1
ja 0x77d87
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x80(%rsp), %rsi
callq 0x640ba
leaq 0xc8(%rsp), %rdi
leaq 0x180(%rsp), %rsi
movq %rbx, %rdx
callq 0x642ae
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
movq %rbx, %rdi
callq 0x6402e
movl 0x8(%rsp), %eax
cmpl $0x1, %eax
je 0x77c10
testl %eax, %eax
jne 0x77c4f
movsd 0x110(%rsp), %xmm0
mulsd 0xa0(%rsp), %xmm0
movsd 0x128(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x84460(%rip), %xmm0    # 0xfc058
divsd %xmm1, %xmm0
leaq 0x60(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x640ba
jmp 0x77c8c
movsd 0x108(%rsp), %xmm0
mulsd 0xa0(%rsp), %xmm0
movsd 0x120(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x84421(%rip), %xmm0    # 0xfc058
divsd %xmm1, %xmm0
leaq 0x60(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x640ba
jmp 0x77c8c
movsd 0x100(%rsp), %xmm0
mulsd 0xa0(%rsp), %xmm0
movsd 0x118(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x843e2(%rip), %xmm0    # 0xfc058
divsd %xmm1, %xmm0
leaq 0x60(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x640ba
movq 0x70(%rsp), %rax
movq %rax, 0xf0(%rsp)
movupd 0x60(%rsp), %xmm0
movapd %xmm0, 0xe0(%rsp)
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0x9434
movq 0x1a8(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x4beaa
andl $0x0, 0x60(%rsp)
andl $0x0, 0x3c(%rsp)
andl $0x0, 0x38(%rsp)
movl 0x8(%rsp), %eax
cmpl $0x1, %eax
je 0x77cf6
testl %eax, %eax
jne 0x77d04
movl $0x1, 0x60(%rsp)
xorl %edx, %edx
xorl %esi, %esi
movl %ebp, %edi
jmp 0x77d12
movl $0x1, 0x3c(%rsp)
xorl %edx, %edx
movl %ebp, %esi
jmp 0x77d10
movl $0x1, 0x38(%rsp)
xorl %esi, %esi
movl %ebp, %edx
xorl %edi, %edi
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %r8
movq 0x50(%rsp), %r9
callq 0x7736b
testb %al, %al
je 0x77d78
movq 0x40(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x9434
movq 0x48(%rsp), %rdi
leaq 0x3c(%rsp), %rsi
callq 0x9434
movq 0x50(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x9434
movq 0x198(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x4beaa
movq 0x58(%rsp), %rax
incl %eax
movq %rax, 0x58(%rsp)
movq 0x18(%rsp), %rax
incl %eax
movq %rax, 0x18(%rsp)
movb $0x1, %r13b
leaq 0xb0(%rsp), %rdi
callq 0xb25c
leaq 0x20(%rsp), %rdi
callq 0xb25c
jmp 0x77982
cmpl 0x1b0(%rsp), %ebx
sete %al
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8d94c(%rip), %rdi     # 0x105712
jmp 0x77dcf
leaq 0x8d8f8(%rip), %rdi     # 0x1056c7
callq 0x4670
pushq $0x1
popq %rdi
callq 0x524c
jmp 0x77df2
jmp 0x77df2
jmp 0x77df2
jmp 0x77df2
jmp 0x77df2
jmp 0x77df2
jmp 0x77df2
jmp 0x77df2
jmp 0x77df2
jmp 0x77df2
jmp 0x77df2
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0xb25c
leaq 0x20(%rsp), %rdi
callq 0xb25c
movq %rbx, %rdi
callq 0x4780