// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x20f4c(%rip), %rsi     # 0x2500a
callq 0x3360
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x40f4
movq 0x26f03(%rip), %rax     # 0x2afd8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0x20f29(%rip), %rsi     # 0x2500c
movb $0x0, %al
callq 0x3400
movl $0x1, %edi
callq 0x3380
movl $0x0, 0x27462(%rip)     # 0x2b560
movq $0x0, -0x20(%rbp)
movl $0x400, 0x27490(%rip)   # imm = 0x400
movslq 0x27489(%rip), %rdi     # 0x2b5a0
shlq $0x0, %rdi
callq 0x33d0
movq %rax, 0x27471(%rip)     # 0x2b598
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x4b40
cmpq $0x0, %rax
je 0x41ea
movq 0x27455(%rip), %rdi     # 0x2b598
leaq 0x20edc(%rip), %rsi     # 0x25026
callq 0x3440
movq %rax, -0x58(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0x20ecb(%rip), %rsi     # 0x25029
callq 0x3440
movq %rax, -0x40(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0x20eb4(%rip), %rsi     # 0x25026
callq 0x3440
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x418e
movq -0x58(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x4190
jmp 0x41ca
movq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rsi
movl $0xa, %edx
callq 0x33f0
cmpl -0x18(%rbp), %eax
jle 0x41bc
movq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rsi
movl $0xa, %edx
callq 0x33f0
movl %eax, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x4153
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movl 0x27384(%rip), %eax     # 0x2b560
addl $0x1, %eax
movl %eax, 0x2737b(%rip)     # 0x2b560
jmp 0x4127
movl -0x18(%rbp), %eax
movl %eax, 0x2731d(%rip)     # 0x2b510
movq -0x30(%rbp), %rdi
callq 0x3070
movsd 0x2738c(%rip), %xmm0    # 0x2b590
movsd %xmm0, 0x2736c(%rip)    # 0x2b578
movslq 0x2734d(%rip), %rdi     # 0x2b560
shlq $0x3, %rdi
callq 0x33d0
movq %rax, 0x27345(%rip)     # 0x2b568
movslq 0x27336(%rip), %rdi     # 0x2b560
shlq $0x3, %rdi
callq 0x33d0
movq %rax, 0x27336(%rip)     # 0x2b570
movq -0x20(%rbp), %rdi
movslq 0x2731b(%rip), %rax     # 0x2b560
addq %rax, %rdi
shlq $0x4, %rdi
callq 0x33d0
movq %rax, 0x27300(%rip)     # 0x2b558
movl $0x0, -0xc(%rbp)
movq $0x0, -0x28(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x272e9(%rip), %eax     # 0x2b560
jge 0x44d7
movl $0x0, -0x10(%rbp)
movq -0x30(%rbp), %rdi
movl 0x27282(%rip), %esi     # 0x2b510
callq 0x4b40
movq 0x272be(%rip), %rdx     # 0x2b558
movq -0x28(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdx
movq 0x272c4(%rip), %rax     # 0x2b570
movslq -0x14(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x272dd(%rip), %rdi     # 0x2b598
leaq 0x20d69(%rip), %rsi     # 0x2502b
callq 0x3440
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x42dd
movl -0x14(%rbp), %edi
addl $0x1, %edi
callq 0x36c0
movq -0x50(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x31e0
movq 0x27277(%rip), %rax     # 0x2b568
movslq -0x14(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
cmpq -0x50(%rbp), %rax
je 0x4310
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x431b
movl -0x14(%rbp), %edi
addl $0x1, %edi
callq 0x36c0
jmp 0x431d
xorl %eax, %eax
movl %eax, %edi
leaq 0x20d01(%rip), %rsi     # 0x25029
callq 0x3440
movq %rax, -0x40(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0x20cea(%rip), %rsi     # 0x25026
callq 0x3440
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x4351
jmp 0x445d
callq 0x3040
movl $0x0, (%rax)
movq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rsi
movl $0xa, %edx
callq 0x33f0
movl %eax, %ecx
movq 0x271e1(%rip), %rax     # 0x2b558
movq -0x28(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x43bd
callq 0x3040
cmpl $0x0, (%rax)
jne 0x43bd
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x43bd
movq 0x271ad(%rip), %rax     # 0x2b558
movq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x10(%rbp), %eax
jg 0x43ca
movl -0x14(%rbp), %edi
addl $0x1, %edi
callq 0x36c0
jmp 0x43e1
movq 0x27187(%rip), %rax     # 0x2b558
movq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x10(%rbp)
callq 0x3040
movl $0x0, (%rax)
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x31e0
movq 0x27158(%rip), %rax     # 0x2b558
movq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movsd %xmm0, 0x8(%rax)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x4441
callq 0x3040
cmpl $0x0, (%rax)
jne 0x4441
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x444c
movq -0x38(%rbp), %rax
movsbl (%rax), %edi
callq 0x3060
cmpl $0x0, %eax
jne 0x444c
movl -0x14(%rbp), %edi
addl $0x1, %edi
callq 0x36c0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x431d
movl -0x10(%rbp), %eax
cmpl -0xc(%rbp), %eax
jle 0x446b
movl -0x10(%rbp), %eax
movl %eax, -0xc(%rbp)
movsd 0x27105(%rip), %xmm0    # 0x2b578
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x44a6
movsd 0x270f4(%rip), %xmm0    # 0x2b578
movq 0x270cd(%rip), %rax     # 0x2b558
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 0x270ab(%rip), %rax     # 0x2b558
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 0x426e
movsd 0x27099(%rip), %xmm0    # 0x2b578
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x4549
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, 0x27070(%rip)     # 0x2b564
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl 0x2705c(%rip), %eax     # 0x2b560
jge 0x4529
movl 0x27058(%rip), %ecx     # 0x2b564
movq 0x2705d(%rip), %rax     # 0x2b570
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 0x44fb
movl 0x27035(%rip), %ecx     # 0x2b564
movq 0x27022(%rip), %rax     # 0x2b558
movq -0x28(%rbp), %rdx
subq $0x2, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
jmp 0x4552
movl -0xc(%rbp), %eax
movl %eax, 0x27012(%rip)     # 0x2b564
movq -0x30(%rbp), %rdi
callq 0x32b0
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)