// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movl %esi, 0x2c(%rsp)
movl %edx, 0x28(%rsp)
movl %ecx, 0x24(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
movb $0x0, 0x23(%rsp)
movl 0x10(%rax), %ecx
subl 0xc(%rax), %ecx
movl %ecx, %ecx
addq $0x1, %rcx
movq %rcx, 0x18(%rsp)
movl 0xc(%rax), %ecx
movq 0x18(%rsp), %rax
movl 0x28(%rsp), %edx
imulq %rdx, %rax
movl 0x24(%rsp), %edx
movl %edx, %esi
xorl %edx, %edx
divq %rsi
movq %rax, %rdx
movq 0x8(%rsp), %rax
subq $0x1, %rdx
addl %edx, %ecx
movl %ecx, 0x10(%rax)
movl 0xc(%rax), %ecx
movq 0x18(%rsp), %rax
movl 0x2c(%rsp), %edx
imulq %rdx, %rax
movl 0x24(%rsp), %edx
movl %edx, %esi
xorl %edx, %edx
divq %rsi
movq %rax, %rdx
movq 0x8(%rsp), %rax
addl %edx, %ecx
movl %ecx, 0xc(%rax)
movq 0x8(%rsp), %rcx
movl 0x10(%rcx), %eax
shrl $0x1f, %eax
movl 0xc(%rcx), %ecx
shrl $0x1f, %ecx
cmpl %ecx, %eax
sete %cl
movb %cl, %al
andb $0x1, %al
movb %al, 0x22(%rsp)
movb $0x1, %al
testb $0x1, %cl
movb %al, 0x7(%rsp)
jne 0x3f14
movq 0x8(%rsp), %rax
movl 0xc(%rax), %ecx
shrl $0x1e, %ecx
andl $0x1, %ecx
xorl %eax, %eax
cmpl $0x1, %ecx
movb %al, 0x6(%rsp)
jne 0x3f03
movq 0x8(%rsp), %rax
movl 0x10(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
sete %al
movb %al, 0x6(%rsp)
movb 0x6(%rsp), %al
movb %al, %cl
andb $0x1, %cl
movb %cl, 0x23(%rsp)
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x3f21
jmp 0x4003
testb $0x1, 0x22(%rsp)
je 0x3fb6
movq 0x8(%rsp), %rax
movl 0x10(%rax), %esi
shrl $0x1f, %esi
movl $0x1, %ecx
xorl %edx, %edx
cmpl $0x0, %esi
cmovel %edx, %ecx
cmpl $0x0, %ecx
setne %cl
andb $0x1, %cl
movb %cl, 0x17(%rsp)
movq (%rax), %rdi
movb 0x17(%rsp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x41c0
movq 0x8(%rsp), %rax
movl 0xc(%rax), %ecx
shll %ecx
movl %ecx, 0xc(%rax)
movl 0x10(%rax), %ecx
shll %ecx
movl %ecx, 0x10(%rax)
movl 0x10(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq 0x8(%rsp), %rax
cmpl $0x0, 0x14(%rax)
jle 0x3fb4
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movb 0x17(%rsp), %al
xorb $-0x1, %al
movzbl %al, %esi
andl $0x1, %esi
callq 0x41c0
movq 0x8(%rsp), %rax
movl 0x14(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x14(%rax)
jmp 0x3f80
jmp 0x3ffe
testb $0x1, 0x23(%rsp)
je 0x3ffc
movq 0x8(%rsp), %rax
movl 0xc(%rax), %ecx
shll %ecx
movl %ecx, 0xc(%rax)
movl 0x10(%rax), %ecx
shll %ecx
movl %ecx, 0x10(%rax)
movl 0x10(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x10(%rax)
movl 0xc(%rax), %ecx
addl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movl 0x10(%rax), %ecx
addl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x10(%rax)
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
jmp 0x3ffe
jmp 0x3ea9
addq $0x38, %rsp
retq
nopl (%rax,%rax)