// File: /workspace/github_c_makefile_star2_O1/ijleesw[P]data-compression/src/arithmetic/arithmetic_encoder.h
// Function: arithmetic_encoder::encode(unsigned int, unsigned int, unsigned int)
inline void encode(DWORD lower_bound, DWORD upper_bound, DWORD total)
  {    
    bool e3_cond = false;
    bool eql_cond;

    QWORD range = (QWORD)(u - l) + 1;

    ASSERT(l < u);
    ASSERT((lower_bound <= upper_bound) && (upper_bound <= total));
    
    u = l + (DWORD)(((range * upper_bound) / total) - 1);
    l = l + (DWORD)((range * lower_bound) / total);

    while( (eql_cond = (MSB(u) == MSB(l))) ||
           (e3_cond  = (M2SB(l) == 1) && (M2SB(u) == 0)) )
    {  
      if(eql_cond)
      {
        bit bit_to_send = ((MSB(u) == 0) ? 0 : 1);
        m_output->send(bit_to_send);
        
        l <<= 1;
        u <<= 1;
        u |= 1;

        while (scale3 > 0)
        {
          m_output->send(!bit_to_send);
          --scale3;
        }
      }
      else if (e3_cond)
      {
        l <<= 1;
        u <<= 1;
        u |= 1;
        
        l += MSB_MASK; 
        u += MSB_MASK;

        ++scale3;
      }
    }
    ASSERT(l < u);
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdi, %rbx
movl 0xc(%rdi), %edi
movl 0x10(%rbx), %r8d
subl %edi, %r8d
incq %r8
movl %edx, %eax
imulq %r8, %rax
movl %ecx, %ecx
xorl %r14d, %r14d
xorl %edx, %edx
divq %rcx
addl %edi, %eax
decl %eax
movl %eax, 0x10(%rbx)
movl %esi, %eax
imulq %r8, %rax
xorl %edx, %edx
divq %rcx
addl %edi, %eax
movl %eax, 0xc(%rbx)
movl 0xc(%rbx), %eax
movl 0x10(%rbx), %r15d
movl %eax, %ecx
xorl %r15d, %ecx
jns 0x2d8e
btl $0x1e, %eax
jae 0x2ecc
testl $0x40000000, %r15d      # imm = 0x40000000
sete %r14b
jne 0x2ecc
testl %ecx, %ecx
js 0x2ea5
movq (%rbx), %r12
cmpl $0x0, 0x1c(%r12)
jne 0x2df5
movb 0x10(%r12), %al
movq 0x8(%r12), %rcx
movl 0x14(%r12), %edx
movb %al, (%rcx,%rdx)
movl 0x14(%r12), %eax
movl 0x18(%r12), %edx
incl %eax
movl %eax, 0x14(%r12)
cmpl %edx, %eax
jne 0x2de6
movl (%r12), %edi
movq 0x8(%r12), %rsi
callq 0x2040
movl $0x0, 0x14(%r12)
cmpl %eax, 0x18(%r12)
jne 0x2e0e
movl $0x8, 0x1c(%r12)
movb $0x0, 0x10(%r12)
decl 0x1c(%r12)
movb 0x10(%r12), %al
addb %al, %al
movl %r15d, %ecx
shrl $0x1f, %ecx
orb %al, %cl
movb %cl, 0x10(%r12)
shll 0xc(%rbx)
movl 0x10(%rbx), %eax
leal 0x1(,%rax,2), %eax
movl %eax, 0x10(%rbx)
cmpl $0x0, 0x14(%rbx)
jle 0x2d65
testl %r15d, %r15d
setns %bpl
movq (%rbx), %r15
cmpl $0x0, 0x1c(%r15)
jne 0x2e81
movb 0x10(%r15), %al
movq 0x8(%r15), %rcx
movl 0x14(%r15), %edx
movb %al, (%rcx,%rdx)
movl 0x14(%r15), %eax
movl 0x18(%r15), %edx
incl %eax
movl %eax, 0x14(%r15)
cmpl %edx, %eax
jne 0x2e74
movl (%r15), %edi
movq 0x8(%r15), %rsi
callq 0x2040
movl $0x0, 0x14(%r15)
cmpl %eax, 0x18(%r15)
jne 0x2e92
movl $0x8, 0x1c(%r15)
movb $0x0, 0x10(%r15)
decl 0x1c(%r15)
movb 0x10(%r15), %al
addb %al, %al
orb %bpl, %al
movb %al, 0x10(%r15)
movl 0x14(%rbx), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x14(%rbx)
cmpl $0x1, %eax
jg 0x2e2f
jmp 0x2d65
testb $0x1, %r14b
je 0x2d65
leal -0x80000000(,%rax,2), %eax
movl %eax, 0xc(%rbx)
leal -0x7fffffff(,%r15,2), %eax
movl %eax, 0x10(%rbx)
incl 0x14(%rbx)
jmp 0x2d65
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop