// File: /workspace/github_cpp_makefile_star2_O2/thunlp[P]KB2E/CTransR/Train_CTransR.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;
		fb_relation_num++;
	}
    FILE* f_kb = fopen("../data/train.txt","r");
    FILE* f_train_cluster = fopen("../cluster/output/train_cluster.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)
        {
            cout<<"miss rel:"<<s3<<endl;
        }
        int e1 = entity2id[s1];
        int e2 = entity2id[s2];
        int rel_fb = relation2id[s3];
        int rel;
        fscanf(f_train_cluster,"%d",&rel);
        left_entity[rel][e1]+=1;
        right_entity[rel][e2]+=1;
        if (cluster2fb.count(rel)==0)
        {
            relation_num+=1;
            cluster2fb[rel]=rel_fb;
        }
        else
        if (cluster2fb[rel]!=rel_fb)
        {
            cout<<"not map:"<<e1<<" "<<e2<<" "<<rel<<' '<<rel_fb<<endl;
            exit(-1);
        }

        fb_left_entity[cluster2fb[rel]][e1]+=1;
        fb_right_entity[cluster2fb[rel]][e2]+=1;
        train.add(e1,e2,rel);
    }
    fclose(f_train_cluster);
    fclose(f_kb);
    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_mean[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_mean[i]=sum2/sum1;
    }


     for (int i=0; i<fb_relation_num; i++)
    {
    	double sum1=0,sum2=0;
    	for (map<int,int>::iterator it = fb_left_entity[i].begin(); it!=fb_left_entity[i].end(); it++)
    	{
    		sum1++;
    		sum2+=it->second;
    	}
    	fb_left_mean[i]=sum2/sum1;
    }
    for (int i=0; i<fb_relation_num; i++)
    {
    	double sum1=0,sum2=0;
    	for (map<int,int>::iterator it = fb_right_entity[i].begin(); it!=fb_right_entity[i].end(); it++)
    	{
    		sum1++;
    		sum2+=it->second;
    	}
    	fb_right_mean[i]=sum2/sum1;
    }
    for (int i=0; i<fb_relation_num; i++)
    	cout<<fb_left_mean[i]<<' '<<fb_right_mean[i]<<endl;
    cout<<"fb_relation_num="<<fb_relation_num<<endl;
    cout<<"relation_num="<<relation_num<<endl;
    cout<<"entity_num="<<entity_num<<endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
