// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
cmpl $0x0, 0x2f20(%rip)      # 0x4118
jne 0x1207
xorl %edi, %edi
callq 0x1140
movl %eax, 0x2f11(%rip)      # 0x4118
movq 0x2dea(%rip), %r12      # 0x3ff8
movq (%r12), %rdi
movl 0x2f00(%rip), %edx      # 0x4118
leaq 0xe5a(%rip), %rsi       # 0x2079
xorl %eax, %eax
callq 0x1120
movl 0x2eec(%rip), %edi      # 0x4118
callq 0x10f0
movq 0x2da0(%rip), %rax      # 0x3fd8
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x2eb9(%rip), %rdi      # 0x4100
shlq $0x4, %rdi
callq 0x1150
movq %rax, %r14
movq (%r12), %rcx
leaq 0xe31(%rip), %rdi       # 0x208f
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
callq 0x11b0
cmpl $0x0, 0x2e88(%rip)      # 0x40f8
jg 0x14a5
movq 0x2ea3(%rip), %rdx      # 0x4120
leaq 0xd9c(%rip), %rsi       # 0x2020
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x1190
leaq 0xe1e(%rip), %rsi       # 0x20ba
movq %rbx, %rdi
callq 0x1170
testq %rax, %rax
je 0x1460
movq %rax, %r15
cmpl $0x2, 0x2e41(%rip)      # 0x40f8
jge 0x14c3
pushq $0x10
popq %r13
pushq $0x1
popq %rbx
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
xorl %ebp, %ebp
movq %r14, (%rsp)
cmpq 0x2e1d(%rip), %rbp      # 0x4100
jl 0x137f
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1835
addq %rbp, 0x8(%rsp)
cmpl $0x2, 0x2df8(%rip)      # 0x40f8
jge 0x13b6
testq %rbp, %rbp
jle 0x1329
movq (%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x11b0
addq $0x10, %r14
decq %rbp
jne 0x130f
movq %r15, %rdi
callq 0x10b0
movq 0x10(%rsp), %r14
incl %r14d
movq 0x2de0(%rip), %rdx      # 0x4120
leaq 0x20(%rsp), %r15
movq %r15, %rdi
leaq 0xcd1(%rip), %rsi       # 0x2020
movl %r14d, %ecx
xorl %eax, %eax
callq 0x1190
movq %r15, %rdi
leaq 0xd57(%rip), %rsi       # 0x20ba
callq 0x1170
testq %rax, %rax
je 0x1476
movq %rax, %r15
movq %r14, 0x10(%rsp)
xorl %ebp, %ebp
movq (%rsp), %r14
movq %rbp, %rdi
shlq $0x4, %rdi
movq %r14, %r12
addq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq 0x18(%rsp), %r14
movq %r14, %rcx
callq 0x1080
movq %r14, %rdi
callq 0x1130
testl %eax, %eax
jne 0x13d8
incq %rbp
movq %r12, %r14
jmp 0x12dc
movq 0x2c3b(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xd1d(%rip), %rsi       # 0x20e4
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x1120
jmp 0x1306
movq %r12, %rdi
movq %rbp, %rsi
callq 0x1835
testq %rbp, %rbp
jle 0x1411
pushq $0x10
popq %r12
pushq $0x1
popq %r14
movq (%rsp), %r13
movq %rbp, %rbx
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x11b0
addq $0x10, %r13
decq %rbx
jne 0x13f7
cmpl $0x2, 0x2ce0(%rip)      # 0x40f8
jge 0x14de
cmpl $0x2, 0x2cd3(%rip)      # 0x40f8
movq (%rsp), %rbx
movq 0x10(%rsp), %r14
jge 0x1503
movq %r15, %rdi
callq 0x10b0
movq %rbx, %rdi
callq 0x1030
incl %r14d
movl %r14d, %edi
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x18c8
leaq 0xbcd(%rip), %rdi       # 0x2034
leaq 0x20(%rsp), %rsi
callq 0x1682
movq %r14, %rdi
jmp 0x148b
leaq 0xbb7(%rip), %rdi       # 0x2034
leaq 0x20(%rsp), %rsi
callq 0x1682
movq (%rsp), %rdi
callq 0x1030
pushq $0x1
popq %rax
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r12), %rdi
movq 0x2c50(%rip), %rdx      # 0x4100
leaq 0xbf1(%rip), %rsi       # 0x20a8
xorl %eax, %eax
callq 0x1120
jmp 0x1276
movq (%r12), %rcx
leaq 0xbee(%rip), %rdi       # 0x20bc
pushq $0x27
popq %rsi
pushq $0x1
popq %rdx
callq 0x11b0
jmp 0x12bd
addq 0x8(%rsp), %rbp
movq 0x2b0e(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xc0a(%rip), %rsi       # 0x20fe
movq %rbp, %rdx
xorl %eax, %eax
callq 0x1120
jmp 0x141e
movq 0x2aee(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leal 0x1(%r14), %edx
leaq 0xc01(%rip), %rsi       # 0x2119
xorl %eax, %eax
callq 0x1120
jmp 0x1434