// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3804
leaq 0x7837(%rip), %rdi      # 0xb015
leaq 0x7bf8(%rip), %rsi      # 0xb3dd
leaq 0x7c51(%rip), %rdx      # 0xb43d
movl $0x115, %ecx            # imm = 0x115
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c5f
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x3844
leaq 0x77f7(%rip), %rdi      # 0xb015
leaq 0x7bb8(%rip), %rsi      # 0xb3dd
leaq 0x7c11(%rip), %rdx      # 0xb43d
movl $0x118, %ecx            # imm = 0x118
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c5f
movb $0x0, -0x21(%rbp)
movl $0x0, -0x28(%rbp)
movslq -0x28(%rbp), %rax
cmpq $0x6, %rax
jae 0x388b
movslq -0x28(%rbp), %rcx
leaq 0xa86c(%rip), %rax      # 0xe0d0
movq (%rax,%rcx,8), %rdi
movq -0x20(%rbp), %rsi
addq $0x4, %rsi
callq 0x10f0
cmpl $0x0, %eax
jne 0x387e
movb $0x1, -0x21(%rbp)
jmp 0x3880
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x384f
movsbl -0x21(%rbp), %eax
cmpl $0x0, %eax
jne 0x38c1
leaq 0x777a(%rip), %rdi      # 0xb015
leaq 0x7b3b(%rip), %rsi      # 0xb3dd
leaq 0x7b94(%rip), %rdx      # 0xb43d
movl $0x121, %ecx            # imm = 0x121
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c5f
movb $0x0, -0x21(%rbp)
movq -0x20(%rbp), %rdi
addq $0x4, %rdi
leaq 0xa7fc(%rip), %rax      # 0xe0d0
movq (%rax), %rsi
callq 0x10f0
cmpl $0x0, %eax
je 0x3a46
movq -0x20(%rbp), %rax
cmpl $0x0, 0x284(%rax)
jg 0x391f
leaq 0x771c(%rip), %rdi      # 0xb015
leaq 0x7add(%rip), %rsi      # 0xb3dd
leaq 0x7b36(%rip), %rdx      # 0xb43d
movl $0x125, %ecx            # imm = 0x125
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c5f
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x2240(%rcx), %eax
jge 0x3a19
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x284(%rcx), %eax
jge 0x3a09
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq 0x240(%rax,%rcx,8), %rax
cmpq $0x0, 0x8(%rax)
jne 0x3997
leaq 0x76a4(%rip), %rdi      # 0xb015
leaq 0x7a65(%rip), %rsi      # 0xb3dd
leaq 0x7abe(%rip), %rdx      # 0xb43d
movl $0x128, %ecx            # imm = 0x128
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c5f
movq -0x20(%rbp), %rdi
addq $0x84, %rdi
movslq -0x30(%rbp), %rax
shlq $0x6, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq 0x240(%rax,%rcx,8), %rax
movq 0x8(%rax), %rsi
addq $0x44, %rsi
callq 0x10f0
cmpl $0x0, %eax
jne 0x39f9
movl -0x2c(%rbp), %edx
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rsi
movl 0x124(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x124(%rsi)
movslq %ecx, %rcx
movl %edx, 0x104(%rax,%rcx,4)
movb $0x1, -0x21(%rbp)
jmp 0x39fb
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x3940
jmp 0x3a0b
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3926
movsbl -0x21(%rbp), %eax
cmpl $0x0, %eax
jne 0x3a44
movq -0x20(%rbp), %rsi
addq $0x44, %rsi
leaq 0x7a19(%rip), %rdi      # 0xb44a
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c5f
jmp 0x3a46
movq -0x10(%rbp), %rax
movl 0x2240(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x100(%rax)
movq -0x18(%rbp), %rdx
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movl 0x2240(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x2240(%rsi)
movslq %ecx, %rcx
movq %rdx, 0x240(%rax,%rcx,8)
movl $0x0, -0x34(%rbp)
movq -0x20(%rbp), %rdi
addq $0x4, %rdi
leaq 0xa638(%rip), %rax      # 0xe0d0
movq (%rax), %rsi
callq 0x10f0
cmpl $0x0, %eax
jne 0x3b42
movq -0x10(%rbp), %rax
movq 0x230(%rax), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x5f60
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x3af6
leaq 0x7545(%rip), %rdi      # 0xb015
leaq 0x7906(%rip), %rsi      # 0xb3dd
leaq 0x795f(%rip), %rdx      # 0xb43d
movl $0x13b, %ecx            # imm = 0x13B
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c5f
movq -0x10(%rbp), %rdi
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %edx
movl %ecx, %esi
callq 0x47f0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x3b3d
leaq 0x74fe(%rip), %rdi      # 0xb015
leaq 0x78bf(%rip), %rsi      # 0xb3dd
leaq 0x7918(%rip), %rdx      # 0xb43d
movl $0x13e, %ecx            # imm = 0x13E
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c5f
jmp 0x3c58
movq -0x18(%rbp), %rax
cmpl $0x0, 0x124(%rax)
jg 0x3b7c
leaq 0x74bf(%rip), %rdi      # 0xb015
leaq 0x7880(%rip), %rsi      # 0xb3dd
leaq 0x78d9(%rip), %rdx      # 0xb43d
movl $0x140, %ecx            # imm = 0x140
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c5f
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x124(%rcx), %eax
jge 0x3bfb
movq -0x10(%rbp), %rax
movq 0x230(%rax), %rdi
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl 0x104(%rax,%rcx,4), %esi
movq -0x18(%rbp), %rax
movl 0x100(%rax), %edx
callq 0x5f60
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x3bee
leaq 0x744a(%rip), %rdi      # 0xb015
leaq 0x780b(%rip), %rsi      # 0xb3dd
leaq 0x7864(%rip), %rdx      # 0xb43d
movl $0x144, %ecx            # imm = 0x144
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c5f
jmp 0x3bf0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x3b83
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x100(%rax), %esi
movq -0x18(%rbp), %rdx
addq $0x104, %rdx            # imm = 0x104
movq -0x18(%rbp), %rax
movl 0x124(%rax), %ecx
callq 0x47f0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x3c56
leaq 0x73e2(%rip), %rdi      # 0xb015
leaq 0x77a3(%rip), %rsi      # 0xb3dd
leaq 0x77fc(%rip), %rdx      # 0xb43d
movl $0x147, %ecx            # imm = 0x147
movb $0x0, %al
callq 0x1030
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3c5f
jmp 0x3c58
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)