// File: /workspace/github_cpp_makefile_star2_O3/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 0x61b0c
movq 0x8(%rbx), %r15
movq 0x10(%rbx), %rdx
movq 0x20(%rbx), %r14
cmpq %rdx, %r15
je 0x61b4c
movl (%rbx), %eax
addl $0x4, %eax
movq %r15, %r12
cmpl $0x0, (%r12)
jne 0x61aee
addq $0x4, %r12
addq $0x4, %r14
movl %eax, (%rbx)
addl $0x4, %eax
cmpq %rdx, %r12
jne 0x61ad2
movq %rdx, %r12
cmpq %r15, %r12
je 0x61b4c
subq %r12, %rdx
je 0x61b37
movq %r15, %rdi
movq %r12, %rsi
callq 0x41a40
movq 0x10(%rbx), %rax
movq %rax, %rcx
jmp 0x61b3d
movl $0x0, (%rbx)
movq 0x8(%rbx), %rax
cmpq %rax, 0x10(%rbx)
je 0x61b20
movq %rax, 0x10(%rbx)
movq 0x20(%rbx), %rax
cmpq %rax, 0x28(%rbx)
je 0x61ce0
movq %rax, 0x28(%rbx)
jmp 0x61ce0
movq %r12, %rax
movq %r12, %rcx
subq %r12, %rax
addq %rax, %r15
cmpq %r15, %rcx
je 0x61b4c
movq %r15, 0x10(%rbx)
movq 0x20(%rbx), %r15
cmpq %r15, %r14
je 0x61b87
movq 0x28(%rbx), %rdx
subq %r14, %rdx
je 0x61b72
movq %r15, %rdi
movq %r14, %rsi
callq 0x41a40
movq 0x28(%rbx), %rax
movq %rax, %rcx
jmp 0x61b78
movq %r14, %rax
movq %r14, %rcx
subq %r14, %rax
addq %rax, %r15
cmpq %r15, %rcx
je 0x61b87
movq %r15, 0x28(%rbx)
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %r8
cmpq %r8, %rdi
je 0x61cab
movl (%rdi), %ecx
testl %ecx, %ecx
je 0x61bc5
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
movl %ecx, %edx
shrl $0x8, %edx
incl %eax
cmpl $0xff, %ecx
movl %edx, %ecx
ja 0x61ba5
testl %eax, %eax
je 0x61c69
movl %eax, %edx
negl %edx
addl $0x4, %eax
jmp 0x61bcc
xorl %eax, %eax
movl $0x4, %edx
addl %edx, (%rbx)
movq %r8, %r9
subq %rdi, %r9
sarq $0x2, %r9
shll $0x3, %edx
cmpq $0x1, %r9
je 0x61c15
leal (,%rax,8), %esi
movl (%rdi), %r11d
movl $0x1, %r10d
movl %edx, %ecx
shll %cl, %r11d
movl (%rdi,%r10,4), %ebp
movl %ebp, %r14d
movl %esi, %ecx
shrl %cl, %r14d
orl %r11d, %r14d
movl %r14d, -0x4(%rdi,%r10,4)
incq %r10
movl %ebp, %r11d
cmpq %r10, %r9
jne 0x61bf1
movl %edx, %ecx
shll %cl, -0x4(%r8)
movq 0x20(%rbx), %r9
movq 0x28(%rbx), %rsi
movq %rsi, %r10
subq %r9, %r10
sarq $0x2, %r10
cmpq $0x1, %r10
je 0x61c62
shll $0x3, %eax
movl (%r9), %ebp
movl $0x1, %r11d
movl %edx, %ecx
shll %cl, %ebp
movl (%r9,%r11,4), %r14d
movl %r14d, %r15d
movl %eax, %ecx
shrl %cl, %r15d
orl %ebp, %r15d
movl %r15d, -0x4(%r9,%r11,4)
incq %r11
movl %r14d, %ebp
cmpq %r11, %r10
jne 0x61c3f
movl %edx, %ecx
shll %cl, -0x4(%rsi)
jmp 0x61c6d
movq 0x28(%rbx), %rsi
movq %rsi, %rax
movq %r8, %rdx
cmpq %rdi, %rdx
je 0x61c8b
leaq -0x4(%rdx), %rcx
addq $-0x4, %rax
cmpl $0x0, -0x4(%rdx)
movq %rcx, %rdx
je 0x61c73
jmp 0x61c8e
movq %rdx, %rcx
addq $0x4, %rcx
addq $0x4, %rax
cmpq %r8, %rcx
je 0x61ca2
movq %rcx, 0x10(%rbx)
movq %rcx, %r8
cmpq %rsi, %rax
je 0x61cab
movq %rax, 0x28(%rbx)
cmpq %r8, %rdi
je 0x61cd9
movl %r8d, %eax
subl %edi, %eax
andl $-0x4, %eax
movl %eax, 0x4(%rbx)
movl -0x4(%r8), %ecx
testb %cl, %cl
jne 0x61ce0
movl %ecx, %edx
decl %eax
shrl $0x8, %edx
testl $0xff00, %ecx           # imm = 0xFF00
movl %edx, %ecx
je 0x61cc5
movl %eax, 0x4(%rbx)
jmp 0x61ce0
movq $0x0, (%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop