// File: /workspace/github_c_makefile_star2_O1/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 0x2c22
movq %rsi, %r13
movq 0x8(%rsi), %rax
testq %rax, %rax
je 0x2c41
movq %rdi, 0x10(%rsp)
movq %rax, 0x18(%rsp)
leaq 0x4(%rax), %r12
xorl %r14d, %r14d
leaq 0x85ff(%rip), %rbx      # 0xb0d0
movl $0x1, %ebp
xorl %r15d, %r15d
movq (%rbx,%r14,8), %rdi
movq %r12, %rsi
callq 0x10f0
testl %eax, %eax
movzbl %r15b, %r15d
cmovel %ebp, %r15d
incq %r14
cmpq $0x6, %r14
jne 0x2ad9
testb %r15b, %r15b
je 0x2c60
movq %r13, 0x20(%rsp)
movq (%rbx), %rsi
movq %r12, %rdi
callq 0x10f0
testl %eax, %eax
movq 0x10(%rsp), %r14
je 0x2cec
movq 0x18(%rsp), %rcx
cmpl $0x0, 0x284(%rcx)
jle 0x2c7f
cmpl $0x0, 0x2240(%r14)
setg %al
jle 0x2cd2
leaq 0x84(%rcx), %rdx
movq %rdx, 0x30(%rsp)
movq $0x0, 0x8(%rsp)
xorl %edi, %edi
cmpl $0x0, 0x284(%rcx)
jle 0x2bea
movb %al, 0x3(%rsp)
movq 0x8(%rsp), %rax
movq 0x240(%r14,%rax,8), %rax
movq 0x8(%rax), %r15
leaq 0x44(%r15), %r13
movq 0x30(%rsp), %rbp
xorl %r14d, %r14d
movq %rdi, 0x28(%rsp)
movl %edi, %eax
movl %eax, 0x4(%rsp)
testq %r15, %r15
je 0x2c9e
movq %rbp, %rdi
movq %r13, %rsi
callq 0x10f0
testl %eax, %eax
jne 0x2bd0
movq 0x20(%rsp), %rdx
movslq 0x124(%rdx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x124(%rdx)
movq 0x8(%rsp), %rcx
movl %ecx, 0x104(%rdx,%rax,4)
movb $0x1, %al
movl %eax, 0x4(%rsp)
incq %r14
movq 0x18(%rsp), %rcx
movslq 0x284(%rcx), %rax
addq $0x40, %rbp
cmpq %rax, %r14
jl 0x2b91
jmp 0x2bf0
movl %edi, %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rsp), %rsi
incq %rsi
movq 0x10(%rsp), %r14
movslq 0x2240(%r14), %rax
movl 0x4(%rsp), %r8d
movl %r8d, %edi
movq %rsi, 0x8(%rsp)
cmpq %rax, %rsi
setl %al
jl 0x2b58
jmp 0x2cd5
leaq 0x541c(%rip), %rdi      # 0x8045
leaq 0x57fd(%rip), %rsi      # 0x842d
leaq 0x5826(%rip), %rdx      # 0x845d
movl $0x115, %ecx            # imm = 0x115
jmp 0x2e67
leaq 0x53fd(%rip), %rdi      # 0x8045
leaq 0x57de(%rip), %rsi      # 0x842d
leaq 0x5807(%rip), %rdx      # 0x845d
movl $0x118, %ecx            # imm = 0x118
jmp 0x2e67
leaq 0x53de(%rip), %rdi      # 0x8045
leaq 0x57bf(%rip), %rsi      # 0x842d
leaq 0x57e8(%rip), %rdx      # 0x845d
movl $0x121, %ecx            # imm = 0x121
jmp 0x2e67
leaq 0x53bf(%rip), %rdi      # 0x8045
leaq 0x57a0(%rip), %rsi      # 0x842d
leaq 0x57c9(%rip), %rdx      # 0x845d
movl $0x125, %ecx            # imm = 0x125
jmp 0x2e67
leaq 0x53a0(%rip), %rdi      # 0x8045
leaq 0x5781(%rip), %rsi      # 0x842d
leaq 0x57aa(%rip), %rdx      # 0x845d
movl $0x128, %ecx            # imm = 0x128
xorl %eax, %eax
callq 0x1030
movq 0x28(%rsp), %rax
movl %eax, %r8d
movq 0x10(%rsp), %r14
movb 0x3(%rsp), %al
jmp 0x2cd5
xorl %r8d, %r8d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testb $0x1, %al
jne 0x2e74
testb %r8b, %r8b
je 0x2e06
movslq 0x2240(%r14), %rax
movq 0x20(%rsp), %r15
movl %eax, 0x100(%r15)
leal 0x1(%rax), %ecx
movl %ecx, 0x2240(%r14)
movq %r15, 0x240(%r14,%rax,8)
movq (%rbx), %rsi
movq %r12, %rdi
callq 0x10f0
testl %eax, %eax
je 0x2db4
cmpl $0x0, 0x124(%r15)
jle 0x2dea
cmpl $0x0, 0x124(%r15)
jle 0x2d70
xorl %ebx, %ebx
movq 0x230(%r14), %rdi
movl 0x104(%r15,%rbx,4), %esi
movl 0x100(%r15), %edx
callq 0x44e1
testl %eax, %eax
jne 0x2e4d
incq %rbx
movslq 0x124(%r15), %rax
cmpq %rax, %rbx
jl 0x2d3e
leaq 0x104(%r15), %rdx
movl 0x100(%r15), %esi
movl 0x124(%r15), %ecx
movq %r14, %rdi
callq 0x3526
testl %eax, %eax
je 0x2e86
leaq 0x52a9(%rip), %rdi      # 0x8045
leaq 0x568a(%rip), %rsi      # 0x842d
leaq 0x56b3(%rip), %rdx      # 0x845d
movl $0x147, %ecx            # imm = 0x147
jmp 0x2e67
movq 0x230(%r14), %rdi
xorl %r13d, %r13d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x44e1
testl %eax, %eax
je 0x2e1f
leaq 0x5270(%rip), %rdi      # 0x8045
leaq 0x5651(%rip), %rsi      # 0x842d
leaq 0x567a(%rip), %rdx      # 0x845d
movl $0x13b, %ecx            # imm = 0x13B
jmp 0x2e67
leaq 0x5254(%rip), %rdi      # 0x8045
leaq 0x5635(%rip), %rsi      # 0x842d
leaq 0x565e(%rip), %rdx      # 0x845d
movl $0x140, %ecx            # imm = 0x140
jmp 0x2e67
movq 0x18(%rsp), %rsi
addq $0x44, %rsi
leaq 0x5654(%rip), %rdi      # 0x846a
xorl %eax, %eax
callq 0x1030
jmp 0x2e74
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3526
testl %eax, %eax
je 0x2e74
leaq 0x520d(%rip), %rdi      # 0x8045
leaq 0x55ee(%rip), %rsi      # 0x842d
leaq 0x5617(%rip), %rdx      # 0x845d
movl $0x13e, %ecx            # imm = 0x13E
jmp 0x2e67
leaq 0x51f1(%rip), %rdi      # 0x8045
leaq 0x55d2(%rip), %rsi      # 0x842d
leaq 0x55fb(%rip), %rdx      # 0x845d
movl $0x144, %ecx            # imm = 0x144
xorl %eax, %eax
callq 0x1030
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
jmp 0x2e74