// File: /workspace/github_c_makefile_star2_O3/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 $0x478, %rsp            # imm = 0x478
movq %r9, %rbx
movq %r8, %r12
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %r14
callq 0x1d57b
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ecx, %ecx
jne 0x1d299
movq (%r12), %r15
addq $0x2, %r15
movzbl -0x2(%r15), %eax
cmpl $0x20, %eax
je 0x1d0f0
cmpl $0x9, %eax
jne 0x1d0f5
incq %r15
jmp 0x1d0e1
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movapd %xmm0, (%rsp)
movq $0x0, 0x20(%rsp)
movzbl -0x2(%r15), %eax
xorl %r8d, %r8d
cmpl $0x21, %eax
je 0x1d189
cmpl $0x3d, %eax
jne 0x1d286
movzbl -0x1(%r15), %eax
cmpl $0x7e, %eax
je 0x1d1f7
cmpl $0x3d, %eax
jne 0x1d286
movq %rsp, %r9
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x1d0a5
movl %eax, %r8d
testl %eax, %eax
jne 0x1d1be
testq %rbx, %rbx
je 0x1d38a
movzbl (%rbx), %eax
cmpl $0x1, %eax
je 0x1d2ed
testl %eax, %eax
jne 0x1d2f8
movsd 0x20(%rbx), %xmm0
ucomisd %xmm0, %xmm0
jnp 0x1d2f8
jmp 0x1d38a
movzbl -0x1(%r15), %eax
cmpl $0x7e, %eax
je 0x1d1f7
cmpl $0x3d, %eax
jne 0x1d286
movq %rsp, %r9
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
callq 0x1d0a5
movl %eax, %r8d
testl %eax, %eax
je 0x1d2ab
movq $0x0, 0x20(%rbx)
movb $0x0, 0x1(%rbx)
movb $0x0, (%rbx)
movzbl (%rsp), %eax
cmpl $0x1, %eax
je 0x1d273
testl %eax, %eax
jne 0x1d27b
movsd 0x20(%rsp), %xmm0
ucomisd %xmm0, %xmm0
jnp 0x1d27b
jmp 0x1d2d0
movq %rsp, %rax
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %r12, %r8
movq %rax, %r12
movq %rax, %r9
callq 0x1d0a5
cmpb $0x0, (%r12)
je 0x1d52b
cmpb $0x0, (%rbx)
je 0x1d52b
movl %eax, %r8d
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
je 0x1d1c6
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x1d1c6
cmpb $0x0, 0x1(%rsp)
js 0x1d1c6
cmpb $0x0, 0x1(%rbx)
js 0x1d1c6
movslq 0xc(%r14), %rcx
movl 0x10(%r14), %edx
movl %r8d, %ebp
cmpl %edx, %ecx
jge 0x1d353
shlq $0x6, %rcx
leaq (%r14,%rcx), %r12
addq $0x18, %r12
jmp 0x1d450
cmpq $0x0, 0x18(%rsp)
je 0x1d2d0
movsd 0x20(%rbx), %xmm0
ucomisd %xmm0, %xmm0
jp 0x1d2d0
movq 0x18(%rsp), %rdi
movl %r8d, %ebx
callq 0x45c0
xorl %eax, %eax
negl %ebx
sbbl %eax, %eax
addq $0x478, %rsp            # imm = 0x478
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rbx, %rbx
je 0x1d38a
movzbl (%rbx), %eax
cmpl $0x1, %eax
je 0x1d322
testl %eax, %eax
jne 0x1d329
movsd 0x20(%rbx), %xmm0
ucomisd %xmm0, %xmm0
jnp 0x1d329
jmp 0x1d38a
movq $0x0, 0x8(%rbx)
movw $0x0, (%rbx)
movabsq $0x7ff8000000000000, %rax # imm = 0x7FF8000000000000
movq %rax, 0x20(%rbx)
jmp 0x1d286
cmpq $0x0, 0x18(%rbx)
je 0x1d38a
movzbl (%rsp), %ecx
cmpl $0x1, %ecx
je 0x1d366
testl %ecx, %ecx
jne 0x1d3a9
movsd 0x20(%rsp), %xmm0
ucomisd %xmm0, %xmm0
jp 0x1d38a
testb %al, %al
jne 0x1d3b1
jmp 0x1d4ba
cmpq $0x0, 0x18(%rbx)
je 0x1d38a
movzbl (%rsp), %ecx
cmpl $0x1, %ecx
je 0x1d377
testl %ecx, %ecx
jne 0x1d3e6
movsd 0x20(%rsp), %xmm0
ucomisd %xmm0, %xmm0
jp 0x1d38a
testb %al, %al
jne 0x1d3ee
jmp 0x1d4ce
cmpl $0x9, %ecx
jle 0x1d425
leaq 0x30(%rsp), %r12
jmp 0x1d437
cmpq $0x0, 0x18(%rsp)
je 0x1d38a
testb %al, %al
jne 0x1d3b1
jmp 0x1d4b6
cmpq $0x0, 0x18(%rsp)
je 0x1d38a
testb %al, %al
jne 0x1d3ee
movb $0x1, %al
jmp 0x1d4e2
movq $0x0, 0x8(%rbx)
movb $0x0, 0x1(%rbx)
movabsq $0x7ff8000000000000, %rax # imm = 0x7FF8000000000000
movq %rax, 0x20(%rbx)
jmp 0x1d1ca
testb %al, %al
je 0x1d4b2
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
setne %al
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1d4b6
movl %r8d, %ebp
callq 0x46c0
movl %ebp, %r8d
testl %eax, %eax
sete %al
jmp 0x1d4e2
testb %al, %al
je 0x1d4c8
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
setne %al
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
setne %cl
andb %al, %cl
movb $0x1, %al
cmpb $0x1, %cl
jne 0x1d4e2
movl %r8d, %ebp
callq 0x46c0
movl %ebp, %r8d
testl %eax, %eax
setne %al
jmp 0x1d4e2
shlq $0x6, %rcx
leaq (%r14,%rcx), %r12
addq $0x18, %r12
incl %edx
movl %edx, 0x10(%r14)
movq %r12, %rdi
movl $0x9, %edx
callq 0x4570
testl %eax, %eax
jne 0x1d4f9
movq 0x18(%rbx), %rax
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x4610
testl %eax, %eax
movl $0x3d, %eax
movl $0x21, %ecx
cmovel %eax, %ecx
cmpb %cl, -0x2(%r15)
je 0x1d47d
xorpd %xmm0, %xmm0
jmp 0x1d485
movsd 0x75b8b(%rip), %xmm0    # 0x93010
movl %ebp, %r8d
movsd %xmm0, 0x20(%rbx)
sete 0x1(%rbx)
leaq 0x30(%rsp), %rax
cmpq %rax, %r12
jne 0x1d4a9
movq %r12, %rdi
movl %r8d, %ebp
callq 0x44c0
movl %ebp, %r8d
incl 0xc(%r14)
jmp 0x1d1ca
testb %cl, %cl
je 0x1d4ba
xorl %eax, %eax
jmp 0x1d4e2
movsd 0x20(%rsp), %xmm0
cmpeqsd 0x20(%rbx), %xmm0
jmp 0x1d4da
movb $0x1, %al
testb %cl, %cl
jne 0x1d4e2
movsd 0x20(%rsp), %xmm0
cmpneqsd 0x20(%rbx), %xmm0
movq %xmm0, %rax
andl $0x1, %eax
movzbl %al, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x20(%rbx)
movb %al, 0x1(%rbx)
jmp 0x1d1ca
leaq 0x70(%rsp), %rbx
movl $0x400, %ecx            # imm = 0x400
movl %eax, %edi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x4220
movq 0x98ac1(%rip), %rax     # 0xb5fd8
movq (%rax), %rdi
leaq 0x798b0(%rip), %rsi     # 0x96dd1
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4700
movq 0x18(%rsp), %rdi
callq 0x45c0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x1d299