// File: /workspace/github_cpp_makefile_star2_O2/dianejdan[P]Eclat/main.cpp
// Function: main
int main(int argc, char* argv[]){

    time_t startT, endT;
    time(&startT); // record start time

    char* filename; // input file name
    int minsup; // min sup
    bool prnt = false; // print or not

    // use getopt to get options and arguments
    int c;
    while((c = getopt(argc, argv, "f:s:p")) != -1){
        switch(c){
            case 'f': // input file
                filename = optarg;
                break;
            case 's': // min sup
                minsup = (int)atof(optarg);
                break;
            case 'p': // print or not
                prnt = true;
                break;
            default: // print usage
                cout << "Usage: \n" << "./main -f input -s minsup [-p]\n"
                     << "(-f input) should be together\n"
                     << "(-s minsup) should be together\n"
                     << "the three argument pairs can be in any order\n";
        }
    }


    DbReader reader; // reader of input file

    // the DbReader class can detect the type of input file, int, char, string
    switch( reader.template_type(filename) ){
        case 1: // int
          {
            cout << "The items are integer.\n";
            PatternStore<int> pS1; // pattern store
            pS1.set_minsup(minsup); // set up min sup
            reader.read_txt(pS1, filename, minsup); // read input and populate single item tid list

            pS1.eclat(pS1.root()); // eclat algorithm
            pS1.display(); // show how many frequent patterns

            if (prnt)
                  pS1.print_patterns(); // if -p is specified, print patterns
            break;
          }
        case 2: // char
          {
            cout << "The items are char.\n";
            PatternStore<char> pS2;
            pS2.set_minsup(minsup);
            reader.read_txt(pS2, filename, minsup);

            pS2.eclat(pS2.root());
            pS2.display();

            if (prnt)
                  pS2.print_patterns();
            break;
          }
        case 3: // string
          {
            cout << "The items are string.\n";
            PatternStore<string> pS3;
            pS3.set_minsup(minsup);
            reader.read_txt(pS3, filename, minsup);

            pS3.eclat(pS3.root());
            pS3.display();

            if (prnt)
                  pS3.print_patterns();
            break;
          }
        default:
            cout << "The format of item in input file cannot be recognized.\n";

    }

    time(&endT);
    cout << "The program takes " << difftime(endT, startT) << " seconds to finish.\n\n"; // output time

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r15
movl %edi, %r12d
leaq -0x60(%rbp), %rdi
callq 0x21c0
movl $0x0, -0x30(%rbp)
leaq 0x4b96(%rip), %r13      # 0x7020
leaq 0x4bdd(%rip), %r14      # 0x706e
leaq 0x4bf6(%rip), %rbx      # 0x708e
movl %r12d, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2060
cmpl $-0x1, %eax
je 0x253f
cmpl $0x73, %eax
je 0x2507
cmpl $0x70, %eax
je 0x2535
cmpl $0x66, %eax
je 0x2522
movq 0x8b13(%rip), %rdi      # 0xafd8
leaq 0x4b5a(%rip), %rsi      # 0x7026
callq 0x21d0
movq %rax, %rdi
leaq 0x4b54(%rip), %rsi      # 0x702f
callq 0x21d0
movq %rax, %rdi
leaq 0x4b65(%rip), %rsi      # 0x704f
callq 0x21d0
movq %rax, %rdi
movq %r14, %rsi
callq 0x21d0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21d0
jmp 0x2498
movq 0x8aba(%rip), %rax      # 0xafc8
movq (%rax), %rdi
callq 0x2220
cvttsd2si %xmm0, %eax
movl %eax, -0x34(%rbp)
jmp 0x2498
movq 0x8a9f(%rip), %rax      # 0xafc8
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x2498
movb $0x1, %al
movl %eax, -0x30(%rbp)
jmp 0x2498
leaq -0x29(%rbp), %rdi
movq -0x58(%rbp), %r14
movq %r14, %rsi
callq 0x26ca
movq 0x8a82(%rip), %rdi      # 0xafd8
cmpl $0x3, %eax
je 0x2616
cmpl $0x2, %eax
je 0x25c5
cmpl $0x1, %eax
jne 0x2667
leaq 0x4b48(%rip), %rsi      # 0x70bc
callq 0x21d0
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x279e
movl -0x34(%rbp), %ecx
movl %ecx, 0xc(%rbx)
leaq -0x29(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x27cc
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x2a96
movq %rbx, %rdi
callq 0x2bec
testb $0x1, -0x30(%rbp)
je 0x2673
leaq -0x50(%rbp), %rdi
callq 0x2c22
jmp 0x2673
leaq 0x4b08(%rip), %rsi      # 0x70d4
callq 0x21d0
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x2c8a
movl -0x34(%rbp), %ecx
movl %ecx, 0xc(%rbx)
leaq -0x29(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2cb8
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x2f84
movq %rbx, %rdi
callq 0x30ea
testb $0x1, -0x30(%rbp)
je 0x2673
leaq -0x50(%rbp), %rdi
callq 0x3120
jmp 0x2673
leaq 0x4acc(%rip), %rsi      # 0x70e9
callq 0x21d0
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x3188
movl -0x34(%rbp), %ecx
movl %ecx, 0xc(%rbx)
leaq -0x29(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x31c6
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x34e2
movq %rbx, %rdi
callq 0x3666
testb $0x1, -0x30(%rbp)
je 0x2673
leaq -0x50(%rbp), %rdi
callq 0x369c
jmp 0x2673
leaq 0x4a92(%rip), %rsi      # 0x7100
callq 0x21d0
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x21c0
movq 0x8952(%rip), %rdi      # 0xafd8
leaq 0x4aab(%rip), %rsi      # 0x7138
callq 0x21d0
movq %rax, %r14
movq (%rbx), %rdi
movq -0x60(%rbp), %rsi
callq 0x20f0
movq %r14, %rdi
callq 0x2290
leaq 0x4a9b(%rip), %rsi      # 0x714b
movq %rax, %rdi
callq 0x21d0
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop