// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
movl %edi, %r12d
movq 0x447d(%rip), %r13      # 0x6ff0
leaq 0x1574(%rip), %rsi      # 0x40ee
movq %r13, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20c0
leaq 0x1581(%rip), %rsi      # 0x4112
movq %rax, %rdi
callq 0x21a0
movl $0x0, -0x2c(%rbp)
leaq 0x15ac(%rip), %rbx      # 0x4153
movl $0x0, -0x30(%rbp)
movq %rax, %rdi
callq 0x20c0
movl %r12d, %edi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2040
cmpl $-0x1, %eax
je 0x2c57
cmpl $0x72, %eax
je 0x2be1
cmpl $0x74, %eax
je 0x2c22
cmpl $0x3f, %eax
jne 0x2bb6
jmp 0x31a8
movq 0x43c0(%rip), %rax      # 0x6fa8
movq (%rax), %rdi
callq 0x2220
movl %eax, %r14d
movq %r13, %rdi
leaq 0x155b(%rip), %rsi      # 0x4158
callq 0x21a0
movq %rax, %rdi
movl %r14d, -0x2c(%rbp)
movl %r14d, %esi
callq 0x2280
movq %rax, %rdi
leaq 0x154e(%rip), %rsi      # 0x4169
callq 0x21a0
jmp 0x2bae
movq 0x437f(%rip), %rax      # 0x6fa8
movq (%rax), %rdi
callq 0x2220
movl %eax, %r14d
movq %r13, %rdi
leaq 0x1547(%rip), %rsi      # 0x4185
callq 0x21a0
movq %rax, %rdi
movl %r14d, -0x30(%rbp)
movl %r14d, %esi
callq 0x2280
jmp 0x2bae
movq 0x4372(%rip), %rbx      # 0x6fd0
movslq (%rbx), %rax
leal 0x2(%rax), %ecx
cmpl %r12d, %ecx
jne 0x2e4b
movq (%r15,%rax,8), %rsi
leaq -0xb0(%rbp), %rdi
leaq -0x278(%rbp), %rdx
callq 0x2090
movslq (%rbx), %rax
movq 0x8(%r15,%rax,8), %rsi
leaq -0x90(%rbp), %rdi
leaq -0x278(%rbp), %rdx
callq 0x2090
movq -0xb0(%rbp), %rdi
leaq 0x1528(%rip), %rsi      # 0x41d5
callq 0x2200
movq %rax, %r14
movq -0x90(%rbp), %rdi
leaq 0x1512(%rip), %rsi      # 0x41d5
callq 0x2200
testq %r14, %r14
je 0x2e6e
movq %rax, %rbx
testq %rax, %rax
je 0x2e7a
cmpl $0x0, -0x30(%rbp)
js 0x2f68
cmpl $0x0, -0x2c(%rbp)
js 0x2fa5
leaq -0x48(%rbp), %r12
andl $0x0, -0x8(%r12)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
andq $0x0, 0x10(%r12)
leaq -0x68(%rbp), %rax
andl $0x0, -0x8(%rax)
movups %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq -0x50(%rbp), %rsi
movq %r14, %rdi
callq 0x328e
movq %r14, %rdi
callq 0x2270
leaq -0x70(%rbp), %rsi
movq %rbx, %rdi
callq 0x328e
movq %rbx, %rdi
callq 0x2270
movq 0x42a8(%rip), %rdi      # 0x6ff0
leaq 0x1511(%rip), %rsi      # 0x4260
callq 0x21a0
movl -0x50(%rbp), %esi
movq %rax, %rdi
callq 0x2280
leaq 0x1514(%rip), %rsi      # 0x427a
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
movq -0x40(%rbp), %rax
subq -0x48(%rbp), %rax
pushq $0x18
popq %rbx
cqto
idivq %rbx
movq %rax, %rsi
callq 0x2110
leaq 0x14f5(%rip), %rsi      # 0x4285
movq %rax, %rdi
callq 0x21a0
movl -0x70(%rbp), %esi
movq %rax, %rdi
callq 0x2280
leaq 0x14d0(%rip), %rsi      # 0x427a
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
movq -0x60(%rbp), %rax
subq -0x68(%rbp), %rax
cqto
idivq %rbx
movq %rax, %rsi
callq 0x2110
movq %rax, %rdi
callq 0x20c0
cmpl $0x0, -0x2c(%rbp)
je 0x2e86
movl $0x4d2, %edi            # imm = 0x4D2
callq 0x2190
movl -0x2c(%rbp), %r14d
subl $0x1, %r14d
jb 0x2e86
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x2e86
callq 0x2060
movslq %eax, %rcx
movq -0x48(%rbp), %r8
movq -0x40(%rbp), %rsi
movq %rsi, %rax
subq %r8, %rax
cqto
idivq %rbx
movq %rax, %rdi
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
addq $-0x18, %rsi
imulq $0x18, %rdx, %rdi
addq %r8, %rdi
callq 0x35be
movq -0x40(%rbp), %rdi
addq $-0x18, %rdi
movq %rdi, -0x40(%rbp)
callq 0x38dc
jmp 0x2dea
movq 0x419e(%rip), %rdi      # 0x6ff0
leaq 0x135e(%rip), %rsi      # 0x41b7
callq 0x21a0
movq %rax, %rdi
callq 0x20c0
pushq $0x1
popq %rbx
jmp 0x2fdb
leaq 0x1363(%rip), %rsi      # 0x41d8
jmp 0x2fac
leaq 0x1379(%rip), %rsi      # 0x41fa
jmp 0x2fac
leaq -0xc8(%rbp), %r13
andl $0x0, -0x8(%r13)
andq $0x0, 0x10(%r13)
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movl -0x50(%rbp), %eax
movl -0x70(%rbp), %r15d
cmpl %r15d, %eax
cmovgl %eax, %r15d
movl -0x30(%rbp), %ebx
testl %ebx, %ebx
je 0x2fef
movq %r12, %r14
xorl %eax, %eax
movl %r15d, %r12d
subl %ebx, %r12d
cmovlel %eax, %r12d
movq 0x4122(%rip), %rdi      # 0x6ff0
leaq 0x13c6(%rip), %rsi      # 0x429b
callq 0x21a0
movq %rax, %rdi
movl %r12d, %esi
callq 0x2280
leaq 0x13b9(%rip), %rsi      # 0x42a5
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
movl %ebx, %esi
callq 0x2280
leaq 0x13ab(%rip), %rsi      # 0x42b0
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
movl %r15d, %esi
callq 0x2280
movq %rax, %rdi
callq 0x20c0
testl %r12d, %r12d
je 0x2f38
movl -0x70(%rbp), %eax
cmpl %ebx, %eax
jle 0x2f38
addl %r12d, %eax
cmpl -0x50(%rbp), %eax
jle 0x31ec
movl %ebx, %esi
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
movl %r12d, %edx
callq 0x2789
movl -0x50(%rbp), %edx
movl (%rbx), %eax
cmpl %eax, %edx
movl %eax, %ecx
cmovgl %edx, %ecx
movl %ecx, %esi
negl %esi
incl %edx
leal (%rsi,%rdx), %edi
cmpl $0x1, %edi
je 0x2f71
movl %edx, -0x50(%rbp)
jmp 0x2f59
leaq 0x12ae(%rip), %rsi      # 0x421d
jmp 0x2fac
movl -0x30(%rbp), %edx
cmpl %ecx, %eax
jge 0x2f7f
incl %eax
movl %eax, -0x70(%rbp)
jmp 0x2f74
leaq -0x50(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x286b
movl -0x50(%rbp), %ecx
movl -0x70(%rbp), %r15d
movl -0xd0(%rbp), %eax
cmpl %r15d, %ecx
cmovgl %ecx, %r15d
movq %r14, %r12
jmp 0x2ffb
leaq 0x1292(%rip), %rsi      # 0x423e
movq 0x403d(%rip), %rdi      # 0x6ff0
callq 0x21a0
movq %rax, %rdi
callq 0x20c0
pushq $0x1
popq %rbx
leaq -0x90(%rbp), %rdi
callq 0x20b0
leaq -0xb0(%rbp), %rdi
callq 0x20b0
movl %ebx, %eax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x2ffb
incl %eax
movl %eax, -0xd0(%rbp)
cmpl %r15d, %eax
jl 0x2ff3
movq 0x3fe9(%rip), %rdi      # 0x6ff0
leaq 0x1312(%rip), %rsi      # 0x4320
callq 0x21a0
movl -0xd0(%rbp), %esi
movq %rax, %rdi
callq 0x2280
leaq 0x1008(%rip), %rsi      # 0x4030
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20c0
leaq -0xd0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x2613
leaq 0x12ed(%rip), %rsi      # 0x4340
leaq -0xb0(%rbp), %rdi
pushq $-0x1
popq %rdx
callq 0x2260
cmpq $-0x1, %rax
je 0x308b
incq %rax
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x2050
leaq -0xb0(%rbp), %rdi
movq %rax, %rsi
callq 0x20e0
leaq 0x12ae(%rip), %rsi      # 0x4340
leaq -0x90(%rbp), %rdi
pushq $-0x1
popq %rdx
callq 0x2260
cmpq $-0x1, %rax
je 0x30ca
incq %rax
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x2050
leaq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x20e0
leaq -0x278(%rbp), %rdi
callq 0x2130
leaq -0x268(%rbp), %rbx
leaq -0xb0(%rbp), %rsi
movq %rbx, %rdi
callq 0x2170
leaq 0xf8b(%rip), %rsi       # 0x407e
movq %rax, %rdi
callq 0x21a0
leaq -0x90(%rbp), %rsi
movq %rax, %rdi
callq 0x2170
cmpl $0x0, -0x30(%rbp)
je 0x312a
leaq 0x122b(%rip), %rsi      # 0x4342
movq %rbx, %rdi
callq 0x21a0
movq %rax, %rdi
movl -0x30(%rbp), %esi
callq 0x2280
cmpl $0x0, -0x2c(%rbp)
je 0x314a
leaq 0x1228(%rip), %rsi      # 0x435f
movq %rbx, %rdi
callq 0x21a0
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x2280
leaq -0x260(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x2230
leaq -0xd0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x29f3
leaq -0xf0(%rbp), %rdi
callq 0x20b0
leaq -0x278(%rbp), %rdi
callq 0x2140
movq %r13, %rdi
callq 0x36ec
leaq -0x68(%rbp), %rdi
callq 0x36ec
movq %r12, %rdi
callq 0x36ec
xorl %ebx, %ebx
jmp 0x2fc3
movq 0x3e41(%rip), %rdi      # 0x6ff0
leaq 0xfea(%rip), %rsi       # 0x41a0
callq 0x21a0
movq 0x3df6(%rip), %rcx      # 0x6fb8
movsbl (%rcx), %esi
movq %rax, %rdi
callq 0x21c0
leaq 0xfe0(%rip), %rsi       # 0x41b4
movq %rax, %rdi
callq 0x21a0
movq %rax, %rdi
callq 0x20c0
pushq $0x1
popq %rdi
callq 0x21d0
leaq 0x10c5(%rip), %rdi      # 0x42b8
leaq 0x1107(%rip), %rsi      # 0x4301
leaq 0x1108(%rip), %rcx      # 0x4309
movl $0xdc, %edx
callq 0x2100
movq %r12, %r14
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
callq 0x20b0
jmp 0x3233
jmp 0x3223
jmp 0x3223
movq %r12, %r14
jmp 0x3228
movq %rax, %rbx
jmp 0x323f
movq %r12, %r14
movq %rax, %rbx
leaq -0x278(%rbp), %rdi
callq 0x2140
movq %r13, %rdi
callq 0x36ec
jmp 0x3258
jmp 0x326b
movq %rax, %rbx
jmp 0x327a
jmp 0x3252
movq %r12, %r14
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x36ec
movq %r14, %rdi
callq 0x36ec
jmp 0x326e
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x20b0
leaq -0xb0(%rbp), %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x2290