// File: /workspace/github_cpp_makefile_star2_O3/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), %rbp
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 %rbp, 0x78(%rsp)
callq 0x43ce
movl $0x8, %esi
movq %rbp, %rdi
callq 0x446a
movq (%rbx), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
leaq 0x40(%rsp), %rsi
movq %rcx, (%rsi)
leaq 0xc0(%rsp), %rdx
movb $0x0, (%rdx)
movq %rbp, %rdi
callq 0x4518
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, 0x30(%rsp)
callq 0x6ac0
leaq 0x40(%rsp), %rsi
movq %r14, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4ac4
movslq (%r12), %rax
movl 0x8(%r12), %r13d
movq %r12, %r15
movl %r13d, %r12d
movq %rax, 0x38(%rsp)
imull %eax, %r12d
leaq 0x40(%rsp), %rsi
movl %r12d, (%rsi)
movq %rbp, %rdi
callq 0x455e
movq 0x28(%rbx), %r14
movl 0x4(%r15), %r15d
movl %r15d, %eax
imull %r13d, %eax
leaq 0x40(%rsp), %rsi
movl %eax, (%rsi)
movb $0x1, %al
leaq 0xc0(%rsp), %rdx
movb %al, (%rdx)
leaq 0xe0(%rsp), %rcx
movb %al, (%rcx)
movq %rbp, %rdi
callq 0x45a4
movq 0x28(%rbx), %rdi
addq $-0x48, %rdi
movq %rdi, 0x80(%rsp)
movl %r15d, %esi
movl %r13d, 0x28(%rsp)
movl %r13d, %edx
callq 0x6cde
movl $0x38, %edi
callq 0x31f0
movq %rax, %r13
addq $-0x48, %r14
movq (%rbx), %rax
movq 0x38(%rbx), %rsi
movq %rax, 0x8(%rsp)
movl 0x28(%rsp), %eax
movl %eax, (%rsp)
movq %r13, %rdi
movq 0x80(%rsp), %rdx
movq %r14, %rcx
movq 0x38(%rsp), %r8
movl %r15d, %r9d
callq 0x6308
leaq 0x40(%rsp), %rsi
movq %r13, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4ac4
leaq 0x40(%rsp), %rsi
movl %r12d, (%rsi)
movq %rbp, %rdi
callq 0x455e
movq 0x28(%rbx), %r12
movl $0x28, %edi
callq 0x31f0
movl 0x28(%rsp), %r8d
movq %rax, %r15
addq $-0x48, %r12
movq (%rbx), %rcx
addq $0x30, %rcx
movq %rax, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x652a
leaq 0x40(%rsp), %rsi
movq %r15, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4ac4
movl $0x18, %edi
callq 0x31f0
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
callq 0x69d0
leaq 0x40(%rsp), %rsi
movq %r14, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4ac4
movl $0x20, %edi
callq 0x31f0
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
movss 0x30(%rsp), %xmm0
callq 0x6ac0
leaq 0x40(%rsp), %rsi
movq %r14, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4ac4
movq %r12, 0x88(%rsp)
leaq 0x130(%rsp), %rax
movl 0xc(%rax), %r12d
movl %r12d, %r15d
imull 0x38(%rsp), %r15d
leaq 0x40(%rsp), %rsi
movl %r15d, (%rsi)
movq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0x455e
movq 0x28(%rbx), %r13
movl %r12d, %eax
movl 0x28(%rsp), %ebp
imull %ebp, %eax
leaq 0x40(%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 0x45a4
movq 0x28(%rbx), %rdi
addq $-0x48, %rdi
movq %rdi, 0x30(%rsp)
movl %ebp, %esi
movl %r12d, %edx
callq 0x6cde
movl %r12d, %ebp
movl $0x30, %edi
callq 0x31f0
movq %rax, %r14
addq $-0x48, %r13
movl %ebp, (%rsp)
movq %rax, %rdi
movq 0x88(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq %r13, %rcx
movq 0x38(%rsp), %r8
movl 0x28(%rsp), %r9d
callq 0x60b0
leaq 0x40(%rsp), %rsi
movq %r14, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4ac4
leaq 0x40(%rsp), %rsi
movl %r15d, (%rsi)
movq 0x78(%rsp), %rdi
callq 0x455e
movq 0x28(%rbx), %r12
addq $-0x48, %r12
movq %r12, 0x40(%rbx)
movl $0x28, %edi
callq 0x31f0
movq %rax, %r14
movq (%rbx), %rcx
addq $0x30, %rcx
movq %rax, %rdi
movq %r13, %rsi
movq %r12, %rdx
movl %ebp, %r8d
callq 0x652a
leaq 0x40(%rsp), %rsi
movq %r14, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4ac4
leaq 0x40(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
movq 0x38(%rsp), %rsi
callq 0x45f0
movq 0x48(%rbx), %rdi
movq 0x58(%rbx), %rsi
movaps 0x40(%rsp), %xmm0
movups %xmm0, 0x48(%rbx)
movq 0x50(%rsp), %rax
movq %rax, 0x58(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
testq %rdi, %rdi
leaq 0x130(%rsp), %r15
je 0x3ad4
subq %rdi, %rsi
callq 0x3200
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3ad4
movq 0x50(%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
movq %rax, %rdi
movl %ebp, %r8d
callq 0x675e
leaq 0x40(%rsp), %rsi
movq %r14, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4ac4
leaq 0xa8(%rsp), %rdi
callq 0x6f4c
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 0x30(%rsp), %rax
movq %rax, 0x10(%rsi)
movb $0x0, 0x18(%rsi)
leaq 0x90(%rsp), %rdi
leaq 0x2f(%rsp), %rcx
movl $0x2, %edx
callq 0x467c
movl 0xb8(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0xa8(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x700a
leaq 0x68(%rbx), %rax
leaq 0x58(%rsp), %r14
movq -0x8(%r14), %rcx
movq %rcx, 0x10(%rax)
movups -0x18(%r14), %xmm0
movups %xmm0, (%rax)
movq 0x90(%rbx), %rax
movups (%r14), %xmm0
movq 0x10(%r14), %rcx
movq %rcx, 0x90(%rbx)
movups 0x80(%rbx), %xmm1
movups %xmm0, 0x80(%rbx)
leaq 0xe0(%rsp), %rdi
movaps %xmm1, (%rdi)
movq %rax, 0x10(%rdi)
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq $0x0, 0x10(%r14)
callq 0x46fe
movq %r14, %rdi
callq 0x46fe
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x3c1e
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 0x3cca
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
jmp 0x3cae
jmp 0x3cc7
jmp 0x3cc7
jmp 0x3c59
jmp 0x3cc7
movq %rax, %r12
movl $0x28, %esi
jmp 0x3cab
jmp 0x3cc7
movq %rax, %r12
movl $0x30, %esi
jmp 0x3cab
jmp 0x3cc7
jmp 0x3cc7
jmp 0x3cc7
jmp 0x3ca3
movq %rax, %r12
movl $0x18, %esi
jmp 0x3cab
movq %rax, %r12
movl $0x28, %esi
movq %r15, %rdi
jmp 0x3cae
jmp 0x3cc7
movq %rax, %r12
movl $0x38, %esi
movq %r13, %rdi
jmp 0x3cae
jmp 0x3cc7
jmp 0x3cc7
jmp 0x3cc7
movq %rax, %r12
movl $0x20, %esi
movq %r14, %rdi
callq 0x3200
jmp 0x3cca
jmp 0x3cc7
jmp 0x3cc7
jmp 0x3cc7
jmp 0x3cc7
jmp 0x3cc7
jmp 0x3cc7
jmp 0x3cc7
jmp 0x3cc7
jmp 0x3cc7
movq %rax, %r12
leaq 0x48(%rbx), %r14
leaq 0x80(%rbx), %rdi
callq 0x46fe
movq (%r14), %rdi
testq %rdi, %rdi
je 0x3cee
movq 0x58(%rbx), %rsi
subq %rdi, %rsi
callq 0x3200
movq 0x78(%rsp), %rdi
callq 0x46c4
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