// File: /workspace/github_c_makefile_star2_O0/devkot[P]SearchEngine/Crawler/utilities.c
// Function: distributeDocs
void distributeDocs(DocumentNode *documentArray, int *incrementArray, int numWorkers, int *fdIn){
    int i, j, lines = 0;
    char tempSize[5], sizeTriple[4] = "000", sizeDouble[3] = "00", sizeSimple[2] = "0";

    for(i = 0; i < numWorkers; i++){
        for(j = 0; j < incrementArray[i]; j++){
            // Pipe atomicity is guaranteed at 4096 bytes max so make the size payload contain 4 digits
            if(strlen(documentArray[lines].text) < 10 )
                sprintf(tempSize, "%s%d",sizeTriple, (int) strlen(documentArray[lines].text));
            else if(strlen(documentArray[lines].text) < 100)
                sprintf(tempSize, "%s%d", sizeDouble, (int) strlen(documentArray[lines].text));
            else if(strlen(documentArray[lines].text) < 1000)
                sprintf(tempSize, "%s%d", sizeSimple, (int) strlen(documentArray[lines].text));

            if((write(fdIn[i], tempSize, strlen(tempSize))) == -1)
                perror("write");

            if((write(fdIn[i], documentArray[lines].text, strlen(documentArray[lines].text))) == -1)
                perror("write");

            lines++;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl 0x263e(%rip), %eax      # 0x5185
movl %eax, -0x35(%rbp)
movw 0x2635(%rip), %ax       # 0x5186
movw %ax, -0x38(%rbp)
movb 0x262d(%rip), %al       # 0x5188
movb %al, -0x36(%rbp)
movw 0x2622(%rip), %ax       # 0x5187
movw %ax, -0x3a(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x2d87
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x10(%rbp), %rcx
movslq -0x24(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x2d77
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x20c0
cmpq $0xa, %rax
jae 0x2bf8
leaq -0x31(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x35(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x20c0
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rdx
movl %eax, %ecx
leaq 0x259d(%rip), %rsi      # 0x5189
movb $0x0, %al
callq 0x2340
jmp 0x2cb8
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x20c0
cmpq $0x64, %rax
jae 0x2c56
leaq -0x31(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x20c0
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rdx
movl %eax, %ecx
leaq 0x253c(%rip), %rsi      # 0x5189
movb $0x0, %al
callq 0x2340
jmp 0x2cb6
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x20c0
cmpq $0x3e8, %rax            # imm = 0x3E8
jae 0x2cb4
leaq -0x31(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x3a(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x20c0
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rdx
movl %eax, %ecx
leaq 0x24dc(%rip), %rsi      # 0x5189
movb $0x0, %al
callq 0x2340
jmp 0x2cb6
jmp 0x2cb8
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x7c(%rbp)
leaq -0x31(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x20c0
movl -0x7c(%rbp), %edi
movq -0x78(%rbp), %rsi
movq %rax, %rdx
callq 0x2080
cmpq $-0x1, %rax
jne 0x2cf8
leaq 0x249b(%rip), %rdi      # 0x518e
callq 0x22e0
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x8c(%rbp)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x20c0
movl -0x8c(%rbp), %edi
movq -0x88(%rbp), %rsi
movq %rax, %rdx
callq 0x2080
cmpq $-0x1, %rax
jne 0x2d60
leaq 0x2433(%rip), %rdi      # 0x518e
callq 0x22e0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2b83
jmp 0x2d79
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x2b70
addq $0x90, %rsp
popq %rbp
retq