// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movq %rdx, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
leaq 0x11a21(%rip), %rsi     # 0x16286
callq 0x3270
movq %rax, %rbx
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r12
movaps %xmm0, (%r12)
movq $0x0, 0x10(%r12)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0x11a1c(%rip), %r13     # 0x162ab
leaq 0x1c(%rsp), %r14
xorl %eax, %eax
movl %eax, %r15d
movl %r15d, 0xc(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3420
cmpl $0x1, %eax
jne 0x4923
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x48d4
movss 0x1c(%rsp), %xmm0
movss %xmm0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x48df
movq %r12, %rdi
movq %r14, %rdx
callq 0x4c10
movq %rbx, %rdi
callq 0x4bc8
testl %eax, %eax
je 0x489e
incq %r15
cmpl $-0x1, %ebp
jne 0x4899
movq 0x28(%rsp), %rbp
subq 0x20(%rsp), %rbp
shrq $0x2, %rbp
movl $0x1, %eax
cmpl $0x0, 0xc(%rsp)
je 0x4896
leaq 0x1199a(%rip), %rdi     # 0x162ae
movl %r15d, %esi
xorl %eax, %eax
callq 0x3050
jmp 0x4a57
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rbx
movq %rbx, 0x40(%rsp)
movq %rax, 0x10(%rsp)
subq %rax, %rbx
sarq $0x2, %rbx
movl 0xc(%rsp), %edi
movq %rbx, %rax
xorl %edx, %edx
divq %rdi
movq %rax, %r13
cmpl %r13d, %ebp
jne 0x4a3b
shlq $0x3, %rdi
callq 0x3030
movq %rax, %r12
cmpl $0x0, 0xc(%rsp)
je 0x499d
movq %r13, %rax
shlq $0x20, %rax
movq %rax, %rcx
sarq $0x1d, %rcx
testq %rax, %rax
movq $-0x1, %r14
cmovnsq %rcx, %r14
movq %r12, %rbp
movq %r14, %rdi
callq 0x3030
movq %rax, (%rbp)
addq $0x8, %rbp
decq %r15
jne 0x4988
movq 0x40(%rsp), %rax
cmpq 0x10(%rsp), %rax
je 0x49f1
cmpq $0x1, %rbx
adcq $0x0, %rbx
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
xorl %edi, %edi
movq 0x10(%rsp), %r8
xorps %xmm0, %xmm0
cvtss2sd (%r8,%rcx,4), %xmm0
movl %edi, %esi
movq (%r12,%rsi,8), %rsi
movslq %edx, %rdx
movsd %xmm0, (%rsi,%rdx,8)
incl %edx
xorl %esi, %esi
cmpl %r13d, %edx
setge %sil
cmovgel %eax, %edx
addl %edi, %esi
incq %rcx
movl %esi, %edi
cmpq %rcx, %rbx
jne 0x49be
jmp 0x49f5
xorl %esi, %esi
xorl %edx, %edx
cmpl 0xc(%rsp), %esi
jne 0x4a49
testl %edx, %edx
jne 0x4a49
movq 0x48(%rsp), %rax
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
movq 0x50(%rsp), %rax
movl %r13d, (%rax)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4a29
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq %r12, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1188c(%rip), %rdi     # 0x162ce
movl %r13d, %esi
movl %ebp, %edx
jmp 0x4a50
leaq 0x118b5(%rip), %rdi     # 0x16305
xorl %eax, %eax
callq 0x3050
movl $0x1, %edi
callq 0x3290
jmp 0x4a65
jmp 0x4a65
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4a7f
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x3210
movq %rbx, %rdi
callq 0x33e0