// File: /workspace/github_cpp_makefile_star2_O1/conp-solutions[P]cnfmiter/Main.cc
// Function: main
int main(int argc, char **argv)
{
    int opt;
    int tseitin = 0;
    int randmom_drop = 0;
    std::cerr << "c CNFmiter generates a CNF formula " << std::endl
              << "c which is unsatisfiable, if the given 2 formulas are equivalent" << std::endl;


    // Retrieve the options:
    while ((opt = getopt(argc, argv, "r:t:")) != -1) { // for each option...
        switch (opt) {
        case 'r':
            randmom_drop = atoi(optarg);
            std::cerr << "c randomly drop " << randmom_drop << " clauses from first formula" << std::endl;
            break;
        case 't':
            tseitin = atoi(optarg);
            std::cerr << "c set tseitin variable to " << tseitin << std::endl;
            break;
        case '?': // unknown option...
            std::cerr << "c unknown option: '" << char(optopt) << "'!" << std::endl;
            exit(1);
            break;
        }
    }

    if (optind + 2 != argc) {
        std::cerr << "not enough parameters, abort!" << std::endl;
        return 1;
    }

    std::string fn1 = (argv[optind + 0]);
    std::string fn2 = (argv[optind + 1]);
    gzFile in1 = gzopen(fn1.c_str(), "rb");
    gzFile in2 = gzopen(fn2.c_str(), "rb");

    if (!in1) {
        std::cerr << "failed to open first file, abort!" << std::endl;
        return 1;
    }
    if (!in2) {
        std::cerr << "failed to open second file, abort!" << std::endl;
        return 1;
    }
    if (tseitin < 0) {
        std::cerr << "tseitin variable negative, abort" << std::endl;
        return 1;
    }
    if (randmom_drop < 0) {
        std::cerr << "random_drop value negative, abort" << std::endl;
        return 1;
    }

    Formula f1, f2;

    parse_DIMACS(in1, f1);
    gzclose(in1);

    parse_DIMACS(in2, f2);
    gzclose(in2);

    std::cerr << "c Parsed formulas 1 with " << f1.nVars() << " vars and " << f1.clauses.size()
              << " and formulas 2 with " << f2.nVars() << " vars and " << f2.clauses.size() << std::endl;

    if (randmom_drop > 0) {
        srand(1234);
        for (int i = 0; i < randmom_drop && f1.clauses.size() > 0; ++i) {
            size_t p = rand() % f1.clauses.size();
            f1.clauses[p] = f1.clauses.back();
            f1.clauses.pop_back();
        }
    }

    Formula miter;

    Var maxV = f1.nVars() > f2.nVars() ? f1.nVars() : f2.nVars();
    if (tseitin > 0) {
        int offset = tseitin;
        offset = maxV > tseitin ? maxV - tseitin : 0;
        std::cerr << "c offset " << offset << " tseitin: " << tseitin << " maxV: " << maxV << std::endl;
        assert(offset == 0 || f2.nVars() <= tseitin || f2.nVars() + offset > f1.nVars());

        rewrite_variable_range(f2, tseitin, offset);

        maxV = f1.nVars() > f2.nVars() ? f1.nVars() : f2.nVars();

        while (f1.nVars() < maxV) f1.newVar();
        while (f2.nVars() < maxV) f2.newVar();

        exchange_definition_clauses(f1, f2, tseitin);
    }

    maxV = f1.nVars() > f2.nVars() ? f1.nVars() : f2.nVars();
    while (miter.nVars() < maxV) miter.newVar();

    std::cerr << "c Miter base formulas reserved " << miter.nVars() << " variables" << std::endl;

    generate_formula_miter(miter, f1, f2);

    std::size_t found = fn1.rfind("/");
    if (found != std::string::npos) fn1 = fn1.erase(0, found + 1);
    found = fn2.rfind("/");
    if (found != std::string::npos) fn2 = fn2.erase(0, found + 1);

    std::stringstream s;
    s << fn1 << " and " << fn2;
    if (tseitin != 0) s << " with tseitin base variable " << tseitin;
    if (randmom_drop) s << " with randomly dropping " << randmom_drop;
    print_formula(miter, s.str());

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rsi, %r12
movl %edi, %r13d
movq 0x4008(%rip), %r15      # 0x6ff0
leaq 0x211b(%rip), %rsi      # 0x510a
movl $0x23, %edx
movq %r15, %rdi
callq 0x21d0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
movq %rax, %r14
leaq 0x2101(%rip), %rsi      # 0x512e
movl $0x40, %edx
movq %rax, %rdi
callq 0x21d0
movl $0x0, -0x30(%rbp)
leaq 0x2127(%rip), %rbx      # 0x516f
movl $0x0, -0x2c(%rbp)
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
movl %r13d, %edi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x2050
cmpl $0x71, %eax
jle 0x3095
cmpl $0x74, %eax
je 0x30a8
cmpl $0x72, %eax
jne 0x3076
jmp 0x30e5
cmpl $-0x1, %eax
je 0x3136
cmpl $0x3f, %eax
jne 0x3076
jmp 0x37bd
movq 0x3ef9(%rip), %rax      # 0x6fa8
movq (%rax), %rdi
callq 0x2250
movl %eax, %r14d
movl $0x1a, %edx
movq %r15, %rdi
leaq 0x20d8(%rip), %rsi      # 0x51a1
callq 0x21d0
movq %r15, %rdi
movl %r14d, -0x2c(%rbp)
movl %r14d, %esi
callq 0x22a0
movq %rax, %r14
jmp 0x304f
movq 0x3ebc(%rip), %rax      # 0x6fa8
movq (%rax), %rdi
callq 0x2250
movl %eax, %r14d
movl $0x10, %edx
movq %r15, %rdi
leaq 0x206e(%rip), %rsi      # 0x5174
callq 0x21d0
movq %r15, %rdi
movl %r14d, -0x30(%rbp)
movl %r14d, %esi
callq 0x22a0
movq %rax, %r14
movl $0x1b, %edx
movq %rax, %rdi
leaq 0x2059(%rip), %rsi      # 0x5185
callq 0x21d0
jmp 0x304f
movq 0x3e93(%rip), %rbx      # 0x6fd0
movslq (%rbx), %rax
leal 0x2(%rax), %ecx
cmpl %r13d, %ecx
jne 0x36d2
movq (%r12,%rax,8), %rsi
leaq -0xb0(%rbp), %rdi
leaq -0x278(%rbp), %rdx
callq 0x20b0
movslq (%rbx), %rax
movq 0x8(%r12,%rax,8), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x278(%rbp), %rdx
callq 0x20b0
movq -0xb0(%rbp), %rdi
leaq 0x2065(%rip), %rsi      # 0x51f1
callq 0x2230
movq %rax, %r14
movq -0x90(%rbp), %rdi
leaq 0x204f(%rip), %rsi      # 0x51f1
callq 0x2230
movl $0x21, %edx
testq %r14, %r14
je 0x3717
movq %rax, %rbx
testq %rax, %rax
je 0x3720
cmpl $0x0, -0x2c(%rbp)
js 0x372e
cmpl $0x0, -0x30(%rbp)
js 0x373c
xorl %eax, %eax
leaq -0x48(%rbp), %r12
movl %eax, -0x8(%r12)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movq %rax, 0x10(%r12)
leaq -0x68(%rbp), %rcx
movl %eax, -0x8(%rcx)
movups %xmm0, (%rcx)
movq %rax, 0x10(%rcx)
leaq -0x50(%rbp), %rsi
movq %r14, %rdi
callq 0x38c4
movq %r14, %rdi
callq 0x2290
leaq -0x70(%rbp), %rsi
movq %rbx, %rdi
callq 0x38c4
movq %rbx, %rdi
callq 0x2290
movq 0x3dc6(%rip), %rdi      # 0x6ff0
leaq 0x204b(%rip), %rsi      # 0x527c
movl $0x19, %edx
callq 0x21d0
movl -0x50(%rbp), %esi
movq 0x3dab(%rip), %rdi      # 0x6ff0
callq 0x22a0
movq %rax, %rbx
leaq 0x2042(%rip), %rsi      # 0x5296
movl $0xa, %edx
movq %rax, %rdi
callq 0x21d0
movq -0x40(%rbp), %rsi
subq -0x48(%rbp), %rsi
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %r14 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r14, %rsi
movq %rbx, %rdi
callq 0x2120
movq %rax, %rbx
leaq 0x2014(%rip), %rsi      # 0x52a1
movl $0x15, %edx
movq %rax, %rdi
callq 0x21d0
movl -0x70(%rbp), %esi
movq %rbx, %rdi
callq 0x22a0
movq %rax, %rbx
leaq 0x1fe7(%rip), %rsi      # 0x5296
movl $0xa, %edx
movq %rax, %rdi
callq 0x21d0
movq -0x60(%rbp), %rsi
subq -0x68(%rbp), %rsi
sarq $0x3, %rsi
imulq %r14, %rsi
movq %rbx, %rdi
callq 0x2120
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
cmpl $0x0, -0x30(%rbp)
je 0x336c
movl $0x4d2, %edi            # imm = 0x4D2
callq 0x2190
movl -0x30(%rbp), %ebx
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x336c
callq 0x2070
cltq
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %rsi
movq %rsi, %rdi
subq %rcx, %rdi
sarq $0x3, %rdi
imulq %r14, %rdi
xorl %edx, %edx
divq %rdi
addq $-0x18, %rsi
leaq (%rdx,%rdx,2), %rax
leaq (%rcx,%rax,8), %rdi
callq 0x3c5c
movq -0x40(%rbp), %rax
leaq -0x18(%rax), %rcx
movq %rcx, -0x40(%rbp)
movq -0x18(%rax), %rdi
testq %rdi, %rdi
je 0x3368
callq 0x2180
decl %ebx
jne 0x3311
leaq -0xc8(%rbp), %r13
movl $0x0, -0x8(%r13)
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movq $0x0, 0x10(%r13)
movl -0x50(%rbp), %eax
movl -0x70(%rbp), %ebx
cmpl %ebx, %eax
cmovgl %eax, %ebx
cmpl $0x0, -0x2c(%rbp)
je 0x3493
xorl %eax, %eax
movl %ebx, %r15d
subl -0x2c(%rbp), %r15d
cmovlel %eax, %r15d
movq 0x3c3c(%rip), %rdi      # 0x6ff0
leaq 0x1efc(%rip), %rsi      # 0x52b7
movl $0x9, %edx
callq 0x21d0
movq 0x3c24(%rip), %rdi      # 0x6ff0
movl %r15d, %esi
callq 0x22a0
movq %rax, %r14
leaq 0x1ee3(%rip), %rsi      # 0x52c1
movl $0xa, %edx
movq %rax, %rdi
callq 0x21d0
movq %r14, %rdi
movl -0x2c(%rbp), %esi
callq 0x22a0
movq %rax, %r14
leaq 0x1ecc(%rip), %rsi      # 0x52cc
movl $0x7, %edx
movq %rax, %rdi
callq 0x21d0
movq %r14, %rdi
movl %ebx, %esi
callq 0x22a0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
testl %r15d, %r15d
je 0x345a
movl -0x70(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jle 0x345a
addl %r15d, %eax
cmpl -0x50(%rbp), %eax
jle 0x3803
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
movl %r15d, %edx
callq 0x29c6
movl -0x50(%rbp), %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
cmovgl %ecx, %eax
jge 0x347b
movl %eax, -0x50(%rbp)
cmpl %eax, -0x70(%rbp)
jge 0x3483
movl %eax, -0x70(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x2ac8
movl -0x50(%rbp), %ecx
movl -0x70(%rbp), %eax
cmpl %eax, %ecx
cmovgl %ecx, %eax
cmpl %eax, -0xd0(%rbp)
jge 0x34ac
movl %eax, -0xd0(%rbp)
movq 0x3b3d(%rip), %rdi      # 0x6ff0
leaq 0x1e82(%rip), %rsi      # 0x533c
movl $0x1f, %edx
callq 0x21d0
movl -0xd0(%rbp), %esi
movq 0x3b1f(%rip), %rdi      # 0x6ff0
callq 0x22a0
movq %rax, %rbx
leaq 0x1b6c(%rip), %rsi      # 0x504c
movl $0xa, %edx
movq %rax, %rdi
callq 0x21d0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
leaq -0xd0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x277b
leaq 0x1e2d(%rip), %rsi      # 0x535c
leaq -0xb0(%rbp), %rdi
movl $0x1, %ecx
movq $-0x1, %rdx
callq 0x2200
cmpq $-0x1, %rax
je 0x3570
incq %rax
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x2060
leaq -0xb0(%rbp), %rdi
movq %rax, %rsi
callq 0x20f0
leaq 0x1de5(%rip), %rsi      # 0x535c
leaq -0x90(%rbp), %rdi
movl $0x1, %ecx
movq $-0x1, %rdx
callq 0x2200
cmpq $-0x1, %rax
je 0x35b8
incq %rax
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x2060
leaq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x20f0
leaq -0x278(%rbp), %rdi
callq 0x2140
leaq -0x268(%rbp), %rbx
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
movq %rbx, %rdi
callq 0x21d0
movq %rax, %r14
leaq 0x1aaf(%rip), %rsi      # 0x509a
movl $0x5, %edx
movq %rax, %rdi
callq 0x21d0
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
movq %r14, %rdi
callq 0x21d0
cmpl $0x0, -0x2c(%rbp)
je 0x3633
leaq 0x1d43(%rip), %rsi      # 0x535e
movl $0x1c, %edx
movq %rbx, %rdi
callq 0x21d0
movq %rbx, %rdi
movl -0x2c(%rbp), %esi
callq 0x22a0
cmpl $0x0, -0x30(%rbp)
je 0x3658
leaq 0x1d3b(%rip), %rsi      # 0x537b
movl $0x18, %edx
movq %rbx, %rdi
callq 0x21d0
movq %rbx, %rdi
movl -0x30(%rbp), %esi
callq 0x22a0
leaq -0x260(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x2260
leaq -0xd0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x2d2d
leaq -0xe0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3693
callq 0x2180
movq 0x38fe(%rip), %rsi      # 0x6f98
leaq -0x278(%rbp), %rdi
callq 0x2150
leaq -0x1f8(%rbp), %rdi
callq 0x2090
movq %r13, %rdi
callq 0x3d70
leaq -0x68(%rbp), %rdi
callq 0x3d70
movq %r12, %rdi
callq 0x3d70
xorl %ebx, %ebx
jmp 0x3782
leaq 0x1afa(%rip), %rsi      # 0x51d3
movl $0x1d, %edx
movq %r15, %rdi
callq 0x21d0
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
movl $0x1, %ebx
jmp 0x37a9
leaq 0x1ad6(%rip), %rsi      # 0x51f4
jmp 0x3743
movl $0x22, %edx
leaq 0x1aea(%rip), %rsi      # 0x5216
jmp 0x3743
movl $0x20, %edx
leaq 0x1aff(%rip), %rsi      # 0x5239
jmp 0x3743
leaq 0x1b17(%rip), %rsi      # 0x525a
movq 0x38a6(%rip), %rbx      # 0x6ff0
movq %rbx, %rdi
callq 0x21d0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq 0x3880(%rip), %rdi      # 0x6ff0
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2130
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3794
callq 0x2180
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37a9
callq 0x2180
movl %ebx, %eax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x382c(%rip), %rdi      # 0x6ff0
leaq 0x19f1(%rip), %rsi      # 0x51bc
callq 0x21b0
movq 0x37e1(%rip), %rcx      # 0x6fb8
movsbl (%rcx), %esi
movq %rax, %rdi
callq 0x21e0
leaq 0x19e7(%rip), %rsi      # 0x51d0
movq %rax, %rdi
callq 0x21b0
movq %rax, %rdi
callq 0x20d0
movl $0x1, %edi
callq 0x21f0
leaq 0x1aca(%rip), %rdi      # 0x52d4
leaq 0x1b0c(%rip), %rsi      # 0x531d
leaq 0x1b0d(%rip), %rcx      # 0x5325
movl $0xdc, %edx
callq 0x2110
movq %rax, %rbx
leaq -0xe0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3845
callq 0x2180
jmp 0x3845
jmp 0x386d
jmp 0x386d
jmp 0x386d
movq %rax, %rbx
movq 0x374c(%rip), %rsi      # 0x6f98
leaq -0x278(%rbp), %rdi
callq 0x2150
leaq -0x1f8(%rbp), %rdi
callq 0x2090
jmp 0x3870
jmp 0x3892
movq %rax, %rbx
jmp 0x38a7
movq %rax, %rbx
movq %r13, %rdi
callq 0x3d70
jmp 0x387f
jmp 0x387c
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x3d70
movq %r12, %rdi
callq 0x3d70
jmp 0x3895
movq %rax, %rbx
leaq -0x80(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x38a7
callq 0x2180
leaq -0xa0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x38bc
callq 0x2180
movq %rbx, %rdi
callq 0x22b0