// File: yueww[P]TSR/produceFlows.c
// Function: produceFromFile(void*)
void *produceFromFile(void *arg){
    pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,NULL);
    pthread_detach(pthread_self());
    FILE *fp=fopen("./data","rb");
    if(fp==NULL){
        printf("fail to open file!\n");
        exit(0);
    }
    while(!feof(fp)){
        int newFlows=FLOWSPERPROCESS;
        int readNum=0;
        pthread_mutex_lock(&mutex);
        while(n+newFlows>BLOCKSIZE) pthread_cond_wait(&cond_p,&mutex);
        if(in==BLOCKSIZE) in=0;
        if((in+newFlows)>BLOCKSIZE){
            readNum=fread(flowBlock+in,FLOWSIZE,BLOCKSIZE-in,fp);
            readNum+=fread(flowBlock,FLOWSIZE,(newFlows-(BLOCKSIZE-in)),fp);
            if(readNum==0){
                printf("error in reading flows or come to file end!\n");
            }else{
                in+=readNum;
            }
        }else{
            readNum=fread(flowBlock+in,FLOWSIZE,newFlows,fp);
            if(readNum==0){
                printf("error in reading flows or come to file end!\n");
            }else{
                in+=readNum;
            }
        }
        n+=readNum;
        printf("add %d flows,current n is %d\n",readNum,n);
        if(n>=FLOWSPERPROCESS) pthread_cond_signal(&cond_c);
        pthread_mutex_unlock(&mutex);
    }
    fclose(fp);
    printf("there is no more flows in flie!\n");
    while(1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl $0x1, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x20d0
callq 0x2290
movq %rax, %rdi
callq 0x21a0
leaq 0x6ec6(%rip), %rdi      # 0xa054
leaq 0x6ec6(%rip), %rsi      # 0xa05b
callq 0x2360
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x31ba
leaq 0x6eb2(%rip), %rdi      # 0xa05e
movb $0x0, %al
callq 0x2040
xorl %edi, %edi
callq 0x2390
jmp 0x31bc
movq -0x10(%rbp), %rdi
callq 0x24a0
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x31d6
jmp 0x336f
movl $0xfa0, -0x14(%rbp)     # imm = 0xFA0
movl $0x0, -0x18(%rbp)
leaq 0xc0f5(%rip), %rdi      # 0xf2e0
callq 0x2440
movl 0xc0de(%rip), %eax      # 0xf2d4
addl -0x14(%rbp), %eax
cmpl $0x61a80, %eax          # imm = 0x61A80
jle 0x3215
leaq 0xc101(%rip), %rdi      # 0xf308
leaq 0xc0d2(%rip), %rsi      # 0xf2e0
callq 0x2480
jmp 0x31f0
cmpl $0x61a80, 0xc0b1(%rip)  # imm = 0x61A80
jne 0x322b
movl $0x0, 0xc0a5(%rip)      # 0xf2d0
movl 0xc09f(%rip), %eax      # 0xf2d0
addl -0x14(%rbp), %eax
cmpl $0x61a80, %eax          # imm = 0x61A80
jbe 0x32d0
movl 0xc08b(%rip), %eax      # 0xf2d0
leaq 0x1c134(%rip), %rdi     # 0x1f380
imulq $0x30, %rax, %rax
addq %rax, %rdi
movl $0x61a80, %eax          # imm = 0x61A80
subl 0xc072(%rip), %eax      # 0xf2d0
movl %eax, %eax
movl %eax, %edx
movq -0x10(%rbp), %rcx
movl $0x30, %esi
callq 0x2460
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
movl $0x61a80, %ecx          # imm = 0x61A80
subl 0xc04f(%rip), %ecx      # 0xf2d0
subl %ecx, %eax
movl %eax, %eax
movl %eax, %edx
movq -0x10(%rbp), %rcx
leaq 0x1c0ee(%rip), %rdi     # 0x1f380
movl $0x30, %esi
callq 0x2460
movq %rax, %rcx
movslq -0x18(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x32bf
leaq 0x6dbc(%rip), %rdi      # 0xa072
movb $0x0, %al
callq 0x2040
jmp 0x32ce
movl -0x18(%rbp), %eax
addl 0xc008(%rip), %eax      # 0xf2d0
movl %eax, 0xc002(%rip)      # 0xf2d0
jmp 0x3320
movl 0xbffa(%rip), %eax      # 0xf2d0
leaq 0x1c0a3(%rip), %rdi     # 0x1f380
imulq $0x30, %rax, %rax
addq %rax, %rdi
movslq -0x14(%rbp), %rdx
movq -0x10(%rbp), %rcx
movl $0x30, %esi
callq 0x2460
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x330f
leaq 0x6d6c(%rip), %rdi      # 0xa072
movb $0x0, %al
callq 0x2040
jmp 0x331e
movl -0x18(%rbp), %eax
addl 0xbfb8(%rip), %eax      # 0xf2d0
movl %eax, 0xbfb2(%rip)      # 0xf2d0
jmp 0x3320
movl -0x18(%rbp), %eax
addl 0xbfab(%rip), %eax      # 0xf2d4
movl %eax, 0xbfa5(%rip)      # 0xf2d4
movl -0x18(%rbp), %esi
movl 0xbf9c(%rip), %edx      # 0xf2d4
leaq 0x6cf7(%rip), %rdi      # 0xa036
movb $0x0, %al
callq 0x2040
cmpl $0xfa0, 0xbf84(%rip)    # imm = 0xFA0
jl 0x335e
leaq 0x6ab12cdf(%rip), %rdi  # 0x6ab16038
callq 0x2030
leaq 0xbf7b(%rip), %rdi      # 0xf2e0
callq 0x21f0
jmp 0x31bc
movq -0x10(%rbp), %rdi
callq 0x22f0
leaq 0x6d20(%rip), %rdi      # 0xa09f
movb $0x0, %al
callq 0x2040
jmp 0x3386
nopl (%rax,%rax)