// File: eryxcc[P]lois/src/solvers.cpp
// Function: lois::SolverSMT::solve(lois::rbool)
virtual int solve(rbool phi) {

    featurelist fl;
    phi->listFeatures(fl);
    if(fl.domains.size() > 1) {
      std::cout << "SMT cannot use multiple domains yet" << std::endl;
      return 1;
      }
    for(auto r: fl.relations) if(!r->worksWith(SMT)) {
      std::cout << "SMT cannot use " << r->getName() << std::endl;
      return 1;
      }

    std::ofstream ofs;

    ofs.open("smtquery.smt", std::ofstream::out);
    
    // set 4 for nice indentation
    // indent = 4; 
    indent = -100;
    
    ofs << "(benchmark test\n  :extrasorts (A)\n  :logic " << smtLogic << "\n  :formula \n    ";
    
    OutputLanguage sav = outlan;
    outlan = SMT;
    ofs << phi << std::endl << "    )" << std::endl;
    outlan = sav;
    ofs.close();
    // system("cvc3 -lang smt < smtquery.smt > smtquery.out");  
    if(system(cmd.c_str()))
      printf("system error\n");
    FILE *f = fopen("smtquery.out", "rt");
    char buf[500];
    char *b = fgets(buf, 500, f);
    if(!b) { printf("ERROR\n"); exit(3); }
    fclose(f);
    std::string ans = buf;
    if(ans == "sat\n") return 2;
    if(ans == "unsat\n") return 0;
    return 1;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5a0, %rsp            # imm = 0x5A0
movq %rsi, -0x520(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x528(%rbp)
leaq -0x78(%rbp), %rdi
movq %rdi, -0x518(%rbp)
callq 0x5b6c0
movq -0x520(%rbp), %rdi
callq 0x3ece0
movq -0x518(%rbp), %rsi
movq %rax, %rdi
movq (%rdi), %rax
movq 0x40(%rax), %rax
callq *%rax
jmp 0x64f36
leaq -0x78(%rbp), %rdi
callq 0x63680
cmpq $0x1, %rax
jbe 0x64fa0
movq 0x4008c(%rip), %rdi     # 0xa4fd8
leaq 0xe7d6(%rip), %rsi      # 0x73729
callq 0x82b0
movq %rax, -0x530(%rbp)
jmp 0x64f61
movq -0x530(%rbp), %rdi
movq 0x40041(%rip), %rsi     # 0xa4fb0
callq 0x8300
jmp 0x64f76
movl $0x1, -0x4(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x65417
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x6542c
leaq -0x78(%rbp), %rax
addq $0x30, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
callq 0x5b6f0
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
callq 0x5b720
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x5b750
testb $0x1, %al
jne 0x64ff1
jmp 0x650ef
leaq -0x98(%rbp), %rdi
callq 0x5b780
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rdi
movq (%rdi), %rax
movq 0x30(%rax), %rax
movl $0x2, %esi
callq *%rax
movb %al, -0x531(%rbp)
jmp 0x65024
movb -0x531(%rbp), %al
testb $0x1, %al
jne 0x650dc
jmp 0x65034
movq 0x3ff9d(%rip), %rdi     # 0xa4fd8
leaq 0xe70b(%rip), %rsi      # 0x7374d
callq 0x82b0
movq %rax, -0x540(%rbp)
jmp 0x65050
movq -0xa8(%rbp), %rsi
movq (%rsi), %rax
movq 0x38(%rax), %rax
leaq -0xc8(%rbp), %rdi
callq *%rax
jmp 0x65069
movq -0x540(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x8280
movq %rax, -0x548(%rbp)
jmp 0x65085
movq -0x548(%rbp), %rdi
movq 0x3ff1d(%rip), %rsi     # 0xa4fb0
callq 0x8300
jmp 0x6509a
leaq -0xc8(%rbp), %rdi
callq 0x8578
movl $0x1, -0x4(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x65417
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x8578
jmp 0x6542c
jmp 0x650de
leaq -0x98(%rbp), %rdi
callq 0x5b7b0
jmp 0x64fd5
leaq -0x2c8(%rbp), %rdi
callq 0x84a0
jmp 0x650fd
leaq 0xe715(%rip), %rsi      # 0x73819
leaq -0x2c8(%rbp), %rdi
movl $0x10, %edx
callq 0x8060
jmp 0x65117
leaq 0x40842(%rip), %rax     # 0xa5960
movl $0xffffff9c, (%rax)     # imm = 0xFFFFFF9C
leaq 0xe6fb(%rip), %rsi      # 0x73826
leaq -0x2c8(%rbp), %rdi
callq 0x82b0
movq %rax, -0x550(%rbp)
jmp 0x65140
movq -0x550(%rbp), %rdi
leaq 0x407b2(%rip), %rsi     # 0xa5900
callq 0x8280
movq %rax, -0x558(%rbp)
jmp 0x6515c
movq -0x558(%rbp), %rdi
leaq 0xe6e8(%rip), %rsi      # 0x73852
callq 0x82b0
jmp 0x65171
movq -0x520(%rbp), %rsi
leaq 0x407e5(%rip), %rax     # 0xa5964
movl (%rax), %ecx
movl %ecx, -0x2cc(%rbp)
movl $0x2, (%rax)
leaq -0x2e0(%rbp), %rdi
movq %rdi, -0x568(%rbp)
callq 0x11030
movq -0x568(%rbp), %rsi
leaq -0x2c8(%rbp), %rdi
callq 0x40060
movq %rax, -0x560(%rbp)
jmp 0x651bc
movq -0x560(%rbp), %rdi
movq 0x3fde6(%rip), %rsi     # 0xa4fb0
callq 0x8300
movq %rax, -0x570(%rbp)
jmp 0x651d8
movq -0x570(%rbp), %rdi
leaq 0xe51b(%rip), %rsi      # 0x73701
callq 0x82b0
movq %rax, -0x578(%rbp)
jmp 0x651f4
movq -0x578(%rbp), %rdi
movq 0x3fdae(%rip), %rsi     # 0xa4fb0
callq 0x8300
jmp 0x65209
leaq -0x2e0(%rbp), %rdi
callq 0x11060
movl -0x2cc(%rbp), %ecx
leaq 0x40742(%rip), %rax     # 0xa5964
movl %ecx, (%rax)
leaq -0x2c8(%rbp), %rdi
callq 0x8400
jmp 0x65232
movq -0x528(%rbp), %rdi
addq $0x8, %rdi
callq 0x8130
movq %rax, %rdi
callq 0x8260
movl %eax, -0x57c(%rbp)
jmp 0x65252
movl -0x57c(%rbp), %eax
cmpl $0x0, %eax
je 0x652a3
leaq 0xe600(%rip), %rdi      # 0x73864
xorl %eax, %eax
callq 0x8050
jmp 0x6526d
jmp 0x652a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x65409
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x2e0(%rbp), %rdi
callq 0x11060
jmp 0x65409
leaq 0xe5ec(%rip), %rdi      # 0x73896
leaq 0xd034(%rip), %rsi      # 0x722e5
callq 0x8380
movq %rax, -0x588(%rbp)
jmp 0x652bf
movq -0x588(%rbp), %rax
movq %rax, -0x2e8(%rbp)
movq -0x2e8(%rbp), %rdx
leaq -0x4e0(%rbp), %rdi
movl $0x1f4, %esi            # imm = 0x1F4
callq 0x8450
movq %rax, -0x590(%rbp)
jmp 0x652ee
movq -0x590(%rbp), %rax
movq %rax, -0x4e8(%rbp)
cmpq $0x0, -0x4e8(%rbp)
jne 0x65320
leaq 0xe565(%rip), %rdi      # 0x73872
xorl %eax, %eax
callq 0x8050
jmp 0x65316
movl $0x3, %edi
callq 0x8390
movq -0x2e8(%rbp), %rdi
callq 0x82c0
jmp 0x6532e
leaq -0x509(%rbp), %rdi
movq %rdi, -0x598(%rbp)
callq 0x84e0
movq -0x598(%rbp), %rdx
leaq -0x508(%rbp), %rdi
leaq -0x4e0(%rbp), %rsi
callq 0x10f40
jmp 0x6535d
leaq -0x509(%rbp), %rdi
callq 0x8320
leaq -0x508(%rbp), %rdi
leaq 0xe504(%rip), %rsi      # 0x7387b
callq 0x50ce0
testb $0x1, %al
jne 0x65382
jmp 0x653b2
movl $0x2, -0x4(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x653ef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x509(%rbp), %rdi
callq 0x8320
jmp 0x65409
leaq -0x508(%rbp), %rdi
leaq 0xe4b9(%rip), %rsi      # 0x73879
callq 0x50ce0
testb $0x1, %al
jne 0x653cb
jmp 0x653de
movl $0x0, -0x4(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x653ef
movl $0x1, -0x4(%rbp)
movl $0x1, -0x88(%rbp)
leaq -0x508(%rbp), %rdi
callq 0x8578
leaq -0x2c8(%rbp), %rdi
callq 0x8430
jmp 0x65417
leaq -0x2c8(%rbp), %rdi
callq 0x8430
jmp 0x6542c
leaq -0x78(%rbp), %rdi
callq 0x5b7e0
movl -0x4(%rbp), %eax
addq $0x5a0, %rsp            # imm = 0x5A0
popq %rbp
retq
leaq -0x78(%rbp), %rdi
callq 0x5b7e0
movq -0x80(%rbp), %rdi
callq 0x84d0
nop