// File: /workspace/github_cpp_makefile_star2_O1/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 0x61d5b
movq 0x8(%rbx), %r15
movq 0x10(%rbx), %rdx
movq 0x20(%rbx), %r14
cmpq %rdx, %r15
je 0x61d86
movl (%rbx), %eax
addl $0x4, %eax
movq %r15, %r12
cmpl $0x0, (%r12)
jne 0x61d89
addq $0x4, %r12
addq $0x4, %r14
movl %eax, (%rbx)
addl $0x4, %eax
cmpq %rdx, %r12
jne 0x61d40
jmp 0x61d89
movl $0x0, (%rbx)
movq 0x8(%rbx), %rax
cmpq %rax, 0x10(%rbx)
je 0x61d6f
movq %rax, 0x10(%rbx)
movq 0x20(%rbx), %rax
cmpq %rax, 0x28(%rbx)
je 0x61f56
movq %rax, 0x28(%rbx)
jmp 0x61f56
movq %r15, %r12
cmpq %r15, %r12
je 0x61db4
subq %r12, %rdx
je 0x61d9e
movq %r15, %rdi
movq %r12, %rsi
callq 0x41a30
movq 0x10(%rbx), %rax
movq %rax, %rcx
subq %r12, %rcx
addq %rcx, %r15
cmpq %r15, %rax
je 0x61db4
movq %r15, 0x10(%rbx)
movq 0x20(%rbx), %r15
cmpq %r15, %r14
je 0x61de7
movq 0x28(%rbx), %rdx
subq %r14, %rdx
je 0x61dd1
movq %r15, %rdi
movq %r14, %rsi
callq 0x41a30
movq 0x28(%rbx), %rax
movq %rax, %rcx
subq %r14, %rcx
addq %rcx, %r15
cmpq %r15, %rax
je 0x61de7
movq %r15, 0x28(%rbx)
movq 0x8(%rbx), %r9
movq 0x10(%rbx), %r8
cmpq %r8, %r9
je 0x61f1b
movl (%r9), %ecx
xorl %eax, %eax
testl %ecx, %ecx
je 0x61e12
movl %ecx, %edx
incl %eax
shrl $0x8, %edx
cmpl $0xff, %ecx
movl %edx, %ecx
ja 0x61e03
movl %eax, %edx
subl $0x4, %edx
je 0x61eae
negl %edx
addl %edx, (%rbx)
movq %r8, %r10
subq %r9, %r10
sarq $0x2, %r10
decq %r10
je 0x61e62
leal (,%rdx,8), %esi
leal (,%rax,8), %edi
xorl %r11d, %r11d
movl (%r9,%r11,4), %ebp
movl 0x4(%r9,%r11,4), %r14d
movl %esi, %ecx
shll %cl, %ebp
movl %edi, %ecx
shrl %cl, %r14d
orl %ebp, %r14d
movl %r14d, (%r9,%r11,4)
incq %r11
cmpq %r11, %r10
jne 0x61e41
shll $0x3, %edx
movl %edx, %ecx
shll %cl, -0x4(%r8)
movq 0x20(%rbx), %rdi
movq 0x28(%rbx), %rsi
movq %rsi, %r10
subq %rdi, %r10
sarq $0x2, %r10
decq %r10
je 0x61ea9
shll $0x3, %eax
xorl %r11d, %r11d
movl (%rdi,%r11,4), %ebp
movl 0x4(%rdi,%r11,4), %r14d
movl %edx, %ecx
shll %cl, %ebp
movl %eax, %ecx
shrl %cl, %r14d
orl %ebp, %r14d
movl %r14d, (%rdi,%r11,4)
incq %r11
cmpq %r11, %r10
jne 0x61e88
movl %edx, %ecx
shll %cl, -0x4(%rsi)
movq 0x28(%rbx), %rax
movq %r8, %rdx
cmpq %r9, %rdx
je 0x61ecd
leaq -0x4(%rdx), %rcx
addq $-0x4, %rax
cmpl $0x0, -0x4(%rdx)
movq %rcx, %rdx
je 0x61eb5
jmp 0x61ed0
movq %rdx, %rcx
xorl %edx, %edx
cmpq %r8, %rcx
setne %dl
shll $0x2, %edx
addq %rdx, %rax
addq %rdx, %rcx
cmpq %r8, %rcx
je 0x61efc
movq 0x10(%rbx), %rdx
movq %rdx, %rsi
subq %r8, %rsi
addq %rsi, %rcx
cmpq %rcx, %rdx
je 0x61efc
movq %rcx, 0x10(%rbx)
movq 0x28(%rbx), %rcx
cmpq %rcx, %rax
je 0x61f1b
movq 0x28(%rbx), %rdx
movq %rdx, %rsi
subq %rcx, %rsi
addq %rsi, %rax
cmpq %rax, %rdx
je 0x61f1b
movq %rax, 0x28(%rbx)
movq 0x8(%rbx), %rdx
movq 0x10(%rbx), %rcx
cmpq %rcx, %rdx
je 0x61f4f
movl %ecx, %eax
subl %edx, %eax
andl $-0x4, %eax
movl %eax, 0x4(%rbx)
movl -0x4(%rcx), %ecx
testb %cl, %cl
jne 0x61f56
movl %ecx, %edx
decl %eax
shrl $0x8, %edx
testl $0xff00, %ecx           # imm = 0xFF00
movl %edx, %ecx
je 0x61f3b
movl %eax, 0x4(%rbx)
jmp 0x61f56
movq $0x0, (%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop