// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movl %edi, %r13d
movl %edi, %eax
movq %rsp, %rbx
movq %rax, -0x38(%rbp)
leaq (%rax,%rax,2), %rax
leaq 0xf(,%rax,8), %rcx
andq $-0x10, %rcx
subq %rcx, %rbx
movq %rbx, %rsp
testl %edi, %edi
je 0x349c
leaq -0x18(,%rax,8), %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
mulq %rcx
shrq $0x4, %rdx
leaq (%rdx,%rdx,2), %rax
leaq 0x18(,%rax,8), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20f0
movslq %r13d, %rsi
leaq -0x58(%rbp), %rdi
leaq -0x2d(%rbp), %rdx
movl %r13d, -0x2c(%rbp)
callq 0x3b4e
movq 0x4d21(%rip), %r15      # 0x81d8
movq 0x4d22(%rip), %r12      # 0x81e0
cmpq %r12, %r15
je 0x34fe
movq %r12, %rax
subq %r15, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x444e
movq %r15, %rdi
movq %r12, %rsi
callq 0x452c
leaq 0x4cd3(%rip), %rsi      # 0x81d8
leaq -0x70(%rbp), %rdi
callq 0x3c98
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
cmpq %rcx, %rax
je 0x352f
xorl %edx, %edx
addl 0x20(%rax), %edx
addq $0x28, %rax
cmpq %rcx, %rax
jne 0x351d
cvtsi2sd %edx, %xmm0
jmp 0x3533
xorpd %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3a50
movq 0x4c98(%rip), %rax      # 0x81e0
movq 0x4c89(%rip), %rcx      # 0x81d8
movq %rax, %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
imulq %rsi, %rdx
leaq 0xf(%rdx), %rsi
andq $-0x10, %rsi
movq %rsp, %r15
subq %rsi, %r15
movq %r15, %rsp
cmpq %rcx, %rax
je 0x358f
cmpq $0x1, %rdx
adcq $0x0, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x20f0
testl %r13d, %r13d
jle 0x35b0
movq -0x38(%rbp), %r14
movq %rbx, %r12
movq (%r12), %rsi
movq %r12, %rdi
callq 0x41ae
addq $0x18, %r12
decq %r14
jne 0x359b
testl %r13d, %r13d
jle 0x3634
xorps %xmm0, %xmm0
cvtsi2sdl -0x2c(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
divsd %xmm0, %xmm1
cvttsd2si %xmm1, %r12d
xorl %r14d, %r14d
movq 0x4c0b(%rip), %rax      # 0x81e0
movq 0x4bfc(%rip), %rsi      # 0x81d8
subq %rsi, %rax
je 0x362b
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
cmpq $0x1, %rax
adcq $0x0, %rax
xorl %r13d, %r13d
cmpb $0x0, (%r15,%r13)
jne 0x360b
cmpl %r12d, 0x20(%rsi)
jle 0x3619
incq %r13
addq $0x28, %rsi
cmpq %r13, %rax
jne 0x35fe
jmp 0x362b
leaq (%r14,%r14,2), %rax
leaq (%rbx,%rax,8), %rdi
callq 0x3be2
movb $0x1, (%r15,%r13)
incq %r14
cmpq -0x38(%rbp), %r14
jne 0x35ce
movq 0x4ba5(%rip), %rax      # 0x81e0
movq 0x4b96(%rip), %rcx      # 0x81d8
subq %rcx, %rax
je 0x36ae
xorl %r14d, %r14d
xorl %r12d, %r12d
movl -0x2c(%rbp), %r13d
cmpb $0x0, (%r15,%r12)
jne 0x3680
callq 0x2050
cltd
idivl %r13d
movslq %edx, %rax
leaq (%rax,%rax,2), %rax
leaq (%rbx,%rax,8), %rdi
movq 0x4b65(%rip), %rsi      # 0x81d8
addq %r14, %rsi
callq 0x3be2
movb $0x1, (%r15,%r12)
incq %r12
movq 0x4b56(%rip), %rax      # 0x81e0
subq 0x4b47(%rip), %rax      # 0x81d8
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
addq $0x28, %r14
cmpq %r12, %rax
ja 0x3651
jmp 0x36c4
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
movl -0x2c(%rbp), %r13d
testl %eax, %eax
setle %cl
jle 0x36f4
cmpb $0x1, (%r15)
jne 0x3706
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x1, %edx
movq %rdx, %rcx
cmpq %rdx, %rax
je 0x36ee
leaq 0x1(%rcx), %rdx
cmpb $0x0, (%r15,%rcx)
jne 0x36db
cmpq %rax, %rcx
setae %cl
testb %cl, %cl
je 0x3706
movl $0x17, %edx
leaq 0x19c9(%rip), %rsi      # 0x50cd
jmp 0x3712
movl $0x32, %edx
leaq 0x19d3(%rip), %rsi      # 0x50e5
movq 0x48af(%rip), %r15      # 0x7fc8
movq %r15, %rdi
callq 0x2200
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x21b0
movsbl %al, %esi
movq 0x4889(%rip), %rdi      # 0x7fc8
callq 0x2030
movq %rax, %rdi
callq 0x2100
testl %r13d, %r13d
jle 0x378b
movq -0x38(%rbp), %rax
leaq (,%rax,8), %r14
xorl %r13d, %r13d
leaq -0x6ef(%rip), %r15      # 0x3078
movq %rbx, %r12
movq -0x58(%rbp), %rdi
addq %r13, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
callq 0x2320
addq $0x18, %r12
addq $0x8, %r13
cmpq %r13, %r14
jne 0x376a
movl -0x2c(%rbp), %r15d
testl %r15d, %r15d
jle 0x37af
xorl %r14d, %r14d
movq -0x58(%rbp), %rax
movq (%rax,%r14,8), %rdi
xorl %esi, %esi
callq 0x2170
incq %r14
cmpq %r14, -0x38(%rbp)
jne 0x3797
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x37c4
movq -0x48(%rbp), %rsi
subq %rdi, %rsi
callq 0x21e0
testl %r15d, %r15d
je 0x37ec
addq $-0x18, %rbx
movq -0x38(%rbp), %rax
leaq (,%rax,8), %rax
leaq (%rax,%rax,2), %r14
leaq (%rbx,%r14), %rdi
callq 0x3c2e
addq $-0x18, %r14
jne 0x37dd
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
jmp 0x3820
jmp 0x3808
jmp 0x3808
jmp 0x3808
jmp 0x3808
movq %rax, %r15
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x3820
movq -0x48(%rbp), %rsi
subq %rdi, %rsi
callq 0x21e0
cmpl $0x0, -0x2c(%rbp)
je 0x3849
addq $-0x18, %rbx
movq -0x38(%rbp), %rax
leaq (,%rax,8), %rax
leaq (%rax,%rax,2), %r14
leaq (%rbx,%r14), %rdi
callq 0x3c2e
addq $-0x18, %r14
jne 0x383a
movq %r15, %rdi
callq 0x2300