// File: /workspace/github_cpp_makefile_star2_O2/jstaursky[P]hutch/src/Sleigh/slghpattern.cc
// Function: PatternBlock::normalize()
void PatternBlock::normalize(void)

{
  if (nonzerosize<=0) {		// Check if alwaystrue or alwaysfalse
    offset = 0;			// in which case we don't need mask and value
    maskvec.clear();
    valvec.clear();
    return;
  }
  vector<uintm>::iterator iter1,iter2;
  
  iter1 = maskvec.begin();	// Cut zeros from beginning of mask
  iter2 = valvec.begin();
  while((iter1 != maskvec.end())&&((*iter1)==0)) {
    iter1++;
    iter2++;
    offset += sizeof(uintm);
  }
  maskvec.erase(maskvec.begin(),iter1);
  valvec.erase(valvec.begin(),iter2);

  if (!maskvec.empty()) {
    int4 suboff = 0;		// Cut off unaligned zeros from beginning of mask
    uintm tmp = maskvec[0];
    while(tmp != 0) {
      suboff += 1;
      tmp >>= 8;
    }
    suboff = sizeof(uintm)-suboff;
    if (suboff != 0) {
      offset += suboff;		// Slide up maskvec by suboff bytes
      for(int4 i=0;i<maskvec.size()-1;++i) {
	tmp = maskvec[i] << (suboff*8);
	tmp |= (maskvec[i+1] >> ((sizeof(uintm)-suboff)*8));
	maskvec[i] = tmp;
      }
      maskvec.back() <<= suboff*8;
      for(int4 i=0;i<valvec.size()-1;++i) { // Slide up valvec by suboff bytes
	tmp = valvec[i] << (suboff*8);
	tmp |= (valvec[i+1] >> ((sizeof(uintm)-suboff)*8));
	valvec[i] = tmp;
      }
      valvec.back() <<= suboff*8;
    }
    
    iter1 = maskvec.end();	// Cut zeros from end of mask
    iter2 = valvec.end();
    while(iter1 != maskvec.begin()) {
      --iter1;
      --iter2;
      if ((*iter1) != 0) break; // Find last non-zero
    }
    if (iter1 != maskvec.end()) {
      iter1++;			// Find first zero, in last zero chain
      iter2++;
    }
    maskvec.erase(iter1,maskvec.end());
    valvec.erase(iter2,valvec.end());
  }

  if (maskvec.empty()) {
    offset = 0;
    nonzerosize = 0;		// Always true
    return;
  }
  nonzerosize = maskvec.size() * sizeof(uintm);
  uintm tmp = maskvec.back();	// tmp must be nonzero
  while( (tmp&0xff) == 0) {
    nonzerosize -= 1;
    tmp >>= 8;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
cmpl $0x0, 0x4(%rdi)
jle 0x6c4e1
leaq 0x8(%rbx), %r15
movq 0x8(%rbx), %rsi
leaq 0x20(%rbx), %r14
movq 0x20(%rbx), %r12
movq 0x10(%rbx), %rax
movl (%rbx), %ecx
addl $0x4, %ecx
movq %rsi, %rdx
cmpq %rax, %rdx
je 0x6c45e
cmpl $0x0, (%rdx)
jne 0x6c45e
addq $0x4, %rdx
addq $0x4, %r12
movl %ecx, (%rbx)
addl $0x4, %ecx
jmp 0x6c445
movq %r15, %rdi
callq 0x4d410
movq 0x20(%rbx), %rsi
movq %r14, %rdi
movq %r12, %rdx
callq 0x4d410
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rdx
cmpq %rdx, %rdi
je 0x6c59b
movl (%rdi), %esi
pushq $-0x20
popq %rax
pushq $-0x4
popq %rcx
testl %esi, %esi
je 0x6c49c
shrl $0x8, %esi
addl $0x8, %eax
incl %ecx
jmp 0x6c48e
testl %eax, %eax
je 0x6c552
subl %ecx, (%rbx)
movq %rdx, %r8
subq %rdi, %r8
sarq $0x2, %r8
decq %r8
movl %eax, %esi
negl %esi
addl $0x20, %eax
xorl %r9d, %r9d
cmpq %r9, %r8
je 0x6c509
movl (%rdi,%r9,4), %r10d
movl 0x4(%rdi,%r9,4), %r11d
movl %esi, %ecx
shll %cl, %r10d
movl %eax, %ecx
shrl %cl, %r11d
orl %r10d, %r11d
movl %r11d, (%rdi,%r9,4)
incq %r9
jmp 0x6c4bd
andl $0x0, (%rbx)
movq 0x8(%rbx), %rax
cmpq %rax, 0x10(%rbx)
je 0x6c4f2
movq %rax, 0x10(%rbx)
movq 0x20(%rbx), %rax
cmpq %rax, 0x28(%rbx)
je 0x6c5bf
movq %rax, 0x28(%rbx)
jmp 0x6c5bf
movl %esi, %ecx
shll %cl, -0x4(%rdx)
movq 0x20(%rbx), %r8
movq 0x28(%rbx), %r12
movq %r12, %r9
subq %r8, %r9
sarq $0x2, %r9
decq %r9
xorl %r10d, %r10d
cmpq %r10, %r9
je 0x6c549
movl (%r8,%r10,4), %r11d
movl 0x4(%r8,%r10,4), %ebp
movl %esi, %ecx
shll %cl, %r11d
movl %eax, %ecx
shrl %cl, %ebp
orl %r11d, %ebp
movl %ebp, (%r8,%r10,4)
incq %r10
jmp 0x6c526
movl %esi, %ecx
shll %cl, -0x4(%r12)
jmp 0x6c556
movq 0x28(%rbx), %r12
movq %rdx, %rax
cmpq %rdi, %rax
je 0x6c571
leaq -0x4(%rax), %rsi
addq $-0x4, %r12
cmpl $0x0, -0x4(%rax)
movq %rsi, %rax
je 0x6c559
jmp 0x6c574
movq %rax, %rsi
addq $0x4, %r12
addq $0x4, %rsi
movq %r15, %rdi
callq 0x4d410
movq 0x28(%rbx), %rdx
movq %r14, %rdi
movq %r12, %rsi
callq 0x4d410
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rdx
cmpq %rdx, %rdi
je 0x6c5bb
movl %edx, %eax
subl %edi, %eax
andl $-0x4, %eax
movl %eax, 0x4(%rbx)
movl -0x4(%rdx), %ecx
decl %eax
testb %cl, %cl
jne 0x6c5bf
movl %eax, 0x4(%rbx)
shrl $0x8, %ecx
jmp 0x6c5ad
andq $0x0, (%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq