// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
testq %rsi, %rsi
je 0x29c6
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x29e5
movq %rdi, %r13
movq %rsi, (%rsp)
movq %rax, 0x8(%rsp)
leaq 0x4(%rax), %r15
xorl %ebx, %ebx
leaq 0x8824(%rip), %rbp      # 0xb0e0
pushq $0x1
popq %r14
xorl %r12d, %r12d
cmpq $0x6, %rbx
je 0x28e5
movq (%rbp,%rbx,8), %rdi
movq %r15, %rsi
callq 0x1100
testl %eax, %eax
movzbl %r12b, %r12d
cmovel %r14d, %r12d
incq %rbx
jmp 0x28c3
testb %r12b, %r12b
je 0x2a04
movq (%rbp), %rsi
movq %r15, %rdi
callq 0x1100
testl %eax, %eax
je 0x2a23
movq 0x8(%rsp), %rax
movl 0x284(%rax), %ebx
testl %ebx, %ebx
jle 0x2ae4
leaq 0x84(%rax), %rdx
xorl %r12d, %r12d
movq $0x0, 0x10(%rsp)
movq %r13, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
movl 0x2240(%r13), %eax
movslq %eax, %rcx
cmpq %rcx, %r12
jge 0x2be6
movq %rdx, %r13
xorl %r14d, %r14d
movslq %ebx, %rax
cmpq %rax, %r14
jge 0x29b4
movq 0x18(%rsp), %rax
movq 0x240(%rax,%r12,8), %rax
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x2ac5
addq $0x44, %rsi
movq %r13, %rdi
callq 0x1100
testl %eax, %eax
jne 0x29ab
movq (%rsp), %rdx
movslq 0x124(%rdx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x124(%rdx)
movl %r12d, 0x104(%rdx,%rax,4)
movq 0x8(%rsp), %rax
movl 0x284(%rax), %ebx
movb $0x1, %al
movq %rax, 0x10(%rsp)
incq %r14
addq $0x40, %r13
jmp 0x294b
incq %r12
movq 0x18(%rsp), %r13
movq 0x20(%rsp), %rdx
jmp 0x2932
leaq 0x4678(%rip), %rdi      # 0x7045
leaq 0x4a59(%rip), %rsi      # 0x742d
leaq 0x4a82(%rip), %rdx      # 0x745d
movl $0x115, %ecx            # imm = 0x115
jmp 0x2b8c
leaq 0x4659(%rip), %rdi      # 0x7045
leaq 0x4a3a(%rip), %rsi      # 0x742d
leaq 0x4a63(%rip), %rdx      # 0x745d
movl $0x118, %ecx            # imm = 0x118
jmp 0x2b8c
leaq 0x463a(%rip), %rdi      # 0x7045
leaq 0x4a1b(%rip), %rsi      # 0x742d
leaq 0x4a44(%rip), %rdx      # 0x745d
movl $0x121, %ecx            # imm = 0x121
jmp 0x2b8c
movl 0x2240(%r13), %eax
movslq %eax, %rcx
movq (%rsp), %r14
movl %eax, 0x100(%r14)
incl %eax
movl %eax, 0x2240(%r13)
movq %r14, 0x240(%r13,%rcx,8)
movq (%rbp), %rsi
movq %r15, %rdi
callq 0x1100
testl %eax, %eax
je 0x2b03
cmpl $0x0, 0x124(%r14)
jle 0x2b40
leaq 0x104(%r14), %r15
xorl %ebx, %ebx
movslq 0x124(%r14), %rcx
cmpq %rcx, %rbx
jge 0x2b5c
movq 0x230(%r13), %rdi
movl 0x104(%r14,%rbx,4), %esi
movl 0x100(%r14), %edx
callq 0x40c4
incq %rbx
testl %eax, %eax
je 0x2a74
leaq 0x4598(%rip), %rdi      # 0x7045
leaq 0x4979(%rip), %rsi      # 0x742d
leaq 0x49a2(%rip), %rdx      # 0x745d
movl $0x144, %ecx            # imm = 0x144
jmp 0x2b8c
leaq 0x4579(%rip), %rdi      # 0x7045
leaq 0x495a(%rip), %rsi      # 0x742d
leaq 0x4983(%rip), %rdx      # 0x745d
movl $0x128, %ecx            # imm = 0x128
jmp 0x2b8c
leaq 0x455a(%rip), %rdi      # 0x7045
leaq 0x493b(%rip), %rsi      # 0x742d
leaq 0x4964(%rip), %rdx      # 0x745d
movl $0x125, %ecx            # imm = 0x125
jmp 0x2b8c
movq 0x230(%r13), %rdi
pushq $-0x1
popq %rbp
xorl %r14d, %r14d
movl %ebp, %esi
xorl %edx, %edx
callq 0x40c4
testl %eax, %eax
je 0x2ba9
leaq 0x451d(%rip), %rdi      # 0x7045
leaq 0x48fe(%rip), %rsi      # 0x742d
leaq 0x4927(%rip), %rdx      # 0x745d
movl $0x13b, %ecx            # imm = 0x13B
jmp 0x2bd5
leaq 0x44fe(%rip), %rdi      # 0x7045
leaq 0x48df(%rip), %rsi      # 0x742d
leaq 0x4908(%rip), %rdx      # 0x745d
movl $0x140, %ecx            # imm = 0x140
jmp 0x2b8c
movl 0x100(%r14), %esi
movq %r13, %rdi
movq %r15, %rdx
callq 0x3274
testl %eax, %eax
je 0x2be1
leaq 0x44cc(%rip), %rdi      # 0x7045
leaq 0x48ad(%rip), %rsi      # 0x742d
leaq 0x48d6(%rip), %rdx      # 0x745d
movl $0x147, %ecx            # imm = 0x147
xorl %eax, %eax
callq 0x1030
pushq $-0x1
popq %r14
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3274
testl %eax, %eax
je 0x2b97
leaq 0x4483(%rip), %rdi      # 0x7045
leaq 0x4864(%rip), %rsi      # 0x742d
leaq 0x488d(%rip), %rdx      # 0x745d
movl $0x13e, %ecx            # imm = 0x13E
xorl %eax, %eax
callq 0x1030
movl %ebp, %r14d
jmp 0x2b97
xorl %r14d, %r14d
jmp 0x2b97
cmpb $0x0, 0x10(%rsp)
movq (%rsp), %r14
jne 0x2a31
movq 0x8(%rsp), %rsi
addq $0x44, %rsi
leaq 0x4865(%rip), %rdi      # 0x746a
xorl %eax, %eax
callq 0x1030
jmp 0x2b93