// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x10129(%rip), %rsi     # 0x12c50
callq 0x2170
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x2b5d
movq 0x134a2(%rip), %rax     # 0x15fe0
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x10106(%rip), %rsi     # 0x12c52
movb $0x0, %al
callq 0x21f0
movl $0x1, %edi
callq 0x2190
movl $0x0, 0x13741(%rip)     # 0x162a8
movq $0x0, -0x20(%rbp)
movl $0x400, 0x1377f(%rip)   # imm = 0x400
movslq 0x13778(%rip), %rdi     # 0x162f8
shlq $0x0, %rdi
callq 0x21c0
movq %rax, 0x13760(%rip)     # 0x162f0
movq -0x30(%rbp), %rdi
callq 0x3390
cmpq $0x0, %rax
je 0x2c0a
movq 0x1374a(%rip), %rdi     # 0x162f0
leaq 0x100bf(%rip), %rsi     # 0x12c6c
callq 0x2210
movq %rax, -0x58(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0x100ab(%rip), %rsi     # 0x12c6c
callq 0x2210
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x2bdd
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x2bdf
jmp 0x2bed
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2bb6
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movl 0x136a9(%rip), %eax     # 0x162a8
addl $0x1, %eax
movl %eax, 0x136a0(%rip)     # 0x162a8
jmp 0x2b90
movq -0x30(%rbp), %rdi
callq 0x2070
movsd 0x136cd(%rip), %xmm0    # 0x162e8
movsd %xmm0, 0x1369d(%rip)    # 0x162c0
movslq 0x1367e(%rip), %rdi     # 0x162a8
shlq $0x3, %rdi
callq 0x21c0
movq %rax, 0x13676(%rip)     # 0x162b0
movslq 0x13667(%rip), %rdi     # 0x162a8
shlq $0x3, %rdi
callq 0x21c0
movq %rax, 0x13667(%rip)     # 0x162b8
movq -0x20(%rbp), %rdi
movslq 0x1364c(%rip), %rax     # 0x162a8
addq %rax, %rdi
shlq $0x4, %rdi
callq 0x21c0
movq %rax, 0x135e1(%rip)     # 0x16250
movl $0x0, -0xc(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x1361a(%rip), %eax     # 0x162a8
jge 0x2ee8
movl $0x0, -0x10(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3390
movq 0x135a5(%rip), %rdx     # 0x16250
movq -0x28(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdx
movq 0x135fb(%rip), %rax     # 0x162b8
movslq -0x14(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x13624(%rip), %rdi     # 0x162f0
leaq 0xff9c(%rip), %rsi      # 0x12c6f
callq 0x2210
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x2cee
movl -0x14(%rbp), %edi
addl $0x1, %edi
callq 0x23f0
movq -0x50(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x20c0
movq 0x135ae(%rip), %rax     # 0x162b0
movslq -0x14(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
cmpq -0x50(%rbp), %rax
je 0x2d21
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x2d2c
movl -0x14(%rbp), %edi
addl $0x1, %edi
callq 0x23f0
jmp 0x2d2e
xorl %eax, %eax
movl %eax, %edi
leaq 0xff3a(%rip), %rsi      # 0x12c73
callq 0x2210
movq %rax, -0x40(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0xff1f(%rip), %rsi      # 0x12c6c
callq 0x2210
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x2d62
jmp 0x2e6e
callq 0x2040
movl $0x0, (%rax)
movq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rsi
movl $0xa, %edx
callq 0x21e0
movl %eax, %ecx
movq 0x134c8(%rip), %rax     # 0x16250
movq -0x28(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x2dce
callq 0x2040
cmpl $0x0, (%rax)
jne 0x2dce
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x2dce
movq 0x13494(%rip), %rax     # 0x16250
movq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x10(%rbp), %eax
jg 0x2ddb
movl -0x14(%rbp), %edi
addl $0x1, %edi
callq 0x23f0
jmp 0x2df2
movq 0x1346e(%rip), %rax     # 0x16250
movq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x10(%rbp)
callq 0x2040
movl $0x0, (%rax)
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x20c0
movq 0x1343f(%rip), %rax     # 0x16250
movq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x2e52
callq 0x2040
cmpl $0x0, (%rax)
jne 0x2e52
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x2e5d
movq -0x38(%rbp), %rax
movsbl (%rax), %edi
callq 0x2060
cmpl $0x0, %eax
jne 0x2e5d
movl -0x14(%rbp), %edi
addl $0x1, %edi
callq 0x23f0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x2d2e
movl -0x10(%rbp), %eax
cmpl -0xc(%rbp), %eax
jle 0x2e7c
movl -0x10(%rbp), %eax
movl %eax, -0xc(%rbp)
movsd 0x1343c(%rip), %xmm0    # 0x162c0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x2eb7
movsd 0x1342b(%rip), %xmm0    # 0x162c0
movq 0x133b4(%rip), %rax     # 0x16250
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movq 0x13392(%rip), %rax     # 0x16250
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
shlq $0x4, %rcx
addq %rcx, %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2c85
movsd 0x133d0(%rip), %xmm0    # 0x162c0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x2f5a
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, 0x133a7(%rip)     # 0x162ac
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x13393(%rip), %eax     # 0x162a8
jge 0x2f3a
movl 0x1338f(%rip), %ecx     # 0x162ac
movq 0x13394(%rip), %rax     # 0x162b8
movslq -0x14(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, -0x20(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2f0c
movl 0x1336c(%rip), %ecx     # 0x162ac
movq 0x13309(%rip), %rax     # 0x16250
movq -0x28(%rbp), %rdx
subq $0x2, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
jmp 0x2f63
movl -0xc(%rbp), %eax
movl %eax, 0x13349(%rip)     # 0x162ac
movq -0x30(%rbp), %rdi
callq 0x2120
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)