// File: /workspace/github_cpp_makefile_star2_O3/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 0x140b0(%rip), %rsi     # 0x182b4
callq 0x3280
testq %rax, %rax
je 0x45fe
movq %rax, %r14
movl $0x0, 0x1a0f9(%rip)     # 0x1e318
movl $0x400, 0x1a12f(%rip)   # imm = 0x400
movl $0x400, %edi            # imm = 0x400
callq 0x32f0
movq %rax, 0x1a116(%rip)     # 0x1e350
movq %r14, 0x18(%rsp)
movq %r14, %rdi
xorl %esi, %esi
callq 0x4a1f
testq %rax, %rax
je 0x42e2
xorl %r14d, %r14d
leaq 0x14074(%rip), %r15     # 0x182d0
leaq 0x14070(%rip), %r12     # 0x182d3
leaq 0x8(%rsp), %r13
xorl %ebp, %ebp
movq 0x1a0df(%rip), %rdi     # 0x1e350
movq %r15, %rsi
callq 0x3370
xorl %edi, %edi
movq %r12, %rsi
callq 0x3370
movq %rax, %rbx
xorl %edi, %edi
movq %r15, %rsi
callq 0x3370
testq %rax, %rax
je 0x42c6
cmpb $0xa, (%rax)
je 0x42c6
movq %rbx, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0x3320
cmpl %eax, %ebp
jge 0x42c1
movq %rbx, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0x3320
movq %rax, %rbp
incq %r14
jmp 0x4279
incq %r14
incl 0x1a049(%rip)           # 0x1e318
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x4a1f
testq %rax, %rax
jne 0x426a
jmp 0x42e7
xorl %ebp, %ebp
xorl %r14d, %r14d
movl %ebp, 0x19fdb(%rip)     # 0x1e2c8
movq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x3070
movsd 0x1a046(%rip), %xmm0    # 0x1e348
movsd %xmm0, (%rsp)
movsd %xmm0, 0x1a021(%rip)    # 0x1e330
movslq 0x1a002(%rip), %r15     # 0x1e318
leaq (,%r15,8), %rbx
movq %rbx, %rdi
callq 0x32f0
movq %rax, 0x19ff3(%rip)     # 0x1e320
movq %rbx, %rdi
callq 0x32f0
movq %rax, 0x19fec(%rip)     # 0x1e328
addq %r15, %r14
shlq $0x4, %r14
movq %r14, %rdi
callq 0x32f0
movq %rax, 0x19fbe(%rip)     # 0x1e310
testq %r15, %r15
jle 0x456c
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r13d, %r13d
movl 0x19f5f(%rip), %esi     # 0x1e2c8
movq %r12, %rdi
callq 0x4a1f
movq %r13, %rbp
shlq $0x4, %rbp
movq 0x19f91(%rip), %rax     # 0x1e310
addq %rbp, %rax
movq 0x19f9f(%rip), %rcx     # 0x1e328
movq %rax, (%rcx,%rbx,8)
movq 0x19fbc(%rip), %rdi     # 0x1e350
leaq 0x13f3a(%rip), %rsi     # 0x182d5
callq 0x3370
testq %rax, %rax
movq %rbx, %r12
je 0x45f6
movq %rax, %r15
movq %r13, %rbx
movq %r14, 0x20(%rsp)
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3170
movq 0x19f55(%rip), %rax     # 0x1e320
movq %r12, 0x10(%rsp)
movsd %xmm0, (%rax,%r12,8)
movq 0x8(%rsp), %rax
cmpq %r15, %rax
je 0x45ec
cmpb $0x0, (%rax)
jne 0x45ec
xorl %r15d, %r15d
xorl %edi, %edi
leaq 0x13eda(%rip), %rsi     # 0x182d3
callq 0x3370
movq %rax, %r13
xorl %edi, %edi
leaq 0x13ec6(%rip), %rsi     # 0x182d0
callq 0x3370
testq %rax, %rax
je 0x4506
movq %rax, %r14
callq 0x3040
movq %rax, (%rsp)
xorl %r12d, %r12d
movq (%rsp), %rax
movl $0x0, (%rax)
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
movl $0xa, %edx
callq 0x3320
movq %rax, %r15
movq 0x19ec3(%rip), %rax     # 0x1e310
movl %r15d, (%rax,%rbp)
movq 0x8(%rsp), %rax
cmpq %r13, %rax
je 0x45d8
movq (%rsp), %rcx
cmpl $0x0, (%rcx)
jne 0x45d8
cmpb $0x0, (%rax)
jne 0x45d8
cmpl %r15d, %r12d
jge 0x45d8
movq (%rsp), %rax
movl $0x0, (%rax)
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x3170
movq 0x19e74(%rip), %rax     # 0x1e310
movsd %xmm0, 0x8(%rax,%rbp)
movq 0x8(%rsp), %rax
cmpq %r14, %rax
je 0x45e2
movq (%rsp), %rcx
cmpl $0x0, (%rcx)
jne 0x45e2
movsbl (%rax), %edi
testl %edi, %edi
je 0x44d1
callq 0x3060
testl %eax, %eax
je 0x45e2
incq %rbx
xorl %edi, %edi
leaq 0x13df6(%rip), %rsi     # 0x182d3
callq 0x3370
movq %rax, %r13
xorl %edi, %edi
leaq 0x13de2(%rip), %rsi     # 0x182d0
callq 0x3370
movq %rax, %r14
addq $0x10, %rbp
movl %r15d, %r12d
testq %rax, %rax
jne 0x4427
movq 0x20(%rsp), %r14
cmpl %r14d, %r15d
cmovgl %r15d, %r14d
movsd 0x19e16(%rip), %xmm1    # 0x1e330
ucomisd 0x13b1e(%rip), %xmm1    # 0x18040
movq 0x19de7(%rip), %rax     # 0x1e310
movq 0x18(%rsp), %r12
jae 0x4535
movq %rbx, %rcx
jmp 0x4543
leaq 0x1(%rbx), %rcx
shlq $0x4, %rbx
movsd %xmm1, 0x8(%rax,%rbx)
leaq 0x1(%rcx), %r13
shlq $0x4, %rcx
movl $0xffffffff, (%rax,%rcx) # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rbx
incq %rbx
movslq 0x19db7(%rip), %r15     # 0x1e318
cmpq %r15, %rbx
jl 0x4363
jmp 0x4577
xorl %r13d, %r13d
xorl %r14d, %r14d
movsd (%rsp), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jae 0x458a
movl %r14d, 0x19d94(%rip)    # 0x1e31c
jmp 0x45c2
incl %r14d
movl %r14d, 0x19d88(%rip)    # 0x1e31c
cmpl $0x2, %r15d
jl 0x45b9
movq 0x19d87(%rip), %rcx     # 0x1e328
movl %r15d, %edx
movl $0x1, %esi
movq (%rcx,%rsi,8), %rdi
movl %r14d, -0x20(%rdi)
incq %rsi
cmpq %rsi, %rdx
jne 0x45a9
shlq $0x4, %r13
movl %r14d, -0x20(%rax,%r13)
movq %r12, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3200
movq 0x10(%rsp), %rdi
callq 0x3550
movq 0x10(%rsp), %rdi
callq 0x352a
movq 0x10(%rsp), %rdi
callq 0x3576
movq %r12, %rdi
callq 0x359c
movq %rbx, %rdi
callq 0x35c2