// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpl %edx, %esi
jne 0x1454d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, %r12d
movq %rdi, %rbx
testl %ecx, %ecx
je 0x14666
movl %edx, %r13d
movl %esi, %ebp
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x14684
testl %r13d, %r13d
setle %al
testl %ebp, %ebp
setns %cl
orb %al, %cl
jne 0x14596
xorl %esi, %esi
testl %r12d, %r12d
setg %sil
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x14684
movq %rbx, 0x10(%rsp)
movl %r12d, %eax
negl %eax
cmovsl %r12d, %eax
movl %eax, 0x4(%rsp)
bsrl %eax, %r14d
testl %r12d, %r12d
movl %ebp, %eax
cmovgl %r13d, %eax
movl %eax, %ebp
negl %ebp
movl %eax, 0xc(%rsp)
cmovsl %eax, %ebp
bsrl %ebp, %eax
movl %eax, 0x8(%rsp)
leal 0x1(%r14), %r13d
pushq $0x2
popq %r12
movl %r12d, %eax
movl %r15d, %ecx
shll %cl, %eax
cmpl $0x0, 0xc(%rsp)
je 0x1460e
cmpl %r15d, 0x8(%rsp)
jbe 0x1460e
cmpl %ebp, %eax
jg 0x1460e
leal 0x1(%r15), %ebx
xorl %esi, %esi
cmpl %r15d, %r14d
sete %sil
movq 0x10(%rsp), %rdi
movl %r12d, %edx
movl %r15d, %ecx
callq 0x14684
movl %ebx, %r15d
cmpl %ebx, %r13d
jne 0x145cf
pushq $0x1
popq %r13
movl %r14d, %ecx
shll %cl, %r13d
pushq $0x3
popq %r12
movq 0x10(%rsp), %rbx
testl %r14d, %r14d
jle 0x1453e
decl %r14d
movl %r13d, %eax
btsl %r14d, %eax
xorl %r15d, %r15d
cmpl %ebp, %eax
jg 0x1465b
xorl %r15d, %r15d
movl 0x4(%rsp), %eax
btl %r14d, %eax
setb %r15b
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
movl %r14d, %ecx
callq 0x14684
movl %r14d, %ecx
shll %cl, %r15d
orl %r15d, %r13d
jmp 0x14621
pushq $0x1
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x14684
nop