// File: /workspace/github_cpp_makefile_star2_O1/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 0x1b2d9
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x10(%rdi), %r10
movzwl (%r10), %r11d
testl %ecx, %ecx
movq %r10, -0x48(%rsp)
je 0x1ae31
movl %edx, -0x4c(%rsp)
movl $0x1000, %eax           # imm = 0x1000
subq %r11, %rax
leaq 0x158df(%rip), %rdx     # 0x30640
movzwl (%rdx,%rax,2), %eax
addq 0x58(%r10), %rax
movq 0x40(%r10), %rbx
movq 0x48(%r10), %rdx
movq %rdx, %r8
subq %rbx, %r8
sarq $0x2, %r8
movabsq $-0x1084210842108421, %r9 # imm = 0xEF7BDEF7BDEF7BDF
imulq %r8, %r9
movq %r9, -0x40(%rsp)
movq %rax, 0x58(%r10)
movq (%rdi), %r14
movzwl (%r14,%r11,4), %r8d
movw %r8w, (%r10)
movq %rdx, -0x28(%rsp)
cmpq %rbx, %rdx
movq %rdi, -0x38(%rsp)
je 0x1aee1
movq 0x18(%rdi), %rdi
movq (%rdi), %rdi
movq 0x60(%r10), %r11
movw $0xffff, %bp            # imm = 0xFFFF
xorl %r15d, %r15d
movq %rbx, %r10
leaq 0x15873(%rip), %rdx     # 0x30640
movq %r15, %r8
shrq $0x6, %r8
movq (%rdi,%r8,8), %r8
btq %r15, %r8
jae 0x1ade3
movq %r10, %r8
jmp 0x1ade7
leaq 0x3e(%r10), %r8
movzwl (%r8), %r12d
movl $0x1000, %r13d          # imm = 0x1000
subq %r12, %r13
movzwl (%rdx,%r13,2), %r13d
addq (%r11,%r15,8), %r13
movq %r13, (%r11,%r15,8)
movzwl (%r14,%r12,4), %r12d
movw %r12w, (%r8)
cmpq %rax, %r13
cmovbq %r13, %rax
movl %r15d, %r12d
cmovael %ebp, %r12d
incq %r15
movl %r15d, %r8d
addq $0x7c, %r10
movl %r12d, %ebp
cmpq %r8, -0x40(%rsp)
ja 0x1adcd
jmp 0x1aee6
leaq 0x15808(%rip), %rax     # 0x30640
movzwl (%rax,%r11,2), %ecx
addq 0x58(%r10), %rcx
movq 0x40(%r10), %rdx
movq 0x48(%r10), %r8
movq %rcx, 0x58(%r10)
movq (%rdi), %rsi
movzwl 0x2(%rsi,%r11,4), %r9d
movw %r9w, (%r10)
subq %rdx, %r8
je 0x1afda
sarq $0x2, %r8
movabsq $-0x1084210842108421, %r12 # imm = 0xEF7BDEF7BDEF7BDF
imulq %r8, %r12
movq 0x18(%rdi), %r8
movq (%r8), %r9
movq 0x60(%r10), %r10
movw $0xffff, %bx            # imm = 0xFFFF
xorl %r11d, %r11d
movq %r11, %r8
shrq $0x6, %r8
movq (%r9,%r8,8), %r8
btq %r11, %r8
jae 0x1ae9d
movq %rdx, %r8
jmp 0x1aea1
leaq 0x3e(%rdx), %r8
movzwl (%r8), %r14d
movzwl (%rax,%r14,2), %r15d
addq (%r10,%r11,8), %r15
movq %r15, (%r10,%r11,8)
movzwl 0x2(%rsi,%r14,4), %ebp
movw %bp, (%r8)
cmpq %rcx, %r15
cmovbq %r15, %rcx
movl %r11d, %r8d
cmovael %ebx, %r8d
incq %r11
movl %r11d, %r14d
addq $0x7c, %rdx
movl %r8d, %ebx
cmpq %r14, %r12
ja 0x1ae87
jmp 0x1afdf
movw $0xffff, %r12w          # imm = 0xFFFF
movq -0x48(%rsp), %r9
movw %r12w, 0x94(%r9)
movl -0x4c(%rsp), %edx
testl %edx, %edx
setle %al
testl %esi, %esi
setns %dil
orb %al, %dil
jne 0x1b006
movzwl 0x2(%r9), %r8d
movl $0x1000, %edi           # imm = 0x1000
subq %r8, %rdi
xorl %edx, %edx
testl %ecx, %ecx
setg %dl
cmovgq %r8, %rdi
leaq 0x15716(%rip), %rax     # 0x30640
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 0x1aff1
movq 0x18(%rax), %r8
movq (%r8), %r15
movq 0x60(%r9), %r12
leaq 0x40(%rbx), %r13
movw $0xffff, %r10w          # imm = 0xFFFF
xorl %r11d, %r11d
leaq 0x156ce(%rip), %r9      # 0x30640
movq %r11, %r8
shrq $0x6, %r8
movq (%r15,%r8,8), %r8
btq %r11, %r8
movq %r13, %r8
jae 0x1af8a
leaq -0x3e(%r13), %r8
movzwl (%r8), %ebp
movl $0x1000, %eax           # imm = 0x1000
subq %rbp, %rax
testl %ecx, %ecx
cmovgq %rbp, %rax
movzwl (%r9,%rax,2), %eax
addq (%r12,%r11,8), %rax
movq %rax, (%r12,%r11,8)
leaq (%r14,%rbp,4), %rbp
movzwl (%rbp,%rdx,2), %ebp
movw %bp, (%r8)
cmpq %rdi, %rax
cmovbq %rax, %rdi
movl %r11d, %ebp
cmovael %r10d, %ebp
incq %r11
movl %r11d, %eax
addq $0x7c, %r13
movl %ebp, %r10d
cmpq %rax, -0x40(%rsp)
ja 0x1af72
jmp 0x1aff5
movw $0xffff, %r8w           # imm = 0xFFFF
movq -0x48(%rsp), %rax
movw %r8w, 0x94(%rax)
jmp 0x1b2cf
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 0x1b17c
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 0x1b17c
movl $0x2, %eax
shll %cl, %eax
cmpl -0x4c(%rsp), %eax
jg 0x1b17c
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 0x155a3(%rip), %rdi     # 0x30640
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 0x1b14c
movq -0x30(%rsp), %rax
movq (%rax), %r12
movq 0x60(%r9), %r11
movw $0xffff, %r13w          # imm = 0xFFFF
movq %r8, %rbx
movq %r8, %rax
xorl %ebp, %ebp
movq %rbp, %rdx
shrq $0x6, %rdx
movq (%r12,%rdx,8), %rdx
btq %rbp, %rdx
movq %rax, %rdx
jae 0x1b0f4
leaq -0x3e(%rax), %rdx
movzwl (%rdx), %r8d
movl $0x1000, %r10d          # imm = 0x1000
subq %r8, %r10
cmpq %rsi, %rcx
cmoveq %r8, %r10
leaq 0x15531(%rip), %r9      # 0x30640
movzwl (%r9,%r10,2), %r10d
addq (%r11,%rbp,8), %r10
movq %r10, (%r11,%rbp,8)
leaq (%r14,%r8,4), %r8
movzwl (%r8,%r15,2), %r8d
movw %r8w, (%rdx)
cmpq %rdi, %r10
cmovbq %r10, %rdi
movl %ebp, %edx
cmovael %r13d, %edx
incq %rbp
movl %ebp, %r8d
addq $0x7c, %rax
movl %edx, %r13d
cmpq %r8, -0x40(%rsp)
ja 0x1b0dc
jmp 0x1b153
movq %r8, %rbx
movw $0xffff, %dx            # imm = 0xFFFF
leaq 0x1(%rcx), %rax
movq -0x48(%rsp), %r9
movw %dx, 0x94(%r9)
movq %rbx, %r8
addq $0x2, %r8
cmpq %rsi, %rcx
movq %rax, %rcx
movq -0x8(%rsp), %rbx
jne 0x1b05e
cmpl $0x1f, -0x10(%rsp)
movq -0x38(%rsp), %rax
je 0x1b2cf
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 0x1b2b5
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 0x15452(%rip), %r8      # 0x30640
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 0x1b29b
movq -0x30(%rsp), %rax
movq (%rax), %rax
movq 0x60(%r9), %r11
movw $0xffff, %r8w           # imm = 0xFFFF
movq %rdi, %r10
xorl %ebp, %ebp
movq %rbp, %rdx
shrq $0x6, %rdx
movq (%rax,%rdx,8), %rdx
btq %rbp, %rdx
movq %r10, %rdx
jae 0x1b243
leaq -0x3e(%r10), %rdx
movzwl (%rdx), %r9d
movl $0x1000, %r15d          # imm = 0x1000
subq %r9, %r15
testl %r12d, %r12d
cmovneq %r9, %r15
leaq 0x153e2(%rip), %rbx     # 0x30640
movzwl (%rbx,%r15,2), %r15d
addq (%r11,%rbp,8), %r15
movq %r15, (%r11,%rbp,8)
leaq (%r14,%r9,4), %r9
movzwl (%r9,%r12,2), %r9d
movw %r9w, (%rdx)
cmpq %r13, %r15
cmovbq %r15, %r13
movl %ebp, %edx
cmovael %r8d, %edx
incq %rbp
movl %ebp, %r9d
addq $0x7c, %r10
movl %edx, %r8d
cmpq %r9, -0x40(%rsp)
ja 0x1b22b
jmp 0x1b29f
movw $0xffff, %dx            # imm = 0xFFFF
movq -0x48(%rsp), %r9
movw %dx, 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 0x1b1a8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq