// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x20768(%rip), %rsi     # 0x2500a
callq 0x3360
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4d50
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rdi
leaq 0x20762(%rip), %rsi     # 0x2502f
xorl %eax, %eax
leaq -0x1c(%rbp), %rdx
callq 0x3500
movl %eax, -0x7c(%rbp)
jmp 0x48dd
movl -0x7c(%rbp), %eax
cmpl $0x1, %eax
jne 0x496f
leaq -0x48(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0x4d70
jmp 0x48f8
movq -0x28(%rbp), %rdi
callq 0x4cd0
movl %eax, -0x80(%rbp)
jmp 0x4906
movl -0x80(%rbp), %eax
cmpl $0x0, %eax
je 0x496a
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x4c(%rbp)
jne 0x4968
leaq -0x48(%rbp), %rdi
callq 0x4de0
movl %eax, -0x4c(%rbp)
cmpl $0x1, -0x2c(%rbp)
je 0x4966
movl -0x2c(%rbp), %esi
leaq 0x206f9(%rip), %rdi     # 0x25032
xorl %eax, %eax
callq 0x3050
jmp 0x4942
movl $0x1, %edi
callq 0x3380
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4e20
jmp 0x4b28
jmp 0x4968
jmp 0x496a
jmp 0x48c2
leaq -0x48(%rbp), %rdi
callq 0x4de0
movslq -0x2c(%rbp), %rcx
xorl %edx, %edx
divq %rcx
movl %eax, -0x60(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x60(%rbp), %eax
je 0x49ac
movl -0x60(%rbp), %esi
movl -0x4c(%rbp), %edx
leaq 0x206b9(%rip), %rdi     # 0x25052
xorl %eax, %eax
callq 0x3050
jmp 0x49a2
movl $0x1, %edi
callq 0x3380
movslq -0x2c(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x3030
movq %rax, -0x88(%rbp)
jmp 0x49d4
movq -0x88(%rbp), %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x4a34
movslq -0x60(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x3030
movq %rax, -0x90(%rbp)
jmp 0x4a16
movq -0x90(%rbp), %rdx
movq -0x68(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x49e6
movl $0x0, -0x70(%rbp)
movl $0x0, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
movslq -0x78(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4de0
movq %rax, %rcx
movq -0x98(%rbp), %rax
cmpq %rcx, %rax
jae 0x4ac4
movslq -0x78(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x4e00
movss (%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x68(%rbp), %rax
movslq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x74(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x60(%rbp), %eax
jl 0x4ab7
movl $0x0, -0x74(%rbp)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x4ab9
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x4a49
movl -0x70(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x4ad2
cmpl $0x0, -0x74(%rbp)
je 0x4af2
movl -0x70(%rbp), %esi
movl -0x74(%rbp), %edx
leaq 0x205aa(%rip), %rdi     # 0x25089
xorl %eax, %eax
callq 0x3050
jmp 0x4ae8
movl $0x1, %edi
callq 0x3380
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl -0x60(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x68(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x4e20
movq -0xa0(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x34b0
nopw %cs:(%rax,%rax)