// File: /workspace/github_cpp_makefile_star2_O2/thunlp[P]KB2E/TransE/Train_TransE.cpp
// Function: prepare()
void prepare()
{
    FILE* f1 = fopen("../data/entity2id.txt","r");
	FILE* f2 = fopen("../data/relation2id.txt","r");
	int x;
	while (fscanf(f1,"%s%d",buf,&x)==2)
	{
		string st=buf;
		entity2id[st]=x;
		id2entity[x]=st;
		entity_num++;
	}
	while (fscanf(f2,"%s%d",buf,&x)==2)
	{
		string st=buf;
		relation2id[st]=x;
		id2relation[x]=st;
		relation_num++;
	}
    FILE* f_kb = fopen("../data/train.txt","r");
	while (fscanf(f_kb,"%s",buf)==1)
    {
        string s1=buf;
        fscanf(f_kb,"%s",buf);
        string s2=buf;
        fscanf(f_kb,"%s",buf);
        string s3=buf;
        if (entity2id.count(s1)==0)
        {
            cout<<"miss entity:"<<s1<<endl;
        }
        if (entity2id.count(s2)==0)
        {
            cout<<"miss entity:"<<s2<<endl;
        }
        if (relation2id.count(s3)==0)
        {
            relation2id[s3] = relation_num;
            relation_num++;
        }
        left_entity[relation2id[s3]][entity2id[s1]]++;
        right_entity[relation2id[s3]][entity2id[s2]]++;
        train.add(entity2id[s1],entity2id[s2],relation2id[s3]);
    }
    for (int i=0; i<relation_num; i++)
    {
    	double sum1=0,sum2=0;
    	for (map<int,int>::iterator it = left_entity[i].begin(); it!=left_entity[i].end(); it++)
    	{
    		sum1++;
    		sum2+=it->second;
    	}
    	left_num[i]=sum2/sum1;
    }
    for (int i=0; i<relation_num; i++)
    {
    	double sum1=0,sum2=0;
    	for (map<int,int>::iterator it = right_entity[i].begin(); it!=right_entity[i].end(); it++)
    	{
    		sum1++;
    		sum2+=it->second;
    	}
    	right_num[i]=sum2/sum1;
    }
    cout<<"relation_num="<<relation_num<<endl;
    cout<<"entity_num="<<entity_num<<endl;
    fclose(f_kb);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
leaq 0x3832(%rip), %rdi      # 0x6080
leaq 0x3841(%rip), %rbx      # 0x6096
movq %rbx, %rsi
callq 0x21f0
movq %rax, %r14
leaq 0x3831(%rip), %rdi      # 0x6098
movq %rbx, %rsi
callq 0x21f0
movq %rax, %rbx
leaq 0x7987(%rip), %r12      # 0xa200
leaq 0x18(%rsp), %r13
leaq 0x28(%rsp), %rbp
movq %r14, %rdi
leaq 0x3823(%rip), %rsi      # 0x60b0
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x2300
cmpl $0x2, %eax
jne 0x28f0
movq %rbp, %rdi
movq %r12, %rsi
leaq 0x48(%rsp), %rdx
callq 0x304c
movl 0x18(%rsp), %r15d
leaq 0x386bd(%rip), %rdi     # 0x3af78
movq %rbp, %rsi
callq 0x3088
movl %r15d, (%rax)
leaq 0x386db(%rip), %rdi     # 0x3afa8
movq %r13, %rsi
callq 0x30ee
movq %rax, %rdi
movq %rbp, %rsi
callq 0x20e0
incl 0x3865e(%rip)           # 0x3af44
movq %rbp, %rdi
callq 0x2338
jmp 0x2883
leaq 0x7909(%rip), %r15      # 0xa200
leaq 0x18(%rsp), %r12
leaq 0x28(%rsp), %r13
leaq 0x386d0(%rip), %rbp     # 0x3afd8
movq %rbx, %rdi
leaq 0x379e(%rip), %rsi      # 0x60b0
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x2300
cmpl $0x2, %eax
jne 0x2971
movq %r13, %rdi
movq %r15, %rsi
leaq 0x48(%rsp), %rdx
callq 0x304c
movl 0x18(%rsp), %r14d
leaq 0x38608(%rip), %rdi     # 0x3af48
movq %r13, %rsi
callq 0x3088
movl %r14d, (%rax)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x30ee
movq %rax, %rdi
movq %r13, %rsi
callq 0x20e0
incl 0x385d9(%rip)           # 0x3af40
movq %r13, %rdi
callq 0x2338
jmp 0x2908
leaq 0x373d(%rip), %rdi      # 0x60b5
leaq 0x3717(%rip), %rsi      # 0x6096
callq 0x21f0
movq %rax, 0x20(%rsp)
leaq 0x3737(%rip), %r15      # 0x60c7
leaq 0x7869(%rip), %r12      # 0xa200
leaq 0x48(%rsp), %r13
leaq 0x68(%rsp), %rbp
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2300
cmpl $0x1, %eax
jne 0x2b9f
leaq 0x28(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x304c
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2300
movq %r13, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x304c
movq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x2300
movq %rbp, %rdi
movq %r12, %r14
movq %r12, %rsi
leaq 0x1f(%rsp), %rdx
callq 0x304c
leaq 0x38560(%rip), %rdi     # 0x3af78
leaq 0x28(%rsp), %rsi
callq 0x313c
testq %rax, %rax
jne 0x2a4f
movq 0x75aa(%rip), %rdi      # 0x9fd8
leaq 0x3695(%rip), %rsi      # 0x60ca
callq 0x2190
movq %rax, %rdi
leaq 0x28(%rsp), %rsi
callq 0x2160
movq %rax, %rdi
callq 0x20c0
leaq 0x38522(%rip), %rdi     # 0x3af78
movq %r13, %rsi
callq 0x313c
testq %rax, %rax
jne 0x2a89
movq 0x756e(%rip), %rdi      # 0x9fd8
leaq 0x3659(%rip), %rsi      # 0x60ca
callq 0x2190
movq %rax, %rdi
movq %r13, %rsi
callq 0x2160
movq %rax, %rdi
callq 0x20c0
leaq 0x384b8(%rip), %rdi     # 0x3af48
movq %rbp, %rsi
callq 0x313c
testq %rax, %rax
jne 0x2aba
movl 0x3849d(%rip), %ebx     # 0x3af40
leaq 0x3849e(%rip), %rdi     # 0x3af48
movq %rbp, %rsi
callq 0x3088
movl %ebx, (%rax)
incl 0x38486(%rip)           # 0x3af40
leaq 0x38487(%rip), %rdi     # 0x3af48
movq %rbp, %rsi
callq 0x3088
leaq 0x38538(%rip), %rdi     # 0x3b008
movq %rax, %rsi
callq 0x3156
movq %rax, %rbx
leaq 0x38496(%rip), %rdi     # 0x3af78
leaq 0x28(%rsp), %rsi
callq 0x3088
movq %rbx, %rdi
movq %rax, %rsi
callq 0x31a4
incl (%rax)
leaq 0x38448(%rip), %rdi     # 0x3af48
movq %rbp, %rsi
callq 0x3088
leaq 0x38529(%rip), %rdi     # 0x3b038
movq %rax, %rsi
callq 0x3156
movq %rax, %rbx
leaq 0x38457(%rip), %rdi     # 0x3af78
movq %r13, %rsi
callq 0x3088
movq %rbx, %rdi
movq %rax, %rsi
callq 0x31a4
incl (%rax)
leaq 0x3843b(%rip), %rdi     # 0x3af78
leaq 0x28(%rsp), %rsi
callq 0x3088
movl (%rax), %ebx
leaq 0x38428(%rip), %rdi     # 0x3af78
movq %r13, %rsi
callq 0x3088
movl (%rax), %r12d
leaq 0x383e6(%rip), %rdi     # 0x3af48
movq %rbp, %rsi
callq 0x3088
movl (%rax), %ecx
leaq 0x38555(%rip), %rdi     # 0x3b0c8
movl %ebx, %esi
movl %r12d, %edx
callq 0x31f2
movq %rbp, %rdi
callq 0x2338
movq %r13, %rdi
callq 0x2338
leaq 0x28(%rsp), %rdi
callq 0x2338
movq %r14, %r12
jmp 0x29a1
xorl %ecx, %ecx
leaq 0x38460(%rip), %rbx     # 0x3b008
leaq 0x28(%rsp), %r14
leaq 0x384b4(%rip), %r15     # 0x3b068
movl %ecx, 0x28(%rsp)
movl 0x38382(%rip), %eax     # 0x3af40
cmpl %eax, %ecx
jge 0x2c62
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3156
movq 0x18(%rax), %r12
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3156
addq $0x8, %rax
cmpq %rax, %r12
je 0x2c30
movsd 0x10(%rsp), %xmm0
addsd 0x3412(%rip), %xmm0     # 0x6018
movsd %xmm0, 0x10(%rsp)
cvtsi2sdl 0x24(%r12), %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %r12, %rdi
callq 0x2100
movq %rax, %r12
jmp 0x2be4
movsd 0x8(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x327e
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x28(%rsp), %ecx
incl %ecx
jmp 0x2bb4
xorl %ecx, %ecx
leaq 0x383cd(%rip), %rbx     # 0x3b038
leaq 0x28(%rsp), %r14
leaq 0x38421(%rip), %r15     # 0x3b098
movl %ecx, 0x28(%rsp)
cmpl %eax, %ecx
jge 0x2d25
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3156
movq 0x18(%rax), %r12
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3156
addq $0x8, %rax
cmpq %rax, %r12
je 0x2ced
movsd 0x10(%rsp), %xmm0
addsd 0x3355(%rip), %xmm0     # 0x6018
movsd %xmm0, 0x10(%rsp)
cvtsi2sdl 0x24(%r12), %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %r12, %rdi
callq 0x2100
movq %rax, %r12
jmp 0x2ca1
movsd 0x8(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x327e
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x28(%rsp), %ecx
incl %ecx
movl 0x38220(%rip), %eax     # 0x3af40
jmp 0x2c77
movq 0x72ac(%rip), %rbx      # 0x9fd8
leaq 0x33a4(%rip), %rsi      # 0x60d7
movq %rbx, %rdi
callq 0x2190
movl 0x381ff(%rip), %esi     # 0x3af40
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20c0
leaq 0x338d(%rip), %rsi      # 0x60e5
movq %rbx, %rdi
callq 0x2190
movl 0x381de(%rip), %esi     # 0x3af44
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20c0
movq 0x20(%rsp), %rdi
callq 0x21a0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2da1
jmp 0x2d98
jmp 0x2da8
movq %rax, %rbx
jmp 0x2dba
jmp 0x2da8
jmp 0x2da1
movq %rax, %rbx
jmp 0x2dce
jmp 0x2da8
movq %rax, %rbx
jmp 0x2dc4
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x2338
leaq 0x48(%rsp), %rdi
callq 0x2338
leaq 0x28(%rsp), %rdi
callq 0x2338
movq %rbx, %rdi
callq 0x22d0