// File: thunlp[P]KB2E/cluster/prepare.cpp
// Function: main
int main()
{
    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++;
	}
	fclose(f1);
	fclose(f2);
    FILE* f_ent_vec = fopen("../TransE/entity2vec.txt2","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]);
        }
    }
    fclose(f_ent_vec);
    FILE* f_kb_train = fopen("../data/train.txt","r");
    vector<int> train_e1,train_e2,train_rel,train_index,train_cluster;
    int train_num=0;
	while (fscanf(f_kb_train,"%s",buf)==1)
    {
        string s1=buf;
        fscanf(f_kb_train,"%s",buf);
        string s2=buf;
        fscanf(f_kb_train,"%s",buf);
        string s3=buf;
        int e1 = entity2id[s1];
        int e2 = entity2id[s2];
        int rel = relation2id[s3];
        train_num+=1;
        train_e1.push_back(e1);
        train_e2.push_back(e2);
        train_rel.push_back(rel);
    }
    train_cluster.resize(train_num);
    fclose(f_kb_train);
    int cluster_num=0;
    map<int,int> cluster2id;
    rel_cluster_set.resize(relation_num);
    for (int rel =0; rel<relation_num; rel++)
    {
        map<int,int> ok;
        ok.clear();
        string s;
        stringstream ss;
        ss<<rel;
        ss>>s;
        cout<<s<<endl;
        FILE* f_index = fopen(("data/id2index"+s+".txt").c_str(),"r");
        FILE* f_cluster = fopen(("data/cluster"+s+".txt").c_str(),"r");
        int x,y;
        while (fscanf(f_index,"%d",&x)==1)
        {
            if (f_cluster!=NULL)
                fscanf(f_cluster,"%d",&y);
            else
                y=0;
            if (ok.count(y)==0)
            {
                ok[y]=cluster_num;
                cluster2id[cluster_num]=x;
                rel_cluster_set[train_rel[x]].push_back(cluster_num);

                cluster_size.push_back(0);
                vector<double> tmp;
                tmp.resize(vec_size);
                cluster_center.push_back(tmp);
                cluster_num+=1;
            }
            for (int ii=0; ii<vec_size; ii++)
                cluster_center[ok[y]][ii]+=entity_vec[train_e1[x]][ii]-entity_vec[train_e2[x]][ii];
            train_cluster[x]=ok[y];
            cluster_size[ok[y]]+=1;
        }
        fclose(f_index);
        if (f_cluster!=NULL)
            fclose(f_cluster);
    }
    FILE* f_train_cluster = fopen("output/train_cluster.txt","w");
    for (int i=0; i<train_num; i++)
        fprintf(f_train_cluster,"%d\n",train_cluster[i]);
    fclose(f_train_cluster);
    cout<<cluster_num<<endl;
    FILE* f_test_cluster = fopen("output/test_cluster.txt","w");
    FILE* f_kb_test = fopen("../data/test.txt","r");
   // for (int i=0; i<cluster_num; i++)
   // {
  //      cout<<cluster_center[i][0]/cluster_size[i]<<endl;
   // }
    int step=0;
	while (fscanf(f_kb_test,"%s",buf)==1)
    {
        cout<<step++<<endl;
        string s1=buf;
        fscanf(f_kb_test,"%s",buf);
        string s2=buf;
        fscanf(f_kb_test,"%s",buf);
        string s3=buf;
        int e1 = entity2id[s1];
        int e2 = entity2id[s2];
        int rel = relation2id[s3];
       // cout<<"here"<<endl;
        for (int h=0; h<entity_num; h++)
        {
            double dis = 1e9;
            int k=-1;
            for (int i=0; i<rel_cluster_set[rel].size(); i++)
            {
                double tmp = 0;
                int x = rel_cluster_set[rel][i];
               // cout<<x<<' '<<rel_cluster_set[rel][i]<<' '<<h<<' '<<train_e1[x]<<' '<<train_e2[x]<<endl;
                for (int ii=0; ii<50; ii++)
                    tmp+=sqr(entity_vec[h][ii]-entity_vec[e2][ii]-cluster_center[x][ii]/cluster_size[x]);

               // cout<<x<<endl;
                if (tmp<dis)
                {
                    dis = tmp;
                    k = rel_cluster_set[rel][i];
                }
            }
            fprintf(f_test_cluster,"%d\t",k);
        }

       // cout<<"here"<<endl;
        fprintf(f_test_cluster,"\n");
        for (int t=0; t<entity_num; t++)
        {
            double dis = 1e9;
            int k=-1;
            for (int i=0; i<rel_cluster_set[rel].size(); i++)
            {
                double tmp = 0;
                int x = rel_cluster_set[rel][i];
                for (int ii=0; ii<50; ii++)
                    tmp+=sqr(entity_vec[e1][ii]-entity_vec[t][ii]-cluster_center[x][ii]/cluster_size[x]);
               // cout<<"tmp="<<tmp<<' '<<rel_cluster_set[rel][i]<<endl;
                if (tmp<dis)
                {
                    dis = tmp;
                    k = rel_cluster_set[rel][i];
                }
            }
            fprintf(f_test_cluster,"%d\t",k);
        }
        fprintf(f_test_cluster,"\n");
    }
    fclose(f_kb_test);
    return 0;
}

