// File: /workspace/github_cpp_makefile_star2_O1/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 0x2190
movl %eax, %edi
callq 0x21a0
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl $0x1, %r14d
leaq 0x18b8(%rip), %r13      # 0x519e
movl %r12d, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2040
cmpl $0x68, %eax
jne 0x3900
callq 0x3851
jmp 0x38e6
cmpl $-0x1, %eax
je 0x393a
cmpl $0x61, %eax
je 0x3927
cmpl $0x74, %eax
jne 0x39f9
movq 0x4696(%rip), %rax      # 0x7fb0
movq (%rax), %rdi
callq 0x22c0
movl %eax, %r14d
jmp 0x38e6
movq 0x4682(%rip), %rax      # 0x7fb0
movq (%rax), %rdi
callq 0x22c0
movl %eax, %ebx
jmp 0x38e6
movq 0x4697(%rip), %rax      # 0x7fd8
movslq (%rax), %rax
cmpl %r12d, %eax
jge 0x3a01
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 0x22b0
leaq -0x58(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x3d4a
leaq -0x68(%rbp), %rdi
callq 0x2a76
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x39af
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x21e0
testl %r14d, %r14d
jle 0x3a06
cmpl $0x1, %ebx
je 0x39c7
testl %ebx, %ebx
jne 0x3a0b
movl %r14d, %edi
callq 0x3436
jmp 0x39cf
movl %r14d, %edi
callq 0x31eb
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x39e8
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21e0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x23e8
callq 0x2370
callq 0x23c0
callq 0x2398
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r15, %rdi
je 0x3a2f
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x21e0
jmp 0x3a2f
jmp 0x3a2c
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x3a48
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x21e0
movq %rbx, %rdi
callq 0x2300