// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/bitops.c
// Function: checkSignedBitfieldOverflow
int checkSignedBitfieldOverflow(int64_t value, int64_t incr, uint64_t bits, int owtype, int64_t *limit) {
    int64_t max = (bits == 64) ? INT64_MAX : (((int64_t)1<<(bits-1))-1);
    int64_t min = (-max)-1;

    /* Note that maxincr and minincr could overflow, but we use the values
     * only after checking 'value' range, so when we use it no overflow
     * happens. */
    int64_t maxincr = max-value;
    int64_t minincr = min-value;

    if (value > max || (bits != 64 && incr > maxincr) || (value >= 0 && incr > 0 && incr > maxincr))
    {
        if (limit) {
            if (owtype == BFOVERFLOW_WRAP) {
                goto handle_wrap;
            } else if (owtype == BFOVERFLOW_SAT) {
                *limit = max;
            }
        }
        return 1;
    } else if (value < min || (bits != 64 && incr < minincr) || (value < 0 && incr < 0 && incr < minincr)) {
        if (limit) {
            if (owtype == BFOVERFLOW_WRAP) {
                goto handle_wrap;
            } else if (owtype == BFOVERFLOW_SAT) {
                *limit = min;
            }
        }
        return -1;
    }
    return 0;

handle_wrap:
    {
        uint64_t mask = ((uint64_t)-1) << bits;
        uint64_t msb = (uint64_t)1 << (bits-1);
        uint64_t a = value, b = incr, c;
        c = a+b; /* Perform addition as unsigned so that's defined. */

        /* If the sign bit is set, propagate to all the higher order
         * bits, to cap the negative value. If it's clear, mask to
         * the positive integer limit. */
        if (c & msb) {
            c |= mask;
        } else {
            c &= ~mask;
        }
        *limit = c;
    }
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
cmpq $0x40, -0x20(%rbp)
jne 0x90aae
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
movq %rax, -0x80(%rbp)
jmp 0x90ac6
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movl $0x1, %eax
shlq %cl, %rax
subq $0x1, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x38(%rbp)
xorl %eax, %eax
subq -0x38(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
subq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
subq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
cmpq -0x38(%rbp), %rax
jg 0x90b27
cmpq $0x40, -0x20(%rbp)
je 0x90b0f
movq -0x18(%rbp), %rax
cmpq -0x48(%rbp), %rax
jg 0x90b27
cmpq $0x0, -0x10(%rbp)
jl 0x90b5a
cmpq $0x0, -0x18(%rbp)
jle 0x90b5a
movq -0x18(%rbp), %rax
cmpq -0x48(%rbp), %rax
jle 0x90b5a
cmpq $0x0, -0x30(%rbp)
je 0x90b4e
cmpl $0x0, -0x24(%rbp)
jne 0x90b39
jmp 0x90bcb
cmpl $0x1, -0x24(%rbp)
jne 0x90b4a
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
jmp 0x90b4c
jmp 0x90b4e
movl $0x1, -0x4(%rbp)
jmp 0x90c4b
movq -0x10(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x90b8d
cmpq $0x40, -0x20(%rbp)
je 0x90b75
movq -0x18(%rbp), %rax
cmpq -0x50(%rbp), %rax
jl 0x90b8d
cmpq $0x0, -0x10(%rbp)
jge 0x90bbd
cmpq $0x0, -0x18(%rbp)
jge 0x90bbd
movq -0x18(%rbp), %rax
cmpq -0x50(%rbp), %rax
jge 0x90bbd
cmpq $0x0, -0x30(%rbp)
je 0x90bb1
cmpl $0x0, -0x24(%rbp)
jne 0x90b9c
jmp 0x90bcb
cmpl $0x1, -0x24(%rbp)
jne 0x90bad
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
jmp 0x90baf
jmp 0x90bb1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x90c4b
jmp 0x90bbf
movl $0x0, -0x4(%rbp)
jmp 0x90c4b
movq -0x20(%rbp), %rcx
movq $-0x1, %rax
shlq %cl, %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
andq -0x60(%rbp), %rax
cmpq $0x0, %rax
je 0x90c29
movq -0x58(%rbp), %rax
orq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x90c39
movq -0x58(%rbp), %rax
xorq $-0x1, %rax
andq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq