// File: /workspace/github_cpp_makefile_star2_O3/waltersharpWEI[P]CommentEliminator/main.cpp
// Function: main
int main(int argc, char * argv[]) {
    srand(time(NULL));

    //The Directory of target Project
    string ProjectDir;
    //The number of threads,default = 1
    int NumThread = 1;
    int Strategy = 0;

    int Option;

    while ((Option = getopt(argc,argv,"ht:a:")) != -1) {
        switch (Option) {
        case 'h':
            showHelp();
            break;
        case 't':
            NumThread = atoi(optarg);
            break;
        case 'a':
            Strategy = atoi(optarg);
            break;
        default:
            fprintf(stderr, "Usage: %s [-h] [-t threads] [-a method] targetDirectory\n",argv[0]);
            exit(EXIT_FAILURE);
        }
    }

    if (optind >= argc) {
        fprintf(stderr, "Expected argument after options\n");
        exit(EXIT_FAILURE);
    }
    
    ProjectDir = argv[optind];

    //initialize the FileList to include all source file
    //in project directory and its size
    initializeSourceFileDir(ProjectDir);
    //sort the FileList based on size
    //sort(FileList.begin(),FileList.end(),less<FileRecord>());
    //display the FileList
    //displayFileList();
    //distribute the task to these threads

    if (NumThread <= 0) {
        fprintf(stderr, "Number of Thread must be bigger than 0\n");
        exit(EXIT_FAILURE);
    }

    switch (Strategy) {
    case 0:{
        balanceThreadsGreedy(NumThread);
    }
        break;
    case 1:{
        balanceThreads(NumThread);
    }
        break;
    default: {
        fprintf(stderr, "Invalid Algorithm parameter\n");
        exit(EXIT_FAILURE);
    }
        break;
    };
    
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movl %edi, %r12d
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x2180
movl %eax, %edi
callq 0x2190
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl $0x1, %r14d
leaq 0x18e0(%rip), %r13      # 0x519b
movl %r12d, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2040
cmpl $0x68, %eax
jne 0x38d5
callq 0x3826
jmp 0x38bb
cmpl $-0x1, %eax
je 0x390f
cmpl $0x61, %eax
je 0x38fc
cmpl $0x74, %eax
jne 0x39ce
movq 0x46c1(%rip), %rax      # 0x7fb0
movq (%rax), %rdi
callq 0x22b0
movl %eax, %r14d
jmp 0x38bb
movq 0x46ad(%rip), %rax      # 0x7fb0
movq (%rax), %rdi
callq 0x22b0
movl %eax, %ebx
jmp 0x38bb
movq 0x46c2(%rip), %rax      # 0x7fd8
movslq (%rax), %rax
cmpl %r12d, %eax
jge 0x39d6
movq (%r15,%rax,8), %r15
leaq -0x48(%rbp), %r12
movq 0x8(%r12), %r13
movq %r15, %rdi
callq 0x20b0
movq %r12, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r15, %rcx
movq %rax, %r8
callq 0x22a0
leaq -0x58(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x3d2c
leaq -0x68(%rbp), %rdi
callq 0x2a6a
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x3984
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x21d0
testl %r14d, %r14d
jle 0x39db
cmpl $0x1, %ebx
je 0x399c
testl %ebx, %ebx
jne 0x39e0
movl %r14d, %edi
callq 0x3408
jmp 0x39a4
movl %r14d, %edi
callq 0x31bb
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x39bd
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21d0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x23d8
callq 0x2360
callq 0x23b0
callq 0x2388
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x3a04
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x21d0
jmp 0x3a04
jmp 0x3a01
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3a1d
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x22f0
nop