// File: /workspace/github_cpp_makefile_star2_O1/thunlp[P]KB2E/TransR/Train_TransR.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++;
        }
        entity2num[entity2id[s1]]++;
        entity2num[entity2id[s2]]++;
        left_entity[relation2id[s3]][entity2id[s1]].push_back(entity2id[s2]);
        right_entity[relation2id[s3]][entity2id[s2]].push_back(entity2id[s1]);
        train.add(entity2id[s1],entity2id[s2],relation2id[s3]);
    }
    for (int i=0; i<relation_num; i++)
    {
    	double sum1=0,sum2=0,sum3 = 0;
    	for (map<int,vector<int> >::iterator it = left_entity[i].begin(); it!=left_entity[i].end(); it++)
    	{
    		sum1++;
    		sum2+=it->second.size();
    		sum3+=sqr(it->second.size());
    	}
    	left_mean[i]=sum2/sum1;

    	left_var[i]=sum3/sum1-sqr(left_mean[i]);
    }
    for (int i=0; i<relation_num; i++)
    {
    	double sum1=0,sum2=0,sum3=0;
    	for (map<int,vector<int> >::iterator it = right_entity[i].begin(); it!=right_entity[i].end(); it++)
    	{
    		sum1++;
    		sum2+=it->second.size();
    		sum3+=sqr(it->second.size());
    	}
    	right_mean[i]=sum2/sum1;
    	right_var[i]=sum3/sum1-sqr(right_mean[i]);
    }

    fclose(f_kb);
    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 0x5638(%rip), %rdi      # 0x80b0
