// File: /workspace/github_cpp_makefile_star2_O2/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, %r15
movq %rsi, 0x38(%rsp)
leaq 0x1107f(%rip), %rsi     # 0x152b4
callq 0x32a0
movq %rax, %r13
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rbp
movaps %xmm0, (%rbp)
andq $0x0, 0x10(%rbp)
pushq $-0x1
popq %rax
movq %rax, 0x8(%rsp)
leaq 0x1107c(%rip), %rbx     # 0x152d9
leaq 0x44(%rsp), %r14
xorl %eax, %eax
movl %eax, %r12d
movl %r12d, 0x4(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3470
cmpl $0x1, %eax
jne 0x42d5
movq %rbp, %rdi
movq %r14, %rsi
callq 0x456e
movq %r13, %rdi
callq 0x4526
testl %eax, %eax
je 0x426c
incq %r12
cmpl $-0x1, 0x8(%rsp)
jne 0x4267
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
shrq $0x2, %rax
movq %rax, 0x8(%rsp)
pushq $0x1
popq %rax
cmpl $0x0, 0x4(%rsp)
je 0x4264
leaq 0x11016(%rip), %rdi     # 0x152dc
movl %r12d, %esi
xorl %eax, %eax
callq 0x3050
jmp 0x43d2
movq %r15, 0x30(%rsp)
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r13
subq %r14, %r13
sarq $0x2, %r13
movl 0x4(%rsp), %edi
movq %r13, %rax
xorl %edx, %edx
divq %rdi
movq %rax, %rbx
cmpl %ebx, 0x8(%rsp)
jne 0x43b4
shlq $0x3, %rdi
callq 0x3030
movq %rax, %r15
shlq $0x20, %rbx
movq %rbx, %rax
sarq $0x1d, %rax
testq %rbx, %rbx
pushq $-0x1
popq %rbx
cmovnsq %rax, %rbx
movq %r15, %rbp
subq $0x1, %r12
jb 0x4340
movq %rbx, %rdi
callq 0x3030
movq %rax, (%rbp)
addq $0x8, %rbp
jmp 0x4328
xorl %eax, %eax
xorl %ecx, %ecx
xorl %esi, %esi
xorl %edx, %edx
cmpq %rcx, %r13
je 0x4377
cvtss2sd (%r14,%rcx,4), %xmm0
movl %esi, %edi
movq (%r15,%rdi,8), %rdi
movslq %edx, %rdx
movsd %xmm0, (%rdi,%rdx,8)
incl %edx
xorl %edi, %edi
cmpl 0x8(%rsp), %edx
setge %dil
cmovgel %eax, %edx
addl %edi, %esi
incq %rcx
jmp 0x4348
cmpl 0x4(%rsp), %esi
jne 0x43c4
testl %edx, %edx
jne 0x43c4
movq 0x38(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
movq 0x30(%rsp), %rax
movq 0x8(%rsp), %rcx
movl %ecx, (%rax)
leaq 0x10(%rsp), %rdi
callq 0x459c
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10f41(%rip), %rdi     # 0x152fc
movl %ebx, %esi
movq 0x8(%rsp), %rdx
jmp 0x43cb
leaq 0x10f68(%rip), %rdi     # 0x15333
xorl %eax, %eax
callq 0x3050
pushq $0x1
popq %rdi
callq 0x32c0
jmp 0x43de
jmp 0x43de
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x459c
movq %rbx, %rdi
callq 0x3430