// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rsp, %rbx
leaq (,%r13,2), %rax
addq %r13, %rax
leaq 0xf(,%rax,8), %rcx
andq $-0x10, %rcx
subq %rcx, %rbx
movq %rbx, %rsp
movl %edi, -0x2c(%rbp)
testl %edi, %edi
je 0x3472
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 0x20e0
movslq -0x2c(%rbp), %rsi
leaq -0x58(%rbp), %rdi
leaq -0x2d(%rbp), %rdx
movq %r13, -0x40(%rbp)
callq 0x3b28
movq 0x4d42(%rip), %r15      # 0x81d0
movq 0x4d43(%rip), %r12      # 0x81d8
cmpq %r12, %r15
je 0x34d5
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 0x441a
movq %r15, %rdi
movq %r12, %rsi
callq 0x44f8
leaq 0x4cf4(%rip), %rsi      # 0x81d0
leaq -0x70(%rbp), %rdi
callq 0x3c7a
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
cmpq %rcx, %rax
je 0x3506
xorl %edx, %edx
addl 0x20(%rax), %edx
addq $0x28, %rax
cmpq %rcx, %rax
jne 0x34f4
cvtsi2sd %edx, %xmm0
jmp 0x350a
xorpd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3a26
movq 0x4cb9(%rip), %rax      # 0x81d8
movq 0x4caa(%rip), %rcx      # 0x81d0
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 0x3566
cmpq $0x1, %rdx
adcq $0x0, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x20e0
cmpl $0x0, -0x2c(%rbp)
jle 0x3619
xorps %xmm0, %xmm0
cvtsi2sdl -0x2c(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
movq %r13, %r14
movq %rbx, %r12
movq (%r12), %rsi
movq %r12, %rdi
callq 0x41a2
addq $0x18, %r12
decq %r14
jne 0x358c
cmpl $0x0, -0x2c(%rbp)
jle 0x3619
cvttsd2si -0x38(%rbp), %r12d
xorl %r14d, %r14d
movq 0x4c21(%rip), %rax      # 0x81d8
movq 0x4c12(%rip), %rsi      # 0x81d0
subq %rsi, %rax
je 0x360d
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 0x35ed
cmpl %r12d, 0x20(%rsi)
jle 0x35fb
incq %r13
addq $0x28, %rsi
cmpq %r13, %rax
jne 0x35e0
jmp 0x360d
leaq (%r14,%r14,2), %rax
leaq (%rbx,%rax,8), %rdi
callq 0x3bc0
movb $0x1, (%r15,%r13)
incq %r14
movq -0x40(%rbp), %r13
cmpq %r13, %r14
jne 0x35b0
movq 0x4bb8(%rip), %rcx      # 0x81d8
movq 0x4ba9(%rip), %rdx      # 0x81d0
movq %rcx, %rax
subq %rdx, %rax
je 0x3698
xorl %r12d, %r12d
xorl %r14d, %r14d
cmpb $0x0, (%r15,%r14)
jne 0x3672
callq 0x2050
cltd
idivl -0x2c(%rbp)
movslq %edx, %rax
leaq (%rax,%rax,2), %rax
leaq (%rbx,%rax,8), %rdi
movq 0x4b79(%rip), %rsi      # 0x81d0
addq %r12, %rsi
callq 0x3bc0
movb $0x1, (%r15,%r14)
movq 0x4b6d(%rip), %rcx      # 0x81d8
movq 0x4b5e(%rip), %rdx      # 0x81d0
incq %r14
movq %rcx, %rax
subq %rdx, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rsi # imm = 0xCCCCCCCCCCCCCCCD
imulq %rsi, %rax
addq $0x28, %r12
cmpq %r14, %rax
ja 0x3635
jmp 0x36aa
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rcx, %rax
movl $0x17, %edx
leaq 0x1a14(%rip), %rsi      # 0x50ca
testl %eax, %eax
jle 0x36ee
cmpb $0x1, (%r15)
jne 0x36e2
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x1, %edi
movq %rdi, %rcx
cmpq %rdi, %rax
je 0x36dd
leaq 0x1(%rcx), %rdi
cmpb $0x0, (%r15,%rcx)
jne 0x36ca
cmpq %rax, %rcx
jae 0x36ee
movl $0x32, %edx
leaq 0x19f4(%rip), %rsi      # 0x50e2
movq 0x48d3(%rip), %r15      # 0x7fc8
movq %r15, %rdi
callq 0x21f0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq 0x48ad(%rip), %rdi      # 0x7fc8
callq 0x2030
movq %rax, %rdi
callq 0x20f0
cmpl $0x0, -0x2c(%rbp)
jle 0x3788
leaq (,%r13,8), %r14
xorl %r13d, %r13d
leaq -0x6f8(%rip), %r15      # 0x3048
movq %rbx, %r12
movq -0x58(%rbp), %rdi
addq %r13, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r12, %rcx
callq 0x2310
addq $0x18, %r12
addq $0x8, %r13
cmpq %r13, %r14
jne 0x3743
cmpl $0x0, -0x2c(%rbp)
movq -0x40(%rbp), %r13
jle 0x3788
xorl %r14d, %r14d
movq -0x58(%rbp), %rax
movq (%rax,%r14,8), %rdi
xorl %esi, %esi
callq 0x2160
incq %r14
cmpq %r14, %r13
jne 0x3771
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x379d
movq -0x48(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
cmpl $0x0, -0x2c(%rbp)
je 0x37c5
addq $-0x18, %rbx
shlq $0x3, %r13
leaq (,%r13,2), %r14
addq %r13, %r14
leaq (%rbx,%r14), %rdi
callq 0x3c0c
addq $-0x18, %r14
jne 0x37b6
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
jmp 0x37f9
jmp 0x37e1
jmp 0x37e1
jmp 0x37e1
jmp 0x37e1
movq %rax, %r15
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x37f9
movq -0x48(%rbp), %rsi
subq %rdi, %rsi
callq 0x21d0
cmpl $0x0, -0x2c(%rbp)
je 0x381e
addq $-0x18, %rbx
movq -0x40(%rbp), %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %r14
leaq (%rbx,%r14), %rdi
callq 0x3c0c
addq $-0x18, %r14
jne 0x380f
movq %r15, %rdi
callq 0x22f0