// File: /workspace/github_cpp_makefile_star2_O1/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 0x21a0
movl $0x0, -0x30(%rbp)
leaq 0x4b66(%rip), %r13      # 0x7020
movq 0x7b17(%rip), %r14      # 0x9fd8
leaq 0x4bc6(%rip), %rbx      # 0x708e
movl %r12d, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2070
cmpl $0x6f, %eax
jg 0x24f9
cmpl $-0x1, %eax
je 0x2591
cmpl $0x66, %eax
jne 0x2507
movq 0x7ad8(%rip), %rax      # 0x9fc8
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x24c8
cmpl $0x70, %eax
je 0x2587
cmpl $0x73, %eax
je 0x256c
movl $0x8, %edx
movq %r14, %rdi
leaq 0x4b10(%rip), %rsi      # 0x7026
callq 0x21f0
movl $0x1f, %edx
movq %r14, %rdi
leaq 0x4b05(%rip), %rsi      # 0x702f
callq 0x21f0
movl $0x1e, %edx
movq %r14, %rdi
leaq 0x4b11(%rip), %rsi      # 0x704f
callq 0x21f0
movl $0x1f, %edx
movq %r14, %rdi
leaq 0x4b1c(%rip), %rsi      # 0x706e
callq 0x21f0
movl $0x2d, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x21f0
jmp 0x24c8
movq 0x7a55(%rip), %rax      # 0x9fc8
movq (%rax), %rdi
callq 0x2200
cvttsd2si %xmm0, %eax
movl %eax, -0x34(%rbp)
jmp 0x24c8
movb $0x1, %al
movl %eax, -0x30(%rbp)
jmp 0x24c8
leaq -0x29(%rbp), %rdi
movq -0x58(%rbp), %r14
movq %r14, %rsi
callq 0x27b4
movq 0x7a30(%rip), %rdi      # 0x9fd8
cmpl $0x3, %eax
je 0x26bb
cmpl $0x2, %eax
je 0x263f
cmpl $0x1, %eax
jne 0x2743
leaq 0x4af2(%rip), %rsi      # 0x70bc
movl $0x17, %edx
callq 0x21f0
leaq -0x50(%rbp), %rbx
movl $0x0, 0x8(%rbx)
movl $0x38, %edi
callq 0x21c0
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
movupd %xmm0, 0x18(%rax)
movupd %xmm0, 0x28(%rax)
movq %rax, (%rbx)
movl -0x34(%rbp), %ecx
movl %ecx, 0xc(%rbx)
leaq -0x29(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x28ee
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x2d3c
movq %rbx, %rdi
callq 0x2f06
testb $0x1, -0x30(%rbp)
je 0x2754
leaq -0x50(%rbp), %rdi
callq 0x2f64
jmp 0x2754
leaq 0x4a8e(%rip), %rsi      # 0x70d4
movl $0x14, %edx
callq 0x21f0
leaq -0x50(%rbp), %rbx
movl $0x0, 0x8(%rbx)
movl $0x38, %edi
callq 0x21c0
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%rax)
movupd %xmm0, 0x18(%rax)
movupd %xmm0, 0x28(%rax)
movq %rax, (%rbx)
movl -0x34(%rbp), %ecx
movl %ecx, 0xc(%rbx)
leaq -0x29(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2ff4
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x343e
movq %rbx, %rdi
callq 0x360c
testb $0x1, -0x30(%rbp)
je 0x2754
leaq -0x50(%rbp), %rdi
callq 0x366a
jmp 0x2754
leaq 0x4a27(%rip), %rsi      # 0x70e9
movl $0x16, %edx
callq 0x21f0
leaq -0x50(%rbp), %rbx
movl $0x0, 0x8(%rbx)
movl $0x50, %edi
callq 0x21c0
leaq 0x10(%rax), %rcx
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x20(%rax)
movupd %xmm0, 0x30(%rax)
movupd %xmm0, 0x40(%rax)
movq %rax, (%rbx)
movl -0x34(%rbp), %ecx
movl %ecx, 0xc(%rbx)
leaq -0x29(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x36fa
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x3bf8
movq %rbx, %rdi
callq 0x3e24
testb $0x1, -0x30(%rbp)
je 0x2754
leaq -0x50(%rbp), %rdi
callq 0x3e82
jmp 0x2754
leaq 0x49b6(%rip), %rsi      # 0x7100
movl $0x37, %edx
callq 0x21f0
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x21a0
movq 0x7871(%rip), %r14      # 0x9fd8
leaq 0x49ca(%rip), %rsi      # 0x7138
movl $0x12, %edx
movq %r14, %rdi
callq 0x21f0
movq (%rbx), %rdi
movq -0x60(%rbp), %rsi
callq 0x20e0
movq %r14, %rdi
callq 0x2260
leaq 0x49b5(%rip), %rsi      # 0x714b
movl $0x15, %edx
movq %rax, %rdi
callq 0x21f0
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq