// File: /workspace/github_cpp_makefile_star2_O3/qmmlib[P]QmmLibrary/train.c
// Function: read_transform_matrix(char*, int&, int&)
double ** read_transform_matrix(char* filename,int & _nr, int & _nc)
{
    float read_float;    
    FILE * fp = fopen(filename,"r");
    int nlines = 0;
    std::vector<float> v_read_floats;
    int check_ncols = -1;
    while (fscanf(fp,"%f",&read_float) == 1)
	{
		v_read_floats.push_back(read_float);
		if(endofline(fp))
		{
			nlines++;
			if(check_ncols==-1)
			{
				check_ncols = v_read_floats.size();
				if(nlines!=1)
				{
					printf("\nERROR: This is illogical (%d)\n",nlines);
					exit(1);
				}
					
			}
		}
	}
	int ncols = v_read_floats.size()/nlines;
	if(check_ncols!=ncols)
	{
		printf("\nERROR (1): File does not seem like a matrix! (%d %d)\n",ncols,check_ncols);
		exit(1);
	}

	double ** transform_matrix = new double*[nlines];
	for(int i = 0 ; i<nlines; i++)
		transform_matrix[i] = new double[ncols];
	
	int row = 0;
	int col = 0;
	for(int i = 0 ; i<v_read_floats.size(); i++)
	{
		transform_matrix[row][col] = (double)v_read_floats[i];
		col++;
		if(col >= ncols)
		{
			col = 0;
			row++;
		}
	}
	
	if(row!=nlines || col!=0)
	{
		printf("\nERROR (2): File does not seem like a matrix! (%d %d)\n",row,col);
		exit(1);
	}
		
	_nr = nlines;
	_nc = ncols;
	
	return transform_matrix;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
leaq 0x13ad3(%rip), %rsi     # 0x182b4
callq 0x3280
movq %rax, %r14
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r15
movaps %xmm0, (%r15)
movq $0x0, 0x10(%r15)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x8(%rsp)
leaq 0x13acb(%rip), %rbp     # 0x182d9
leaq 0x1c(%rsp), %r12
xorl %eax, %eax
movl %eax, %r13d
movl %r13d, 0x4(%rsp)
movq %r14, %rdi
movq %rbp, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3430
movq 0x28(%rsp), %rbx
cmpl $0x1, %eax
jne 0x48b0
cmpq 0x30(%rsp), %rbx
je 0x4853
movss 0x1c(%rsp), %xmm0
movss %xmm0, (%rbx)
addq $0x4, %rbx
movq %rbx, 0x28(%rsp)
jmp 0x4861
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x4b9a
movq %r14, %rdi
callq 0x4b51
testl %eax, %eax
je 0x481d
incq %r13
cmpl $-0x1, 0x8(%rsp)
jne 0x4818
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
shrq $0x2, %rax
movq %rax, 0x8(%rsp)
movl $0x1, %eax
cmpl $0x0, 0x4(%rsp)
je 0x4815
leaq 0x13a3b(%rip), %rdi     # 0x182dc
movl %r13d, %esi
xorl %eax, %eax
callq 0x3050
jmp 0x49df
movq 0x20(%rsp), %rax
movq %rbx, %r14
movq %rax, 0x10(%rsp)
subq %rax, %r14
sarq $0x2, %r14
movl 0x4(%rsp), %edi
movq %r14, %rax
xorl %edx, %edx
divq %rdi
movq %rax, %r15
cmpl %r15d, 0x8(%rsp)
jne 0x49c0
shlq $0x3, %rdi
callq 0x3030
movq %rax, %r12
cmpl $0x0, 0x4(%rsp)
je 0x4922
shlq $0x20, %r15
movq %r15, %rax
sarq $0x1d, %rax
testq %r15, %r15
movq $-0x1, %r15
cmovnsq %rax, %r15
movq %r12, %rbp
movq %r15, %rdi
callq 0x3030
movq %rax, (%rbp)
addq $0x8, %rbp
decq %r13
jne 0x490d
movq 0x10(%rsp), %rdi
cmpq %rdi, %rbx
je 0x4977
cmpq $0x1, %r14
adcq $0x0, %r14
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
xorl %r9d, %r9d
movq 0x8(%rsp), %r8
xorps %xmm0, %xmm0
cvtss2sd (%rdi,%rcx,4), %xmm0
movl %r9d, %esi
movq (%r12,%rsi,8), %rsi
movslq %edx, %rdx
movsd %xmm0, (%rsi,%rdx,8)
incl %edx
xorl %esi, %esi
cmpl %r8d, %edx
setge %sil
cmovgel %eax, %edx
addl %r9d, %esi
incq %rcx
movl %esi, %r9d
cmpq %rcx, %r14
jne 0x4942
jmp 0x497b
xorl %esi, %esi
xorl %edx, %edx
cmpl 0x4(%rsp), %esi
jne 0x49d1
testl %edx, %edx
jne 0x49d1
movq 0x38(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
movq 0x40(%rsp), %rax
movq 0x8(%rsp), %rcx
movl %ecx, (%rax)
testq %rdi, %rdi
je 0x49ae
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x3220
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x13935(%rip), %rdi     # 0x182fc
movl %r15d, %esi
movq 0x8(%rsp), %rdx
jmp 0x49d8
leaq 0x1395b(%rip), %rdi     # 0x18333
xorl %eax, %eax
callq 0x3050
movl $0x1, %edi
callq 0x32a0
jmp 0x49eb
movq %rax, %rbx
jmp 0x49fd
movq %rax, %rbx
movq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x4a17
movq 0x30(%rsp), %rsi
movq 0x10(%rsp), %rdi
subq %rdi, %rsi
callq 0x3220
movq %rbx, %rdi
callq 0x33f0