// File: /workspace/github_cpp_makefile_star2_O2/qmmlib[P]QmmLibrary/train.c
// Function: read_problem(char const*)
void read_problem(const char *filename)
{
	int max_index, inst_max_index, i, max_index_=0;
	long int elements, j;
	FILE *fp = fopen(filename,"r");
	char *endptr;
	char *idx, *val, *label;

	if(fp == NULL)
	{
		fprintf(stderr,"can't open input file %s\n",filename);
		exit(1);
	}

	prob.l = 0;
	elements = 0;
	max_line_len = 1024;
	line = Malloc(char,max_line_len);
	while(readline(fp, 0)!=NULL) 
	{
		char *p = strtok(line," \t"); // label

		// features
		while(1)
		{
			idx = strtok(NULL,":"); 
			p = strtok(NULL," \t");
			if(p == NULL || *p == '\n') // check '\n' as ' ' may be after the last feature
				break;
			if((int) strtol(idx,&endptr,10)>max_index_) 
				max_index_ = (int) strtol(idx,&endptr,10); 
			elements++;
		}
		elements++; // for bias term
		prob.l++;
	}
	param.real_dim = max_index_; 
	rewind(fp);

	prob.bias=bias;

	prob.y = Malloc(double,prob.l);
	prob.x = Malloc(struct feature_node *,prob.l);
	x_space = Malloc(struct feature_node,elements+prob.l);

	max_index = 0;
	j=0;
	for(i=0;i<prob.l;i++)
	{
		inst_max_index = 0; // strtol gives 0 if wrong format
		readline(fp, param.real_dim); //sym
		prob.x[i] = &x_space[j];
		label = strtok(line," \t\n");
		if(label == NULL) // empty line
			exit_input_error(i+1);

		prob.y[i] = strtod(label,&endptr);
		if(endptr == label || *endptr != '\0')
			exit_input_error(i+1);

		while(1)
		{
			idx = strtok(NULL,":");
			val = strtok(NULL," \t");

			if(val == NULL)
				break;

			errno = 0;
			x_space[j].index = (int) strtol(idx,&endptr,10);
			if(endptr == idx || errno != 0 || *endptr != '\0' || x_space[j].index <= inst_max_index)
				exit_input_error(i+1);
			else
				inst_max_index = x_space[j].index;

			errno = 0;
			x_space[j].value = strtod(val,&endptr);
			if(endptr == val || errno != 0 || (*endptr != '\0' && !isspace(*endptr)))
				exit_input_error(i+1);

			++j;
		}

		if(inst_max_index > max_index)
			max_index = inst_max_index;

		if(prob.bias >= 0)
			x_space[j++].value = prob.bias;

		x_space[j++].index = -1;
	}

	if(prob.bias >= 0)
	{
		prob.n=max_index+1;
		for(i=1;i<prob.l;i++)
			(prob.x[i]-2)->index = prob.n; 
		x_space[j-2].index = prob.n;
	}
	else
		prob.n=max_index;

	fclose(fp);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x115c7(%rip), %rsi     # 0x152b4
callq 0x32a0
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x4061
andl $0x0, 0x16631(%rip)     # 0x1a338
movl $0x400, 0x16667(%rip)   # imm = 0x400
movl $0x400, %edi            # imm = 0x400
callq 0x3320
movq %rax, 0x1664e(%rip)     # 0x1a370
xorl %ebx, %ebx
leaq 0x115a5(%rip), %r15     # 0x152d0
movq %rsp, %r13
pushq $0xa
popq %rbp
xorl %r14d, %r14d
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x43f3
testq %rax, %rax
je 0x3da7
movq 0x16624(%rip), %rdi     # 0x1a370
movq %r15, %rsi
callq 0x33b0
incq %r14
xorl %edi, %edi
leaq 0x11573(%rip), %rsi     # 0x152d3
callq 0x33b0
movq %rax, %r12
xorl %edi, %edi
movq %r15, %rsi
callq 0x33b0
testq %rax, %rax
je 0x3d9f
cmpb $0xa, (%rax)
je 0x3d9f
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x3360
cmpl %eax, %ebx
jge 0x3d54
movq %r12, %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x3360
movq %rax, %rbx
jmp 0x3d54
incl 0x16593(%rip)           # 0x1a338
jmp 0x3d34
movl %ebx, 0x1653b(%rip)     # 0x1a2e8
movq 0x18(%rsp), %rdi
callq 0x3070
movsd 0x165a9(%rip), %xmm0    # 0x1a368
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0x16583(%rip)    # 0x1a350
movslq 0x16564(%rip), %r15     # 0x1a338
leaq (,%r15,8), %rbx
movq %rbx, %rdi
callq 0x3320
movq %rax, 0x16555(%rip)     # 0x1a340
movq %rbx, %rdi
callq 0x3320
movq %rax, 0x1654e(%rip)     # 0x1a348
addq %r15, %r14
shlq $0x4, %r14
movq %r14, %rdi
callq 0x3320
movq %rax, 0x16520(%rip)     # 0x1a330
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r13d, %r13d
movslq %r15d, %rcx
cmpq %rcx, %r14
jge 0x3fea
movl 0x164bd(%rip), %esi     # 0x1a2e8
movq 0x18(%rsp), %rdi
callq 0x43f3
movq %r12, %rbp
shlq $0x4, %rbp
movq 0x164ed(%rip), %rax     # 0x1a330
addq %rbp, %rax
movq 0x164fb(%rip), %rcx     # 0x1a348
movq %rax, (%rcx,%r14,8)
movq 0x16518(%rip), %rdi     # 0x1a370
leaq 0x11476(%rip), %rsi     # 0x152d5
callq 0x33b0
testq %rax, %rax
je 0x4056
movq %rax, %rbx
movq %r12, 0x20(%rsp)
movl %r13d, 0x10(%rsp)
movq %rax, %rdi
movq %rsp, %rsi
callq 0x3180
movq 0x164b4(%rip), %rax     # 0x1a340
movq %r14, 0x8(%rsp)
movsd %xmm0, (%rax,%r14,8)
movq (%rsp), %rax
cmpq %rbx, %rax
je 0x404a
cmpb $0x0, (%rax)
jne 0x404a
orq $0x8, %rbp
xorl %r12d, %r12d
xorl %edi, %edi
leaq 0x11416(%rip), %rsi     # 0x152d3
callq 0x33b0
movq %rax, %r13
xorl %edi, %edi
leaq 0x11402(%rip), %rsi     # 0x152d0
callq 0x33b0
testq %rax, %rax
je 0x3f86
movq %rax, %r14
callq 0x3040
movq %rax, %r15
andl $0x0, (%rax)
movq %r13, %rdi
movq %rsp, %rsi
pushq $0xa
popq %rdx
callq 0x3360
movq %rax, %rbx
movq 0x1642e(%rip), %rax     # 0x1a330
movl %ebx, -0x8(%rax,%rbp)
movq (%rsp), %rax
cmpq %r13, %rax
je 0x404a
cmpl $0x0, (%r15)
jne 0x404a
cmpb $0x0, (%rax)
jne 0x404a
cmpl %ebx, %r12d
jge 0x404a
andl $0x0, (%r15)
movq %r14, %rdi
movq %rsp, %rsi
callq 0x3180
movq 0x163eb(%rip), %rax     # 0x1a330
movsd %xmm0, (%rax,%rbp)
movq (%rsp), %rax
cmpq %r14, %rax
je 0x404a
cmpl $0x0, (%r15)
jne 0x404a
movsbl (%rax), %edi
testl %edi, %edi
je 0x3f75
callq 0x3060
testl %eax, %eax
je 0x404a
incq 0x20(%rsp)
addq $0x10, %rbp
movl %ebx, %r12d
jmp 0x3eb4
movl 0x10(%rsp), %r13d
cmpl %r13d, %r12d
cmovgl %r12d, %r13d
movsd 0x163b6(%rip), %xmm0    # 0x1a350
ucomisd 0x1109e(%rip), %xmm0    # 0x15040
movq 0x16387(%rip), %rax     # 0x1a330
movsd %xmm0, 0x10(%rsp)
jae 0x3fbd
movq 0x8(%rsp), %r14
movq 0x20(%rsp), %rdx
jmp 0x3fcf
movq 0x20(%rsp), %rdx
incq %rdx
movsd %xmm0, (%rax,%rbp)
movq 0x8(%rsp), %r14
leaq 0x1(%rdx), %r12
shlq $0x4, %rdx
orl $-0x1, (%rax,%rdx)
incq %r14
movl 0x16353(%rip), %r15d    # 0x1a338
jmp 0x3e19
xorpd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x4003
movl %r13d, 0x1633b(%rip)    # 0x1a33c
jmp 0x4032
incl %r13d
movl %r13d, 0x1632f(%rip)    # 0x1a33c
pushq $0x1
popq %rdx
movq 0x16331(%rip), %rsi     # 0x1a348
cmpq %rcx, %rdx
jge 0x4029
movq (%rsi,%rdx,8), %rdi
movl %r13d, -0x20(%rdi)
incq %rdx
jmp 0x4017
shlq $0x4, %r12
movl %r13d, -0x20(%rax,%r12)
movq 0x18(%rsp), %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3220
movq 0x8(%rsp), %rdi
incl %edi
callq 0x35f2
incl %r14d
movl %r14d, %edi
callq 0x35f2
movq 0x15f70(%rip), %rax     # 0x19fd8
movq (%rax), %rdi
leaq 0x11244(%rip), %rsi     # 0x152b6
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3370
pushq $0x1
popq %rdi
callq 0x32c0