// File: /workspace/github_c_makefile_star2_O2/xtanitfy[P]Murphy/src/log.c
// Function: LOG_writeBlobToTxtFile
int LOG_writeBlobToTxtFile(char *txtFile,BLOB_s *pBlob)
{
	char filepath[256];
	sprintf(filepath,"bin/%s",txtFile);
	
	int fd = open(filepath,O_RDWR | O_CREAT | O_TRUNC,0666);
	CHECK_EXPR_RET(fd < 0,-1);

	BLOB_DATA_PTR(pBlob,ptr);
	
	char buf[256];

	if (pBlob->type == BLOB_TYPE_BIAS) {
		for (int i_out = 0;i_out < pBlob->channelSize;i_out++) {
			sprintf(buf,"%.8f ",ptr[0][i_out][0][0]);
			write(fd,buf,strlen(buf));
			write(fd,"\n",1);
		}
		close(fd);
		return 0;	
	}

	if (pBlob->type == BLOB_TYPE_WEIGHT) {
		for (int i_out = 0;i_out < pBlob->numSize;i_out++) {
			for (int i_in = 0;i_in < pBlob->channelSize;i_in++) {	
				for (int i_height = 0;i_height < pBlob->heightSize;i_height++) {	
					for (int i_width = 0;i_width < pBlob->widthSize;i_width++) {	
						sprintf(buf,"%.8f ",ptr[i_out][i_in][i_height][i_width]);
						write(fd,buf,strlen(buf));
					}
					if (pBlob->widthSize> 1) {
						write(fd,"\n",1);
					}
				}
				write(fd,"\n\n",1);
			}
			write(fd,"\n",1);
		}
		
		close(fd);
		return 0;
	}
	
	
	for (int i_batch = 0;i_batch < 2/*pBlob->batches*/;i_batch++) {
		for (int i_num = 0;i_num < pBlob->channelSize;i_num++) {	
			for (int i_height = 0;i_height < (pBlob->heightSize - pBlob->pady*2);i_height++) {	
				for (int i_width = 0;i_width < (pBlob->widthSize - pBlob->padx*2);i_width++) {	
					sprintf(buf,"%.8f ",ptr[i_batch][i_num][i_height+pBlob->pady][i_width+pBlob->padx]);
					write(fd,buf,strlen(buf));
				}
				write(fd,"\n",1);
			}
			write(fd,"\n",1);
		}
		write(fd,"\n",1);
	}	

	close(fd);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rsi, %rbx
movq %rdi, %rdx
leaq 0xdd8(%rip), %rsi       # 0x2065
leaq 0x140(%rsp), %r14
movq %r14, %rdi
xorl %eax, %eax
callq 0x1040
movq %r14, %rdi
movl $0x242, %esi            # imm = 0x242
movl $0x1b6, %edx            # imm = 0x1B6
xorl %eax, %eax
callq 0x1080
movl %eax, 0x4(%rsp)
testl %eax, %eax
js 0x13fe
movq 0x8(%rbx), %rax
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rcx
movq 0x20(%rbx), %rdx
movq 0x28(%rbx), %rbp
movl (%rbx), %eax
cmpl $0x2, %eax
je 0x1425
imulq %rbp, %rdx
cmpl $0x1, %eax
jne 0x1498
imulq %rdx, %rcx
shlq $0x3, %rcx
shlq $0x3, %rdx
movq %rdx, 0x30(%rsp)
shlq $0x3, %rbp
movq %rbp, 0x38(%rsp)
xorl %eax, %eax
leaq 0xd74(%rip), %r14       # 0x2083
leaq 0x40(%rsp), %r15
movq %rcx, 0x18(%rsp)
cmpq %rax, 0x10(%rbx)
jbe 0x15df
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %r13
xorl %eax, %eax
cmpq %rax, 0x18(%rbx)
jbe 0x13d4
movq %rax, 0x20(%rsp)
movq %r13, 0x28(%rsp)
xorl %ebp, %ebp
cmpq %rbp, 0x20(%rbx)
jbe 0x13aa
xorl %r12d, %r12d
movq 0x28(%rbx), %rax
cmpq %r12, %rax
jbe 0x1387
movsd (%r13,%r12,8), %xmm0
movq %r15, %rdi
movq %r14, %rsi
movb $0x1, %al
callq 0x1040
movq %r15, %rdi
callq 0x1060
movl 0x4(%rsp), %edi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1050
incq %r12
jmp 0x134e
cmpq $0x1, %rax
jbe 0x13a0
movl 0x4(%rsp), %edi
leaq 0xcf2(%rip), %rsi       # 0x208a
pushq $0x1
popq %rdx
callq 0x1050
incq %rbp
addq 0x38(%rsp), %r13
jmp 0x1345
movl 0x4(%rsp), %edi
leaq 0xcd4(%rip), %rsi       # 0x2089
pushq $0x1
popq %rdx
callq 0x1050
movq 0x20(%rsp), %rax
incq %rax
movq 0x28(%rsp), %r13
addq 0x30(%rsp), %r13
jmp 0x132f
movl 0x4(%rsp), %edi
leaq 0xcab(%rip), %rsi       # 0x208a
pushq $0x1
popq %rdx
callq 0x1050
movq 0x10(%rsp), %rax
incq %rax
movq 0x18(%rsp), %rcx
addq %rcx, 0x8(%rsp)
jmp 0x1319
leaq 0xc3b(%rip), %rdi       # 0x2040
leaq 0xc4a(%rip), %rsi       # 0x2056
leaq 0xc59(%rip), %rdx       # 0x206c
pushq $0x1a
popq %rcx
xorl %eax, %eax
callq 0x1030
pushq $-0x1
popq %rax
jmp 0x15ea
imulq %rdx, %rbp
shlq $0x3, %rbp
xorl %r14d, %r14d
leaq 0x40(%rsp), %r15
movl 0x4(%rsp), %r13d
cmpq %r14, %rcx
jbe 0x15df
movq 0x8(%rsp), %r12
movsd (%r12), %xmm0
movq %r15, %rdi
leaq 0xc2b(%rip), %rsi       # 0x2083
movb $0x1, %al
callq 0x1040
movq %r15, %rdi
callq 0x1060
movl %r13d, %edi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1050
movl %r13d, %edi
leaq 0xc0b(%rip), %rsi       # 0x208a
pushq $0x1
popq %rdx
callq 0x1050
incq %r14
movq 0x18(%rbx), %rcx
addq %rbp, %r12
movq %r12, 0x8(%rsp)
jmp 0x143a
movq %rcx, %rax
movq %rdx, 0x30(%rsp)
imulq %rdx, %rax
xorl %ecx, %ecx
leaq 0x40(%rsp), %r15
movq %rax, 0x18(%rsp)
cmpq $0x2, %rcx
je 0x15df
movq %rcx, 0x10(%rsp)
imulq %rcx, %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
movq %rax, 0x20(%rsp)
xorl %ecx, %ecx
cmpq %rcx, 0x18(%rbx)
jbe 0x15ba
movq 0x30(%rsp), %rax
movq %rcx, 0x28(%rsp)
imulq %rcx, %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax,8), %r13
xorl %edx, %edx
movq 0x20(%rbx), %rax
movslq 0x38(%rbx), %rcx
addq %rcx, %rcx
subq %rcx, %rax
cmpq %rdx, %rax
jbe 0x159a
movq %rdx, 0x38(%rsp)
movslq %edx, %r12
xorl %r14d, %r14d
movq 0x28(%rbx), %rcx
movslq 0x3c(%rbx), %rax
subq %rax, %rcx
subq %rax, %rcx
cmpq %r14, %rcx
jbe 0x157a
movl %eax, %eax
movslq 0x38(%rbx), %rcx
addq %r12, %rcx
imulq %rbp, %rcx
leaq (,%rcx,8), %rcx
addq %r13, %rcx
addl %r14d, %eax
cltq
movsd (%rcx,%rax,8), %xmm0
movq %r15, %rdi
leaq 0xb2c(%rip), %rsi       # 0x2083
movb $0x1, %al
callq 0x1040
movq %r15, %rdi
callq 0x1060
movl 0x4(%rsp), %edi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1050
incq %r14
jmp 0x1518
movl 0x4(%rsp), %edi
leaq 0xb05(%rip), %rsi       # 0x208a
pushq $0x1
popq %rdx
callq 0x1050
movq 0x38(%rsp), %rdx
incq %rdx
jmp 0x14f6
movl 0x4(%rsp), %edi
leaq 0xae5(%rip), %rsi       # 0x208a
pushq $0x1
popq %rdx
callq 0x1050
movq 0x28(%rsp), %rcx
incq %rcx
jmp 0x14d3
movl 0x4(%rsp), %edi
leaq 0xac5(%rip), %rsi       # 0x208a
pushq $0x1
popq %rdx
callq 0x1050
movq 0x10(%rsp), %rcx
incq %rcx
movq 0x18(%rsp), %rax
jmp 0x14b0
movl 0x4(%rsp), %edi
callq 0x10e0
xorl %eax, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq