// File: /workspace/github_c_makefile_star2_O3/xtanitfy[P]Murphy/src/net.c
// Function: NET_Register
int NET_Register(NET_s *pNet,LAYER_s *pLayer)
{
	CHECK_EXPR_RET(pLayer == NULL,-1);

	LAYER_PARA_s *layerPara =  pLayer->para;
	CHECK_EXPR_RET(layerPara == NULL,-1);
	
	/*�жϵ�ǰ�����������Ƿ�����*/
	BOOL isExist = FALSE;
	for (int i = 0;i < sizeof(gLayersTypeName)/sizeof(gLayersTypeName[0]);i++) {
		if (strcmp(gLayersTypeName[i],layerPara->typeName) == 0) {
			isExist = TRUE;
		}
	}
	CHECK_EXPR_RET(isExist == FALSE,-1);
	/*�ж�֮ǰ�����еĲ������Ƿ�����,�������ھͼ�¼֮ǰ�����в���ID*/
	isExist = FALSE;
	if (strcmp(layerPara->typeName,gLayersTypeName[0]) != 0) {
		CHECK_EXPR_RET(layerPara->nNamePrev <=0,-1);
		for (int i = 0;i < pNet->layerId;i++) {
			for (int j = 0;j < layerPara->nNamePrev;j++) {
				CHECK_EXPR_RET(pNet->layers[i]->para == NULL,-1);
				if (strcmp(layerPara->namePrev[j],pNet->layers[i]->para->name) == 0) {
					pLayer->idPrev[pLayer->nIdPrev++] = i;
					isExist = TRUE;
				}
			}
		}
		if (isExist == FALSE) {
			printf("[%s] previous name is not exist!\n",layerPara->name);
			return -1;
		}
	}
	pLayer->idCurr = pNet->layerId;
	pNet->layers[pNet->layerId++] = pLayer;

	int ret = 0;
	if (strcmp(layerPara->typeName,gLayersTypeName[0]) == 0) {
		/*�����ǵ�һ����Ҫ���⴦��*/
		ret = MTREE_addItem(pNet->pMTree,-1,0);
		CHECK_EXPR_RET(ret != 0,-1);
		
		ret = NETLayerInit(pNet,0,NULL,0);
		CHECK_EXPR_RET(ret != 0,-1);
	} else {
		CHECK_EXPR_RET(pLayer->nIdPrev <= 0,-1);
		
		for (int i = 0;i < pLayer->nIdPrev;i++) {
			ret = MTREE_addItem(pNet->pMTree,pLayer->idPrev[i],pLayer->idCurr);
			CHECK_EXPR_RET(ret != 0,-1);
		}
		ret = NETLayerInit(pNet,pLayer->idCurr,pLayer->idPrev,pLayer->nIdPrev);
		CHECK_EXPR_RET(ret != 0,-1);
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
testq %rsi, %rsi
je 0x2bb4
movq %rsi, %r14
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x2bd3
movq %rdi, 0x10(%rsp)
movq %rax, 0x18(%rsp)
leaq 0x4(%rax), %r15
xorl %r12d, %r12d
leaq 0x7693(%rip), %rbx      # 0xa0e0
movl $0x1, %ebp
xorl %r13d, %r13d
movq (%rbx,%r12,8), %rdi
movq %r15, %rsi
callq 0x1100
testl %eax, %eax
movzbl %r13b, %r13d
cmovel %ebp, %r13d
incq %r12
cmpq $0x6, %r12
jne 0x2a55
testb %r13b, %r13b
je 0x2bf2
movq (%rbx), %rsi
movq %r15, %rdi
callq 0x1100
testl %eax, %eax
je 0x2c11
movq 0x18(%rsp), %rsi
movl 0x284(%rsi), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
movq 0x10(%rsp), %r12
jle 0x2cd0
movl 0x2240(%r12), %eax
testl %eax, %eax
jle 0x2b9d
leaq 0x84(%rsi), %rbp
movq $0x0, 0x8(%rsp)
movq $0x0, 0x20(%rsp)
movq %rbp, 0x28(%rsp)
cmpl $0x0, 0x4(%rsp)
jle 0x2b79
movq 0x8(%rsp), %rax
movq 0x240(%r12,%rax,8), %rax
movq 0x8(%rax), %r12
leaq 0x44(%r12), %rax
movq %rax, 0x30(%rsp)
xorl %r13d, %r13d
testq %r12, %r12
je 0x2cef
movq %rbp, %rdi
movq 0x30(%rsp), %rsi
callq 0x1100
testl %eax, %eax
jne 0x2b51
movslq 0x124(%r14), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x124(%r14)
movq 0x8(%rsp), %rcx
movl %ecx, 0x104(%r14,%rax,4)
movq 0x18(%rsp), %rax
movl 0x284(%rax), %eax
movl %eax, 0x4(%rsp)
movb $0x1, %al
movq %rax, 0x20(%rsp)
incq %r13
movslq 0x4(%rsp), %rax
addq $0x40, %rbp
cmpq %rax, %r13
jl 0x2b03
movq 0x10(%rsp), %r12
movl 0x2240(%r12), %eax
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rbp
movq 0x8(%rsp), %rdi
incq %rdi
movslq %eax, %rcx
movq %rdi, 0x8(%rsp)
cmpq %rcx, %rdi
jl 0x2ada
cmpb $0x0, 0x20(%rsp)
jne 0x2c1e
addq $0x44, %rsi
leaq 0x48c2(%rip), %rdi      # 0x746a
xorl %eax, %eax
callq 0x1030
jmp 0x2db0
leaq 0x448a(%rip), %rdi      # 0x7045
leaq 0x486b(%rip), %rsi      # 0x742d
leaq 0x4894(%rip), %rdx      # 0x745d
movl $0x115, %ecx            # imm = 0x115
jmp 0x2da9
leaq 0x446b(%rip), %rdi      # 0x7045
leaq 0x484c(%rip), %rsi      # 0x742d
leaq 0x4875(%rip), %rdx      # 0x745d
movl $0x118, %ecx            # imm = 0x118
jmp 0x2da9
leaq 0x444c(%rip), %rdi      # 0x7045
leaq 0x482d(%rip), %rsi      # 0x742d
leaq 0x4856(%rip), %rdx      # 0x745d
movl $0x121, %ecx            # imm = 0x121
jmp 0x2da9
movq 0x10(%rsp), %r12
movl 0x2240(%r12), %eax
movl %eax, 0x100(%r14)
leal 0x1(%rax), %ecx
movl %ecx, 0x2240(%r12)
cltq
movq %r14, 0x240(%r12,%rax,8)
movq (%rbx), %rsi
movq %r15, %rdi
callq 0x1100
testl %eax, %eax
je 0x2d0e
cmpl $0x0, 0x124(%r14)
jle 0x2d45
xorl %ebx, %ebx
movq 0x230(%r12), %rdi
movl 0x104(%r14,%rbx,4), %esi
movl 0x100(%r14), %edx
callq 0x43a9
testl %eax, %eax
jne 0x2d61
incq %rbx
movslq 0x124(%r14), %rcx
cmpq %rcx, %rbx
jl 0x2c5d
movl 0x100(%r14), %esi
addq $0x104, %r14            # imm = 0x104
movq %r12, %rdi
movq %r14, %rdx
callq 0x3460
testl %eax, %eax
je 0x2dc8
leaq 0x438d(%rip), %rdi      # 0x7045
leaq 0x476e(%rip), %rsi      # 0x742d
leaq 0x4797(%rip), %rdx      # 0x745d
movl $0x147, %ecx            # imm = 0x147
jmp 0x2da9
leaq 0x436e(%rip), %rdi      # 0x7045
leaq 0x474f(%rip), %rsi      # 0x742d
leaq 0x4778(%rip), %rdx      # 0x745d
movl $0x125, %ecx            # imm = 0x125
jmp 0x2da9
leaq 0x434f(%rip), %rdi      # 0x7045
leaq 0x4730(%rip), %rsi      # 0x742d
leaq 0x4759(%rip), %rdx      # 0x745d
movl $0x128, %ecx            # imm = 0x128
jmp 0x2da9
movq 0x230(%r12), %rdi
xorl %r14d, %r14d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x43a9
testl %eax, %eax
je 0x2d7d
leaq 0x4315(%rip), %rdi      # 0x7045
leaq 0x46f6(%rip), %rsi      # 0x742d
leaq 0x471f(%rip), %rdx      # 0x745d
movl $0x13b, %ecx            # imm = 0x13B
jmp 0x2da9
leaq 0x42f9(%rip), %rdi      # 0x7045
leaq 0x46da(%rip), %rsi      # 0x742d
leaq 0x4703(%rip), %rdx      # 0x745d
movl $0x140, %ecx            # imm = 0x140
jmp 0x2da9
leaq 0x42dd(%rip), %rdi      # 0x7045
leaq 0x46be(%rip), %rsi      # 0x742d
leaq 0x46e7(%rip), %rdx      # 0x745d
movl $0x144, %ecx            # imm = 0x144
jmp 0x2da9
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3460
testl %eax, %eax
je 0x2db6
leaq 0x42af(%rip), %rdi      # 0x7045
leaq 0x4690(%rip), %rsi      # 0x742d
leaq 0x46b9(%rip), %rdx      # 0x745d
movl $0x13e, %ecx            # imm = 0x13E
xorl %eax, %eax
callq 0x1030
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
jmp 0x2db6