// File: /workspace/github_cpp_makefile_star2_O3/thunlp[P]KB2E/TransE/Train_TransE.cpp
// Function: Train::bfgs()
void bfgs()
    {
        res=0;
        int nbatches=100;
        int nepoch = 1000;
        int batchsize = fb_h.size()/nbatches;
            for (int epoch=0; epoch<nepoch; epoch++)
            {

            	res=0;
             	for (int batch = 0; batch<nbatches; batch++)
             	{
             		relation_tmp=relation_vec;
            		entity_tmp = entity_vec;
             		for (int k=0; k<batchsize; k++)
             		{
						int i=rand_max(fb_h.size());
						int j=rand_max(entity_num);
						double pr = 1000*right_num[fb_r[i]]/(right_num[fb_r[i]]+left_num[fb_r[i]]);
						if (method ==0)
                            pr = 500;
						if (rand()%1000<pr)
						{
							while (ok[make_pair(fb_h[i],fb_r[i])].count(j)>0)
								j=rand_max(entity_num);
							train_kb(fb_h[i],fb_l[i],fb_r[i],fb_h[i],j,fb_r[i]);
						}
						else
						{
							while (ok[make_pair(j,fb_r[i])].count(fb_l[i])>0)
								j=rand_max(entity_num);
							train_kb(fb_h[i],fb_l[i],fb_r[i],j,fb_l[i],fb_r[i]);
						}
                		norm(relation_tmp[fb_r[i]]);
                		norm(entity_tmp[fb_h[i]]);
                		norm(entity_tmp[fb_l[i]]);
                		norm(entity_tmp[j]);
             		}
		            relation_vec = relation_tmp;
		            entity_vec = entity_tmp;
             	}
                cout<<"epoch:"<<epoch<<' '<<res<<endl;
                FILE* f2 = fopen(("relation2vec."+version).c_str(),"w");
                FILE* f3 = fopen(("entity2vec."+version).c_str(),"w");
                for (int i=0; i<relation_num; i++)
                {
                    for (int ii=0; ii<n; ii++)
                        fprintf(f2,"%.6lf\t",relation_vec[i][ii]);
                    fprintf(f2,"\n");
                }
                for (int i=0; i<entity_num; i++)
                {
                    for (int ii=0; ii<n; ii++)
                        fprintf(f3,"%.6lf\t",entity_vec[i][ii]);
                    fprintf(f3,"\n");
                }
                fclose(f2);
                fclose(f3);
            }
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
movq 0x70(%rdi), %rax
subq 0x68(%rdi), %rax
sarq $0x2, %rax
shrq $0x2, %rax
movabsq $0x28f5c28f5c28f5c3, %rcx # imm = 0x28F5C28F5C28F5C3
mulq %rcx
shrq $0x2, %rdx
movq %rdx, 0x70(%rsp)
leaq 0xc8(%rdi), %r14
leaq 0xf8(%rdi), %r15
leaq 0xe0(%rdi), %r12
leaq 0x110(%rdi), %rbp
movq $0x0, 0x18(%rsp)
leaq 0x30(%rsp), %r13
movq %r14, 0x68(%rsp)
movq %r15, 0x60(%rsp)
movq %r12, 0x58(%rsp)
movq %rbp, 0x50(%rsp)
movq $0x0, 0x38(%rbx)
xorl %eax, %eax
movl %eax, 0x2c(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x4c12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x4c12
cmpl $0x0, 0x70(%rsp)
jle 0x4645
xorl %r15d, %r15d
movq 0x70(%rbx), %rsi
subq 0x68(%rbx), %rsi
shrq $0x2, %rsi
movq %rbx, %rdi
callq 0x4db0
movl %eax, %ebp
movl 0x36b65(%rip), %esi     # 0x3af34
movq %rbx, %rdi
callq 0x4db0
movl %eax, %r12d
movslq %ebp, %rbp
leaq (,%rbp,4), %r14
movq 0x98(%rbx), %rsi
addq %r14, %rsi
leaq 0x36c92(%rip), %r13     # 0x3b088
movq %r13, %rdi
callq 0x36ac
movsd (%rax), %xmm0
mulsd 0x2c3e(%rip), %xmm0     # 0x7048
movsd %xmm0, 0x10(%rsp)
movq 0x98(%rbx), %rsi
addq %r14, %rsi
movq %r13, %rdi
callq 0x36ac
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x98(%rbx), %rsi
addq %r14, %rsi
leaq 0x36c1b(%rip), %rdi     # 0x3b058
callq 0x36ac
cmpl $0x0, 0x34(%rbx)
movsd 0x2c02(%rip), %xmm0     # 0x7050
je 0x4464
movsd 0x20(%rsp), %xmm1
addsd (%rax), %xmm1
movsd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x2080
cltq
imulq $0x10624dd3, %rax, %rcx # imm = 0x10624DD3
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x26, %rcx
addl %edx, %ecx
imull $0x3e8, %ecx, %ecx      # imm = 0x3E8
subl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
leaq 0x30(%rsp), %r13
jbe 0x4517
movq 0x68(%rbx), %rax
movq 0x98(%rbx), %rcx
movl (%rax,%rbp,4), %eax
movl (%rcx,%rbp,4), %ecx
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, 0x30(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3da2
movq 0x10(%rax), %rcx
testq %rcx, %rcx
je 0x4565
addq $0x8, %rax
movq %rax, %rdx
xorl %esi, %esi
cmpl %r12d, 0x20(%rcx)
setl %sil
cmovgeq %rcx, %rdx
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x44e1
cmpq %rax, %rdx
je 0x4565
cmpl 0x20(%rdx), %r12d
jl 0x4565
movl 0x36a2a(%rip), %esi     # 0x3af34
movq %rbx, %rdi
callq 0x4db0
movl %eax, %r12d
jmp 0x44a5
movq 0x98(%rbx), %rax
movl (%rax,%rbp,4), %eax
shlq $0x20, %rax
movl %r12d, %ecx
orq %rax, %rcx
movq %rcx, 0x30(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3da2
movq 0x80(%rbx), %rsi
addq %r14, %rsi
movq %rax, %rdi
callq 0x4df4
testq %rax, %rax
je 0x458e
movl 0x369dc(%rip), %esi     # 0x3af34
movq %rbx, %rdi
callq 0x4db0
movl %eax, %r12d
jmp 0x4517
movq 0x68(%rbx), %rax
movq 0x80(%rbx), %rcx
movl (%rax,%rbp,4), %esi
movl (%rcx,%rbp,4), %edx
movq 0x98(%rbx), %rax
movl (%rax,%rbp,4), %ecx
movl %ecx, (%rsp)
movq %rbx, %rdi
movl %esi, %r8d
movl %r12d, %r9d
jmp 0x45b5
movq 0x68(%rbx), %rax
movq 0x80(%rbx), %rcx
movl (%rax,%rbp,4), %esi
movl (%rcx,%rbp,4), %edx
movq 0x98(%rbx), %rax
movl (%rax,%rbp,4), %ecx
movl %ecx, (%rsp)
movq %rbx, %rdi
movl %r12d, %r8d
movl %edx, %r9d
callq 0x4e3c
movq 0x98(%rbx), %rax
movslq (%rax,%rbp,4), %rax
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0xf8(%rbx), %rsi
movq %rbx, %rdi
callq 0x4280
movq 0x68(%rbx), %rax
movslq (%rax,%rbp,4), %rax
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x110(%rbx), %rsi
movq %rbx, %rdi
callq 0x4280
movq 0x80(%rbx), %rax
movslq (%rax,%rbp,4), %rax
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x110(%rbx), %rsi
movq %rbx, %rdi
callq 0x4280
movslq %r12d, %rax
leaq (%rax,%rax,2), %rsi
shlq $0x3, %rsi
addq 0x110(%rbx), %rsi
movq %rbx, %rdi
callq 0x4280
incl %r15d
cmpl 0x70(%rsp), %r15d
jne 0x43b3
movq 0x68(%rsp), %r14
movq %r14, %rdi
movq 0x60(%rsp), %r15
movq %r15, %rsi
callq 0x4c12
movq 0x58(%rsp), %r12
movq %r12, %rdi
movq 0x50(%rsp), %rbp
movq %rbp, %rsi
callq 0x4c12
movl 0x2c(%rsp), %eax
incl %eax
cmpl $0x64, %eax
jne 0x438b
movl $0x6, %edx
movq 0x594e(%rip), %r14      # 0x9fd8
movq %r14, %rdi
leaq 0x2af6(%rip), %rsi      # 0x718a
callq 0x21f0
movq %r14, %rdi
movq 0x18(%rsp), %rsi
callq 0x22d0
movb $0x20, 0x30(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x21f0
movsd 0x38(%rbx), %xmm0
movq %rax, %rdi
callq 0x22a0
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq %r13, %rdi
leaq 0x2a95(%rip), %rsi      # 0x7191
leaq 0x5ac5(%rip), %rdx      # 0xa1c8
callq 0x4edf
movq 0x30(%rsp), %rdi
leaq 0x2a8b(%rip), %rsi      # 0x719f
callq 0x2200
movq %rax, %r14
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4738
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21d0
movq %r14, 0x10(%rsp)
movq %r13, %rdi
leaq 0x2a5a(%rip), %rsi      # 0x71a1
leaq 0x5a7a(%rip), %rdx      # 0xa1c8
callq 0x4edf
movq 0x30(%rsp), %rdi
leaq 0x2a40(%rip), %rsi      # 0x719f
callq 0x2200
movq %rax, 0x20(%rsp)
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x4785
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21d0
cmpl $0x0, 0x367a4(%rip)     # 0x3af30
jle 0x47f0
xorl %r14d, %r14d
cmpl $0x0, 0x30(%rbx)
leaq 0x2a11(%rip), %r12      # 0x71ad
movq 0x10(%rsp), %rbp
jle 0x47d4
xorl %r15d, %r15d
movq 0xc8(%rbx), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax,%r15,8), %xmm0
movq %rbp, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x2240
incq %r15
movslq 0x30(%rbx), %rax
cmpq %rax, %r15
jl 0x47a6
movl $0xa, %edi
movq %rbp, %rsi
callq 0x2220
incq %r14
movslq 0x36745(%rip), %rax     # 0x3af30
cmpq %rax, %r14
jl 0x4791
cmpl $0x0, 0x3673d(%rip)     # 0x3af34
movq 0x20(%rsp), %rbp
jle 0x485b
xorl %r14d, %r14d
cmpl $0x0, 0x30(%rbx)
leaq 0x29a1(%rip), %r12      # 0x71ad
jle 0x483f
xorl %r15d, %r15d
movq 0xe0(%rbx), %rax
leaq (%r14,%r14,2), %rcx
movq (%rax,%rcx,8), %rax
movsd (%rax,%r15,8), %xmm0
movq %rbp, %rdi
movq %r12, %rsi
movb $0x1, %al
callq 0x2240
incq %r15
movslq 0x30(%rbx), %rax
cmpq %rax, %r15
jl 0x4811
movl $0xa, %edi
movq %rbp, %rsi
callq 0x2220
incq %r14
movslq 0x366de(%rip), %rax     # 0x3af34
cmpq %rax, %r14
jl 0x4801
movq 0x10(%rsp), %rdi
callq 0x21b0
movq %rbp, %rdi
callq 0x21b0
movq 0x18(%rsp), %rax
incl %eax
movq %rax, 0x18(%rsp)
cmpl $0x3e8, %eax            # imm = 0x3E8
movq 0x68(%rsp), %r14
movq 0x60(%rsp), %r15
movq 0x58(%rsp), %r12
movq 0x50(%rsp), %rbp
jne 0x4381
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop