// File: /workspace/github_cpp_makefile_star2_O1/jstaursky[P]hutch/src/Sleigh/slghpatexpress.cc
// Function: TokenPattern::buildLittleBlock(int, int, int, long)
PatternBlock *TokenPattern::buildLittleBlock(int4 size,int4 bitstart,int4 bitend,intb value)

{				// Build pattern block given a littleendian contiguous
				// range of bits and a value for those bits
  PatternBlock *tmpblock,*block;
  int4 startbit,endbit;

  block = (PatternBlock *)0;

  // we need to convert a bit range specified on a little endian token where the
  // bit indices label the least sig bit as 0 into a bit range on big endian bytes
  // where the indices label the most sig bit as 0.  The reversal due to
  // little->big endian cancels part of the reversal due to least->most sig bit
  // labelling, but not on the lower 3 bits.  So the transform becomes
  // leave the upper bits the same, but transform the lower 3-bit value x into 7-x.

  startbit = (bitstart/8) * 8;	// Get the high-order portion of little/LSB labelling
  endbit = (bitend/8) * 8;
  bitend = bitend % 8;		// Get the low-order portion of little/LSB labelling
  bitstart = bitstart % 8;

  if (startbit == endbit) {
    startbit += 7 - bitend;
    endbit += 7 - bitstart;
    block = buildSingle(startbit,endbit,(uintm)value);
  }
  else {
    block = buildSingle(startbit,startbit+(7-bitstart),(uintm)value);
    value >>= (8-bitstart);	// Cut off bits we just encoded
    startbit += 8;
    while(startbit != endbit) {
      tmpblock = buildSingle(startbit,startbit+7,(uintm)value);
      if (block == (PatternBlock *)0)
	block = tmpblock;
      else {
	PatternBlock *newblock = block->intersect(tmpblock);
	delete block;
	delete tmpblock;
	block = newblock;
      }
      value >>= 8;
      startbit += 8;
    }
    tmpblock = buildSingle(endbit+(7-bitend),endbit+7,(uintm)value);
    if (block == (PatternBlock *)0)
      block = tmpblock;
    else {
      PatternBlock *newblock = block->intersect(tmpblock);
      delete block;
      delete tmpblock;
      block = newblock;
    }
  }
  return block;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movl %esi, %r14d
leal 0x7(%r14), %r15d
testl %esi, %esi
cmovnsl %esi, %r15d
andl $-0x8, %r15d
leal 0x7(%rdx), %ebp
testl %edx, %edx
cmovnsl %edx, %ebp
andl $-0x8, %ebp
subl %ebp, %edx
subl %r15d, %r14d
cmpl %ebp, %r15d
jne 0x5ba9b
subl %edx, %r15d
addl $0x7, %r15d
subl %r14d, %ebp
addl $0x7, %ebp
movl %r15d, %edi
movl %ebp, %esi
movl %ebx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42220
movq %rdx, (%rsp)
movl %r15d, %esi
subl %r14d, %esi
addl $0x7, %esi
movl %r15d, %edi
movl %ebx, %edx
callq 0x42220
movb $0x8, %cl
subb %r14b, %cl
sarq %cl, %rbx
movq %rax, %r13
addl $0x8, %r15d
cmpl %ebp, %r15d
jne 0x5bace
movq %r13, %r12
jmp 0x5bb7f
leal 0x7(%r15), %esi
movl %r15d, %edi
movl %ebx, %edx
callq 0x42220
movq %rax, %r12
testq %r13, %r13
je 0x5bb6b
movq %r13, %rdi
movq %r12, %rsi
callq 0x40f20
movq %rax, %r14
movq 0x20(%r13), %rdi
testq %rdi, %rdi
je 0x5bb0b
movq 0x30(%r13), %rsi
subq %rdi, %rsi
callq 0x40870
movq 0x8(%r13), %rdi
testq %rdi, %rdi
je 0x5bb20
movq 0x18(%r13), %rsi
subq %rdi, %rsi
callq 0x40870
movl $0x38, %esi
movq %r13, %rdi
callq 0x40870
movq 0x20(%r12), %rdi
testq %rdi, %rdi
je 0x5bb44
movq 0x30(%r12), %rsi
subq %rdi, %rsi
callq 0x40870
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x5bb5b
movq 0x18(%r12), %rsi
subq %rdi, %rsi
callq 0x40870
movl $0x38, %esi
movq %r12, %rdi
callq 0x40870
movq %r14, %r12
sarq $0x8, %rbx
addl $0x8, %r15d
movq %r12, %r13
cmpl %r15d, %ebp
jne 0x5bace
movl %ebp, %edi
subl (%rsp), %edi
addl $0x7, %edi
orl $0x7, %ebp
movl %ebp, %esi
movl %ebx, %edx
callq 0x42220
movq %rax, %rbx
testq %r12, %r12
je 0x5bc22
movq %r12, %rdi
movq %rbx, %rsi
callq 0x40f20
movq %rax, %r14
movq 0x20(%r12), %rdi
testq %rdi, %rdi
je 0x5bbc4
movq 0x30(%r12), %rsi
subq %rdi, %rsi
callq 0x40870
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x5bbdb
movq 0x18(%r12), %rsi
subq %rdi, %rsi
callq 0x40870
movl $0x38, %esi
movq %r12, %rdi
callq 0x40870
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x5bbfd
movq 0x30(%rbx), %rsi
subq %rdi, %rsi
callq 0x40870
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x5bc12
movq 0x18(%rbx), %rsi
subq %rdi, %rsi
callq 0x40870
movl $0x38, %esi
movq %rbx, %rdi
callq 0x40870
movq %r14, %rbx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq