// File: /workspace/github_cpp_makefile_star2_O3/cloudinary[P]fuif/encoding/../maniac/symbol_enc.h
// Function: void writer<15, CompoundSymbolBitCoder<SimpleBitChance, RacDummy<DummyIO>, 15>>(CompoundSymbolBitCoder<SimpleBitChance, RacDummy<DummyIO>, 15>&, int, int, int)
void writer(SymbolCoder& coder, int min, int max, int value) {
    assert(min<=max);
    assert(value>=min);
    assert(value<=max);

    // avoid doing anything if the value is already known
    if (min == max) return;

    if (value == 0) { // value is zero
        coder.write(true, BIT_ZERO);
        return;
    }

    assert(min <= 0 && max >= 0); // should always be the case, because guess should always be in valid range

    coder.write(false,BIT_ZERO);
    int sign = (value > 0 ? 1 : 0);
    if (max > 0 && min < 0) {
        // only output sign bit if value can be both pos and neg
        coder.write(sign,BIT_SIGN);
    }
    const int a = abs(value);
    const int e = maniac::util::ilog2(a);
    int amax = sign ? abs(max) : abs(min);

    int emax = maniac::util::ilog2(amax);

    int i = 0; //maniac::util::ilog2(amin);
    while (i < emax) {
        // if exponent >i is impossible, we are done
        if ((1 << (i+1)) > amax) break;
        // if exponent i is possible, output the exponent bit
        coder.write(i==e, BIT_EXP, i);
        if (i==e) break;
        i++;
    }

    int have = (1 << e);
    int left = have-1;
    for (int pos = e; pos>0;) {
        int bit = 1;
        left ^= (1 << (--pos));
        int minabs1 = have | (1<<pos);
        if (minabs1 > amax) { // 1-bit is impossible
            bit = 0;
        } else {
            bit = (a >> pos) & 1;
            coder.write(bit, BIT_MANT, pos);
        }
        have |= (bit << pos);
    }
}

