// File: jstaursky[P]hutch/src/Sleigh/slgh_compile.cc
// Function: SleighCompile::defineBitrange(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, VarnodeSymbol*, unsigned int, unsigned int)
void SleighCompile::defineBitrange(string *name,VarnodeSymbol *sym,uint4 bitoffset,uint4 numb)

{ // Define a new symbol as a subrange of bits within another symbol
  // If the ends of the range fall on byte boundaries, we
  // simply define a normal VarnodeSymbol, otherwise we create
  // a special symbol which is a place holder for the bitrange operator
  string namecopy = *name;
  delete name;
  uint4 size = 8*sym->getSize(); // Number of bits
  if (numb == 0) {
    reportError("Size of bitrange is zero for: "+namecopy,true);
    return;
  }
  if ((bitoffset >= size)||((bitoffset+numb)>size)) {
    reportError("Bad bitrange for: "+namecopy,true);
    return;
  }
  if ((bitoffset%8 == 0)&&(numb%8 == 0)) {
    // This can be reduced to an ordinary varnode definition
    AddrSpace *newspace = sym->getFixedVarnode().space;
    uintb newoffset = sym->getFixedVarnode().offset;
    int4 newsize = numb/8;
    if (isBigEndian())
      newoffset += (size-bitoffset-numb)/8;
    else
      newoffset += bitoffset/8;
    addSymbol( new VarnodeSymbol(namecopy,newspace,newoffset,newsize) );
  }
  else				// Otherwise define the special symbol
    addSymbol( new BitrangeSymbol(namecopy,sym,bitoffset,numb) );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x40(%rbp), %rdi
callq 0x11200
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0x64594
movq -0xc0(%rbp), %rdi
callq 0x11300
movq -0xc0(%rbp), %rdi
movl $0x20, %esi
callq 0x11450
movq -0x18(%rbp), %rdi
movq (%rdi), %rax
movq 0x48(%rax), %rax
callq *%rax
movl %eax, -0xcc(%rbp)
jmp 0x645a9
movl -0xcc(%rbp), %eax
shll $0x3, %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x64628
leaq 0x75119(%rip), %rsi     # 0xd96db
leaq -0x78(%rbp), %rdi
leaq -0x40(%rbp), %rdx
callq 0x147f0
jmp 0x645d1
movq -0xc8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0x1, %edx
callq 0x603b0
jmp 0x645e8
leaq -0x78(%rbp), %rdi
callq 0x11300
movl $0x1, -0x7c(%rbp)
jmp 0x64848
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x6485a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x11300
jmp 0x6485a
movl -0x1c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0x6463b
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
cmpl -0x44(%rbp), %eax
jbe 0x646a3
leaq 0x750b8(%rip), %rsi     # 0xd96fa
leaq -0xa0(%rbp), %rdi
leaq -0x40(%rbp), %rdx
callq 0x147f0
jmp 0x64654
movq -0xc8(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
movl $0x1, %edx
callq 0x603b0
jmp 0x6466e
leaq -0xa0(%rbp), %rdi
callq 0x11300
movl $0x1, -0x7c(%rbp)
jmp 0x64848
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x11300
jmp 0x6485a
movl -0x1c(%rbp), %eax
andl $0x7, %eax
cmpl $0x0, %eax
jne 0x647db
movl -0x20(%rbp), %eax
andl $0x7, %eax
cmpl $0x0, %eax
jne 0x647db
movq -0x18(%rbp), %rdi
callq 0x57780
movq %rax, -0xd8(%rbp)
jmp 0x646d3
movq -0xd8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x57780
movq %rax, -0xe0(%rbp)
jmp 0x646f6
movq -0xc8(%rbp), %rdi
movq -0xe0(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xb0(%rbp)
movl -0x20(%rbp), %eax
shrl $0x3, %eax
movl %eax, -0xb4(%rbp)
callq 0x57c80
movb %al, -0xe1(%rbp)
jmp 0x64728
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0x64734
jmp 0x64752
movl -0x44(%rbp), %eax
subl -0x1c(%rbp), %eax
subl -0x20(%rbp), %eax
shrl $0x3, %eax
movl %eax, %eax
addq -0xb0(%rbp), %rax
movq %rax, -0xb0(%rbp)
jmp 0x64768
movl -0x1c(%rbp), %eax
shrl $0x3, %eax
movl %eax, %eax
addq -0xb0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movl $0x58, %edi
callq 0x11440
movq %rax, -0xf0(%rbp)
jmp 0x6477b
movq -0xf0(%rbp), %rdi
movq -0xa8(%rbp), %rdx
movq -0xb0(%rbp), %rcx
movl -0xb4(%rbp), %r8d
leaq -0x40(%rbp), %rsi
callq 0xa6800
jmp 0x647a2
movq -0xf0(%rbp), %rsi
movq -0xc8(%rbp), %rdi
callq 0x60f90
jmp 0x647b7
jmp 0x64841
movq -0xf0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x58, %esi
callq 0x11450
jmp 0x6485a
movl $0x40, %edi
callq 0x11440
movq %rax, -0xf8(%rbp)
jmp 0x647ee
movq -0xf8(%rbp), %rdi
movq -0x18(%rbp), %rdx
movl -0x1c(%rbp), %ecx
movl -0x20(%rbp), %r8d
leaq -0x40(%rbp), %rsi
callq 0x6bf50
jmp 0x6480b
movq -0xf8(%rbp), %rsi
movq -0xc8(%rbp), %rdi
callq 0x60f90
jmp 0x64820
jmp 0x64841
movq -0xf8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x40, %esi
callq 0x11450
jmp 0x6485a
movl $0x0, -0x7c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x11300
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x11300
movq -0x50(%rbp), %rdi
callq 0x118b0
nopl (%rax)