// File: KokiKishimoto[P]cp_decomposition/cp.cpp
// Function: CP::computeGradients(Triple&, double)
double computeGradients(Triple& triple, double y) {
		const std::vector<double>& subj_v = subjVec[triple.subj];
		const std::vector<double>& obj_v = objVec[triple.obj];
		const std::vector<double>& relation_v = relationVec[triple.relation];

		op.product(subj_v, obj_v, relation_v, outVec1, outVec2, outVec3);

		double score = op.innerProduct(relation_v, outVec1);

		double yscore = y * score;
		double loss = std::log(1.0 + std::exp(-yscore));
		fs = -(y * sigmoid(-yscore));

		for (int i = 0; i < vecDim; i++) {
			outVec1[i] = fs * outVec1[i];
			outVec2[i] = fs * outVec2[i];
			outVec3[i] = fs * outVec3[i];
		}

		norms[0] = op.norm(outVec1);
		norms[1] = op.norm(outVec2);
		norms[2] = op.norm(outVec3);

		return loss;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x78(%rbp)
addq $0x30, %rdi
movq -0x10(%rbp), %rax
movslq (%rax), %rsi
callq 0xaa60
movq -0x78(%rbp), %rdi
movq %rax, -0x20(%rbp)
addq $0x48, %rdi
movq -0x10(%rbp), %rax
movslq 0x4(%rax), %rsi
callq 0xaa60
movq -0x78(%rbp), %rdi
movq %rax, -0x28(%rbp)
addq $0x60, %rdi
movq -0x10(%rbp), %rax
movslq 0x8(%rax), %rsi
callq 0xaa60
movq -0x78(%rbp), %rsi
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movq %rsi, %r9
addq $0x190, %r9             # imm = 0x190
movq %rsi, %r10
addq $0x1a8, %r10            # imm = 0x1A8
movq %rsi, %rax
addq $0x1c0, %rax            # imm = 0x1C0
leaq -0x48(%rbp), %rdi
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xe4a0
leaq -0x48(%rbp), %rdi
callq 0x9b10
movq -0x78(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq %rdi, %rdx
addq $0x190, %rdx            # imm = 0x190
callq 0xe600
movsd %xmm0, -0x50(%rbp)
movsd -0x18(%rbp), %xmm0
mulsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0x3460
movaps %xmm0, %xmm1
movsd 0x3ebb(%rip), %xmm0     # 0x10010
addsd %xmm1, %xmm0
callq 0x3220
movq -0x78(%rbp), %rdi
movsd %xmm0, -0x60(%rbp)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x58(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0xe6a0
movq -0x78(%rbp), %rax
movaps %xmm0, %xmm1
movsd -0x70(%rbp), %xmm0
mulsd %xmm1, %xmm0
movq %xmm0, %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
xorq %rdx, %rcx
movq %rcx, %xmm0
movsd %xmm0, 0x1f0(%rax)
movl $0x0, -0x64(%rbp)
movq -0x78(%rbp), %rcx
movl -0x64(%rbp), %eax
cmpl 0x200(%rcx), %eax
jge 0xc2eb
movq -0x78(%rbp), %rdi
movsd 0x1f0(%rdi), %xmm0
movsd %xmm0, -0xa8(%rbp)
addq $0x190, %rdi            # imm = 0x190
movslq -0x64(%rbp), %rsi
callq 0xaab0
movsd -0xa8(%rbp), %xmm0
movq -0x78(%rbp), %rdi
mulsd (%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
addq $0x190, %rdi            # imm = 0x190
movslq -0x64(%rbp), %rsi
callq 0xaab0
movsd -0xa0(%rbp), %xmm0
movq -0x78(%rbp), %rdi
movsd %xmm0, (%rax)
movsd 0x1f0(%rdi), %xmm0
movsd %xmm0, -0x98(%rbp)
addq $0x1a8, %rdi            # imm = 0x1A8
movslq -0x64(%rbp), %rsi
callq 0xaab0
movsd -0x98(%rbp), %xmm0
movq -0x78(%rbp), %rdi
mulsd (%rax), %xmm0
movsd %xmm0, -0x90(%rbp)
addq $0x1a8, %rdi            # imm = 0x1A8
movslq -0x64(%rbp), %rsi
callq 0xaab0
movsd -0x90(%rbp), %xmm0
movq -0x78(%rbp), %rdi
movsd %xmm0, (%rax)
movsd 0x1f0(%rdi), %xmm0
movsd %xmm0, -0x88(%rbp)
addq $0x1c0, %rdi            # imm = 0x1C0
movslq -0x64(%rbp), %rsi
callq 0xaab0
movsd -0x88(%rbp), %xmm0
movq -0x78(%rbp), %rdi
mulsd (%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
addq $0x1c0, %rdi            # imm = 0x1C0
movslq -0x64(%rbp), %rsi
callq 0xaab0
movsd -0x80(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xc1c8
movq -0x78(%rbp), %rdi
movq %rdi, %rsi
addq $0x190, %rsi            # imm = 0x190
callq 0xe6f0
movq -0x78(%rbp), %rdi
movsd %xmm0, -0xc0(%rbp)
addq $0x1d8, %rdi            # imm = 0x1D8
xorl %eax, %eax
movl %eax, %esi
callq 0xaab0
movsd -0xc0(%rbp), %xmm0
movq -0x78(%rbp), %rdi
movsd %xmm0, (%rax)
movq %rdi, %rsi
addq $0x1a8, %rsi            # imm = 0x1A8
callq 0xe6f0
movq -0x78(%rbp), %rdi
movsd %xmm0, -0xb8(%rbp)
addq $0x1d8, %rdi            # imm = 0x1D8
movl $0x1, %esi
callq 0xaab0
movsd -0xb8(%rbp), %xmm0
movq -0x78(%rbp), %rdi
movsd %xmm0, (%rax)
movq %rdi, %rsi
addq $0x1c0, %rsi            # imm = 0x1C0
callq 0xe6f0
movq -0x78(%rbp), %rdi
movsd %xmm0, -0xb0(%rbp)
addq $0x1d8, %rdi            # imm = 0x1D8
movl $0x2, %esi
callq 0xaab0
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, (%rax)
movsd -0x60(%rbp), %xmm0
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)