// File: /workspace/github_cpp_makefile_star2_O3/Myyura[P]MyyuraSat/./source/../include/util/dimacs.hpp
// Function: MyyuraSat::parse_dimacs(_IO_FILE*, MyyuraSat::Solver&)
void parse_dimacs(FILE* in, Solver& s) {
    UnitParser p(in);
    Vector<Literal> lits;
    int vars = 0;
    int clauses = 0;
    int count = 0;

    for (; p.read_line();) {
        p.skip_whitespace();
        if (p.current_char() == '\0') {
            continue;
        }

        if (p.current_char() == 'p') {
            if (p.match("p cnf")) {
                vars = p.parse_integer();
                clauses = p.parse_integer();
            } else {
                fprintf(stderr, "PARSE ERROR! Unexpected char: %c\n", p.current_char());
                exit(3);
            }
        } else if (p.current_char() == 'c' || p.current_char() == 'p') {
            continue;
        } else {
            count++;

            // Read clause
            int parsed_lit, var;
            lits.clear();
            for (; ;) {
                parsed_lit = p.parse_integer();
                if (parsed_lit == 0) {
                    break;
                }
                var = std::abs(parsed_lit) - 1;

                for (; var >= s.n_variables();) {
                    // std::cout << var << std::endl;
                    s.new_variable();
                }

                lits.push((parsed_lit > 0) ? Literal(var) : ~Literal(var));
            }

            s.add_clause(lits);
        }
    }

    if (count != clauses) {
        fprintf(stderr, "PARSE ERROR! DIMACS header mismatch: wrong number ofclauses\n");
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movq %rdi, %r13
movq %rdi, -0x48(%rbp)
movl $0x400, -0x34(%rbp)     # imm = 0x400
movl $0x400, %edi            # imm = 0x400
callq 0x21b0
movq %rax, -0x40(%rbp)
testq %rax, %rax
je 0x2704
movq %rax, %r14
xorps %xmm0, %xmm0
movaps %xmm0, -0x60(%rbp)
movl $0x400, %r12d           # imm = 0x400
movq %rax, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdx
callq 0x2210
testq %rax, %rax
je 0x26d1
leaq 0x2b0(%rbx), %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0x68(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x5, %edi
xorl %ecx, %ecx
movq %rcx, %r15
movzbl (%r14,%rcx), %eax
leal -0x9(%rax), %ecx
cmpl $0x5, %ecx
jae 0x2579
incq %r15
incl %edi
movq %r15, %rcx
jmp 0x255f
cmpl $0x20, %eax
je 0x256f
movslq %r15d, %rax
movzbl (%r14,%rax), %eax
testl %eax, %eax
je 0x258f
cmpl $0x63, %eax
jne 0x25b1
movq %r14, %rdi
movl %r12d, %esi
movq %r13, %rdx
callq 0x2210
movl $0x5, %edi
movl $0x0, %ecx
testq %rax, %rax
jne 0x255f
jmp 0x26be
cmpl $0x70, %eax
jne 0x260d
movslq %r15d, %rax
leaq (%r14,%rax), %rcx
incq %rcx
xorl %edx, %edx
leaq 0x5a57(%rip), %r8       # 0x8020
leaq -0x48(%rbp), %r12
movb 0x1(%rdx,%r8), %al
cmpq $0x4, %rdx
je 0x25ea
leaq 0x1(%rdx), %rsi
cmpb (%rcx,%rdx), %al
movq %rsi, %rdx
je 0x25cd
addl %esi, %r15d
movl %r15d, %edi
movl %edi, -0x38(%rbp)
testb %al, %al
jne 0x2732
movq %r12, %rdi
callq 0x2768
movq %r12, %rdi
callq 0x2768
movl %eax, -0x2c(%rbp)
jmp 0x2697
movl %r15d, -0x38(%rbp)
cmpq $0x0, -0x60(%rbp)
leaq -0x48(%rbp), %r12
leaq -0x60(%rbp), %r13
je 0x2627
movl $0x0, -0x58(%rbp)
movq %r12, %rdi
callq 0x2768
movl %eax, %r14d
testl %eax, %eax
je 0x2673
movl %r14d, %r15d
negl %r15d
cmovsl %r14d, %r15d
cmpl 0xf0(%rbx), %r15d
jle 0x2655
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2804
jmp 0x2640
xorl %eax, %eax
testl %r14d, %r14d
setle %al
leal -0x2(%rax,%r15,2), %eax
movl %eax, -0x6c(%rbp)
movq %r13, %rdi
leaq -0x6c(%rbp), %rsi
callq 0x59c8
jmp 0x2627
movq %r13, %rdi
movq -0x78(%rbp), %r14
movq %r14, %rsi
callq 0x6a50
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2978
movq -0x68(%rbp), %rax
incl %eax
movq %rax, -0x68(%rbp)
movq -0x48(%rbp), %r13
movq -0x40(%rbp), %r14
movl -0x34(%rbp), %r12d
movl -0x38(%rbp), %r15d
movq %r14, %rdi
movl %r12d, %esi
movq %r13, %rdx
callq 0x2210
testq %rax, %rax
jne 0x2558
movl %r15d, -0x38(%rbp)
movl -0x2c(%rbp), %eax
cmpl %eax, -0x68(%rbp)
je 0x26d8
callq 0x22db
jmp 0x26d8
movl $0x0, -0x38(%rbp)
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x26ed
movl $0x0, -0x58(%rbp)
callq 0x2180
movq %r14, %rdi
callq 0x2180
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x8, %edi
callq 0x20a0
movq 0x986b(%rip), %rcx      # 0xbf80
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x987d(%rip), %rsi      # 0xbfa0
movq 0x9846(%rip), %rdx      # 0xbf70
movq %rax, %rdi
callq 0x2250
movq %r14, %rsi
callq 0x22b0
jmp 0x273e
jmp 0x273e
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x2756
movl $0x0, -0x58(%rbp)
callq 0x2180
movq -0x40(%rbp), %rdi
callq 0x2180
movq %rbx, %rdi
callq 0x2270
nop