leaq 0x568a(%rip), %rdi      # 0x80a0
leaq 0x5699(%rip), %rbx      # 0x80b6
movq %rbx, %rsi
callq 0x21f0
movq %rax, %r14
leaq 0x5689(%rip), %rdi      # 0x80b8
movq %rbx, %rsi
callq 0x21f0
movq %rax, %rbx
leaq 0x97bf(%rip), %r12      # 0xc200
leaq 0x1c(%rsp), %r13
leaq 0x20(%rsp), %rbp
movq %r14, %rdi
leaq 0x567b(%rip), %rsi      # 0x80d0
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x2300
cmpl $0x2, %eax
jne 0x2ab8
movq %rbp, %rdi
movq %r12, %rsi
leaq 0x48(%rsp), %rdx
callq 0x35de
movl 0x1c(%rsp), %r15d
leaq 0x3a52d(%rip), %rdi     # 0x3cfb0
movq %rbp, %rsi
callq 0x361a
movl %r15d, (%rax)
leaq 0x3a54b(%rip), %rdi     # 0x3cfe0
movq %r13, %rsi
callq 0x3680
movq %rax, %rdi
movq %rbp, %rsi
callq 0x20e0
incl 0x3a496(%rip)           # 0x3cf44
movq %rbp, %rdi
callq 0x2338
jmp 0x2a4b
leaq 0x9741(%rip), %r15      # 0xc200
leaq 0x1c(%rsp), %r12
leaq 0x20(%rsp), %r13
leaq 0x3a540(%rip), %rbp     # 0x3d010
movq %rbx, %rdi
leaq 0x55f6(%rip), %rsi      # 0x80d0
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x2300
cmpl $0x2, %eax
jne 0x2b39
movq %r13, %rdi
movq %r15, %rsi
leaq 0x48(%rsp), %rdx
callq 0x35de
movl 0x1c(%rsp), %r14d
leaq 0x3a478(%rip), %rdi     # 0x3cf80
movq %r13, %rsi
callq 0x361a
movl %r14d, (%rax)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x3680
movq %rax, %rdi
movq %r13, %rsi
callq 0x20e0
incl 0x3a419(%rip)           # 0x3cf48
movq %r13, %rdi
callq 0x2338
jmp 0x2ad0
leaq 0x5595(%rip), %rdi      # 0x80d5
leaq 0x556f(%rip), %r14      # 0x80b6
movq %r14, %rsi
callq 0x21f0
movq %rax, %rbx
leaq 0x558e(%rip), %rdi      # 0x80e7
movq %r14, %rsi
callq 0x21f0
movq %rax, (%rsp)
leaq 0x9694(%rip), %r12      # 0xc200
leaq 0x48(%rsp), %rbp
leaq 0x68(%rsp), %r14
leaq 0x44(%rsp), %r15
movq %rbx, %rdi
leaq 0x5586(%rip), %rsi      # 0x810b
movq %r12, %rdx
xorl %eax, %eax
callq 0x2300
cmpl $0x1, %eax
jne 0x2e04
leaq 0x20(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x35de
movq %rbx, %rdi
leaq 0x5559(%rip), %rsi      # 0x810b
movq %r12, %rdx
xorl %eax, %eax
callq 0x2300
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x35de
movq %rbx, %rdi
leaq 0x5537(%rip), %rsi      # 0x810b
movq %r12, %rdx
xorl %eax, %eax
callq 0x2300
movq %r14, %rdi
movq %r12, %rsi
leaq 0x14(%rsp), %rdx
callq 0x35de
leaq 0x3a3bb(%rip), %rdi     # 0x3cfb0
leaq 0x20(%rsp), %rsi
callq 0x36ce
testq %rax, %rax
jne 0x2c2c
movq 0x93cd(%rip), %rdi      # 0xbfd8
leaq 0x54fc(%rip), %rsi      # 0x810e
callq 0x2190
movq %rax, %rdi
leaq 0x20(%rsp), %rsi
callq 0x2160
movq %rax, %rdi
callq 0x20c0
leaq 0x3a37d(%rip), %rdi     # 0x3cfb0
movq %rbp, %rsi
callq 0x36ce
testq %rax, %rax
jne 0x2c66
movq 0x9391(%rip), %rdi      # 0xbfd8
leaq 0x54c0(%rip), %rsi      # 0x810e
callq 0x2190
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2160
movq %rax, %rdi
callq 0x20c0
leaq 0x3a313(%rip), %rdi     # 0x3cf80
movq %r14, %rsi
callq 0x36ce
testq %rax, %rax
jne 0x2ca0
movq 0x9357(%rip), %rdi      # 0xbfd8
leaq 0x5493(%rip), %rsi      # 0x811b
callq 0x2190
movq %rax, %rdi
movq %r14, %rsi
callq 0x2160
movq %rax, %rdi
callq 0x20c0
leaq 0x3a309(%rip), %r13     # 0x3cfb0
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x361a
movl (%rax), %eax
movl %eax, 0x14(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x361a
movl (%rax), %eax
movl %eax, 0x18(%rsp)
leaq 0x3a2ae(%rip), %rdi     # 0x3cf80
movq %r14, %rsi
callq 0x361a
movl (%rax), %r13d
movq (%rsp), %rdi
leaq 0x53ea(%rip), %rsi      # 0x80d2
movq %r15, %rdx
xorl %eax, %eax
callq 0x2300
leaq 0x3a377(%rip), %rdi     # 0x3d070
movq %r15, %rsi
callq 0x36e8
movq %rax, %rdi
leaq 0x14(%rsp), %rsi
callq 0x3736
incl (%rax)
leaq 0x3a389(%rip), %rdi     # 0x3d0a0
movq %r15, %rsi
callq 0x36e8
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x3736
incl (%rax)
leaq 0x3a21b(%rip), %rdi     # 0x3cf50
movq %r15, %rsi
callq 0x3784
testq %rax, %rax
je 0x2d5b
leaq 0x3a207(%rip), %rdi     # 0x3cf50
movq %r15, %rsi
callq 0x3736
cmpl %r13d, (%rax)
je 0x2d73
jmp 0x3209
incl 0x3a1df(%rip)           # 0x3cf40
leaq 0x3a1e8(%rip), %rdi     # 0x3cf50
movq %r15, %rsi
callq 0x3736
movl %r13d, (%rax)
leaq 0x3a1d6(%rip), %rdi     # 0x3cf50
movq %r15, %rsi
callq 0x3736
leaq 0x3a3a7(%rip), %rdi     # 0x3d130
movq %rax, %rsi
callq 0x36e8
movq %rax, %rdi
leaq 0x14(%rsp), %rsi
callq 0x3736
incl (%rax)
leaq 0x3a1a9(%rip), %rdi     # 0x3cf50
movq %r15, %rsi
callq 0x3736
leaq 0x3a3aa(%rip), %rdi     # 0x3d160
movq %rax, %rsi
callq 0x36e8
movq %rax, %rdi
leaq 0x18(%rsp), %rsi
callq 0x3736
incl (%rax)
movl 0x14(%rsp), %esi
movl 0x18(%rsp), %edx
movl 0x44(%rsp), %ecx
leaq 0x3a410(%rip), %rdi     # 0x3d1f0
callq 0x379e
movq %r14, %rdi
callq 0x2338
movq %rbp, %rdi
callq 0x2338
leaq 0x20(%rsp), %rdi
callq 0x2338
jmp 0x2b7b
movq (%rsp), %rdi
callq 0x21a0
movq %rbx, %rdi
callq 0x21a0
xorl %ecx, %ecx
leaq 0x3a252(%rip), %rbx     # 0x3d070
leaq 0x20(%rsp), %r14
leaq 0x3a2a6(%rip), %r15     # 0x3d0d0
movl %ecx, 0x20(%rsp)
movl 0x3a10c(%rip), %eax     # 0x3cf40
cmpl %eax, %ecx
jge 0x2ed2
movq %rbx, %rdi
movq %r14, %rsi
callq 0x36e8
movq 0x18(%rax), %r12
xorps %xmm0, %xmm0
movsd %xmm0, (%rsp)
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x36e8
addq $0x8, %rax
cmpq %rax, %r12
je 0x2ea3
movsd 0x8(%rsp), %xmm0
addsd 0x51a5(%rip), %xmm0     # 0x8020
movsd %xmm0, 0x8(%rsp)
cvtsi2sdl 0x24(%r12), %xmm0
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq %r12, %rdi
callq 0x2100
movq %rax, %r12
jmp 0x2e59
movsd (%rsp), %xmm0
divsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x386e
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x20(%rsp), %ecx
incl %ecx
jmp 0x2e2a
xorl %ecx, %ecx
leaq 0x3a1c5(%rip), %rbx     # 0x3d0a0
leaq 0x20(%rsp), %r14
leaq 0x3a219(%rip), %r15     # 0x3d100
movl %ecx, 0x20(%rsp)
cmpl %eax, %ecx
jge 0x2f8f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x36e8
movq 0x18(%rax), %r12
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x36e8
addq $0x8, %rax
cmpq %rax, %r12
je 0x2f5a
movsd 0x8(%rsp), %xmm0
addsd 0x50ee(%rip), %xmm0     # 0x8020
movsd %xmm0, 0x8(%rsp)
cvtsi2sdl 0x24(%r12), %xmm0
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq %r12, %rdi
callq 0x2100
movq %rax, %r12
jmp 0x2f10
movsd (%rsp), %xmm0
divsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x386e
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x20(%rsp), %ecx
incl %ecx
movl 0x39fb6(%rip), %eax     # 0x3cf40
jmp 0x2ee7
xorl %ecx, %ecx
leaq 0x3a198(%rip), %rbx     # 0x3d130
leaq 0x20(%rsp), %r14
leaq 0x3a1ec(%rip), %r15     # 0x3d190
movl %ecx, 0x20(%rsp)
movl 0x39f9a(%rip), %eax     # 0x3cf48
cmpl %eax, %ecx
jge 0x304c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x36e8
movq 0x18(%rax), %r12
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x36e8
addq $0x8, %rax
cmpq %rax, %r12
je 0x301d
movsd 0x8(%rsp), %xmm0
addsd 0x502b(%rip), %xmm0     # 0x8020
movsd %xmm0, 0x8(%rsp)
cvtsi2sdl 0x24(%r12), %xmm0
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq %r12, %rdi
callq 0x2100
movq %rax, %r12
jmp 0x2fd3
movsd (%rsp), %xmm0
divsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x386e
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x20(%rsp), %ecx
incl %ecx
jmp 0x2fa4
xorl %ecx, %ecx
leaq 0x3a10b(%rip), %rbx     # 0x3d160
leaq 0x20(%rsp), %r14
leaq 0x3a15f(%rip), %r15     # 0x3d1c0
movl %ecx, 0x20(%rsp)
cmpl %eax, %ecx
jge 0x3109
movq %rbx, %rdi
movq %r14, %rsi
callq 0x36e8
movq 0x18(%rax), %r12
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x36e8
addq $0x8, %rax
cmpq %rax, %r12
je 0x30d4
movsd 0x8(%rsp), %xmm0
addsd 0x4f74(%rip), %xmm0     # 0x8020
movsd %xmm0, 0x8(%rsp)
cvtsi2sdl 0x24(%r12), %xmm0
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq %r12, %rdi
callq 0x2100
movq %rax, %r12
jmp 0x308a
movsd (%rsp), %xmm0
divsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x386e
movsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x20(%rsp), %ecx
incl %ecx
movl 0x39e44(%rip), %eax     # 0x3cf48
jmp 0x3061
xorl %ecx, %ecx
leaq 0x3a07e(%rip), %rbx     # 0x3d190
leaq 0x20(%rsp), %r14
movq 0x8eba(%rip), %r15      # 0xbfd8
pushq $0x20
popq %rbp
leaq 0x3a098(%rip), %r12     # 0x3d1c0
movl %ecx, 0x20(%rsp)
cmpl %eax, %ecx
jge 0x3181
movq %rbx, %rdi
movq %r14, %rsi
callq 0x386e
movsd (%rax), %xmm0
movq %r15, %rdi
callq 0x2290
movq %rax, %rdi
movl %ebp, %esi
callq 0x21e0
movq %rax, %r13
movq %r12, %rdi
movq %r14, %rsi
callq 0x386e
movsd (%rax), %xmm0
movq %r13, %rdi
callq 0x2290
movq %rax, %rdi
callq 0x20c0
movl 0x20(%rsp), %ecx
incl %ecx
movl 0x39dc9(%rip), %eax     # 0x3cf48
jmp 0x3128
movq 0x8e50(%rip), %rbx      # 0xbfd8
leaq 0x4f9f(%rip), %rsi      # 0x812e
movq %rbx, %rdi
callq 0x2190
movl 0x39dab(%rip), %esi     # 0x3cf48
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20c0
leaq 0x4f7d(%rip), %rsi      # 0x8131
movq %rbx, %rdi
callq 0x2190
movl 0x39d7e(%rip), %esi     # 0x3cf40
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20c0
leaq 0x4f66(%rip), %rsi      # 0x813f
movq %rbx, %rdi
callq 0x2190
movl 0x39d5d(%rip), %esi     # 0x3cf44
movq %rax, %rdi
callq 0x22c0
movq %rax, %rdi
callq 0x20c0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8dc8(%rip), %rdi      # 0xbfd8
leaq 0x4f0e(%rip), %rsi      # 0x8125
callq 0x2190
movl 0x14(%rsp), %esi
movq %rax, %rdi
callq 0x22c0
leaq 0x4f7a(%rip), %rsi      # 0x81a9
movq %rax, %rdi
callq 0x2190
movl 0x18(%rsp), %esi
movq %rax, %rdi
callq 0x22c0
leaq 0x4f5f(%rip), %rsi      # 0x81a9
movq %rax, %rdi
callq 0x2190
movl 0x44(%rsp), %esi
movq %rax, %rdi
callq 0x22c0
pushq $0x20
popq %rsi
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
movl %r13d, %esi
callq 0x22c0
movq %rax, %rdi
callq 0x20c0
pushq $-0x1
popq %rdi
callq 0x2200
jmp 0x32a9
jmp 0x32a9
jmp 0x32a2
jmp 0x329b
jmp 0x32a9
jmp 0x32a9
jmp 0x3292
movq %rax, %rbx
jmp 0x32b6
jmp 0x32a2
jmp 0x329b
movq %rax, %rbx
jmp 0x32ca
jmp 0x32a2
movq %rax, %rbx
jmp 0x32c0
jmp 0x32a9
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x2338
leaq 0x48(%rsp), %rdi
callq 0x2338
leaq 0x20(%rsp), %rdi
callq 0x2338
movq %rbx, %rdi
callq 0x22d0