// File: /workspace/github_c_makefile_star2_O0/stanfordnlp[P]GloVe/src/shuffle.c
// Function: shuffle_by_chunks
int shuffle_by_chunks(void) {
    if (seed == 0) {
        seed = time(0);
    }
    fprintf(stderr, "Using random seed %d\n", seed);
    srand(seed);
    long i = 0, l = 0;
    int fidcounter = 0;
    char filename[MAX_STRING_LENGTH];
    CREC *array;
    FILE *fin = stdin, *fid;
    array = malloc(sizeof(CREC) * array_size);
    
    fprintf(stderr,"SHUFFLING COOCCURRENCES\n");
    if (verbose > 0) fprintf(stderr,"array size: %lld\n", array_size);
    sprintf(filename,"%s_%04d.bin",file_head, fidcounter);
    fid = fopen(filename,"w");
    if (fid == NULL) {
        log_file_loading_error("file", filename);
        free(array);
        return 1;
    }
    if (verbose > 1) fprintf(stderr, "Shuffling by chunks: processed 0 lines.");
    
    while (1) { //Continue until EOF
        if (i >= array_size) {// If array is full, shuffle it and save to temporary file
            shuffle(array, i);
            l += i;
            if (verbose > 1) fprintf(stderr, "\033[22Gprocessed %ld lines.", l);
            write_chunk(array,i,fid);
            fclose(fid);
            fidcounter++;
            sprintf(filename,"%s_%04d.bin",file_head, fidcounter);
            fid = fopen(filename,"w");
            if (fid == NULL) {
                log_file_loading_error("file", filename);
                free(array);
                return 1;
            }
            i = 0;
        }
        fread(&array[i], sizeof(CREC), 1, fin);
        if (feof(fin)) break;
        i++;
    }
    shuffle(array, i); //Last chunk may be smaller than array_size
    write_chunk(array,i,fid);
    l += i;
    if (verbose > 1) fprintf(stderr, "\033[22Gprocessed %ld lines.\n", l);
    if (verbose > 1) fprintf(stderr, "Wrote %d temporary file(s).\n", fidcounter + 1);
    fclose(fid);
    free(array);
    return shuffle_merge(fidcounter + 1); // Merge and shuffle together temporary files
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
cmpl $0x0, 0x3976(%rip)      # 0x5108
jne 0x17a3
xorl %eax, %eax
movl %eax, %edi
callq 0x1120
movl %eax, 0x3965(%rip)      # 0x5108
movq 0x384e(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movl 0x3955(%rip), %edx      # 0x5108
leaq 0x18bc(%rip), %rsi      # 0x3076
movb $0x0, %al
callq 0x1100
movl 0x3941(%rip), %edi      # 0x5108
callq 0x10d0
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq 0x37ee(%rip), %rax      # 0x4fd8
movq (%rax), %rax
movq %rax, -0x420(%rbp)
movq 0x38f5(%rip), %rdi      # 0x50f0
shlq $0x4, %rdi
callq 0x1130
movq %rax, -0x418(%rbp)
movq 0x37e6(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x1870(%rip), %rsi      # 0x308c
movb $0x0, %al
callq 0x1100
cmpl $0x0, 0x38be(%rip)      # 0x50e8
jle 0x184b
movq 0x37c5(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq 0x38b3(%rip), %rdx      # 0x50f0
leaq 0x1861(%rip), %rsi      # 0x30a5
movb $0x0, %al
callq 0x1100
leaq -0x410(%rbp), %rdi
movq 0x38b7(%rip), %rdx      # 0x5110
movl -0x1c(%rbp), %ecx
leaq 0x17bd(%rip), %rsi      # 0x3020
movb $0x0, %al
callq 0x1170
leaq -0x410(%rbp), %rdi
leaq 0x183f(%rip), %rsi      # 0x30b7
callq 0x1150
movq %rax, -0x428(%rbp)
cmpq $0x0, -0x428(%rbp)
jne 0x18b9
leaq -0x410(%rbp), %rsi
leaq 0x1798(%rip), %rdi      # 0x3034
callq 0x2200
movq -0x418(%rbp), %rdi
callq 0x1030
movl $0x1, -0x4(%rbp)
jmp 0x1ac1
cmpl $0x1, 0x3828(%rip)      # 0x50e8
jle 0x18da
movq 0x372f(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
leaq 0x17e6(%rip), %rsi      # 0x30b9
movb $0x0, %al
callq 0x1100
jmp 0x18dc
movq -0x10(%rbp), %rax
cmpq 0x3809(%rip), %rax      # 0x50f0
jl 0x19d0
movq -0x418(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1320
movq -0x10(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0x1, 0x37d8(%rip)      # 0x50e8
jle 0x192e
movq 0x36df(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x17ba(%rip), %rsi      # 0x30e1
movb $0x0, %al
callq 0x1100
movq -0x418(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x428(%rbp), %rdx
callq 0x12b0
movq -0x428(%rbp), %rdi
callq 0x10a0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
leaq -0x410(%rbp), %rdi
movq 0x37a8(%rip), %rdx      # 0x5110
movl -0x1c(%rbp), %ecx
leaq 0x16ae(%rip), %rsi      # 0x3020
movb $0x0, %al
callq 0x1170
leaq -0x410(%rbp), %rdi
leaq 0x1730(%rip), %rsi      # 0x30b7
callq 0x1150
movq %rax, -0x428(%rbp)
cmpq $0x0, -0x428(%rbp)
jne 0x19c8
leaq -0x410(%rbp), %rsi
leaq 0x1689(%rip), %rdi      # 0x3034
callq 0x2200
movq -0x418(%rbp), %rdi
callq 0x1030
movl $0x1, -0x4(%rbp)
jmp 0x1ac1
movq $0x0, -0x10(%rbp)
movq -0x418(%rbp), %rdi
movq -0x10(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq -0x420(%rbp), %rcx
movl $0x10, %esi
movl $0x1, %edx
callq 0x1070
movq -0x420(%rbp), %rdi
callq 0x1110
cmpl $0x0, %eax
je 0x1a0b
jmp 0x1a1c
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x18dc
movq -0x418(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1320
movq -0x418(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x428(%rbp), %rdx
callq 0x12b0
movq -0x10(%rbp), %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0x1, 0x3692(%rip)      # 0x50e8
jle 0x1a74
movq 0x3599(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x168e(%rip), %rsi      # 0x30fb
movb $0x0, %al
callq 0x1100
cmpl $0x1, 0x366d(%rip)      # 0x50e8
jle 0x1a9b
movq 0x3574(%rip), %rax      # 0x4ff8
movq (%rax), %rdi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
leaq 0x1682(%rip), %rsi      # 0x3116
movb $0x0, %al
callq 0x1100
movq -0x428(%rbp), %rdi
callq 0x10a0
movq -0x418(%rbp), %rdi
callq 0x1030
movl -0x1c(%rbp), %edi
addl $0x1, %edi
callq 0x1450
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
nopl (%rax)