// File: 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
subq $0x80, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x21e0
movl %eax, %edi
callq 0x21f0
leaq -0x30(%rbp), %rdi
callq 0x22f0
movl $0x1, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x5470(%rip), %rdx      # 0x919e
callq 0x2060
movl %eax, -0x3c(%rbp)
cmpl $-0x1, %eax
je 0x3dd0
movl -0x3c(%rbp), %eax
movl %eax, -0x74(%rbp)
subl $0x61, %eax
je 0x3d8e
jmp 0x3d4c
movl -0x74(%rbp), %eax
subl $0x68, %eax
je 0x3d60
jmp 0x3d56
movl -0x74(%rbp), %eax
subl $0x74, %eax
je 0x3d7a
jmp 0x3da2
callq 0x3cb0
jmp 0x3d67
jmp 0x3dcb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3eeb
movq 0xa237(%rip), %rax      # 0xdfb8
movq (%rax), %rdi
callq 0x2380
movl %eax, -0x34(%rbp)
jmp 0x3dcb
movq 0xa223(%rip), %rax      # 0xdfb8
movq (%rax), %rdi
callq 0x2380
movl %eax, -0x38(%rbp)
jmp 0x3dcb
movq 0xa227(%rip), %rax      # 0xdfd0
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x53ea(%rip), %rsi      # 0x91a4
movb $0x0, %al
callq 0x2310
movl $0x1, %edi
callq 0x22b0
jmp 0x3d20
movq 0xa201(%rip), %rax      # 0xdfd8
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jl 0x3e00
movq 0xa1eb(%rip), %rax      # 0xdfd0
movq (%rax), %rdi
leaq 0x53ee(%rip), %rsi      # 0x91dd
movb $0x0, %al
callq 0x2310
movl $0x1, %edi
callq 0x22b0
movq -0x10(%rbp), %rax
movq 0xa1cd(%rip), %rcx      # 0xdfd8
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x30(%rbp), %rdi
callq 0x22e0
jmp 0x3e1d
leaq -0x70(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x20e0
jmp 0x3e2c
leaq -0x70(%rbp), %rdi
callq 0x2c30
jmp 0x3e37
leaq -0x70(%rbp), %rdi
callq 0x2130
cmpl $0x0, -0x34(%rbp)
jg 0x3e7f
movq 0xa183(%rip), %rax      # 0xdfd0
movq (%rax), %rdi
leaq 0x53a7(%rip), %rsi      # 0x91fe
movb $0x0, %al
callq 0x2310
movl $0x1, %edi
callq 0x22b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x2130
jmp 0x3eeb
movl -0x38(%rbp), %eax
movl %eax, -0x78(%rbp)
testl %eax, %eax
je 0x3e95
jmp 0x3e8b
movl -0x78(%rbp), %eax
subl $0x1, %eax
je 0x3ea1
jmp 0x3ead
movl -0x34(%rbp), %edi
callq 0x3660
jmp 0x3e9f
jmp 0x3ecf
movl -0x34(%rbp), %edi
callq 0x32b0
jmp 0x3eab
jmp 0x3ecf
movq 0xa11c(%rip), %rax      # 0xdfd0
movq (%rax), %rdi
leaq 0x5368(%rip), %rsi      # 0x9226
movb $0x0, %al
callq 0x2310
movl $0x1, %edi
callq 0x22b0
movl $0x0, -0x4(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2130
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x2130
movq -0x48(%rbp), %rdi
callq 0x23c0
nopl (%rax)