// File: /workspace/github_cpp_makefile_star2_O2/thunlp[P]KB2E/cluster/generate.cpp
// Function: main
int main(int argc, char** argv)
{
    int rel_now=-1;
    if (argc ==2)
        rel_now =  atoi(argv[1]);
    else
        return 0;
    cout<<rel_now<<endl;


    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");
    vector<int> train_e1,train_e2,train_rel,train_index;
    int index=-1;
	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;
        int e1 = entity2id[s1];
        int e2 = entity2id[s2];
        int rel = relation2id[s3];
        index+=1;
        if (rel!=rel_now)
            continue;
        train_index.push_back(index);
        train_e1.push_back(e1);
        train_e2.push_back(e2);
        train_rel.push_back(rel);
    }
    FILE* f_ent_vec = fopen("../TransE/entity2vec.txt","r");

   // FILE* f_ent_vec = fopen("../data/entity_vec_word2vec.txt","r");
    int vec_size=50;
    entity_vec.resize(entity_num);
    for (int i=0; i<entity_num;i++)
    {
        entity_vec[i].resize(vec_size);
        for (int ii=0; ii<vec_size; ii++)
        {
            fscanf(f_ent_vec,"%lf",&entity_vec[i][ii]);
        }
    }
    double sum = 0;
    int n=train_e1.size();
    FILE* g_sim = fopen("similarity.txt","w");
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
        if (i!=j)
        {
            double tmp=0;
            for (int ii=0; ii<vec_size; ii++)
                tmp-=sqr(entity_vec[train_e1[i]][ii]-entity_vec[train_e2[i]][ii]-
                          entity_vec[train_e1[j]][ii]+entity_vec[train_e2[j]][ii]);
            a.push_back(tmp);
            if (tmp>1e6)
            {
                vec_output(entity_vec[train_e1[i]]);
                vec_output(entity_vec[train_e2[i]]);
                vec_output(entity_vec[train_e1[j]]);
                vec_output(entity_vec[train_e2[j]]);
                exit(0);
            }
            fprintf(g_sim,"%d\t%d\t%lf\n",i+1,j+1,tmp);
        }
    fclose(g_sim);
    if (n>1)
    {
        sort(a.begin(),a.end());
        cout<<a[0]<<' '<<a[a.size()-1]<<' '<<a[0]-(a[a.size()-1]-a[0])<<endl;
        sum = a[0]-10*(a[a.size()-1]-a[0]);
    }
    FILE* g_pre = fopen("pre.txt","w");
    for (int i=0; i<n; i++)
        fprintf(g_pre,"%lf\n",sum);
    fclose(g_pre);
    FILE* g_env = fopen(("data/id2index"+string(argv[1])+".txt").c_str(),"w");
    for (int i=0; i<n; i++)
    {
        fprintf(g_env,"%d\n",train_index[i]);
    }
    fclose(g_env);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