leaq 0x5647(%rip), %rbx      # 0x80c6
movq %rbx, %rsi
callq 0x2200
movq %rax, %r14
leaq 0x5637(%rip), %rdi      # 0x80c8
movq %rbx, %rsi
callq 0x2200
movq %rax, 0x8(%rsp)
leaq 0x563b(%rip), %rsi      # 0x80e0
leaq 0x9744(%rip), %r15      # 0xc1f0
leaq 0x14(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2310
cmpl $0x2, %eax
jne 0x2b5e
leaq 0x28(%rsp), %rbp
leaq 0x18(%rsp), %r12
leaq 0x14(%rsp), %r13
movq %rbp, 0x18(%rsp)
movq %r15, %rdi
callq 0x20d0
leaq (%rax,%r15), %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x678a
movl 0x14(%rsp), %ebx
leaq 0x3a46b(%rip), %rdi     # 0x3cf68
movq %r12, %rsi
callq 0x37ac
movl %ebx, (%rax)
leaq 0x3a48a(%rip), %rdi     # 0x3cf98
movq %r13, %rsi
callq 0x3828
movq %rax, %rdi
movq %r12, %rsi
callq 0x20f0
incl 0x3a40d(%rip)           # 0x3cf34
movq 0x18(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2b3e
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %r14, %rdi
leaq 0x5598(%rip), %rsi      # 0x80e0
movq %r15, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x2310
cmpl $0x2, %eax
je 0x2ad6
leaq 0x557b(%rip), %rsi      # 0x80e0
leaq 0x9684(%rip), %r14      # 0xc1f0
leaq 0x14(%rsp), %rcx
movq 0x8(%rsp), %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2310
cmpl $0x2, %eax
jne 0x2c27
leaq 0x28(%rsp), %r12
leaq 0x18(%rsp), %r15
leaq 0x14(%rsp), %rbp
leaq 0x5541(%rip), %rbx      # 0x80e0
movq %r12, 0x18(%rsp)
movq %r14, %rdi
callq 0x20d0
leaq (%rax,%r14), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x678a
movl 0x14(%rsp), %r13d
leaq 0x3a371(%rip), %rdi     # 0x3cf38
movq %r15, %rsi
callq 0x37ac
movl %r13d, (%rax)
leaq 0x3a3ef(%rip), %rdi     # 0x3cfc8
movq %rbp, %rsi
callq 0x3828
movq %rax, %rdi
movq %r15, %rsi
callq 0x20f0
incl 0x3a33e(%rip)           # 0x3cf30
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
je 0x2c09
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x2310
cmpl $0x2, %eax
je 0x2b9f
leaq 0x54b7(%rip), %rdi      # 0x80e5
leaq 0x5491(%rip), %rsi      # 0x80c6
callq 0x2200
movq %rax, %rbp
leaq 0x54b3(%rip), %rsi      # 0x80f7
leaq 0x95a5(%rip), %r14      # 0xc1f0
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2310
cmpl $0x1, %eax
jne 0x2fe8
leaq 0x548f(%rip), %rbx      # 0x80f7
leaq 0x3a2f9(%rip), %r12     # 0x3cf68
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %r14, %rdi
callq 0x20d0
leaq (%rax,%r14), %rdx
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x678a
movq %rbp, %rdi
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2310
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %r14, %rdi
callq 0x20d0
leaq (%rax,%r14), %rdx
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x678a
movq %rbp, %rdi
movq %rbx, %r13
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2310
movq %rbp, %r15
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
movq %r14, %rdi
callq 0x20d0
leaq (%rax,%r14), %rdx
leaq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x678a
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
callq 0x6e10
leaq 0x3a25e(%rip), %rcx     # 0x3cf70
cmpq %rcx, %rax
jne 0x2d6f
movl $0xc, %edx
movq 0x92b5(%rip), %rdi      # 0xbfd8
leaq 0x53d0(%rip), %rsi      # 0x80fa
callq 0x21f0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq 0x9298(%rip), %rdi      # 0xbfd8
callq 0x21f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq %r12, %rdi
leaq 0x48(%rsp), %rsi
callq 0x6e10
leaq 0x3a1ed(%rip), %rcx     # 0x3cf70
cmpq %rcx, %rax
jne 0x2de0
movl $0xc, %edx
movq 0x9244(%rip), %rdi      # 0xbfd8
leaq 0x535f(%rip), %rsi      # 0x80fa
callq 0x21f0
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0x9227(%rip), %rdi      # 0xbfd8
callq 0x21f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
leaq 0x3a151(%rip), %rdi     # 0x3cf38
leaq 0x68(%rsp), %rsi
callq 0x6e10
leaq 0x3a148(%rip), %rcx     # 0x3cf40
cmpq %rcx, %rax
jne 0x2e1c
movl 0x3a12d(%rip), %ebx     # 0x3cf30
leaq 0x3a12e(%rip), %rdi     # 0x3cf38
leaq 0x68(%rsp), %rsi
callq 0x37ac
movl %ebx, (%rax)
incl 0x3a114(%rip)           # 0x3cf30
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
callq 0x37ac
leaq 0x3a1c8(%rip), %rdi     # 0x3cff8
movq %rax, %rsi
callq 0x388c
incl (%rax)
movq %r12, %rdi
leaq 0x48(%rsp), %rsi
callq 0x37ac
leaq 0x3a1aa(%rip), %rdi     # 0x3cff8
movq %rax, %rsi
callq 0x388c
incl (%rax)
leaq 0x3a0d9(%rip), %rdi     # 0x3cf38
leaq 0x68(%rsp), %rsi
callq 0x37ac
leaq 0x3a1b8(%rip), %rdi     # 0x3d028
movq %rax, %rsi
callq 0x38f0
movq %rax, %rbx
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
callq 0x37ac
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3954
movq %rax, %rbx
movq %r12, %rdi
leaq 0x48(%rsp), %rsi
callq 0x37ac
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2ebb
movl (%rax), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2ec6
movq %rbx, %rdi
movq %rax, %rdx
callq 0x6242
leaq 0x3a06b(%rip), %rdi     # 0x3cf38
leaq 0x68(%rsp), %rsi
callq 0x37ac
leaq 0x3a17a(%rip), %rdi     # 0x3d058
movq %rax, %rsi
callq 0x38f0
movq %rax, %rbx
movq %r12, %rdi
leaq 0x48(%rsp), %rsi
callq 0x37ac
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3954
movq %rax, %rbx
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
callq 0x37ac
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x2f29
movl (%rax), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x2f34
movq %rbx, %rdi
movq %rax, %rdx
callq 0x6242
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
callq 0x37ac
movl (%rax), %ebx
movq %r12, %rdi
leaq 0x48(%rsp), %rsi
callq 0x37ac
movl (%rax), %ebp
leaq 0x39fdf(%rip), %rdi     # 0x3cf38
leaq 0x68(%rsp), %rsi
callq 0x37ac
movl (%rax), %ecx
leaq 0x3a1dc(%rip), %rdi     # 0x3d148
movl %ebx, %esi
movl %ebp, %edx
callq 0x39b8
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x2f91
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
movq %r15, %rbp
je 0x2fb0
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
movq %r13, %rbx
je 0x2fcf
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %rbp, %rdi
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2310
cmpl $0x1, %eax
je 0x2c6f
movl $0x0, 0x18(%rsp)
cmpl $0x0, 0x39f39(%rip)     # 0x3cf30
jle 0x3170
leaq 0x3a024(%rip), %rbx     # 0x3d028
leaq 0x18(%rsp), %r14
leaq 0x3a078(%rip), %r15     # 0x3d088
leaq 0x3a0d1(%rip), %r12     # 0x3d0e8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x38f0
movq 0x18(%rax), %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0x38f0
addq $0x8, %rax
cmpq %rax, %r13
je 0x30d9
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
addsd 0x4fc9(%rip), %xmm1     # 0x8020
movsd %xmm1, 0x40(%rsp)
movq 0x30(%r13), %rax
subq 0x28(%r13), %rax
sarq $0x2, %rax
movq %rax, %xmm0
punpckldq 0x4fea(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x4ff2(%rip), %xmm0     # 0x8070
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
addsd %xmm1, %xmm2
movsd %xmm2, 0x38(%rsp)
mulsd %xmm1, %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
callq 0x2120
movq %rax, %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0x38f0
movsd 0x38(%rsp), %xmm2
movsd 0x40(%rsp), %xmm1
addq $0x8, %rax
cmpq %rax, %r13
jne 0x304f
jmp 0x30eb
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, 0x40(%rsp)
divsd %xmm1, %xmm2
movsd %xmm2, 0x38(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3a8a
movsd 0x38(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0x8(%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3a8a
movsd (%rax), %xmm0
mulsd %xmm0, %xmm0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x3a8a
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x18(%rsp), %eax
incl %eax
movl %eax, 0x18(%rsp)
cmpl 0x39dc6(%rip), %eax     # 0x3cf30
jl 0x3017
movl $0x0, 0x18(%rsp)
cmpl $0x0, 0x39db1(%rip)     # 0x3cf30
jle 0x32f9
leaq 0x39ecc(%rip), %rbx     # 0x3d058
leaq 0x18(%rsp), %r14
leaq 0x39f20(%rip), %r15     # 0x3d0b8
leaq 0x39f79(%rip), %r12     # 0x3d118
movq %rbx, %rdi
movq %r14, %rsi
callq 0x38f0
movq 0x18(%rax), %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0x38f0
addq $0x8, %rax
cmpq %rax, %r13
je 0x3262
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorpd %xmm2, %xmm2
xorpd %xmm1, %xmm1
addsd 0x4e40(%rip), %xmm1     # 0x8020
movsd %xmm1, 0x40(%rsp)
movq 0x30(%r13), %rax
subq 0x28(%r13), %rax
sarq $0x2, %rax
movq %rax, %xmm0
punpckldq 0x4e61(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x4e69(%rip), %xmm0     # 0x8070
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
addsd %xmm1, %xmm2
movsd %xmm2, 0x38(%rsp)
mulsd %xmm1, %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
callq 0x2120
movq %rax, %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0x38f0
movsd 0x38(%rsp), %xmm2
movsd 0x40(%rsp), %xmm1
addq $0x8, %rax
cmpq %rax, %r13
jne 0x31d8
jmp 0x3274
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, 0x40(%rsp)
divsd %xmm1, %xmm2
movsd %xmm2, 0x38(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3a8a
movsd 0x38(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0x8(%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x3a8a
movsd (%rax), %xmm0
mulsd %xmm0, %xmm0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x3a8a
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x18(%rsp), %eax
incl %eax
movl %eax, 0x18(%rsp)
cmpl 0x39c3d(%rip), %eax     # 0x3cf30
jl 0x319f
movq %rbp, %rdi
callq 0x21b0
movq 0x8cd0(%rip), %rbx      # 0xbfd8
leaq 0x4df8(%rip), %rsi      # 0x8107
movl $0xd, %edx
movq %rbx, %rdi
callq 0x21f0
movl 0x39c0e(%rip), %esi     # 0x3cf30
movq %rbx, %rdi
callq 0x22d0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
leaq 0x4dba(%rip), %rsi      # 0x8115
movl $0xb, %edx
movq %rbx, %rdi
callq 0x21f0
movl 0x39bc6(%rip), %esi     # 0x3cf34
movq %rbx, %rdi
callq 0x22d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x33c4
jmp 0x33b6
movq %rax, %rbx
jmp 0x3422
jmp 0x33bd
movq %rax, %rbx
jmp 0x3406
jmp 0x33c4
movq %rax, %rbx
jmp 0x343e
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r12, %rdi
jne 0x3431
jmp 0x343e
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %rbp, %rdi
jne 0x3431
jmp 0x343e
movq %rax, %rbx
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x3406
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x3422
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x343e
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x22e0