// File: /workspace/github_cpp_makefile_star2_O2/cjlin1[P]liblinear/train.c
// Function: read_problem(char const*)
void read_problem(const char *filename)
{
	int max_index, inst_max_index, i;
	size_t 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)!=NULL)
	{
		char *p = strtok(line," \t"); // label

		// features
		while(1)
		{
			p = strtok(NULL," \t");
			if(p == NULL || *p == '\n') // check '\n' as ' ' may be after the last feature
				break;
			elements++;
		}
		elements++; // for bias term
		prob.l++;
	}
	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);
		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 0x99a2(%rip), %rsi      # 0xc31b
callq 0x2190
testq %rax, %rax
je 0x2cb4
movq %rax, %r12
andl $0x0, 0xe877(%rip)      # 0x11208
movl $0x400, 0xe8bd(%rip)    # imm = 0x400
movl $0x400, %edi            # imm = 0x400
callq 0x21f0
movq %rax, 0xe8a4(%rip)      # 0x11250
xorl %r14d, %r14d
leaq 0x9981(%rip), %rbx      # 0xc337
movq %r12, %rdi
callq 0x2f50
testq %rax, %rax
je 0x29f1
movq 0xe886(%rip), %rdi      # 0x11250
movq %rbx, %rsi
callq 0x2250
incq %r14
xorl %edi, %edi
movq %rbx, %rsi
callq 0x2250
testq %rax, %rax
je 0x29e9
cmpb $0xa, (%rax)
jne 0x29d2
incl 0xe819(%rip)            # 0x11208
jmp 0x29b6
movq %r12, %rdi
callq 0x2070
movsd 0xe847(%rip), %xmm0     # 0x11248
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0xe811(%rip)     # 0x11220
movslq 0xe7f2(%rip), %r15      # 0x11208
leaq (,%r15,8), %rbx
movq %rbx, %rdi
callq 0x21f0
movq %rax, 0xe7e3(%rip)      # 0x11210
movq %rbx, %rdi
callq 0x21f0
movq %rax, 0xe7dc(%rip)      # 0x11218
addq %r15, %r14
shlq $0x4, %r14
movq %r14, %rdi
callq 0x21f0
movq %rax, 0xe75e(%rip)      # 0x111b0
xorl %r14d, %r14d
xorl %ebx, %ebx
xorl %r13d, %r13d
movq %r12, 0x20(%rsp)
movslq %r15d, %rcx
cmpq %rcx, %r14
jge 0x2c3d
movq %r12, %rdi
callq 0x2f50
movq %rbx, %r15
movq %rbx, %rbp
shlq $0x4, %rbp
movq 0xe72c(%rip), %rax      # 0x111b0
addq %rbp, %rax
movq 0xe78a(%rip), %rcx      # 0x11218
movq %rax, (%rcx,%r14,8)
movq 0xe7b7(%rip), %rdi      # 0x11250
leaq 0x989a(%rip), %rsi      # 0xc33a
callq 0x2250
testq %rax, %rax
je 0x2ca9
movq %rax, %rbx
movl %r13d, 0x10(%rsp)
movq %rax, %rdi
leaq 0x8(%rsp), %rsi
callq 0x20c0
movq 0xe746(%rip), %rax      # 0x11210
movq %r14, (%rsp)
movsd %xmm0, (%rax,%r14,8)
movq 0x8(%rsp), %rax
cmpq %rbx, %rax
je 0x2c9e
cmpb $0x0, (%rax)
jne 0x2c9e
orq $0x8, %rbp
movq %rbp, 0x18(%rsp)
xorl %ebp, %ebp
xorl %edi, %edi
leaq 0x983f(%rip), %rsi      # 0xc33e
callq 0x2250
movq %rax, %r13
xorl %edi, %edi
leaq 0x9827(%rip), %rsi      # 0xc337
callq 0x2250
testq %rax, %rax
je 0x2be0
movq %rax, %r14
movq %r15, %r12
callq 0x2040
movq %rax, %r15
andl $0x0, (%rax)
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
pushq $0xa
popq %rdx
callq 0x2210
movq %rax, %rbx
movq 0xe667(%rip), %rax      # 0x111b0
movq 0x18(%rsp), %rcx
movl %ebx, -0x8(%rax,%rcx)
movq 0x8(%rsp), %rax
cmpq %r13, %rax
je 0x2c9e
cmpl $0x0, (%r15)
jne 0x2c9e
cmpb $0x0, (%rax)
jne 0x2c9e
cmpl %ebx, %ebp
jge 0x2c9e
andl $0x0, (%r15)
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x20c0
movq 0xe61d(%rip), %rax      # 0x111b0
movq 0x18(%rsp), %r13
movsd %xmm0, (%rax,%r13)
movq 0x8(%rsp), %rax
cmpq %r14, %rax
je 0x2c9e
cmpl $0x0, (%r15)
jne 0x2c9e
movsbl (%rax), %edi
testl %edi, %edi
je 0x2bca
callq 0x2060
testl %eax, %eax
je 0x2c9e
movq %r12, %r15
incq %r15
addq $0x10, %r13
movq %r13, 0x18(%rsp)
movl %ebx, %ebp
jmp 0x2af6
movl 0x10(%rsp), %r13d
cmpl %r13d, %ebp
cmovgl %ebp, %r13d
movsd 0xe62c(%rip), %xmm0     # 0x11220
ucomisd 0x943c(%rip), %xmm0     # 0xc038
movq 0xe5ad(%rip), %rax      # 0x111b0
movq 0x20(%rsp), %r12
movsd %xmm0, 0x10(%rsp)
jb 0x2c1d
incq %r15
movq 0x18(%rsp), %rcx
movsd %xmm0, (%rax,%rcx)
movq (%rsp), %r14
leaq 0x1(%r15), %rbx
shlq $0x4, %r15
orl $-0x1, (%rax,%r15)
incq %r14
movl 0xe5d0(%rip), %r15d     # 0x11208
jmp 0x2a5f
xorpd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jae 0x2c56
movl %r13d, 0xe5b8(%rip)     # 0x1120c
jmp 0x2c88
movq %rbx, %r8
incl %r13d
movl %r13d, 0xe5a9(%rip)     # 0x1120c
pushq $0x1
popq %rdx
movq 0xe5ab(%rip), %rsi      # 0x11218
cmpq %rcx, %rdx
jge 0x2c7f
movq (%rsi,%rdx,8), %rdi
movl %r13d, -0x20(%rdi)
incq %rdx
jmp 0x2c6d
shlq $0x4, %r8
movl %r13d, -0x20(%rax,%r8)
movq %r12, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2130
movq (%rsp), %rdi
incl %edi
callq 0x2412
incl %r14d
movl %r14d, %edi
callq 0x2412
movq 0xe325(%rip), %rax      # 0x10fe0
movq (%rax), %rdi
leaq 0x9658(%rip), %rsi      # 0xc31d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2220
pushq $0x1
popq %rdi
callq 0x21b0