// File: /workspace/github_cpp_makefile_star2_O2/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 0x2170
movl %eax, %edi
callq 0x2180
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
pushq $0x1
popq %r14
leaq 0x2054(%rip), %r13      # 0x519b
movl %r12d, %edi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2030
cmpl $0x68, %eax
jne 0x3161
callq 0x30e5
jmp 0x3147
cmpl $-0x1, %eax
je 0x319b
cmpl $0x61, %eax
je 0x3188
cmpl $0x74, %eax
jne 0x3214
movq 0x4e3d(%rip), %rax      # 0x7fb8
movq (%rax), %rdi
callq 0x22a0
movl %eax, %r14d
jmp 0x3147
movq 0x4e29(%rip), %rax      # 0x7fb8
movq (%rax), %rdi
callq 0x22a0
movl %eax, %ebx
jmp 0x3147
movq 0x4e36(%rip), %rax      # 0x7fd8
movslq (%rax), %rax
cmpl %r12d, %eax
jge 0x3237
movq (%r15,%rax,8), %rsi
leaq -0x48(%rbp), %rdi
callq 0x2330
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x2220
leaq -0x68(%rbp), %rdi
callq 0x284b
leaq -0x68(%rbp), %rdi
callq 0x20a0
testl %r14d, %r14d
jle 0x324c
cmpl $0x1, %ebx
je 0x31f2
testl %ebx, %ebx
jne 0x3261
movl %r14d, %edi
callq 0x2e05
jmp 0x31fa
movl %r14d, %edi
callq 0x2c17
leaq -0x48(%rbp), %rdi
callq 0x20a0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4db5(%rip), %rax      # 0x7fd0
movq (%rax), %rdi
movq (%r15), %rdx
leaq 0x1f79(%rip), %rsi      # 0x51a1
xorl %eax, %eax
callq 0x2240
pushq $0x1
popq %rdi
callq 0x21f0
movq 0x4d92(%rip), %rax      # 0x7fd0
movq (%rax), %rcx
leaq 0x1f92(%rip), %rdi      # 0x51da
pushq $0x20
jmp 0x3274
movq 0x4d7d(%rip), %rax      # 0x7fd0
movq (%rax), %rcx
leaq 0x1f9e(%rip), %rdi      # 0x51fb
pushq $0x27
jmp 0x3274
movq 0x4d68(%rip), %rax      # 0x7fd0
movq (%rax), %rcx
leaq 0x1fb1(%rip), %rdi      # 0x5223
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
callq 0x2340
jmp 0x322f
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x20a0
jmp 0x3292
jmp 0x328f
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x22e0
nop