// File: thunlp[P]KB2E/TransR/Train_TransR.cpp
// Function: Train::calc_sum(int, int, int, int)
double calc_sum(int e1,int e2,int rel,int same)
    {
    	vector<double> e1_vec;
        e1_vec.resize(m);
        vector<double> e2_vec;
        e2_vec.resize(m);
        for (int ii=0; ii<m; ii++)
        {
            for (int jj=0; jj<n; jj++)
            {
                e1_vec[ii]+=A[rel][jj][ii]*entity_vec[e1][jj];
                e2_vec[ii]+=A[rel][jj][ii]*entity_vec[e2][jj];
            }
        }
        double sum=0;
        if (L1_flag)
        	for (int ii=0; ii<m; ii++)
            	sum+=fabs(e2_vec[ii]-e1_vec[ii]-same*relation_vec[rel][ii]);
        else
        	for (int ii=0; ii<m; ii++)
            	sum+=sqr(e2_vec[ii]-e1_vec[ii]-same*relation_vec[rel][ii]);
        return sum;
    }

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movl %esi, 0xdc(%rsp)
movl %edx, 0xd8(%rsp)
movl %ecx, 0xd4(%rsp)
movl %r8d, 0xd0(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0xb8(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0xa2c0
movq 0x68(%rsp), %rax
movq 0x70(%rsp), %rdi
movslq 0x34(%rax), %rsi
callq 0x8270
jmp 0xe6e0
leaq 0x90(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0xa2c0
movq 0x68(%rsp), %rax
movq 0x60(%rsp), %rdi
movslq 0x34(%rax), %rsi
callq 0x8270
jmp 0xe707
movl $0x0, 0x8c(%rsp)
movq 0x68(%rsp), %rcx
movl 0x8c(%rsp), %eax
cmpl 0x34(%rcx), %eax
jge 0xe902
movl $0x0, 0x88(%rsp)
movq 0x68(%rsp), %rcx
movl 0x88(%rsp), %eax
cmpl 0x30(%rcx), %eax
jge 0xe8ea
movq 0x68(%rsp), %rdi
addq $0x100, %rdi            # imm = 0x100
movslq 0xd4(%rsp), %rsi
callq 0x8190
movq %rax, %rdi
movslq 0x88(%rsp), %rsi
callq 0x8250
movq %rax, %rdi
movslq 0x8c(%rsp), %rsi
callq 0x3c80
movq 0x68(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
addq $0xb8, %rdi
movslq 0xdc(%rsp), %rsi
callq 0x8250
movq %rax, %rdi
movslq 0x88(%rsp), %rsi
callq 0x3c80
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movslq 0x8c(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x3c80
movsd 0x40(%rsp), %xmm0
movsd 0x48(%rsp), %xmm2
movq 0x68(%rsp), %rdi
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
addq $0x100, %rdi            # imm = 0x100
movslq 0xd4(%rsp), %rsi
callq 0x8190
movq %rax, %rdi
movslq 0x88(%rsp), %rsi
callq 0x8250
movq %rax, %rdi
movslq 0x8c(%rsp), %rsi
callq 0x3c80
movq 0x68(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
addq $0xb8, %rdi
movslq 0xd8(%rsp), %rsi
callq 0x8250
movq %rax, %rdi
movslq 0x88(%rsp), %rsi
callq 0x3c80
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
movslq 0x8c(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x3c80
movsd 0x50(%rsp), %xmm0
movsd 0x58(%rsp), %xmm2
movsd (%rax), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movl 0x88(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x88(%rsp)
jmp 0xe732
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
jmp 0xeb25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x6950
jmp 0xeb25
jmp 0xe8ec
movl 0x8c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8c(%rsp)
jmp 0xe712
xorps %xmm0, %xmm0
movsd %xmm0, 0x80(%rsp)
testb $0x1, 0x1190b(%rip)     # 0x20220
je 0xea09
movl $0x0, 0x7c(%rsp)
movq 0x68(%rsp), %rcx
movl 0x7c(%rsp), %eax
cmpl 0x34(%rcx), %eax
jge 0xea04
movslq 0x7c(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x3c80
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movslq 0x7c(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x3c80
movsd 0x28(%rsp), %xmm0
movq 0x68(%rsp), %rdi
subsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
cvtsi2sdl 0xd0(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
addq $0xa0, %rdi
movslq 0xd4(%rsp), %rsi
callq 0x8250
movq %rax, %rdi
movslq 0x7c(%rsp), %rsi
callq 0x3c80
movsd 0x30(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
movsd (%rax), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movaps 0x7692(%rip), %xmm1     # 0x16070
pand %xmm1, %xmm0
addsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0xe923
jmp 0xeaee
movl $0x0, 0x78(%rsp)
movq 0x68(%rsp), %rcx
movl 0x78(%rsp), %eax
cmpl 0x34(%rcx), %eax
jge 0xeaec
movslq 0x78(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x3c80
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movslq 0x78(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x3c80
movsd 0x10(%rsp), %xmm0
movq 0x68(%rsp), %rdi
subsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
cvtsi2sdl 0xd0(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
addq $0xa0, %rdi
movslq 0xd4(%rsp), %rsi
callq 0x8250
movq %rax, %rdi
movslq 0x78(%rsp), %rsi
callq 0x3c80
movsd 0x18(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd (%rax), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x29e0
addsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movl 0x78(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x78(%rsp)
jmp 0xea11
jmp 0xeaee
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x6950
leaq 0xb8(%rsp), %rdi
callq 0x6950
movsd 0x8(%rsp), %xmm0
addq $0xe8, %rsp
retq
leaq 0xb8(%rsp), %rdi
callq 0x6950
movq 0xb0(%rsp), %rdi
callq 0x23a0
nop