// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/hts_expr.c
// Function: eq_expr
static int eq_expr(hts_filter_t *filt, void *data, hts_expr_sym_func *fn,
                   char *str, char **end, hts_expr_val_t *res) {
    if (cmp_expr(filt, data, fn, str, end, res)) return -1;

    str = ws(*end);

    int err = 0, eq_done = 0;
    hts_expr_val_t val = HTS_EXPR_VAL_INIT;

    // numeric vs numeric comparison is as expected
    // string vs string comparison is as expected
    // numeric vs string is false
    if (str[0] == '=' && str[1] == '=') {
        eq_done = 1;
        if ((err = eq_expr(filt, data, fn, str+2, end, &val))) {
            res->is_true = res->d = 0;
        } else {
            if (!hts_expr_val_exists(res) || !hts_expr_val_exists(&val)) {
                hts_expr_val_undef(res);
            } else {
                res->is_true = res->d = res->is_str
                    ? (res->s.s && val.s.s ?strcmp(res->s.s, val.s.s)==0 :0)
                    : !res->is_str && !val.is_str && res->d == val.d;
            }
        }
        res->is_str = 0;

    } else if (str[0] == '!' && str[1] == '=') {
        eq_done = 1;
        if ((err = eq_expr(filt, data, fn, str+2, end, &val))) {
            res->is_true = res->d = 0;
        } else {
            if (!hts_expr_val_exists(res) || !hts_expr_val_exists(&val)) {
                hts_expr_val_undef(res);
            } else {
                res->is_true = res->d = res->is_str
                    ? (res->s.s && val.s.s ?strcmp(res->s.s, val.s.s) != 0 :1)
                    : res->is_str != val.is_str || res->d != val.d;
            }
        }
        res->is_str = 0;

    } else if ((str[0] == '=' && str[1] == '~') ||
               (str[0] == '!' && str[1] == '~')) {
        eq_done = 1;
        err = eq_expr(filt, data, fn, str+2, end, &val);
        if (!val.is_str || !res->is_str) {
            hts_expr_val_free(&val);
            return -1;
        }
        if (val.s.s && res->s.s && val.is_true >= 0 && res->is_true >= 0) {
            regex_t preg_, *preg;
            if (filt->curr_regex >= filt->max_regex) {
                // Compile regex if not seen before
                if (filt->curr_regex >= MAX_REGEX) {
                    preg = &preg_;
                } else {
                    preg = &filt->preg[filt->curr_regex];
                    filt->max_regex++;
                }

                int ec = regcomp(preg, val.s.s, REG_EXTENDED | REG_NOSUB);
                if (ec != 0) {
                    char errbuf[1024];
                    regerror(ec, preg, errbuf, 1024);
                    fprintf(stderr, "Failed regex: %.1024s\n", errbuf);
                    hts_expr_val_free(&val);
                    return -1;
                }
            } else {
                preg = &filt->preg[filt->curr_regex];
            }
            res->is_true = res->d = regexec(preg, res->s.s, 0, NULL, 0) == 0
                ? *str == '='  // matcn
                : *str == '!'; // no-match
            if (preg == &preg_)
                regfree(preg);

            filt->curr_regex++;
        } else {
            // nul regexp or input is considered false
            res->is_true = 0;
        }
        res->is_str = 0;
    }

    if (eq_done && ((!hts_expr_val_exists(&val)) || !hts_expr_val_exists(res)))
        hts_expr_val_undef(res);
    hts_expr_val_free(&val);

    return err ? -1 : 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x488, %rsp            # imm = 0x488
movq %r9, %rbx
movq %r8, %r12
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %r14
callq 0x195e7
testl %eax, %eax
je 0x1922f
pushq $-0x1
popq %rax
jmp 0x193a5
movq (%r12), %rdi
callq 0x191b7
movq %rax, %r15
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movapd %xmm0, 0x10(%rsp)
andq $0x0, 0x30(%rsp)
movzbl (%rax), %eax
cmpl $0x21, %eax
je 0x19308
cmpl $0x3d, %eax
jne 0x1938b
movzbl 0x1(%r15), %eax
cmpl $0x7e, %eax
je 0x193b7
movl $0x0, 0xc(%rsp)
cmpl $0x3d, %eax
jne 0x19393
addq $0x2, %r15
leaq 0x10(%rsp), %r9
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x191fe
movl %eax, 0xc(%rsp)
testl %eax, %eax
jne 0x1934c
movq %rbx, %rdi
callq 0x191cd
testl %eax, %eax
je 0x1948f
leaq 0x10(%rsp), %rdi
callq 0x191cd
testl %eax, %eax
je 0x1948f
cmpb $0x0, (%rbx)
je 0x194b7
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
setne %al
movq 0x28(%rsp), %rsi
testq %rsi, %rsi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x194c2
callq 0x46c0
testl %eax, %eax
sete %al
jmp 0x19578
movzbl 0x1(%r15), %eax
cmpl $0x7e, %eax
je 0x193b7
movl $0x0, 0xc(%rsp)
cmpl $0x3d, %eax
jne 0x19393
addq $0x2, %r15
leaq 0x10(%rsp), %r9
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x191fe
movl %eax, 0xc(%rsp)
testl %eax, %eax
je 0x1943f
andq $0x0, 0x20(%rbx)
movb $0x0, 0x1(%rbx)
movb $0x0, (%rbx)
leaq 0x10(%rsp), %rdi
callq 0x191cd
testl %eax, %eax
je 0x19372
movq %rbx, %rdi
callq 0x191cd
testl %eax, %eax
jne 0x19393
andq $0x0, 0x8(%rbx)
andw $0x0, (%rbx)
movabsq $0x7ff8000000000000, %rax # imm = 0x7FF8000000000000
movq %rax, 0x20(%rbx)
jmp 0x19393
movl $0x0, 0xc(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x18e75
xorl %eax, %eax
negl 0xc(%rsp)
sbbl %eax, %eax
addq $0x488, %rsp            # imm = 0x488
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rcx
addq $0x2, %rcx
leaq 0x10(%rsp), %rax
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r12, %r8
movq %rax, %r12
movq %rax, %r9
callq 0x191fe
cmpb $0x0, (%r12)
je 0x195c1
cmpb $0x0, (%rbx)
je 0x195c1
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rsi
testq %rsi, %rsi
je 0x19351
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x19351
cmpb $0x0, 0x11(%rsp)
js 0x19351
cmpb $0x0, 0x1(%rbx)
js 0x19351
movslq 0xc(%r14), %rcx
movl 0x10(%r14), %edx
cmpl %edx, %ecx
jge 0x194ab
shlq $0x6, %rcx
leaq (%r14,%rcx), %r12
addq $0x18, %r12
jmp 0x19510
movq %rbx, %rdi
callq 0x191cd
testl %eax, %eax
je 0x1948f
leaq 0x10(%rsp), %rdi
callq 0x191cd
testl %eax, %eax
je 0x1948f
cmpb $0x0, (%rbx)
je 0x194c9
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
setne %al
movq 0x28(%rsp), %rsi
testq %rsi, %rsi
setne %cl
andb %al, %cl
movb $0x1, %al
cmpb $0x1, %cl
jne 0x19578
callq 0x46c0
testl %eax, %eax
setne %al
jmp 0x19578
andq $0x0, 0x8(%rbx)
movb $0x0, 0x1(%rbx)
movabsq $0x7ff8000000000000, %rax # imm = 0x7FF8000000000000
movq %rax, 0x20(%rbx)
jmp 0x19355
cmpl $0x9, %ecx
jle 0x194e7
leaq 0x40(%rsp), %r12
jmp 0x194f9
cmpb $0x0, 0x10(%rsp)
je 0x19564
xorl %eax, %eax
jmp 0x19578
movb $0x1, %al
cmpb $0x0, 0x10(%rsp)
jne 0x19578
movsd 0x30(%rsp), %xmm0
cmpneqsd 0x20(%rbx), %xmm0
jmp 0x19570
shlq $0x6, %rcx
leaq (%r14,%rcx), %r12
addq $0x18, %r12
incl %edx
movl %edx, 0x10(%r14)
pushq $0x9
popq %rdx
movq %r12, %rdi
callq 0x4570
testl %eax, %eax
jne 0x1958c
movq 0x18(%rbx), %rax
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x4610
testl %eax, %eax
pushq $0x3d
popq %rax
pushq $0x21
popq %rcx
cmovel %eax, %ecx
cmpb %cl, (%r15)
je 0x19538
xorpd %xmm0, %xmm0
jmp 0x19540
movsd 0x5bad0(%rip), %xmm0    # 0x75010
movsd %xmm0, 0x20(%rbx)
sete 0x1(%rbx)
leaq 0x40(%rsp), %rax
cmpq %rax, %r12
jne 0x1955b
movq %r12, %rdi
callq 0x44c0
incl 0xc(%r14)
jmp 0x19355
movsd 0x30(%rsp), %xmm0
cmpeqsd 0x20(%rbx), %xmm0
movq %xmm0, %rax
andl $0x1, %eax
movzbl %al, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x20(%rbx)
movb %al, 0x1(%rbx)
jmp 0x19355
leaq 0x80(%rsp), %rbx
movl $0x400, %ecx            # imm = 0x400
movl %eax, %edi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x4220
movq 0x84a2b(%rip), %rax     # 0x9dfd8
movq (%rax), %rdi
leaq 0x5f80a(%rip), %rsi     # 0x78dc1
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4700
leaq 0x18(%rsp), %rdi
callq 0x18e75
jmp 0x19227