// Assembly:
cmpl %edx, %esi
je 0x1b02e
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x10(%rdi), %r9
movzwl (%r9), %r10d
testl %ecx, %ecx
movq %r9, -0x48(%rsp)
je 0x1aba7
movl %edx, -0x4c(%rsp)
movl $0x1000, %eax           # imm = 0x1000
subq %r10, %rax
leaq 0x15b57(%rip), %rdx     # 0x30630
movzwl (%rdx,%rax,2), %eax
addq 0x58(%r9), %rax
movq 0x40(%r9), %rbx
movq 0x48(%r9), %rdx
movq %rdx, %r8
subq %rbx, %r8
sarq $0x2, %r8
movabsq $-0x1084210842108421, %r9 # imm = 0xEF7BDEF7BDEF7BDF
imulq %r8, %r9
movq %r9, -0x40(%rsp)
movq -0x48(%rsp), %r9
movq %rax, 0x58(%r9)
movq (%rdi), %r14
movzwl (%r14,%r10,4), %r8d
movw %r8w, (%r9)
movq %rdx, -0x28(%rsp)
cmpq %rbx, %rdx
movq %rdi, -0x38(%rsp)
je 0x1ac51
movq 0x18(%rdi), %rdi
movq (%rdi), %r11
movq 0x60(%r9), %r10
movw $0xffff, %di            # imm = 0xFFFF
xorl %r15d, %r15d
movq %rbx, %r12
leaq 0x15ae6(%rip), %rdx     # 0x30630
movl %r15d, %r8d
shrl $0x6, %r8d
movq (%r11,%r8,8), %r8
btq %r15, %r8
jae 0x1ab60
movq %r12, %r8
jmp 0x1ab65
leaq 0x3e(%r12), %r8
movzwl (%r8), %r13d
movl $0x1000, %ebp           # imm = 0x1000
subq %r13, %rbp
movzwl (%rdx,%rbp,2), %ebp
addq (%r10,%r15,8), %rbp
movq %rbp, (%r10,%r15,8)
movzwl (%r14,%r13,4), %r13d
movw %r13w, (%r8)
cmpq %rax, %rbp
cmovbq %rbp, %rax
cmovbl %r15d, %edi
incq %r15
movl %r15d, %r8d
addq $0x7c, %r12
cmpq %r8, -0x40(%rsp)
ja 0x1ab4a
jmp 0x1ac55
leaq 0x15a82(%rip), %rax     # 0x30630
movzwl (%rax,%r10,2), %ecx
addq 0x58(%r9), %rcx
movq 0x40(%r9), %rdx
movq 0x48(%r9), %r8
movq %rcx, 0x58(%r9)
movq (%rdi), %rsi
movzwl 0x2(%rsi,%r10,4), %r10d
movw %r10w, (%r9)
subq %rdx, %r8
je 0x1ad3f
sarq $0x2, %r8
movabsq $-0x1084210842108421, %r12 # imm = 0xEF7BDEF7BDEF7BDF
imulq %r8, %r12
movq 0x18(%rdi), %r8
movq (%r8), %r10
movq 0x60(%r9), %r11
movw $0xffff, %r9w           # imm = 0xFFFF
xorl %ebx, %ebx
movl %ebx, %r8d
shrl $0x6, %r8d
movq (%r10,%r8,8), %r8
btq %rbx, %r8
jae 0x1ac13
movq %rdx, %r8
jmp 0x1ac17
leaq 0x3e(%rdx), %r8
movzwl (%r8), %r14d
movzwl (%rax,%r14,2), %r15d
addq (%r11,%rbx,8), %r15
movq %r15, (%r11,%rbx,8)
movzwl 0x2(%rsi,%r14,4), %ebp
movw %bp, (%r8)
cmpq %rcx, %r15
cmovbq %r15, %rcx
cmovbl %ebx, %r9d
incq %rbx
movl %ebx, %r8d
addq $0x7c, %rdx
cmpq %r8, %r12
ja 0x1abfd
jmp 0x1ad44
movw $0xffff, %di            # imm = 0xFFFF
movw %di, 0x94(%r9)
movl -0x4c(%rsp), %edx
testl %edx, %edx
setle %al
testl %esi, %esi
setns %dil
orb %al, %dil
jne 0x1ad6b
movzwl 0x2(%r9), %r8d
movl $0x1000, %edi           # imm = 0x1000
subq %r8, %rdi
xorl %edx, %edx
testl %ecx, %ecx
setg %dl
cmovgq %r8, %rdi
leaq 0x1599c(%rip), %rax     # 0x30630
movzwl (%rax,%rdi,2), %edi
addq 0x58(%r9), %rdi
movq %rdi, 0x58(%r9)
leaq (%r14,%r8,4), %r8
movzwl (%r8,%rdx,2), %r8d
movw %r8w, 0x2(%r9)
cmpq %rbx, -0x28(%rsp)
movq -0x38(%rsp), %rax
je 0x1ad56
movq 0x18(%rax), %r8
movq (%r8), %r15
movq 0x60(%r9), %r12
leaq 0x40(%rbx), %r11
movw $0xffff, %bp            # imm = 0xFFFF
xorl %r10d, %r10d
leaq 0x15955(%rip), %r9      # 0x30630
movl %r10d, %r8d
shrl $0x6, %r8d
movq (%r15,%r8,8), %r8
btq %r10, %r8
movq %r11, %r13
jae 0x1acf3
leaq -0x3e(%r11), %r13
movzwl (%r13), %r8d
movl $0x1000, %eax           # imm = 0x1000
subq %r8, %rax
testl %ecx, %ecx
cmovgq %r8, %rax
movzwl (%r9,%rax,2), %eax
addq (%r12,%r10,8), %rax
movq %rax, (%r12,%r10,8)
leaq (%r14,%r8,4), %r8
movzwl (%r8,%rdx,2), %r8d
movw %r8w, (%r13)
cmpq %rdi, %rax
cmovbq %rax, %rdi
cmovbl %r10d, %ebp
incq %r10
movl %r10d, %eax
addq $0x7c, %r11
cmpq %rax, -0x40(%rsp)
ja 0x1acdb
jmp 0x1ad5a
movw $0xffff, %r9w           # imm = 0xFFFF
movq -0x48(%rsp), %rax
movw %r9w, 0x94(%rax)
jmp 0x1b024
movw $0xffff, %bp            # imm = 0xFFFF
movq -0x48(%rsp), %r9
movw %bp, 0x94(%r9)
movl -0x4c(%rsp), %edx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
movl %eax, -0xc(%rsp)
bsrl %eax, %edi
movl %edi, %eax
xorl $0x1f, %eax
movl %eax, -0x10(%rsp)
testl %ecx, %ecx
cmovgl %edx, %esi
movl %esi, %eax
negl %eax
cmovsl %esi, %eax
movl %edi, -0x14(%rsp)
movl %edi, %esi
movl %eax, -0x4c(%rsp)
testl %eax, %eax
movq %rbx, -0x8(%rsp)
je 0x1aedc
movq -0x38(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rsp)
bsrl -0x4c(%rsp), %eax
movq %rax, -0x20(%rsp)
leaq 0x42(%rbx), %r8
xorl %ecx, %ecx
cmpq -0x20(%rsp), %rcx
je 0x1aedc
movl $0x2, %eax
shll %cl, %eax
cmpl -0x4c(%rsp), %eax
jg 0x1aedc
movzwl 0x4(%r9,%rcx,2), %eax
movl $0x1000, %edx           # imm = 0x1000
subq %rax, %rdx
xorl %r15d, %r15d
cmpq %rsi, %rcx
sete %r15b
cmoveq %rax, %rdx
leaq 0x1582e(%rip), %rdi     # 0x30630
movzwl (%rdi,%rdx,2), %edi
addq 0x58(%r9), %rdi
movq %rdi, 0x58(%r9)
leaq (%r14,%rax,4), %rax
movzwl (%rax,%r15,2), %eax
movw %ax, 0x4(%r9,%rcx,2)
cmpq %rbx, -0x28(%rsp)
je 0x1aeab
movq -0x30(%rsp), %rax
movq (%rax), %r11
movq 0x60(%r9), %r10
movw $0xffff, %r12w          # imm = 0xFFFF
movq %r8, %rbx
movq %r8, %rax
xorl %r13d, %r13d
movl %r13d, %edx
shrl $0x6, %edx
movq (%r11,%rdx,8), %rdx
btq %r13, %rdx
movq %rax, %rdx
jae 0x1ae59
leaq -0x3e(%rax), %rdx
movzwl (%rdx), %r8d
movl $0x1000, %ebp           # imm = 0x1000
subq %r8, %rbp
cmpq %rsi, %rcx
cmoveq %r8, %rbp
leaq 0x157bd(%rip), %r9      # 0x30630
movzwl (%r9,%rbp,2), %ebp
addq (%r10,%r13,8), %rbp
movq %rbp, (%r10,%r13,8)
leaq (%r14,%r8,4), %r8
movzwl (%r8,%r15,2), %r8d
movw %r8w, (%rdx)
cmpq %rdi, %rbp
cmovbq %rbp, %rdi
cmovbl %r13d, %r12d
incq %r13
movl %r13d, %edx
addq $0x7c, %rax
cmpq %rdx, -0x40(%rsp)
ja 0x1ae42
jmp 0x1aeb3
movq %r8, %rbx
movw $0xffff, %r12w          # imm = 0xFFFF
leaq 0x1(%rcx), %rax
movq -0x48(%rsp), %r9
movw %r12w, 0x94(%r9)
movq %rbx, %r8
addq $0x2, %r8
cmpq %rsi, %rcx
movq %rax, %rcx
movq -0x8(%rsp), %rbx
jne 0x1adc3
cmpl $0x1f, -0x10(%rsp)
movq -0x38(%rsp), %rax
je 0x1b024
movl $0x1, %edx
movl -0x14(%rsp), %ecx
shll %cl, %edx
movq 0x18(%rax), %rax
movq %rax, -0x30(%rsp)
leaq (%rbx,%rsi,2), %rdi
addq $0x5c, %rdi
leaq -0x1(%rsi), %rcx
movl %edx, %eax
btsl %ecx, %eax
movl $0x0, %r12d
cmpl -0x4c(%rsp), %eax
jg 0x1b00a
movl %edx, -0x20(%rsp)
movzwl 0x20(%r9,%rcx,2), %eax
movl $0x1000, %edx           # imm = 0x1000
subq %rax, %rdx
xorl %r12d, %r12d
movl -0xc(%rsp), %r8d
btl %ecx, %r8d
setb %r12b
cmovbq %rax, %rdx
leaq 0x156e2(%rip), %r8      # 0x30630
movzwl (%r8,%rdx,2), %r13d
addq 0x58(%r9), %r13
movq %r13, 0x58(%r9)
leaq (%r14,%rax,4), %rax
movzwl (%rax,%r12,2), %eax
movw %ax, 0x20(%r9,%rcx,2)
cmpq %rbx, -0x28(%rsp)
je 0x1aff0
movq -0x30(%rsp), %rax
movq (%rax), %r11
movq 0x60(%r9), %r10
movw $0xffff, %ax            # imm = 0xFFFF
movq %rdi, %rbp
xorl %edx, %edx
movl %edx, %r8d
shrl $0x6, %r8d
movq (%r11,%r8,8), %r8
btq %rdx, %r8
movq %rbp, %r8
jae 0x1af9e
leaq -0x3e(%rbp), %r8
movzwl (%r8), %r9d
movl $0x1000, %r15d          # imm = 0x1000
subq %r9, %r15
testl %r12d, %r12d
cmovneq %r9, %r15
leaq 0x15677(%rip), %rbx     # 0x30630
movzwl (%rbx,%r15,2), %r15d
addq (%r10,%rdx,8), %r15
movq %r15, (%r10,%rdx,8)
leaq (%r14,%r9,4), %r9
movzwl (%r9,%r12,2), %r9d
movw %r9w, (%r8)
cmpq %r13, %r15
cmovbq %r15, %r13
cmovbl %edx, %eax
incq %rdx
movl %edx, %r8d
addq $0x7c, %rbp
cmpq %r8, -0x40(%rsp)
ja 0x1af86
jmp 0x1aff4
movw $0xffff, %ax            # imm = 0xFFFF
movq -0x48(%rsp), %r9
movw %ax, 0x94(%r9)
movq -0x8(%rsp), %rbx
movl -0x20(%rsp), %edx
shll %cl, %r12d
orl %edx, %r12d
addq $-0x2, %rdi
movl %r12d, %edx
cmpq $0x1, %rsi
movq %rcx, %rsi
jg 0x1af08
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop