// File: /workspace/github_cpp_makefile_star2_O2/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 $0xe8, %rsp
movq %rdi, %r15
addq $0x8, %rdi
leaq 0x20(%r15), %rbx
xorps %xmm0, %xmm0
andq $0x0, 0x58(%r15)
movups %xmm0, 0x48(%r15)
andq $0x0, 0x90(%r15)
leaq 0x48(%r15), %rax
movq %rax, 0x78(%rsp)
movups %xmm0, 0x80(%r15)
movups %xmm0, 0x8(%r15)
movups %xmm0, 0x18(%r15)
movups %xmm0, 0x28(%r15)
movaps 0x120(%rsp), %xmm0
movaps 0x130(%rsp), %xmm1
movups %xmm0, 0x98(%r15)
movups %xmm1, 0xa8(%r15)
movl 0x140(%rsp), %eax
movl %eax, 0xb8(%r15)
movq %rsi, (%r15)
pushq $0x8
popq %rsi
movq %rdi, 0x20(%rsp)
movq %rbx, 0x30(%rsp)
callq 0x405a
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x40f0
movq (%r15), %rax
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
leaq 0x48(%rsp), %rsi
movq %rcx, (%rsi)
leaq 0xc8(%rsp), %rdx
movb $0x0, (%rdx)
movq %rbx, %rdi
callq 0x4192
movq 0x28(%r15), %r14
addq $-0x48, %r14
movq %r14, 0x38(%r15)
pushq $0x20
popq %rdi
callq 0x31f0
movq %rax, %rbx
leaq 0x120(%rsp), %r12
movss 0x10(%r12), %xmm0
movq %rax, %rdi
movq %r14, %rsi
movss %xmm0, 0x28(%rsp)
callq 0x64ae
leaq 0x48(%rsp), %rsi
movq %rbx, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4858
movslq (%r12), %rax
movq %r12, %rbp
movl 0x8(%r12), %r12d
movl %r12d, %r13d
movq %rax, 0x40(%rsp)
imull %eax, %r13d
leaq 0x48(%rsp), %rsi
movl %r13d, (%rsi)
movq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x41ce
movq 0x28(%r15), %rbx
movl 0x4(%rbp), %ebp
movl %ebp, %eax
imull %r12d, %eax
leaq 0x48(%rsp), %rsi
movl %eax, (%rsi)
movb $0x1, %al
leaq 0xc8(%rsp), %rdx
movb %al, (%rdx)
leaq 0x90(%rsp), %rcx
movb %al, (%rcx)
movq %r14, %rdi
callq 0x4208
movq 0x28(%r15), %rdi
addq $-0x48, %rdi
movq %rdi, 0x88(%rsp)
movl %ebp, %esi
movl %r12d, %edx
callq 0x6690
pushq $0x38
popq %rdi
callq 0x31f0
movq %rax, %r14
addq $-0x48, %rbx
movq (%r15), %rax
movq 0x38(%r15), %rsi
movq %rax, 0x8(%rsp)
movl %r12d, (%rsp)
movq %r14, %rdi
movq 0x88(%rsp), %rdx
movq %rbx, %rcx
movq 0x40(%rsp), %r8
movl %ebp, %r9d
callq 0x5da2
leaq 0x48(%rsp), %rsi
movq %r14, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4858
leaq 0x48(%rsp), %rsi
movl %r13d, (%rsi)
movq 0x30(%rsp), %rdi
callq 0x41ce
movq 0x28(%r15), %r13
pushq $0x28
popq %rdi
callq 0x31f0
movq %rax, %r14
addq $-0x48, %r13
movq (%r15), %rcx
addq $0x30, %rcx
movq %rax, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movl %r12d, %r8d
callq 0x5fa6
leaq 0x48(%rsp), %rsi
movq %r14, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4858
pushq $0x18
popq %rdi
callq 0x31f0
movq %rax, %rbx
movq %rax, %rdi
movq %r13, %rsi
callq 0x63ea
leaq 0x48(%rsp), %rsi
movq %rbx, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4858
pushq $0x20
popq %rdi
callq 0x31f0
movq %rax, %rbx
movq %rax, %rdi
movq %r13, %rsi
movss 0x28(%rsp), %xmm0
callq 0x64ae
leaq 0x48(%rsp), %rsi
movq %rbx, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4858
movq %r13, 0xa8(%rsp)
movl %r12d, 0x28(%rsp)
leaq 0x120(%rsp), %rax
movl 0xc(%rax), %r14d
movl %r14d, %r12d
imull 0x40(%rsp), %r12d
leaq 0x48(%rsp), %rsi
movl %r12d, (%rsi)
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x41ce
movq 0x28(%r15), %rbp
movl %r14d, %eax
movl 0x28(%rsp), %r13d
imull %r13d, %eax
leaq 0x48(%rsp), %rsi
movl %eax, (%rsi)
movb $0x1, %al
leaq 0xc8(%rsp), %rdx
movb %al, (%rdx)
leaq 0x90(%rsp), %rcx
movb %al, (%rcx)
movq %rbx, %rdi
callq 0x4208
movq 0x28(%r15), %rdi
addq $-0x48, %rdi
movq %rdi, 0x80(%rsp)
movl %r13d, %esi
movl %r14d, 0x3c(%rsp)
movl %r14d, %edx
callq 0x6690
pushq $0x30
popq %rdi
callq 0x31f0
movq %rax, %rbx
addq $-0x48, %rbp
movl 0x3c(%rsp), %eax
movl %eax, (%rsp)
movq %rbx, %rdi
movq 0xa8(%rsp), %rsi
movq 0x80(%rsp), %rdx
movq %rbp, %rcx
movq 0x40(%rsp), %r8
movl 0x28(%rsp), %r9d
callq 0x5b44
leaq 0x48(%rsp), %rsi
movq %rbx, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4858
leaq 0x48(%rsp), %rsi
movl %r12d, (%rsi)
movq 0x30(%rsp), %rdi
callq 0x41ce
movq 0x28(%r15), %r12
addq $-0x48, %r12
movq %r12, 0x40(%r15)
pushq $0x28
popq %rdi
callq 0x31f0
movl 0x3c(%rsp), %r13d
movq %rax, %rbx
movq (%r15), %rcx
addq $0x30, %rcx
movq %rax, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movl %r13d, %r8d
callq 0x5fa6
leaq 0x48(%rsp), %rsi
movq %rbx, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4858
leaq 0x48(%rsp), %rdi
leaq 0xc8(%rsp), %rdx
movq 0x40(%rsp), %rsi
callq 0x4248
leaq 0x48(%rsp), %rbx
movq 0x78(%rsp), %rdi
movq %rbx, %rsi
callq 0x4cca
movq %rbx, %rdi
callq 0x4586
pushq $0x28
popq %rdi
callq 0x31f0
leaq 0x120(%rsp), %r14
movq %rax, %rbx
movq 0x40(%r15), %rsi
movq 0x48(%r15), %rdx
leaq 0x60(%r15), %rcx
movq %rax, %rdi
movl %r13d, %r8d
callq 0x61ca
leaq 0x48(%rsp), %rsi
movq %rbx, (%rsi)
movq 0x20(%rsp), %rdi
callq 0x4858
leaq 0x90(%rsp), %rdi
callq 0x6944
movss 0x14(%r14), %xmm0
movss %xmm0, 0x90(%rsp)
movss 0x18(%r14), %xmm0
movss %xmm0, 0xa0(%rsp)
leaq 0xc8(%rsp), %rsi
movq 0x88(%rsp), %rax
movq %rax, (%rsi)
movb $0x1, 0x8(%rsi)
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsi)
movb $0x0, 0x18(%rsi)
leaq 0xb0(%rsp), %rdi
pushq $0x2
popq %rdx
leaq 0x2f(%rsp), %rcx
callq 0x429a
movl 0xa0(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x90(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x48(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x69f0
addq $0x68, %r15
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
callq 0x42d4
leaq 0x60(%rsp), %rdi
callq 0x43ae
leaq 0xb0(%rsp), %rdi
callq 0x4d7e
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r12
leaq 0xb0(%rsp), %rdi
callq 0x4d7e
jmp 0x3b75
jmp 0x3b72
jmp 0x3b72
jmp 0x3b17
jmp 0x3b72
movq %rax, %r12
pushq $0x28
jmp 0x3b55
jmp 0x3b72
movq %rax, %r12
pushq $0x30
jmp 0x3b55
jmp 0x3b72
jmp 0x3b72
jmp 0x3b72
jmp 0x3b50
movq %rax, %r12
pushq $0x18
jmp 0x3b55
movq %rax, %r12
pushq $0x28
jmp 0x3b44
jmp 0x3b72
movq %rax, %r12
pushq $0x38
popq %rsi
movq %r14, %rdi
jmp 0x3b59
jmp 0x3b72
jmp 0x3b72
jmp 0x3b72
movq %rax, %r12
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0x3200
jmp 0x3b75
jmp 0x3b72
jmp 0x3b72
jmp 0x3b72
jmp 0x3b72
jmp 0x3b72
jmp 0x3b72
jmp 0x3b72
jmp 0x3b72
jmp 0x3b72
movq %rax, %r12
subq $-0x80, %r15
movq %r15, %rdi
callq 0x43ae
movq 0x78(%rsp), %rdi
callq 0x4586
movq 0x30(%rsp), %rdi
callq 0x42f8
movq 0x20(%rsp), %rdi
callq 0x444c
movq %r12, %rdi
callq 0x3360
nop