// File: /workspace/github_c_makefile_star2_O0/stanfordnlp[P]GloVe/src/shuffle.c
// Function: shuffle_merge
int shuffle_merge(int num) {
    long i, j, k, l = 0;
    int fidcounter = 0;
    CREC *array;
    char filename[MAX_STRING_LENGTH];
    FILE **fid, *fout = stdout;
    
    array = malloc(sizeof(CREC) * array_size);
    fid = calloc(num, sizeof(FILE));
    for (fidcounter = 0; fidcounter < num; fidcounter++) { //num = number of temporary files to merge
        sprintf(filename,"%s_%04d.bin",file_head, fidcounter);
        fid[fidcounter] = fopen(filename, "rb");
        if (fid[fidcounter] == NULL) {
            log_file_loading_error("temp file", filename);
            free(array);
            free_fid(fid, num);
            return 1;
        }
    }
    if (verbose > 0) fprintf(stderr, "Merging temp files: processed %ld lines.", l);
    
    while (1) { //Loop until EOF in all files
        i = 0;
        //Read at most array_size values into array, roughly array_size/num from each temp file
        for (j = 0; j < num; j++) {
            if (feof(fid[j])) continue;
            for (k = 0; k < array_size / num; k++){
                fread(&array[i], sizeof(CREC), 1, fid[j]);
                if (feof(fid[j])) break;
                i++;
            }
        }
        if (i == 0) break;
        l += i;
        shuffle(array, i); // Shuffles lines between temp files
        write_chunk(array,i,fout);
        if (verbose > 0) fprintf(stderr, "\033[31G%ld lines.", l);
    }
    fprintf(stderr, "\033[0GMerging temp files: processed %ld lines.", l);
    for (fidcounter = 0; fidcounter < num; fidcounter++) {
        fclose(fid[fidcounter]);
        sprintf(filename,"%s_%04d.bin",file_head, fidcounter);
        remove(filename);
    }
    fprintf(stderr, "\n\n");
    free(array);
    free(fid);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x440, %rsp            # imm = 0x440
movl %edi, -0x8(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq 0x3b5c(%rip), %rax      # 0x4fd0
movq (%rax), %rax
movq %rax, -0x430(%rbp)
movq 0x3c6b(%rip), %rdi      # 0x50f0
shlq $0x4, %rdi
callq 0x1130
movq %rax, -0x38(%rbp)
movslq -0x8(%rbp), %rdi
movl $0xd8, %esi
callq 0x10e0
movq %rax, -0x428(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x1557
leaq -0x420(%rbp), %rdi
movq 0x3c48(%rip), %rdx      # 0x5110
movl -0x2c(%rbp), %ecx
leaq 0x1b4e(%rip), %rsi      # 0x3020
movb $0x0, %al
callq 0x1170
leaq -0x420(%rbp), %rdi
leaq 0x1b45(%rip), %rsi      # 0x302c
callq 0x1150
movq %rax, %rdx
movq -0x428(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x428(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x1547
leaq -0x420(%rbp), %rsi
leaq 0x1b11(%rip), %rdi      # 0x302f
callq 0x2200
movq -0x38(%rbp), %rdi
callq 0x1030
movq -0x428(%rbp), %rdi
movl -0x8(%rbp), %esi
callq 0x21a0
movl $0x1, -0x4(%rbp)
jmp 0x1770
jmp 0x1549
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x14ae
cmpl $0x0, 0x3b8a(%rip)      # 0x50e8
jle 0x157c
movq 0x3a91(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x1ad8(%rip), %rsi      # 0x304d
movb $0x0, %al
callq 0x1100
jmp 0x157e
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movslq -0x8(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1667
movq -0x428(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1110
cmpl $0x0, %eax
je 0x15bd
jmp 0x1656
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x438(%rbp)
movq 0x3b19(%rip), %rax      # 0x50f0
movslq -0x8(%rbp), %rcx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x438(%rbp), %rax
cmpq %rcx, %rax
jge 0x1654
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq -0x428(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movl $0x10, %esi
movl $0x1, %edx
callq 0x1070
movq -0x428(%rbp), %rax
movq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1110
cmpl $0x0, %eax
je 0x1637
jmp 0x1654
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x15c5
jmp 0x1656
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x158e
cmpq $0x0, -0x10(%rbp)
jne 0x1670
jmp 0x16c7
movq -0x10(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1320
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x430(%rbp), %rdx
callq 0x12b0
cmpl $0x0, 0x3a44(%rip)      # 0x50e8
jle 0x16c2
movq 0x394b(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x197e(%rip), %rsi      # 0x3039
movb $0x0, %al
callq 0x1100
jmp 0x157e
movq 0x392a(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x196d(%rip), %rsi      # 0x3049
movb $0x0, %al
callq 0x1100
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x173c
movq -0x428(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x10a0
leaq -0x420(%rbp), %rdi
movq 0x39fc(%rip), %rdx      # 0x5110
movl -0x2c(%rbp), %ecx
leaq 0x1902(%rip), %rsi      # 0x3020
movb $0x0, %al
callq 0x1170
leaq -0x420(%rbp), %rdi
callq 0x1050
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x16ea
movq 0x38b5(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1a5a(%rip), %rsi      # 0x31a7
movb $0x0, %al
callq 0x1100
movq -0x38(%rbp), %rdi
callq 0x1030
movq -0x428(%rbp), %rdi
callq 0x1030
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x440, %rsp            # imm = 0x440
popq %rbp
retq
nopl (%rax)