// File: /workspace/github_c_makefile_star2_O3/DVaronos[P]AnLogProject1/hash.c
// Function: Readjson
LHash* Readjson(char* filename,LHash* H,LHash* Common,WHash** L){ //Diavazei to Json kai apothikei tis leksis sto leksilogio kai se ena WHash
  FILE* fp;
  if( (fp=fopen(filename,"r"))==NULL){
    perror("Fopen");
  }

  char symbols[] =  " /,\\,\n,[,],(,),*,&,^,%,$,#,@,!,:,;,<,>,`,~,+,_,-,=,{,}|,\",.," "";  //Ta simvolia ta opia tha xwrizoun tis lekseis
  (*L)=CreateWHash(200);
  char line[250];
  char* word;
  int count=0;

	while(fgets(line, sizeof(line),fp)){  //Diavazei to json grami gami

		word = strtok(line, """:");		//skip labels
		word=strtok(NULL,symbols);

		while(word!=NULL){ //Gia kathe leksi tis gramhs
			if(strlen(word)>2)
			{
				count++;
				for(int j=0; j<=strlen(word);j++){  //Metatrepei ta kefalea se peza
					if(word[j]>=65 && word[j]<=90)	word[j]=word[j]+32;
				}
				if(!LHashFind(Common,word)){  //Ean h leksh den einai mia apo tis common
					if(!WHashFind(*L,word))  H=LHashInsert(H,word); //Ean den exw isagi thn leksh allh fora sto stigekrimeno json
					*L=InsertWHash(*L,word);
				}
			}
			word=strtok(NULL,symbols);
		}
	}
	fclose(fp);
	(*L)=WHashTF(*L); //Ipoligismos twn tf gia kathe leksh tou TF
	for(int i=0 ; i<(*L)->size ; i++){
		if((*L)[i].word!=NULL){
			H=LHashIncreaseTf(H,(*L)[i].word,(*L)[i].tfidf);
		}
	}
return H;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r14
leaq 0xd71(%rip), %rsi       # 0x6010
callq 0x1200
movq %rax, %r13
testq %rax, %rax
je 0x542a
movq %r14, -0x30(%rbp)
movl $0xc8, %edi
callq 0x39bf
movq %rax, (%rbx)
leaq -0x140(%rbp), %rdi
movl $0xfa, %esi
movq %r13, %rdx
callq 0x1110
testq %rax, %rax
je 0x53c4
leaq -0x140(%rbp), %r14
leaq 0x1034(%rip), %r12      # 0x6320
movq %r13, -0x38(%rbp)
movq %r14, %rdi
leaq 0x101b(%rip), %rsi      # 0x6315
callq 0x1220
xorl %edi, %edi
movq %r12, %rsi
callq 0x1220
testq %rax, %rax
je 0x53a0
movq %rax, %r13
movq %r13, %rdi
callq 0x10c0
cmpq $0x3, %rax
jb 0x538a
movq $-0x1, %r14
movb 0x1(%r13,%r14), %al
leal -0x41(%rax), %ecx
cmpb $0x19, %cl
ja 0x533e
orb $0x20, %al
movb %al, 0x1(%r13,%r14)
movq %r13, %rdi
callq 0x10c0
incq %r14
cmpq %r14, %rax
ja 0x532a
movq %r15, %rdi
movq %r13, %rsi
callq 0x4ec2
testl %eax, %eax
jne 0x538a
movq (%rbx), %rdi
movq %r13, %rsi
callq 0x3d69
testl %eax, %eax
jne 0x537c
movq -0x30(%rbp), %rdi
movq %r13, %rsi
callq 0x4b0a
movq %rax, -0x30(%rbp)
movq (%rbx), %rdi
movq %r13, %rsi
callq 0x3a0d
movq %rax, (%rbx)
xorl %edi, %edi
movq %r12, %rsi
callq 0x1220
movq %rax, %r13
testq %rax, %rax
jne 0x5315
leaq -0x140(%rbp), %r14
movq %r14, %rdi
movl $0xfa, %esi
movq -0x38(%rbp), %r13
movq %r13, %rdx
callq 0x1110
testq %rax, %rax
jne 0x52f0
movq %r13, %rdi
callq 0x10a0
movq (%rbx), %rdi
callq 0x3cbb
movq %rax, (%rbx)
cmpl $0x0, 0x14(%rax)
movq -0x30(%rbp), %r14
jle 0x5415
movl $0x8, %r15d
xorl %r12d, %r12d
movq (%rax,%r15), %rsi
testq %rsi, %rsi
je 0x5405
movsd -0x8(%rax,%r15), %xmm0
movq %r14, %rdi
callq 0x51c3
movq (%rbx), %rax
incq %r12
movslq 0x14(%rax), %rcx
addq $0x18, %r15
cmpq %rcx, %r12
jl 0x53ea
movq %r14, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbf2(%rip), %rdi       # 0x6023
callq 0x1210
jmp 0x52b0
nop