// Assembly:
subq $0x728, %rsp            # imm = 0x728
movl $0x0, 0x724(%rsp)
leaq 0xa947(%rip), %rdi      # 0xd010
leaq 0xa9bf(%rip), %rsi      # 0xd08f
callq 0x2280
movq %rax, 0x718(%rsp)
leaq 0xa942(%rip), %rdi      # 0xd026
leaq 0xa9a4(%rip), %rsi      # 0xd08f
callq 0x2280
movq %rax, 0x710(%rsp)
movq 0x718(%rsp), %rdi
leaq 0xa937(%rip), %rsi      # 0xd03e
leaq 0x10bc2(%rip), %rdx     # 0x132d0
leaq 0x70c(%rsp), %rcx
movb $0x0, %al
callq 0x2370
cmpl $0x2, %eax
jne 0x2845
leaq 0x6e7(%rsp), %rdi
movq %rdi, 0x1b0(%rsp)
callq 0x2350
movq 0x1b0(%rsp), %rdx
leaq 0x10b86(%rip), %rsi     # 0x132d0
leaq 0x6e8(%rsp), %rdi
callq 0x4120
jmp 0x2759
leaq 0x6e7(%rsp), %rdi
callq 0x2250
movl 0x70c(%rsp), %eax
movl %eax, 0x1a4(%rsp)
leaq 0x10abd(%rip), %rdi     # 0x13238
leaq 0x6e8(%rsp), %rsi
callq 0x41e0
movq %rax, 0x1a8(%rsp)
jmp 0x2792
movq 0x1a8(%rsp), %rax
movl 0x1a4(%rsp), %ecx
movl %ecx, (%rax)
leaq 0x10abe(%rip), %rdi     # 0x13268
leaq 0x70c(%rsp), %rsi
callq 0x42d0
movq %rax, 0x198(%rsp)
jmp 0x27c1
movq 0x198(%rsp), %rdi
leaq 0x6e8(%rsp), %rsi
callq 0x2040
jmp 0x27d8
movl 0x10aea(%rip), %eax     # 0x132c8
addl $0x1, %eax
movl %eax, 0x10ae1(%rip)     # 0x132c8
leaq 0x6e8(%rsp), %rdi
callq 0x2130
jmp 0x26f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x6e7(%rsp), %rdi
callq 0x2250
jmp 0x3f7c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x6e8(%rsp), %rdi
callq 0x2130
jmp 0x3f7c
jmp 0x2847
movq 0x710(%rsp), %rdi
leaq 0xa7e8(%rip), %rsi      # 0xd03e
leaq 0x10a73(%rip), %rdx     # 0x132d0
leaq 0x70c(%rsp), %rcx
movb $0x0, %al
callq 0x2370
cmpl $0x2, %eax
jne 0x2994
leaq 0x6af(%rsp), %rdi
movq %rdi, 0x190(%rsp)
callq 0x2350
movq 0x190(%rsp), %rdx
leaq 0x10a37(%rip), %rsi     # 0x132d0
leaq 0x6b0(%rsp), %rdi
callq 0x4120
jmp 0x28a8
leaq 0x6af(%rsp), %rdi
callq 0x2250
movl 0x70c(%rsp), %eax
movl %eax, 0x184(%rsp)
leaq 0x1093e(%rip), %rdi     # 0x13208
leaq 0x6b0(%rsp), %rsi
callq 0x41e0
movq %rax, 0x188(%rsp)
jmp 0x28e1
movq 0x188(%rsp), %rax
movl 0x184(%rsp), %ecx
movl %ecx, (%rax)
leaq 0x1099f(%rip), %rdi     # 0x13298
leaq 0x70c(%rsp), %rsi
callq 0x42d0
movq %rax, 0x178(%rsp)
jmp 0x2910
movq 0x178(%rsp), %rdi
leaq 0x6b0(%rsp), %rsi
callq 0x2040
jmp 0x2927
movl 0x1099f(%rip), %eax     # 0x132cc
addl $0x1, %eax
movl %eax, 0x10996(%rip)     # 0x132cc
leaq 0x6b0(%rsp), %rdi
callq 0x2130
jmp 0x2847
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x6af(%rsp), %rdi
callq 0x2250
jmp 0x3f7c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x6b0(%rsp), %rdi
callq 0x2130
jmp 0x3f7c
movq 0x718(%rsp), %rdi
callq 0x21f0
movq 0x710(%rsp), %rdi
callq 0x21f0
leaq 0xa68e(%rip), %rdi      # 0xd043
leaq 0xa6d3(%rip), %rsi      # 0xd08f
callq 0x2280
movq %rax, 0x6a0(%rsp)
movl $0x32, 0x69c(%rsp)
movslq 0x108ed(%rip), %rsi     # 0x132c8
leaq 0x4162e(%rip), %rdi     # 0x44010
callq 0x43c0
movl $0x0, 0x698(%rsp)
movl 0x698(%rsp), %eax
cmpl 0x108c9(%rip), %eax     # 0x132c8
jge 0x2abc
movslq 0x698(%rsp), %rsi
leaq 0x415fc(%rip), %rdi     # 0x44010
callq 0x4460
movq %rax, %rdi
movslq 0x69c(%rsp), %rsi
callq 0x4480
movl $0x0, 0x694(%rsp)
movl 0x694(%rsp), %eax
cmpl 0x69c(%rsp), %eax
jge 0x2aa4
movq 0x6a0(%rsp), %rax
movq %rax, 0x170(%rsp)
movslq 0x698(%rsp), %rsi
leaq 0x415ad(%rip), %rdi     # 0x44010
callq 0x4460
movq %rax, %rdi
movslq 0x694(%rsp), %rsi
callq 0x4520
movq 0x170(%rsp), %rdi
movq %rax, %rdx
leaq 0xa5d3(%rip), %rsi      # 0xd05d
movb $0x0, %al
callq 0x2370
movl 0x694(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x694(%rsp)
jmp 0x2a34
jmp 0x2aa6
movl 0x698(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x698(%rsp)
jmp 0x29f2
movq 0x6a0(%rsp), %rdi
callq 0x21f0
leaq 0xa591(%rip), %rdi      # 0xd061
leaq 0xa5b8(%rip), %rsi      # 0xd08f
callq 0x2280
movq %rax, 0x688(%rsp)
leaq 0x670(%rsp), %rdi
callq 0x40b0
leaq 0x658(%rsp), %rdi
callq 0x40b0
leaq 0x640(%rsp), %rdi
callq 0x40b0
leaq 0x628(%rsp), %rdi
callq 0x40b0
leaq 0x610(%rsp), %rdi
callq 0x40b0
movl $0x0, 0x60c(%rsp)
movq 0x688(%rsp), %rdi
leaq 0xa534(%rip), %rsi      # 0xd073
leaq 0x1078a(%rip), %rdx     # 0x132d0
xorl %eax, %eax
callq 0x2370
movl %eax, 0x16c(%rsp)
jmp 0x2b56
movl 0x16c(%rsp), %eax
cmpl $0x1, %eax
jne 0x2e66
leaq 0x5e7(%rsp), %rdi
movq %rdi, 0x160(%rsp)
callq 0x2350
movq 0x160(%rsp), %rdx
leaq 0x10746(%rip), %rsi     # 0x132d0
leaq 0x5e8(%rsp), %rdi
callq 0x4120
jmp 0x2b99
leaq 0x5e7(%rsp), %rdi
callq 0x2250
movq 0x688(%rsp), %rdi
leaq 0xa4be(%rip), %rsi      # 0xd073
leaq 0x10714(%rip), %rdx     # 0x132d0
xorl %eax, %eax
callq 0x2370
jmp 0x2bc5
leaq 0x5bf(%rsp), %rdi
movq %rdi, 0x158(%rsp)
callq 0x2350
movq 0x158(%rsp), %rdx
leaq 0x106e7(%rip), %rsi     # 0x132d0
leaq 0x5c0(%rsp), %rdi
callq 0x4120
jmp 0x2bf8
leaq 0x5bf(%rsp), %rdi
callq 0x2250
movq 0x688(%rsp), %rdi
leaq 0xa45f(%rip), %rsi      # 0xd073
leaq 0x106b5(%rip), %rdx     # 0x132d0
xorl %eax, %eax
callq 0x2370
jmp 0x2c24
leaq 0x597(%rsp), %rdi
movq %rdi, 0x150(%rsp)
callq 0x2350
movq 0x150(%rsp), %rdx
leaq 0x10688(%rip), %rsi     # 0x132d0
leaq 0x598(%rsp), %rdi
callq 0x4120
jmp 0x2c57
leaq 0x597(%rsp), %rdi
callq 0x2250
leaq 0x105cd(%rip), %rdi     # 0x13238
leaq 0x5e8(%rsp), %rsi
callq 0x41e0
movq %rax, 0x148(%rsp)
jmp 0x2c82
movq 0x148(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x590(%rsp)
leaq 0x1059e(%rip), %rdi     # 0x13238
leaq 0x5c0(%rsp), %rsi
callq 0x41e0
movq %rax, 0x140(%rsp)
jmp 0x2cb1
movq 0x140(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x58c(%rsp)
leaq 0x1053f(%rip), %rdi     # 0x13208
leaq 0x598(%rsp), %rsi
callq 0x41e0
movq %rax, 0x138(%rsp)
jmp 0x2ce0
movq 0x138(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x588(%rsp)
movl 0x60c(%rsp), %eax
incl %eax
movl %eax, 0x60c(%rsp)
leaq 0x670(%rsp), %rdi
leaq 0x590(%rsp), %rsi
callq 0x4540
jmp 0x2d18
leaq 0x658(%rsp), %rdi
leaq 0x58c(%rsp), %rsi
callq 0x4540
jmp 0x2d2f
leaq 0x640(%rsp), %rdi
leaq 0x588(%rsp), %rsi
callq 0x4540
jmp 0x2d46
leaq 0x598(%rsp), %rdi
callq 0x2130
leaq 0x5c0(%rsp), %rdi
callq 0x2130
leaq 0x5e8(%rsp), %rdi
callq 0x2130
jmp 0x2b30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
jmp 0x3f3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x5e7(%rsp), %rdi
callq 0x2250
jmp 0x3f3b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
jmp 0x2e54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x5bf(%rsp), %rdi
callq 0x2250
jmp 0x2e54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
jmp 0x2e47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x597(%rsp), %rdi
callq 0x2250
jmp 0x2e47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x598(%rsp), %rdi
callq 0x2130
leaq 0x5c0(%rsp), %rdi
callq 0x2130
leaq 0x5e8(%rsp), %rdi
callq 0x2130
jmp 0x3f3b
movslq 0x60c(%rsp), %rsi
leaq 0x610(%rsp), %rdi
callq 0x45b0
jmp 0x2e7d
movq 0x688(%rsp), %rdi
callq 0x21f0
jmp 0x2e8c
movl $0x0, 0x584(%rsp)
leaq 0x550(%rsp), %rdi
callq 0x4650
movslq 0x10421(%rip), %rsi     # 0x132cc
leaq 0x41176(%rip), %rdi     # 0x44028
callq 0x4660
jmp 0x2eb9
movl $0x0, 0x54c(%rsp)
movl 0x54c(%rsp), %eax
cmpl 0x103fb(%rip), %eax     # 0x132cc
jge 0x35b5
leaq 0x518(%rsp), %rdi
movq %rdi, 0x130(%rsp)
callq 0x4650
movq 0x130(%rsp), %rdi
callq 0x4700
leaq 0x4f8(%rsp), %rdi
callq 0x22b0
leaq 0x370(%rsp), %rdi
callq 0x2170
jmp 0x2f15
leaq 0x380(%rsp), %rdi
movl 0x54c(%rsp), %esi
callq 0x2330
jmp 0x2f2b
leaq 0x370(%rsp), %rdi
leaq 0x4f8(%rsp), %rsi
callq 0x22a0
jmp 0x2f42
movq 0x1008f(%rip), %rdi     # 0x12fd8
leaq 0x4f8(%rsp), %rsi
callq 0x21e0
movq %rax, 0x128(%rsp)
jmp 0x2f60
movq 0x128(%rsp), %rdi
movq 0x10059(%rip), %rsi     # 0x12fc8
callq 0x2230
jmp 0x2f76
leaq 0xa0f9(%rip), %rsi      # 0xd076
leaq 0x328(%rsp), %rdi
leaq 0x4f8(%rsp), %rdx
callq 0x4760
jmp 0x2f94
leaq 0xa09e(%rip), %rdx      # 0xd039
leaq 0x348(%rsp), %rdi
leaq 0x328(%rsp), %rsi
callq 0x4710
jmp 0x2fb2
leaq 0x348(%rsp), %rdi
callq 0x20c0
movq %rax, %rdi
leaq 0xa0c6(%rip), %rsi      # 0xd08f
callq 0x2280
movq %rax, 0x120(%rsp)
jmp 0x2fd8
leaq 0x348(%rsp), %rdi
callq 0x2130
leaq 0x328(%rsp), %rdi
callq 0x2130
movq 0x120(%rsp), %rax
movq %rax, 0x368(%rsp)
leaq 0xa07b(%rip), %rsi      # 0xd084
leaq 0x2e0(%rsp), %rdi
leaq 0x4f8(%rsp), %rdx
callq 0x4760
jmp 0x3020
leaq 0xa012(%rip), %rdx      # 0xd039
leaq 0x300(%rsp), %rdi
leaq 0x2e0(%rsp), %rsi
callq 0x4710
jmp 0x303e
leaq 0x300(%rsp), %rdi
callq 0x20c0
movq %rax, %rdi
leaq 0xa03a(%rip), %rsi      # 0xd08f
callq 0x2280
movq %rax, 0x118(%rsp)
jmp 0x3064
leaq 0x300(%rsp), %rdi
callq 0x2130
leaq 0x2e0(%rsp), %rdi
callq 0x2130
movq 0x118(%rsp), %rax
movq %rax, 0x320(%rsp)
movq 0x368(%rsp), %rdi
leaq 0x9fa3(%rip), %rsi      # 0xd040
xorl %eax, %eax
leaq 0x2dc(%rsp), %rdx
callq 0x2370
movl %eax, 0x114(%rsp)
jmp 0x30b5
movl 0x114(%rsp), %eax
cmpl $0x1, %eax
jne 0x3521
cmpq $0x0, 0x320(%rsp)
je 0x31d6
movq 0x320(%rsp), %rdi
leaq 0x9f5d(%rip), %rsi      # 0xd040
xorl %eax, %eax
leaq 0x2d8(%rsp), %rdx
callq 0x2370
jmp 0x30f4
jmp 0x31e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
jmp 0x3f2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
jmp 0x3596
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
jmp 0x3589
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
jmp 0x317b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x348(%rsp), %rdi
callq 0x2130
leaq 0x328(%rsp), %rdi
callq 0x2130
jmp 0x3589
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
jmp 0x31c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x300(%rsp), %rdi
callq 0x2130
leaq 0x2e0(%rsp), %rdi
callq 0x2130
jmp 0x3589
movl $0x0, 0x2d8(%rsp)
leaq 0x518(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
callq 0x4890
movq %rax, 0x108(%rsp)
jmp 0x3200
movq 0x108(%rsp), %rax
cmpq $0x0, %rax
jne 0x336d
movl 0x584(%rsp), %eax
movl %eax, 0xfc(%rsp)
leaq 0x518(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
callq 0x48f0
movq %rax, 0x100(%rsp)
jmp 0x323f
movq 0x100(%rsp), %rax
movl 0xfc(%rsp), %ecx
movl %ecx, (%rax)
movl 0x2dc(%rsp), %eax
movl %eax, 0xec(%rsp)
leaq 0x550(%rsp), %rdi
leaq 0x584(%rsp), %rsi
callq 0x48f0
movq %rax, 0xf0(%rsp)
jmp 0x327d
movq 0xf0(%rsp), %rax
movl 0xec(%rsp), %ecx
movl %ecx, (%rax)
movslq 0x2dc(%rsp), %rsi
leaq 0x640(%rsp), %rdi
callq 0x4a00
movslq (%rax), %rsi
leaq 0x40d7b(%rip), %rdi     # 0x44028
callq 0x49e0
movq %rax, %rdi
leaq 0x584(%rsp), %rsi
callq 0x4540
jmp 0x32c4
movl $0x0, 0x2d4(%rsp)
leaq 0x40d82(%rip), %rdi     # 0x44058
leaq 0x2d4(%rsp), %rsi
callq 0x4a20
jmp 0x32e5
leaq 0x2b8(%rsp), %rdi
movq %rdi, 0xe0(%rsp)
callq 0x4a50
movq 0xe0(%rsp), %rdi
movslq 0x69c(%rsp), %rsi
callq 0x4480
jmp 0x3311
leaq 0x40d28(%rip), %rdi     # 0x44040
leaq 0x2b8(%rsp), %rsi
callq 0x4a60
jmp 0x3327
movl 0x584(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x584(%rsp)
leaq 0x2b8(%rsp), %rdi
callq 0x4ad0
jmp 0x336d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x2b8(%rsp), %rdi
callq 0x4ad0
jmp 0x3589
movl $0x0, 0x2b4(%rsp)
movl 0x2b4(%rsp), %eax
cmpl 0x69c(%rsp), %eax
jge 0x3491
movslq 0x2dc(%rsp), %rsi
leaq 0x670(%rsp), %rdi
callq 0x4a00
movslq (%rax), %rsi
leaq 0x40c65(%rip), %rdi     # 0x44010
movq %rdi, 0xc0(%rsp)
callq 0x4460
movq %rax, %rdi
movslq 0x2b4(%rsp), %rsi
callq 0x4520
movsd (%rax), %xmm0
movsd %xmm0, 0xc8(%rsp)
movslq 0x2dc(%rsp), %rsi
leaq 0x658(%rsp), %rdi
callq 0x4a00
movq 0xc0(%rsp), %rdi
movslq (%rax), %rsi
callq 0x4460
movq %rax, %rdi
movslq 0x2b4(%rsp), %rsi
callq 0x4520
movsd 0xc8(%rsp), %xmm0
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0xd0(%rsp)
leaq 0x518(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
callq 0x48f0
movq %rax, 0xd8(%rsp)
jmp 0x3443
movq 0xd8(%rsp), %rax
movslq (%rax), %rsi
leaq 0x40beb(%rip), %rdi     # 0x44040
callq 0x4460
movq %rax, %rdi
movslq 0x2b4(%rsp), %rsi
callq 0x4520
movsd 0xd0(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movl 0x2b4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2b4(%rsp)
jmp 0x3378
leaq 0x518(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
callq 0x48f0
movq %rax, 0xb8(%rsp)
jmp 0x34b0
movq 0xb8(%rsp), %rax
movl (%rax), %eax
movl %eax, 0xac(%rsp)
movslq 0x2dc(%rsp), %rsi
leaq 0x610(%rsp), %rdi
callq 0x4a00
movl 0xac(%rsp), %ecx
movl %ecx, (%rax)
leaq 0x518(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
callq 0x48f0
movq %rax, 0xb0(%rsp)
jmp 0x34fe
movq 0xb0(%rsp), %rax
movslq (%rax), %rsi
leaq 0x40b48(%rip), %rdi     # 0x44058
callq 0x4a00
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x308e
movq 0x368(%rsp), %rdi
callq 0x21f0
jmp 0x3530
cmpq $0x0, 0x320(%rsp)
je 0x354c
movq 0x320(%rsp), %rdi
callq 0x21f0
jmp 0x354a
jmp 0x354c
leaq 0x370(%rsp), %rdi
callq 0x2190
leaq 0x4f8(%rsp), %rdi
callq 0x2130
leaq 0x518(%rsp), %rdi
callq 0x4b30
movl 0x54c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54c(%rsp)
jmp 0x2ec4
leaq 0x370(%rsp), %rdi
callq 0x2190
leaq 0x4f8(%rsp), %rdi
callq 0x2130
leaq 0x518(%rsp), %rdi
callq 0x4b30
jmp 0x3f2e
leaq 0x9ad5(%rip), %rdi      # 0xd091
leaq 0x9ae7(%rip), %rsi      # 0xd0aa
callq 0x2280
movq %rax, 0xa0(%rsp)
jmp 0x35d2
movq 0xa0(%rsp), %rax
movq %rax, 0x2a8(%rsp)
movl $0x0, 0x2a4(%rsp)
movl 0x2a4(%rsp), %eax
cmpl 0x60c(%rsp), %eax
jge 0x364d
movq 0x2a8(%rsp), %rax
movq %rax, 0x98(%rsp)
movslq 0x2a4(%rsp), %rsi
leaq 0x610(%rsp), %rdi
callq 0x4a00
movq 0x98(%rsp), %rdi
movl (%rax), %edx
leaq 0x9a79(%rip), %rsi      # 0xd0ac
movb $0x0, %al
callq 0x22c0
movl 0x2a4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2a4(%rsp)
jmp 0x35ed
movq 0x2a8(%rsp), %rdi
callq 0x21f0
jmp 0x365c
movl 0x584(%rsp), %esi
movq 0xf96e(%rip), %rdi      # 0x12fd8
callq 0x2330
movq %rax, 0x90(%rsp)
jmp 0x3679
movq 0x90(%rsp), %rdi
movq 0xf940(%rip), %rsi      # 0x12fc8
callq 0x2230
jmp 0x368f
leaq 0x9a1a(%rip), %rdi      # 0xd0b0
leaq 0x9a0d(%rip), %rsi      # 0xd0aa
callq 0x2280
movq %rax, 0x88(%rsp)
jmp 0x36ac
movq 0x88(%rsp), %rax
movq %rax, 0x298(%rsp)
leaq 0x9a05(%rip), %rdi      # 0xd0c8
leaq 0x99c5(%rip), %rsi      # 0xd08f
callq 0x2280
movq %rax, 0x80(%rsp)
jmp 0x36d9
movq 0x80(%rsp), %rax
movq %rax, 0x290(%rsp)
movl $0x0, 0x28c(%rsp)
movq 0x290(%rsp), %rdi
leaq 0x9970(%rip), %rsi      # 0xd073
leaq 0xfbc6(%rip), %rdx      # 0x132d0
xorl %eax, %eax
callq 0x2370
movl %eax, 0x7c(%rsp)
jmp 0x3717
movl 0x7c(%rsp), %eax
cmpl $0x1, %eax
jne 0x3eb7
movl 0x28c(%rsp), %esi
movl %esi, %eax
incl %eax
movl %eax, 0x28c(%rsp)
movq 0xf89b(%rip), %rdi      # 0x12fd8
callq 0x2330
movq %rax, 0x70(%rsp)
jmp 0x3749
movq 0x70(%rsp), %rdi
movq 0xf873(%rip), %rsi      # 0x12fc8
callq 0x2230
jmp 0x375c
leaq 0x267(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x2350
movq 0x68(%rsp), %rdx
leaq 0xfb56(%rip), %rsi      # 0x132d0
leaq 0x268(%rsp), %rdi
callq 0x4120
jmp 0x3789
leaq 0x267(%rsp), %rdi
callq 0x2250
movq 0x290(%rsp), %rdi
leaq 0x98ce(%rip), %rsi      # 0xd073
leaq 0xfb24(%rip), %rdx      # 0x132d0
xorl %eax, %eax
callq 0x2370
jmp 0x37b5
leaq 0x23f(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x2350
movq 0x60(%rsp), %rdx
leaq 0xfafd(%rip), %rsi      # 0x132d0
leaq 0x240(%rsp), %rdi
callq 0x4120
jmp 0x37e2
leaq 0x23f(%rsp), %rdi
callq 0x2250
movq 0x290(%rsp), %rdi
leaq 0x9875(%rip), %rsi      # 0xd073
leaq 0xfacb(%rip), %rdx      # 0x132d0
xorl %eax, %eax
callq 0x2370
jmp 0x380e
leaq 0x217(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x2350
movq 0x58(%rsp), %rdx
leaq 0xfaa4(%rip), %rsi      # 0x132d0
leaq 0x218(%rsp), %rdi
callq 0x4120
jmp 0x383b
leaq 0x217(%rsp), %rdi
callq 0x2250
leaq 0xf9e9(%rip), %rdi      # 0x13238
leaq 0x268(%rsp), %rsi
callq 0x41e0
movq %rax, 0x50(%rsp)
jmp 0x3863
movq 0x50(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x210(%rsp)
leaq 0xf9c0(%rip), %rdi      # 0x13238
leaq 0x240(%rsp), %rsi
callq 0x41e0
movq %rax, 0x48(%rsp)
jmp 0x388c
movq 0x48(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x20c(%rsp)
leaq 0xf967(%rip), %rdi      # 0x13208
leaq 0x218(%rsp), %rsi
callq 0x41e0
movq %rax, 0x40(%rsp)
jmp 0x38b5
movq 0x40(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x208(%rsp)
movl $0x0, 0x204(%rsp)
movl 0x204(%rsp), %eax
cmpl 0xf9ed(%rip), %eax      # 0x132c8
jge 0x3be9
movsd 0x971f(%rip), %xmm0     # 0xd008
movsd %xmm0, 0x1f8(%rsp)
movl $0xffffffff, 0x1f4(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0x1f0(%rsp)
movslq 0x1f0(%rsp), %rax
movq %rax, 0x38(%rsp)
movslq 0x208(%rsp), %rsi
leaq 0x40704(%rip), %rdi     # 0x44028
callq 0x49e0
movq %rax, %rdi
callq 0x4b40
movq %rax, %rcx
movq 0x38(%rsp), %rax
cmpq %rcx, %rax
jae 0x3bb6
xorps %xmm0, %xmm0
movsd %xmm0, 0x1e8(%rsp)
movslq 0x208(%rsp), %rsi
leaq 0x406cb(%rip), %rdi     # 0x44028
callq 0x49e0
movq %rax, %rdi
movslq 0x1f0(%rsp), %rsi
callq 0x4a00
movl (%rax), %eax
movl %eax, 0x1e4(%rsp)
movl $0x0, 0x1e0(%rsp)
cmpl $0x32, 0x1e0(%rsp)
jge 0x3b47
movslq 0x204(%rsp), %rsi
leaq 0x4066d(%rip), %rdi     # 0x44010
callq 0x4460
movq %rax, %rdi
movslq 0x1e0(%rsp), %rsi
callq 0x4520
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movslq 0x20c(%rsp), %rsi
leaq 0x4063f(%rip), %rdi     # 0x44010
callq 0x4460
movq %rax, %rdi
movslq 0x1e0(%rsp), %rsi
callq 0x4520
movsd 0x20(%rsp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movslq 0x1e4(%rsp), %rsi
leaq 0x4063b(%rip), %rdi     # 0x44040
callq 0x4460
movq %rax, %rdi
movslq 0x1e0(%rsp), %rsi
callq 0x4520
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movslq 0x1e4(%rsp), %rsi
leaq 0x40625(%rip), %rdi     # 0x44058
callq 0x4a00
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm0
cvtsi2sdl (%rax), %xmm2
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
callq 0x2690
addsd 0x1e8(%rsp), %xmm0
movsd %xmm0, 0x1e8(%rsp)
movl 0x1e0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1e0(%rsp)
jmp 0x3986
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x267(%rsp), %rdi
callq 0x2250
jmp 0x3f2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
jmp 0x3ea8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x23f(%rsp), %rdi
callq 0x2250
jmp 0x3ea8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
jmp 0x3e9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x217(%rsp), %rdi
callq 0x2250
jmp 0x3e9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x6d8(%rsp)
movl %eax, 0x6d4(%rsp)
leaq 0x218(%rsp), %rdi
callq 0x2130
jmp 0x3e9b
movsd 0x1e8(%rsp), %xmm1
movsd 0x1f8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3b9e
movsd 0x1e8(%rsp), %xmm0
movsd %xmm0, 0x1f8(%rsp)
movslq 0x208(%rsp), %rsi
leaq 0x404a8(%rip), %rdi     # 0x44028
callq 0x49e0
movq %rax, %rdi
movslq 0x1f0(%rsp), %rsi
callq 0x4a00
movl (%rax), %eax
movl %eax, 0x1f4(%rsp)
jmp 0x3ba0
movl 0x1f0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1f0(%rsp)
jmp 0x3908
movq 0x298(%rsp), %rdi
movl 0x1f4(%rsp), %edx
leaq 0x950d(%rip), %rsi      # 0xd0d9
movb $0x0, %al
callq 0x22c0
movl 0x204(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x204(%rsp)
jmp 0x38ce
movq 0x298(%rsp), %rdi
leaq 0x94b6(%rip), %rsi      # 0xd0ae
movb $0x0, %al
callq 0x22c0
movl $0x0, 0x1dc(%rsp)
movl 0x1dc(%rsp), %eax
cmpl 0xf6b1(%rip), %eax      # 0x132c8
jge 0x3e59
movsd 0x93e3(%rip), %xmm0     # 0xd008
movsd %xmm0, 0x1d0(%rsp)
movl $0xffffffff, 0x1cc(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0x1c8(%rsp)
movslq 0x1c8(%rsp), %rax
movq %rax, 0x18(%rsp)
movslq 0x208(%rsp), %rsi
leaq 0x403c8(%rip), %rdi     # 0x44028
callq 0x49e0
movq %rax, %rdi
callq 0x4b40
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x3e26
xorps %xmm0, %xmm0
movsd %xmm0, 0x1c0(%rsp)
movslq 0x208(%rsp), %rsi
leaq 0x4038f(%rip), %rdi     # 0x44028
callq 0x49e0
movq %rax, %rdi
movslq 0x1c8(%rsp), %rsi
callq 0x4a00
movl (%rax), %eax
movl %eax, 0x1bc(%rsp)
movl $0x0, 0x1b8(%rsp)
cmpl $0x32, 0x1b8(%rsp)
jge 0x3db7
movslq 0x210(%rsp), %rsi
leaq 0x40331(%rip), %rdi     # 0x44010
callq 0x4460
movq %rax, %rdi
movslq 0x1b8(%rsp), %rsi
callq 0x4520
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
movslq 0x1dc(%rsp), %rsi
leaq 0x40304(%rip), %rdi     # 0x44010
callq 0x4460
movq %rax, %rdi
movslq 0x1b8(%rsp), %rsi
callq 0x4520
movsd (%rsp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movslq 0x1bc(%rsp), %rsi
leaq 0x40301(%rip), %rdi     # 0x44040
callq 0x4460
movq %rax, %rdi
movslq 0x1b8(%rsp), %rsi
callq 0x4520
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movslq 0x1bc(%rsp), %rsi
leaq 0x402eb(%rip), %rdi     # 0x44058
callq 0x4a00
movsd 0x8(%rsp), %xmm1
movsd 0x10(%rsp), %xmm0
cvtsi2sdl (%rax), %xmm2
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
callq 0x2690
addsd 0x1c0(%rsp), %xmm0
movsd %xmm0, 0x1c0(%rsp)
movl 0x1b8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1b8(%rsp)
jmp 0x3cc2
movsd 0x1c0(%rsp), %xmm1
movsd 0x1d0(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3e0e
movsd 0x1c0(%rsp), %xmm0
movsd %xmm0, 0x1d0(%rsp)
movslq 0x208(%rsp), %rsi
leaq 0x40238(%rip), %rdi     # 0x44028
callq 0x49e0
movq %rax, %rdi
movslq 0x1c8(%rsp), %rsi
callq 0x4a00
movl (%rax), %eax
movl %eax, 0x1cc(%rsp)
jmp 0x3e10
movl 0x1c8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c8(%rsp)
jmp 0x3c44
movq 0x298(%rsp), %rdi
movl 0x1cc(%rsp), %edx
leaq 0x929d(%rip), %rsi      # 0xd0d9
movb $0x0, %al
callq 0x22c0
movl 0x1dc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1dc(%rsp)
jmp 0x3c0a
movq 0x298(%rsp), %rdi
leaq 0x9246(%rip), %rsi      # 0xd0ae
movb $0x0, %al
callq 0x22c0
leaq 0x218(%rsp), %rdi
callq 0x2130
leaq 0x240(%rsp), %rdi
callq 0x2130
leaq 0x268(%rsp), %rdi
callq 0x2130
jmp 0x36f4
leaq 0x240(%rsp), %rdi
callq 0x2130
leaq 0x268(%rsp), %rdi
callq 0x2130
jmp 0x3f2e
movq 0x290(%rsp), %rdi
callq 0x21f0
jmp 0x3ec6
movl $0x0, 0x724(%rsp)
leaq 0x550(%rsp), %rdi
callq 0x4b30
leaq 0x610(%rsp), %rdi
callq 0x40c0
leaq 0x628(%rsp), %rdi
callq 0x40c0
leaq 0x640(%rsp), %rdi
callq 0x40c0
leaq 0x658(%rsp), %rdi
callq 0x40c0
leaq 0x670(%rsp), %rdi
callq 0x40c0
movl 0x724(%rsp), %eax
addq $0x728, %rsp            # imm = 0x728
retq
leaq 0x550(%rsp), %rdi
callq 0x4b30
leaq 0x610(%rsp), %rdi
callq 0x40c0
leaq 0x628(%rsp), %rdi
callq 0x40c0
leaq 0x640(%rsp), %rdi
callq 0x40c0
leaq 0x658(%rsp), %rdi
callq 0x40c0
leaq 0x670(%rsp), %rdi
callq 0x40c0
movq 0x6d8(%rsp), %rdi
callq 0x2340
nopl (%rax)