// File: yuang-chen[P]paraGCN/src/module.cpp
// Function: GraphSum::backward()
void GraphSum::backward() {
    in->zero_grad();
    for(int src = 0; src < graph->indptr.size() - 1; src++) {
        for(int i = graph->indptr[src]; i < graph->indptr[src + 1]; i++) {
            int dst = graph->indices[i];
            float coef = 1.0 / sqrtf(
                (graph->indptr[src + 1] - graph->indptr[src]) * (graph->indptr[dst + 1] - graph->indptr[dst])
            );

            for(int j = 0; j < dim; j++) {
                in->grad[src*dim + j] += coef * in->data[dst * dim + j];
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq 0x8(%rax), %rdi
callq 0xcff0
movl $0x0, -0xc(%rbp)
movq -0x28(%rbp), %rax
movslq -0xc(%rbp), %rcx
movq %rcx, -0x30(%rbp)
movq 0x18(%rax), %rdi
addq $0x18, %rdi
callq 0x4ea0
movq %rax, %rcx
movq -0x30(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0xc1fe
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
addq $0x18, %rdi
movslq -0xc(%rbp), %rsi
callq 0x5540
movl (%rax), %eax
movl %eax, -0x10(%rbp)
movq -0x28(%rbp), %rax
movl -0x10(%rbp), %ecx
movl %ecx, -0x34(%rbp)
movq 0x18(%rax), %rdi
addq $0x18, %rdi
movl -0xc(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x5540
movq %rax, %rcx
movl -0x34(%rbp), %eax
cmpl (%rcx), %eax
jge 0xc1ee
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
movslq -0x10(%rbp), %rsi
callq 0x5540
movq %rax, %rcx
movq -0x28(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0x14(%rbp)
movq 0x18(%rax), %rdi
addq $0x18, %rdi
movl -0xc(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x5540
movq %rax, %rcx
movq -0x28(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0x40(%rbp)
movq 0x18(%rax), %rdi
addq $0x18, %rdi
movslq -0xc(%rbp), %rsi
callq 0x5540
movl -0x40(%rbp), %ecx
movq %rax, %rdx
movq -0x28(%rbp), %rax
subl (%rdx), %ecx
movl %ecx, -0x38(%rbp)
movq 0x18(%rax), %rdi
addq $0x18, %rdi
movl -0x14(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x5540
movq %rax, %rcx
movq -0x28(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, -0x3c(%rbp)
movq 0x18(%rax), %rdi
addq $0x18, %rdi
movslq -0x14(%rbp), %rsi
callq 0x5540
movl -0x3c(%rbp), %ecx
movq %rax, %rdx
movl -0x38(%rbp), %eax
subl (%rdx), %ecx
imull %ecx, %eax
cvtsi2ss %eax, %xmm0
callq 0x3450
cvtss2sd %xmm0, %xmm1
movsd 0x4072(%rip), %xmm0     # 0x101c0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x28(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl 0x20(%rcx), %eax
jge 0xc1de
movq -0x28(%rbp), %rcx
movss -0x18(%rbp), %xmm0
movss %xmm0, -0x48(%rbp)
movq 0x8(%rcx), %rdi
movl -0x14(%rbp), %eax
imull 0x20(%rcx), %eax
addl -0x1c(%rbp), %eax
movslq %eax, %rsi
callq 0x5520
movq -0x28(%rbp), %rcx
movss (%rax), %xmm0
movss %xmm0, -0x44(%rbp)
movq 0x8(%rcx), %rdi
addq $0x18, %rdi
movl -0xc(%rbp), %eax
imull 0x20(%rcx), %eax
addl -0x1c(%rbp), %eax
movslq %eax, %rsi
callq 0x5520
movss -0x48(%rbp), %xmm0
movss -0x44(%rbp), %xmm2
movss (%rax), %xmm1
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movss %xmm0, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xc162
jmp 0xc1e0
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xc06b
jmp 0xc1f0
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xc024
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)