// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
leaq 0x4791(%rip), %rdi      # 0x7080
leaq 0x47a0(%rip), %rbx      # 0x7096
movq %rbx, %rsi
callq 0x2200
movq %rax, %r14
leaq 0x4790(%rip), %rdi      # 0x7098
movq %rbx, %rsi
callq 0x2200
movq %rax, 0x8(%rsp)
leaq 0x4794(%rip), %rsi      # 0x70b0
leaq 0x78cd(%rip), %r15      # 0xa1f0
leaq 0x4(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2310
cmpl $0x2, %eax
jne 0x29d5
leaq 0x20(%rsp), %rbp
leaq 0x10(%rsp), %r12
leaq 0x4(%rsp), %r13
movq %rbp, 0x10(%rsp)
movq %r15, %rdi
callq 0x20d0
leaq (%rax,%r15), %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x58ec
movl 0x4(%rsp), %ebx
leaq 0x385f4(%rip), %rdi     # 0x3af68
movq %r12, %rsi
callq 0x341e
movl %ebx, (%rax)
leaq 0x38613(%rip), %rdi     # 0x3af98
movq %r13, %rsi
callq 0x349a
movq %rax, %rdi
movq %r12, %rsi
callq 0x20f0
incl 0x38596(%rip)           # 0x3af34
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x29b5
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %r14, %rdi
leaq 0x46f1(%rip), %rsi      # 0x70b0
movq %r15, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x2310
cmpl $0x2, %eax
je 0x294d
leaq 0x46d4(%rip), %rsi      # 0x70b0
leaq 0x780d(%rip), %r14      # 0xa1f0
leaq 0x4(%rsp), %rcx
movq 0x8(%rsp), %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2310
cmpl $0x2, %eax
jne 0x2a9e
leaq 0x20(%rsp), %r12
leaq 0x10(%rsp), %r15
leaq 0x4(%rsp), %rbp
leaq 0x469a(%rip), %rbx      # 0x70b0
movq %r12, 0x10(%rsp)
movq %r14, %rdi
callq 0x20d0
leaq (%rax,%r14), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x58ec
movl 0x4(%rsp), %r13d
leaq 0x384fa(%rip), %rdi     # 0x3af38
movq %r15, %rsi
callq 0x341e
movl %r13d, (%rax)
leaq 0x38578(%rip), %rdi     # 0x3afc8
movq %rbp, %rsi
callq 0x349a
movq %rax, %rdi
movq %r15, %rsi
callq 0x20f0
incl 0x384c7(%rip)           # 0x3af30
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x2a80
movq 0x20(%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 0x2a16
leaq 0x4610(%rip), %rdi      # 0x70b5
leaq 0x45ea(%rip), %rsi      # 0x7096
callq 0x2200
movq %rax, %rbx
leaq 0x460c(%rip), %rsi      # 0x70c7
leaq 0x772e(%rip), %r14      # 0xa1f0
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2310
cmpl $0x1, %eax
jne 0x2dc3
leaq 0x45e8(%rip), %r15      # 0x70c7
leaq 0x38482(%rip), %r12     # 0x3af68
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r14, %rdi
callq 0x20d0
leaq (%rax,%r14), %rdx
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x58ec
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2310
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
movq %r14, %rdi
callq 0x20d0
leaq (%rax,%r14), %rdx
leaq 0x58(%rsp), %rdi
movq %r14, %rsi
callq 0x58ec
movq %rbx, %rdi
movq %r15, %rbp
movq %r15, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2310
movq %rbx, %r15
leaq 0x48(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %r14, %rdi
callq 0x20d0
leaq (%rax,%r14), %rdx
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x58ec
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x5f72
leaq 0x383e7(%rip), %rcx     # 0x3af70
cmpq %rcx, %rax
jne 0x2be6
movl $0xc, %edx
movq 0x743e(%rip), %rdi      # 0x9fd8
leaq 0x4529(%rip), %rsi      # 0x70ca
callq 0x21f0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x7421(%rip), %rdi      # 0x9fd8
callq 0x21f0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq %r12, %rdi
leaq 0x58(%rsp), %rsi
callq 0x5f72
leaq 0x38376(%rip), %rcx     # 0x3af70
cmpq %rcx, %rax
jne 0x2c57
movl $0xc, %edx
movq 0x73cd(%rip), %rdi      # 0x9fd8
leaq 0x44b8(%rip), %rsi      # 0x70ca
callq 0x21f0
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x73b0(%rip), %rdi      # 0x9fd8
callq 0x21f0
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
leaq 0x382da(%rip), %rdi     # 0x3af38
leaq 0x38(%rsp), %rsi
callq 0x5f72
leaq 0x382d1(%rip), %rcx     # 0x3af40
cmpq %rcx, %rax
jne 0x2c93
movl 0x382b6(%rip), %ebx     # 0x3af30
leaq 0x382b7(%rip), %rdi     # 0x3af38
leaq 0x38(%rsp), %rsi
callq 0x341e
movl %ebx, (%rax)
incl 0x3829d(%rip)           # 0x3af30
leaq 0x3829e(%rip), %rdi     # 0x3af38
leaq 0x38(%rsp), %rsi
callq 0x341e
leaq 0x3834d(%rip), %rdi     # 0x3aff8
movq %rax, %rsi
callq 0x34fe
movq %rax, %r13
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x341e
movq %r13, %rdi
movq %rax, %rsi
callq 0x3562
incl (%rax)
leaq 0x38261(%rip), %rdi     # 0x3af38
leaq 0x38(%rsp), %rsi
callq 0x341e
leaq 0x38340(%rip), %rdi     # 0x3b028
movq %rax, %rsi
callq 0x34fe
movq %rax, %r13
movq %r12, %rdi
leaq 0x58(%rsp), %rsi
callq 0x341e
movq %r13, %rdi
movq %rax, %rsi
callq 0x3562
incl (%rax)
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x341e
movl (%rax), %r13d
movq %r12, %rdi
leaq 0x58(%rsp), %rsi
callq 0x341e
movl (%rax), %ebx
leaq 0x38205(%rip), %rdi     # 0x3af38
leaq 0x38(%rsp), %rsi
callq 0x341e
movl (%rax), %ecx
leaq 0x38372(%rip), %rdi     # 0x3b0b8
movl %r13d, %esi
movl %ebx, %edx
callq 0x35c6
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x2d6c
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
movq %r15, %rbx
je 0x2d8b
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
movq %rbp, %r15
je 0x2daa
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2310
cmpl $0x1, %eax
je 0x2ae6
movl $0x0, 0x10(%rsp)
cmpl $0x0, 0x3815e(%rip)     # 0x3af30
jle 0x2e9f
leaq 0x38219(%rip), %r14     # 0x3aff8
leaq 0x10(%rsp), %r15
leaq 0x3826d(%rip), %r12     # 0x3b058
movq %r14, %rdi
movq %r15, %rsi
callq 0x34fe
movq 0x18(%rax), %r13
movq %r14, %rdi
movq %r15, %rsi
callq 0x34fe
addq $0x8, %rax
movsd 0x4207(%rip), %xmm1     # 0x7018
cmpq %rax, %r13
je 0x2e6e
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
addsd 0x41fa(%rip), %xmm2     # 0x7020
movsd %xmm2, 0x30(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x24(%r13), %xmm0
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %r13, %rdi
callq 0x2120
movq %rax, %r13
movq %r14, %rdi
movq %r15, %rsi
callq 0x34fe
movsd 0x30(%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
addq $0x8, %rax
cmpq %rax, %r13
jne 0x2e1e
divsd %xmm2, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x36a0
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x10(%rsp), %eax
incl %eax
movl %eax, 0x10(%rsp)
cmpl 0x38097(%rip), %eax     # 0x3af30
jl 0x2deb
movq %rbx, %rbp
movl $0x0, 0x10(%rsp)
cmpl $0x0, 0x3807f(%rip)     # 0x3af30
jle 0x2f7e
leaq 0x3816a(%rip), %r14     # 0x3b028
leaq 0x10(%rsp), %r15
leaq 0x381be(%rip), %r12     # 0x3b088
movq %r14, %rdi
movq %r15, %rsi
callq 0x34fe
movq 0x18(%rax), %r13
movq %r14, %rdi
movq %r15, %rsi
callq 0x34fe
addq $0x8, %rax
movsd 0x4128(%rip), %xmm1     # 0x7018
cmpq %rax, %r13
je 0x2f4d
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
addsd 0x411b(%rip), %xmm2     # 0x7020
movsd %xmm2, 0x30(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x24(%r13), %xmm0
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %r13, %rdi
callq 0x2120
movq %rax, %r13
movq %r14, %rdi
movq %r15, %rsi
callq 0x34fe
movsd 0x30(%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
addq $0x8, %rax
cmpq %rax, %r13
jne 0x2efd
divsd %xmm2, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0x36a0
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x10(%rsp), %eax
incl %eax
movl %eax, 0x10(%rsp)
cmpl 0x37fb8(%rip), %eax     # 0x3af30
jl 0x2eca
movq 0x7053(%rip), %r14      # 0x9fd8
leaq 0x414b(%rip), %rsi      # 0x70d7
movl $0xd, %edx
movq %r14, %rdi
callq 0x21f0
movl 0x37f91(%rip), %esi     # 0x3af30
movq %r14, %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
leaq 0x410d(%rip), %rsi      # 0x70e5
movl $0xb, %edx
movq %r14, %rdi
callq 0x21f0
movl 0x37f49(%rip), %esi     # 0x3af34
movq %r14, %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
movq %rbp, %rdi
callq 0x21b0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3046
jmp 0x3038
movq %rax, %rbx
jmp 0x30a4
jmp 0x303f
movq %rax, %rbx
jmp 0x3088
jmp 0x3046
movq %rax, %rbx
jmp 0x30c0
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
jne 0x30b3
jmp 0x30c0
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
jne 0x30b3
jmp 0x30c0
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x3088
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x30a4
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21d0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x30c0
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x22e0