// File: /workspace/github_cpp_makefile_star2_O2/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 %edx, %ecx
movl %esi, %eax
pushq $0x8
popq %rsi
cltd
idivl %esi
movl %edx, %r12d
movl %eax, %r14d
movl %ecx, %eax
cltd
idivl %esi
movl %eax, %ebp
shll $0x3, %r14d
shll $0x3, %ebp
cmpl %ebp, %r14d
jne 0x6715c
movl %r14d, %edi
subl %edx, %edi
addl $0x7, %edi
subl %r12d, %r14d
addl $0x7, %r14d
movl %r14d, %esi
movl %ebx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x51d40
movl %edx, 0x4(%rsp)
movl %r14d, %esi
subl %r12d, %esi
addl $0x7, %esi
movl %r14d, %edi
movl %ebx, %edx
callq 0x51d40
movb $0x8, %cl
subb %r12b, %cl
sarq %cl, %rbx
movq %rax, %r15
addl $0x8, %r14d
cmpl %r14d, %ebp
je 0x671e5
leal 0x7(%r14), %esi
movl %r14d, %edi
movl %ebx, %edx
callq 0x51d40
movq %rax, %r12
testq %r15, %r15
je 0x671d8
movq %r15, %rdi
movq %r12, %rsi
callq 0x501a0
movq %rax, %r13
movq %r15, %rdi
callq 0x4e1e0
movq %r15, %rdi
pushq $0x38
popq %r15
movq %r15, %rsi
callq 0x4f670
movq %r12, %rdi
callq 0x4e1e0
movq %r12, %rdi
movq %r15, %rsi
callq 0x4f670
movq %r13, %r12
sarq $0x8, %rbx
addl $0x8, %r14d
movq %r12, %r15
jmp 0x67182
movl %ebp, %edi
subl 0x4(%rsp), %edi
addl $0x7, %edi
orl $0x7, %ebp
movl %ebp, %esi
movl %ebx, %edx
callq 0x51d40
movq %rax, %rbx
testq %r15, %r15
je 0x6723f
movq %r15, %rdi
movq %rbx, %rsi
callq 0x501a0
movq %rax, %r14
movq %r15, %rdi
callq 0x4e1e0
pushq $0x38
popq %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x4f670
movq %rbx, %rdi
callq 0x4e1e0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4f670
movq %r14, %rax
jmp 0x67242
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop