// File: /workspace/github_cpp_makefile_star2_O1/yuang-chen[P]paraGCN/src/gcn.cpp
// Function: GCN::GCN(GCNParams, GCNData*)
GCN::GCN(GCNParams params, GCNData *input_data) {
    this->params = params;
    this->data = input_data;
    modules.reserve(8);
    variables.reserve(8);
    //1.1 register and initialize the input data
    variables.emplace_back(data->feature_index.indices.size(), false);
    input = &variables.back();
//1.2 dropout the input data
    modules.push_back(new Dropout(input, params.dropout));
    //2.1 register and get the * at layer 1
    variables.emplace_back(params.num_nodes * params.hidden_dim);
    Variable *layer1_var1 = &variables.back();
    //2.2 register weights at layer 1 and randomize them
    variables.emplace_back(params.input_dim * params.hidden_dim, true, true);
    Variable *layer1_weight = &variables.back();
    layer1_weight->glorot(params.input_dim, params.hidden_dim);
  
//2.3 X.spmm(W0): compute the feature with filters 
    modules.push_back(new SparseMatmul(input, layer1_weight, layer1_var1, 
        params.num_nodes, params.input_dim, params.hidden_dim, &data->feature_index));
    //3.1 register and normalized var at layer 1
    variables.emplace_back(params.num_nodes * params.hidden_dim);
    Variable *layer1_var2 = &variables.back();
//3.2  A^XW0: normalize the output from last layer
    modules.push_back(new GraphSum(layer1_var1, layer1_var2,
         &data->graph, params.hidden_dim));
//4. ReLU(A^XW0)
    modules.push_back(new ReLU(layer1_var2));
//5. dropout and get ready for the 2nd layer 
    modules.push_back(new Dropout(layer1_var2, params.dropout));
    //6.1 do it for the 2nd layer
    variables.emplace_back(params.num_nodes * params.output_dim);
    Variable *layer2_var1 = &variables.back();
    //6.2 weights of the 2nd layer 
    variables.emplace_back(params.hidden_dim * params.output_dim, true, true);
    Variable *layer2_weight = &variables.back();
    layer2_weight->glorot(params.hidden_dim, params.output_dim);
//6.3 ReLU(A^XW0)W1: dense matrix multiply
    modules.push_back(new Matmul(layer1_var2, layer2_weight, layer2_var1, 
        params.num_nodes, params.hidden_dim, params.output_dim));
    //7.1 for the output
    variables.emplace_back(params.num_nodes * params.output_dim);
    output = &variables.back();
//7.2 A^(ReLU(A^XW0)W1): normalize layer2_var1,
    modules.push_back(new GraphSum(layer2_var1, output, &data->graph, params.output_dim));
    truth = vector<int>(params.num_nodes);
//8. cross entropy loss, the softmaxt function are inside of it
    modules.push_back(new CrossEntropyLoss(output, truth.data(), &loss, params.output_dim));
    
    AdamParams adam_params = AdamParams::get_default();
    adam_params.lr = params.learning_rate;
    adam_params.weight_decay = params.weight_decay;
    optimizer = Adam({{layer1_weight, true}, {layer2_weight, false}}, adam_params);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdi, %rbx
addq $0x8, %rdi
leaq 0x20(%rbx), %r14
leaq 0x48(%rbx), %rax
movq %rax, 0x78(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rbx)
xorl %eax, %eax
movq %rax, 0x58(%rbx)
movups %xmm0, 0x80(%rbx)
movq %rax, 0x90(%rbx)
movups %xmm0, 0x8(%rbx)
movups %xmm0, 0x18(%rbx)
movups %xmm0, 0x28(%rbx)
movaps 0x130(%rsp), %xmm0
movaps 0x140(%rsp), %xmm1
movups %xmm0, 0x98(%rbx)
movups %xmm1, 0xa8(%rbx)
movl 0x150(%rsp), %eax
movl %eax, 0xb8(%rbx)
movq %rsi, (%rbx)
movl $0x8, %esi
movq %rdi, 0x20(%rsp)
movq %r14, 0x30(%rsp)
callq 0x440a
movl $0x8, %esi
movq %r14, %rdi
callq 0x44a0
movq (%rbx), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
leaq 0x48(%rsp), %rsi
movq %rcx, (%rsi)
leaq 0xc0(%rsp), %rdx
movb $0x0, (%rdx)
movq %r14, %rdi
callq 0x454e
movq 0x28(%rbx), %r15
addq $-0x48, %r15
movq %r15, 0x38(%rbx)
movl $0x20, %edi
callq 0x31f0
movq %rax, %r14
leaq 0x130(%rsp), %r12
movss 0x10(%r12), %xmm0
movq %rax, %rdi
movq %r15, %rsi
movss %xmm0, 0x38(%rsp)
callq 0x6b2e
leaq 0x48(%rsp), %rsi
movq %r14, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4afc
movslq (%r12), %rax
movq %r12, %rbp
movl 0x8(%r12), %r13d
movl %r13d, %r12d
movq %rax, 0x40(%rsp)
imull %eax, %r12d
leaq 0x48(%rsp), %rsi
movl %r12d, (%rsi)
movq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x458e
movq 0x28(%rbx), %r15
movl 0x4(%rbp), %ebp
movl %ebp, %eax
imull %r13d, %eax
leaq 0x48(%rsp), %rsi
movl %eax, (%rsi)
movb $0x1, %al
leaq 0xc0(%rsp), %rdx
movb %al, (%rdx)
leaq 0xe0(%rsp), %rcx
movb %al, (%rcx)
movq %r14, %rdi
callq 0x45cc
movq 0x28(%rbx), %rdi
addq $-0x48, %rdi
movq %rdi, 0x80(%rsp)
movl %ebp, %esi
movl %r13d, 0x28(%rsp)
movl %r13d, %edx
callq 0x6d52
movl $0x38, %edi
callq 0x31f0
movq %rax, %r14
addq $-0x48, %r15
movq (%rbx), %rax
movq 0x38(%rbx), %rsi
movq %rax, 0x8(%rsp)
movl 0x28(%rsp), %eax
movl %eax, (%rsp)
movq %r14, %rdi
movq 0x80(%rsp), %rdx
movq %r15, %rcx
movq 0x40(%rsp), %r8
movl %ebp, %r9d
callq 0x6384
leaq 0x48(%rsp), %rsi
movq %r14, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4afc
leaq 0x48(%rsp), %rsi
movl %r12d, (%rsi)
movq 0x30(%rsp), %rdi
callq 0x458e
movq 0x28(%rbx), %r14
movl $0x28, %edi
callq 0x31f0
movl 0x28(%rsp), %r8d
movq %rax, %r13
addq $-0x48, %r14
movq (%rbx), %rcx
addq $0x30, %rcx
movq %rax, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x6570
leaq 0x48(%rsp), %rsi
movq %r13, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4afc
movl $0x18, %edi
callq 0x31f0
leaq 0x130(%rsp), %r12
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x6a3e
leaq 0x48(%rsp), %rsi
movq %r15, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4afc
movl $0x20, %edi
callq 0x31f0
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
movss 0x38(%rsp), %xmm0
callq 0x6b2e
leaq 0x48(%rsp), %rsi
movq %r15, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4afc
movq %r14, 0x88(%rsp)
movl 0xc(%r12), %r12d
movl %r12d, %r13d
imull 0x40(%rsp), %r13d
leaq 0x48(%rsp), %rsi
movl %r13d, (%rsi)
movq 0x30(%rsp), %r15
movq %r15, %rdi
callq 0x458e
movq 0x28(%rbx), %rbp
movl %r12d, %eax
movl 0x28(%rsp), %r14d
imull %r14d, %eax
leaq 0x48(%rsp), %rsi
movl %eax, (%rsi)
movb $0x1, %al
leaq 0xc0(%rsp), %rdx
movb %al, (%rdx)
leaq 0xe0(%rsp), %rcx
movb %al, (%rcx)
movq %r15, %rdi
callq 0x45cc
movq 0x28(%rbx), %rdi
addq $-0x48, %rdi
movq %rdi, 0x38(%rsp)
movl %r14d, %esi
movl %r12d, %edx
callq 0x6d52
movl $0x30, %edi
callq 0x31f0
movq %rax, %r15
addq $-0x48, %rbp
movl %r12d, (%rsp)
movq %rax, %rdi
movq 0x88(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %rbp, %rcx
movq 0x40(%rsp), %r8
movl 0x28(%rsp), %r9d
callq 0x612c
leaq 0x48(%rsp), %rsi
movq %r15, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4afc
leaq 0x48(%rsp), %rsi
movl %r13d, (%rsi)
movq 0x30(%rsp), %rdi
callq 0x458e
movq 0x28(%rbx), %r15
addq $-0x48, %r15
movq %r15, 0x40(%rbx)
movl $0x28, %edi
callq 0x31f0
movq %rax, %r14
movq (%rbx), %rcx
addq $0x30, %rcx
movq %rax, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movl %r12d, %r8d
callq 0x6570
leaq 0x48(%rsp), %rsi
movq %r14, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4afc
leaq 0x48(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
movq 0x40(%rsp), %rsi
callq 0x4610
leaq 0x48(%rsp), %r14
movq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0x4ee6
movq (%r14), %rdi
testq %rdi, %rdi
leaq 0x130(%rsp), %r15
je 0x3aab
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x3200
movl $0x28, %edi
callq 0x31f0
movq %rax, %r14
movq 0x40(%rbx), %rsi
movq 0x48(%rbx), %rdx
leaq 0x60(%rbx), %rcx
movl 0xc(%r15), %r8d
movq %rax, %rdi
callq 0x67c4
leaq 0x48(%rsp), %rsi
movq %r14, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4afc
leaq 0xa8(%rsp), %rdi
callq 0x6fc0
movss 0x14(%r15), %xmm0
movss %xmm0, 0xa8(%rsp)
movss 0x18(%r15), %xmm0
movss %xmm0, 0xb8(%rsp)
leaq 0xc0(%rsp), %rsi
movq 0x80(%rsp), %rax
movq %rax, (%rsi)
movb $0x1, 0x8(%rsi)
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsi)
movb $0x0, 0x18(%rsi)
leaq 0x90(%rsp), %rdi
leaq 0x2f(%rsp), %rcx
movl $0x2, %edx
callq 0x469a
movl 0xb8(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0xa8(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x707e
leaq 0x68(%rbx), %rax
leaq 0x60(%rsp), %r14
movq -0x8(%r14), %rcx
movq %rcx, 0x10(%rax)
movups -0x18(%r14), %xmm0
movups %xmm0, (%rax)
xorps %xmm0, %xmm0
leaq 0xe0(%rsp), %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq 0x80(%rbx), %rax
movups 0x88(%rbx), %xmm0
movq (%r14), %rcx
movq %rcx, 0x80(%rbx)
movq 0x8(%r14), %rcx
movq %rcx, 0x88(%rbx)
movq 0x10(%r14), %rcx
movq %rcx, 0x90(%rbx)
movq (%rdi), %rcx
movq 0x8(%rdi), %rdx
movq 0x10(%rdi), %rsi
movq %rax, (%rdi)
movups %xmm0, 0x8(%rdi)
movq %rcx, (%r14)
movq %rdx, 0x8(%r14)
movq %rsi, 0x10(%r14)
callq 0x471c
movq %r14, %rdi
callq 0x471c
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x3c15
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3200
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r12
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x3cc9
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
jmp 0x3cad
jmp 0x3cc6
jmp 0x3cc6
jmp 0x3c50
jmp 0x3cc6
movq %rax, %r12
movl $0x28, %esi
jmp 0x3caa
jmp 0x3cc6
movq %rax, %r12
movl $0x30, %esi
jmp 0x3c7e
jmp 0x3cc6
jmp 0x3cc6
jmp 0x3cc6
movq %rax, %r12
movl $0x20, %esi
jmp 0x3c7e
movq %rax, %r12
movl $0x18, %esi
movq %r15, %rdi
jmp 0x3cad
movq %rax, %r12
movl $0x28, %esi
movq %r13, %rdi
jmp 0x3cad
jmp 0x3cc6
movq %rax, %r12
movl $0x38, %esi
jmp 0x3caa
jmp 0x3cc6
jmp 0x3cc6
jmp 0x3cc6
movq %rax, %r12
movl $0x20, %esi
movq %r14, %rdi
callq 0x3200
jmp 0x3cc9
jmp 0x3cc6
jmp 0x3cc6
jmp 0x3cc6
jmp 0x3cc6
jmp 0x3cc6
jmp 0x3cc6
jmp 0x3cc6
jmp 0x3cc6
jmp 0x3cc6
movq %rax, %r12
leaq 0x80(%rbx), %rdi
callq 0x471c
movq 0x78(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x3cee
movq 0x58(%rbx), %rsi
subq %rdi, %rsi
callq 0x3200
movq 0x30(%rsp), %rdi
callq 0x46e2
movq 0x20(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x3d11
movq 0x18(%rbx), %rsi
subq %rdi, %rsi
callq 0x3200
movq %r12, %rdi
callq 0x3360
nop