// File: /workspace/github_cpp_makefile_star2_O2/waltersharpWEI[P]CommentEliminator/main.cpp
// Function: balanceThreadsGreedy(int)
void balanceThreadsGreedy(int NumThread) {
    vector<string> Files[NumThread];
    std::vector<pthread_t> ThreadPointers(NumThread);

    //sort the Source File to descent order on size
    sort(FileList.begin(),FileList.end(),greater<FileRecord>());
    //displayFileList();

    //expected load for each thread
    double Average = sum(FileList) / (double)NumThread;

    //label of whether the File[i] is dispatched already
    bool used[FileList.size()];
    for (int I = 0;I < FileList.size();I++) {
        used[I] = false;
    }

    for (int I = 0;I < NumThread; I++) {
        Files[I].clear();
    }

    //gready distribute the task
    for (int I = 0; I < NumThread; I++) {
        int Capacity = Average;
        for (int J = 0;J < FileList.size();J++) {
            if (!used[J] && FileList[J].size <= Capacity) {
                Files[I].push_back(FileList[J].path);
                Capacity -= FileList[J].size;
                used[J] = true;
                break;
            }
        }
    }

    //Those task can not be handled are assigned randomly
    for (int I = 0; I < FileList.size();I++) {
        if (!used[I]) {
            int TargetThread = rand() % NumThread;
            Files[TargetThread].push_back(FileList[I].path);
            used[I] = true;
        }
    }

    //check whether all task all assigned
    if (completeDistribute(used,FileList.size())) {
        cout << "All tasks are assigned." << endl;
    } else {
        cout << "There are some mistake during the task assignment." << endl;
    }

    for (int I = 0;I < NumThread;I++) {
        pthread_create(&ThreadPointers[I],NULL,threadEliminator,&(Files[I]));
    }
    for (int I = 0; I < NumThread; I++) {
        pthread_join(ThreadPointers[I], NULL);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edi, %eax
movq %rsp, %rbx
movq %rax, -0x48(%rbp)
imulq $0x18, %rax, %r13
leaq 0xf(%r13), %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
movl %edi, -0x2c(%rbp)
testl %edi, %edi
je 0x2e5b
leaq -0x18(%r13), %rcx
pushq $0x18
popq %rsi
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
subq %rdx, %rcx
addq $0x18, %rcx
movq %rbx, %rdi
xorl %esi, %esi
movq %rcx, %rdx
callq 0x20e0
movslq -0x2c(%rbp), %rsi
leaq -0x70(%rbp), %rdi
leaq -0x2d(%rbp), %rdx
movq %rbx, -0x38(%rbp)
callq 0x33ba
movq 0x5359(%rip), %rdi      # 0x81d0
movq 0x535a(%rip), %rsi      # 0x81d8
callq 0x3bde
leaq 0x5346(%rip), %rsi      # 0x81d0
leaq -0x88(%rbp), %rdi
callq 0x3482
leaq -0x88(%rbp), %r15
movq %r15, %rdi
callq 0x2dbb
movl %eax, %r12d
cvtsi2sdl -0x2c(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movq %r15, %rdi
callq 0x32a4
movq 0x5317(%rip), %rax      # 0x81d8
subq 0x5308(%rip), %rax      # 0x81d0
pushq $0x28
popq %rcx
cqto
idivq %rcx
leaq 0xf(%rax), %rcx
andq $-0x10, %rcx
movq %rsp, %r15
subq %rcx, %r15
movq %r15, %rsp
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x2ef2
movb $0x0, (%r15,%rcx)
incq %rcx
jmp 0x2ee3
cvtsi2sd %r12d, %xmm0
movsd %xmm0, -0x50(%rbp)
xorl %ebx, %ebx
movl -0x2c(%rbp), %eax
testl %eax, %eax
cmovgl %eax, %ebx
movq -0x38(%rbp), %r12
movq %rbx, -0x40(%rbp)
subq $0x1, %rbx
jb 0x2f22
movq %r12, %rdi
callq 0x340c
addq $0x18, %r12
jmp 0x2f0e
movsd -0x50(%rbp), %xmm0
divsd -0x58(%rbp), %xmm0
cvttsd2si %xmm0, %r12d
xorl %ebx, %ebx
pushq $0x28
popq %rcx
cmpq -0x40(%rbp), %rbx
je 0x2f8a
movq 0x5295(%rip), %rax      # 0x81d8
movq 0x5286(%rip), %rsi      # 0x81d0
subq %rsi, %rax
cqto
idivq %rcx
xorl %r14d, %r14d
cmpq %r14, %rax
je 0x2f85
cmpb $0x0, (%r15,%r14)
jne 0x2f67
cmpl %r12d, 0x20(%rsi)
jle 0x2f70
incq %r14
addq $0x28, %rsi
jmp 0x2f55
imulq $0x18, %rbx, %rdi
addq -0x38(%rbp), %rdi
callq 0x341a
movb $0x1, (%r15,%r14)
pushq $0x28
popq %rcx
incq %rbx
jmp 0x2f36
xorl %ebx, %ebx
xorl %r12d, %r12d
movq 0x5242(%rip), %rax      # 0x81d8
subq 0x5233(%rip), %rax      # 0x81d0
cqto
idivq %rcx
cmpq %r12, %rax
jbe 0x2fe2
cmpb $0x0, (%r15,%r12)
jne 0x2fd9
callq 0x2040
cltd
idivl -0x2c(%rbp)
movslq %edx, %rax
imulq $0x18, %rax, %rdi
addq -0x38(%rbp), %rdi
movq 0x5207(%rip), %rsi      # 0x81d0
addq %rbx, %rsi
callq 0x341a
movb $0x1, (%r15,%r12)
pushq $0x28
popq %rcx
incq %r12
addq $0x28, %rbx
jmp 0x2f8f
movq %r15, %rdi
movl %eax, %esi
callq 0x2dd8
leaq 0x20d7(%rip), %rcx      # 0x50ca
leaq 0x20e8(%rip), %rsi      # 0x50e2
testb %al, %al
cmovneq %rcx, %rsi
movq 0x4fc1(%rip), %rdi      # 0x7fc8
callq 0x2190
movq %rax, %rdi
callq 0x20b0
movq -0x40(%rbp), %rax
leaq (,%rax,8), %rbx
xorl %r14d, %r14d
leaq -0x4df(%rip), %r15      # 0x2b4b
movq -0x38(%rbp), %r12
cmpq %r14, %rbx
je 0x3051
movq -0x70(%rbp), %rdi
addq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
callq 0x2300
addq $0x8, %r14
addq $0x18, %r12
jmp 0x302e
xorl %ebx, %ebx
movq -0x38(%rbp), %r14
cmpq %rbx, -0x40(%rbp)
je 0x3071
movq -0x70(%rbp), %rax
movq (%rax,%rbx,8), %rdi
xorl %esi, %esi
callq 0x2150
incq %rbx
jmp 0x3057
leaq -0x70(%rbp), %rdi
callq 0x38b8
cmpl $0x0, -0x2c(%rbp)
je 0x3098
addq $-0x18, %r14
imulq $0x18, -0x48(%rbp), %rbx
leaq (%r14,%rbx), %rdi
callq 0x3456
addq $-0x18, %rbx
jne 0x3089
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x30b4
movq %rax, %r15
jmp 0x30c0
jmp 0x30b4
jmp 0x30b4
jmp 0x30b4
movq %rax, %r15
leaq -0x70(%rbp), %rdi
callq 0x38b8
cmpl $0x0, -0x2c(%rbp)
movq -0x38(%rbp), %rbx
je 0x30dd
addq $-0x18, %rbx
leaq (%rbx,%r13), %rdi
callq 0x3456
addq $-0x18, %r13
jne 0x30ce
movq %r15, %rdi
callq 0x22e0