cmpl $0x2, %edi
jne 0x2c39
movq %rsi, 0x98(%rsp)
movq 0x8(%rsi), %rdi
callq 0x21f0
movq 0x5a38(%rip), %rdi      # 0x7fd8
movl %eax, 0x18(%rsp)
movl %eax, %esi
callq 0x2230
movq %rax, %rdi
callq 0x20b0
leaq 0x2a76(%rip), %rdi      # 0x5030
leaq 0x2a85(%rip), %rbx      # 0x5046
movq %rbx, %rsi
callq 0x2180
movq %rax, %r14
leaq 0x2a75(%rip), %rdi      # 0x5048
movq %rbx, %rsi
callq 0x2180
movq %rax, %rbx
leaq 0x5c5b(%rip), %r12      # 0x8240
leaq 0x10(%rsp), %r13
leaq 0x50(%rsp), %rbp
movq %r14, %rdi
leaq 0x2a67(%rip), %rsi      # 0x5060
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x2260
cmpl $0x2, %eax
jne 0x265f
movq %rbp, %rdi
movq %r12, %rsi
leaq 0xa0(%rsp), %rdx
callq 0x2dac
movl 0x10(%rsp), %r15d
leaq 0x5b7e(%rip), %rdi      # 0x81a8
movq %rbp, %rsi
callq 0x2de8
movl %r15d, (%rax)
leaq 0x5b9c(%rip), %rdi      # 0x81d8
movq %r13, %rsi
callq 0x2e4e
movq %rax, %rdi
movq %rbp, %rsi
callq 0x20d0
incl 0x5be3(%rip)            # 0x8238
movq %rbp, %rdi
callq 0x20a0
jmp 0x25ef
leaq 0x5bda(%rip), %r15      # 0x8240
leaq 0x10(%rsp), %r12
leaq 0x50(%rsp), %r13
leaq 0x5b91(%rip), %rbp      # 0x8208
movq %rbx, %rdi
leaq 0x29df(%rip), %rsi      # 0x5060
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x2260
cmpl $0x2, %eax
jne 0x26e3
movq %r13, %rdi
movq %r15, %rsi
leaq 0xa0(%rsp), %rdx
callq 0x2dac
movl 0x10(%rsp), %r14d
leaq 0x5ac6(%rip), %rdi      # 0x8178
movq %r13, %rsi
callq 0x2de8
movl %r14d, (%rax)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2e4e
movq %rax, %rdi
movq %r13, %rsi
callq 0x20d0
incl 0x5b63(%rip)            # 0x823c
movq %r13, %rdi
callq 0x20a0
jmp 0x2677
leaq 0x297b(%rip), %rdi      # 0x5065
leaq 0x2955(%rip), %rsi      # 0x5046
callq 0x2180
movq %rax, %r14
xorpd %xmm0, %xmm0
leaq 0x30(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x70(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x100(%rsp), %rax
andq $0x0, 0x10(%rax)
leaq 0xc0(%rsp), %rcx
andq $0x0, 0x10(%rcx)
leaq 0x14(%rsp), %rdx
orl $-0x1, (%rdx)
movapd %xmm0, (%rax)
movapd %xmm0, (%rcx)
leaq 0x5af6(%rip), %r12      # 0x8240
leaq 0x50(%rsp), %r13
leaq 0xa0(%rsp), %rbx
leaq 0xe0(%rsp), %rbp
movq %r14, %rdi
leaq 0x290e(%rip), %rsi      # 0x5077
movq %r12, %rdx
xorl %eax, %eax
callq 0x2260
cmpl $0x1, %eax
jne 0x2877
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x2dac
movq %r14, %rdi
leaq 0x28e3(%rip), %rsi      # 0x5077
movq %r12, %rdx
xorl %eax, %eax
callq 0x2260
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x2dac
movq %r14, %rdi
leaq 0x28c1(%rip), %rsi      # 0x5077
movq %r12, %rdx
xorl %eax, %eax
callq 0x2260
movq %rbp, %rdi
movq %r12, %rsi
leaq 0xc(%rsp), %rdx
callq 0x2dac
leaq 0x59d1(%rip), %r15      # 0x81a8
movq %r15, %rdi
movq %r13, %rsi
callq 0x2de8
movl (%rax), %eax
movl %eax, 0xc(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2de8
movl (%rax), %eax
movl %eax, 0x2c(%rsp)
leaq 0x5978(%rip), %rdi      # 0x8178
movq %rbp, %rsi
callq 0x2de8
movl (%rax), %eax
movl %eax, 0x28(%rsp)
incl 0x14(%rsp)
cmpl 0x18(%rsp), %eax
jne 0x285a
leaq 0xc0(%rsp), %rdi
leaq 0x14(%rsp), %rsi
callq 0x2e9c
leaq 0x30(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x2e9c
leaq 0x70(%rsp), %rdi
leaq 0x2c(%rsp), %rsi
callq 0x2e9c
leaq 0x100(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x2e9c
movq %rbp, %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x20a0
movq %r13, %rdi
callq 0x20a0
jmp 0x275f
leaq 0x27fc(%rip), %rdi      # 0x507a
leaq 0x27c1(%rip), %rsi      # 0x5046
callq 0x2180
movq %rax, %rbx
movslq 0x59a4(%rip), %rsi      # 0x8238
leaq 0x366e5(%rip), %rdi     # 0x38f80
callq 0x2eba
pushq $0x32
popq %r14
leaq 0x27e8(%rip), %r15      # 0x5093
xorl %r12d, %r12d
movslq 0x5983(%rip), %rax      # 0x8238
cmpq %rax, %r12
jge 0x2901
imulq $0x18, %r12, %r13
movq 0x366bb(%rip), %rdi     # 0x38f80
addq %r13, %rdi
movq %r14, %rsi
callq 0x2ef0
xorl %ebp, %ebp
cmpq $0x190, %rbp            # imm = 0x190
je 0x28fc
movq 0x3669e(%rip), %rax     # 0x38f80
movq (%rax,%r13), %rdx
addq %rbp, %rdx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x2260
addq $0x8, %rbp
jmp 0x28d2
incq %r12
jmp 0x28ae
movq 0x38(%rsp), %r14
subq 0x30(%rsp), %r14
shrq $0x2, %r14
leaq 0x2781(%rip), %rdi      # 0x5097
leaq 0x2789(%rip), %rsi      # 0x50a6
callq 0x2180
movq %rax, %rbx
xorl %ebp, %ebp
testl %r14d, %r14d
movl $0x0, %eax
cmovgl %r14d, %eax
movl %eax, 0x24(%rsp)
movq %rax, 0x18(%rsp)
movq %r14, 0x90(%rsp)
movl %r14d, %r12d
leaq 0x275a(%rip), %r13      # 0x50a8
cmpq 0x18(%rsp), %rbp
je 0x2a35
leaq 0x1(%rbp), %r15
xorl %r14d, %r14d
cmpq %r12, %r14
je 0x2a2d
cmpq %r14, %rbp
jne 0x2973
incq %r14
jmp 0x2960
andq $0x0, 0x50(%rsp)
movq 0x30(%rsp), %rdx
movslq (%rdx,%rbp,4), %rax
movq 0x365f7(%rip), %rsi     # 0x38f80
imulq $0x18, %rax, %rax
movq (%rsi,%rax), %rax
movq 0x70(%rsp), %rdi
movslq (%rdi,%rbp,4), %rcx
imulq $0x18, %rcx, %rcx
movq (%rsi,%rcx), %rcx
movslq (%rdx,%r14,4), %rdx
imulq $0x18, %rdx, %rdx
movq (%rsi,%rdx), %rdx
movslq (%rdi,%r14,4), %rdi
imulq $0x18, %rdi, %rdi
movq (%rsi,%rdi), %rsi
xorpd %xmm0, %xmm0
xorl %edi, %edi
cmpq $0x32, %rdi
je 0x29ed
movsd (%rax,%rdi,8), %xmm1
subsd (%rcx,%rdi,8), %xmm1
subsd (%rdx,%rdi,8), %xmm1
addsd (%rsi,%rdi,8), %xmm1
mulsd %xmm1, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x50(%rsp)
incq %rdi
jmp 0x29c0
leaq 0x365a4(%rip), %rdi     # 0x38f98
leaq 0x50(%rsp), %rsi
callq 0x2f22
movsd 0x50(%rsp), %xmm0
ucomisd 0x25fc(%rip), %xmm0     # 0x5008
ja 0x2c4d
incq %r14
movq %rbx, %rdi
movq %r13, %rsi
movl %r15d, %edx
movl %r14d, %ecx
movb $0x1, %al
callq 0x21c0
jmp 0x2960
movq %r15, %rbp
jmp 0x294e
movq %rbx, %rdi
callq 0x2130
xorpd %xmm0, %xmm0
movsd %xmm0, 0x48(%rsp)
cmpl $0x1, 0x90(%rsp)
movl 0x24(%rsp), %ebp
jle 0x2b09
movq 0x36538(%rip), %rdi     # 0x38f98
movq 0x36539(%rip), %rsi     # 0x38fa0
callq 0x3df0
movq 0x36525(%rip), %rax     # 0x38f98
movsd (%rax), %xmm0
movq 0x555a(%rip), %rdi      # 0x7fd8
callq 0x2200
pushq $0x20
popq %rsi
movq %rax, %rdi
callq 0x2170
movq 0x3650b(%rip), %rcx     # 0x38fa0
movsd -0x8(%rcx), %xmm0
movq %rax, %rdi
callq 0x2200
pushq $0x20
popq %rsi
movq %rax, %rdi
callq 0x2170
movq 0x364e4(%rip), %rcx     # 0x38f98
movsd (%rcx), %xmm0
movq 0x364e1(%rip), %rcx     # 0x38fa0
movsd -0x8(%rcx), %xmm1
subsd %xmm0, %xmm1
subsd %xmm1, %xmm0
movq %rax, %rdi
callq 0x2200
movq %rax, %rdi
callq 0x20b0
movq 0x364b5(%rip), %rax     # 0x38f98
movsd (%rax), %xmm0
movq 0x364b2(%rip), %rax     # 0x38fa0
movsd -0x8(%rax), %xmm1
subsd %xmm0, %xmm1
mulsd 0x2511(%rip), %xmm1     # 0x5010
addsd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
leaq 0x25a3(%rip), %rdi      # 0x50b3
leaq 0x258f(%rip), %rsi      # 0x50a6
callq 0x2180
movq %rax, %rbx
leaq 0x2588(%rip), %r14      # 0x50ae
subl $0x1, %ebp
jb 0x2b40
movq %rbx, %rdi
movq %r14, %rsi
movsd 0x48(%rsp), %xmm0
movb $0x1, %al
callq 0x21c0
jmp 0x2b26
movq %rbx, %rdi
callq 0x2130
movq 0x98(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0xe0(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0x2dac
leaq 0x254e(%rip), %rsi      # 0x50bb
leaq 0xa0(%rsp), %rdi
leaq 0xe0(%rsp), %rdx
callq 0x2f63
leaq 0x2505(%rip), %rdx      # 0x508e
leaq 0x50(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x2f44
leaq 0x50(%rsp), %r14
movq (%r14), %rdi
leaq 0x24fc(%rip), %rsi      # 0x50a6
callq 0x2180
movq %rax, %rbx
movq %r14, %rdi
callq 0x20a0
leaq 0xa0(%rsp), %rdi
callq 0x20a0
leaq 0xe0(%rsp), %rdi
callq 0x20a0
leaq 0x24ee(%rip), %r14      # 0x50c9
xorl %r15d, %r15d
cmpq %r15, 0x18(%rsp)
je 0x2c03
movq 0xc0(%rsp), %rax
movl (%rax,%r15,4), %edx
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x21c0
incq %r15
jmp 0x2bde
movq %rbx, %rdi
callq 0x2130
leaq 0xc0(%rsp), %rdi
callq 0x37b8
leaq 0x100(%rsp), %rdi
callq 0x37b8
leaq 0x70(%rsp), %rdi
callq 0x37b8
leaq 0x30(%rsp), %rdi
callq 0x37b8
xorl %eax, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %ebx
movq 0x30(%rsp), %rax
movslq (%rax,%rbx,4), %rax
imulq $0x18, %rax, %rdi
addq 0x3631d(%rip), %rdi     # 0x38f80
callq 0x2511
movq 0x70(%rsp), %rax
movslq (%rax,%rbx,4), %rax
imulq $0x18, %rax, %rdi
addq 0x36304(%rip), %rdi     # 0x38f80
callq 0x2511
movl %r14d, %ebx
movq 0x30(%rsp), %rax
movslq (%rax,%rbx,4), %rax
imulq $0x18, %rax, %rdi
addq 0x362e8(%rip), %rdi     # 0x38f80
callq 0x2511
movq 0x70(%rsp), %rax
movslq (%rax,%rbx,4), %rax
imulq $0x18, %rax, %rdi
addq 0x362cf(%rip), %rdi     # 0x38f80
callq 0x2511
xorl %edi, %edi
callq 0x2190
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x20a0
jmp 0x2cd2
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
jmp 0x2d23
jmp 0x2d3f
jmp 0x2d3f
jmp 0x2d3f
jmp 0x2d3f
jmp 0x2d01
jmp 0x2d01
jmp 0x2cea
movq %rax, %rbx
jmp 0x2d11
jmp 0x2cf1
movq %rax, %rbx
jmp 0x2d1e
jmp 0x2d3f
jmp 0x2cfa
movq %rax, %rbx
jmp 0x2d70
jmp 0x2d3f
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x20a0
leaq 0xa0(%rsp), %rdi
callq 0x20a0
leaq 0x50(%rsp), %rdi
callq 0x20a0
jmp 0x2d42
jmp 0x2d2c
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x20a0
jmp 0x2d70
jmp 0x2d3f
jmp 0x2d3f
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x37b8
leaq 0x100(%rsp), %rdi
callq 0x37b8
leaq 0x70(%rsp), %rdi
callq 0x37b8
leaq 0x30(%rsp), %rdi
callq 0x37b8
movq %rbx, %rdi
callq 0x2240