// File: /workspace/github_c_makefile_star2_O3/DVaronos[P]AnLogProject1/logistic.c
// Function: Training
Model* Training(Model* model,Input* input,Hash* H,JobSheduler* Sheduler){

  int   i,j,start=0,limit,msize=10,curr=0;
	double w,b;
	Job* job;
	TrainStruct** array=malloc(sizeof(TrainStruct*)*msize);
	while(start<input->size){ //Gia ola ta zevgaria tou input
		if(curr<msize){//Ean iparxei xwros ston array
			array[curr]=malloc(sizeof(TrainStruct)*Sheduler->num); //ftiakse mia lista apo TrainStruct
		}else{//Resize kata 10 thesis ton pinaka array
			msize+=10;
			array=realloc(array,msize*sizeof(TrainStruct*));
			array[curr]=malloc(sizeof(TrainStruct)*Sheduler->num);
		}
		for(i=0 ; i<Sheduler->num ; i++ ){	//Gia kathe thread ftiakse mia domh TrainStruct kai arxikopieise thn
			array[curr][i].w=malloc(model->array_size*sizeof(double));
			for(j=0 ; j<model->array_size ; j++){
				array[curr][i].w[j]=model->weight_array[j];
			}
			array[curr][i].b=model->b;
			array[curr][i].input=input;
			array[curr][i].start=start;
			start+=1000;
			if(start>=input->size) start=input->size;
			array[curr][i].end=start;
			start++;
			job=JobCreate(JobTraining,(void*)(array[curr]+i));	//Dimiourgise ena neo job
			JSAddWork(Sheduler,job);	//Dwse to job ston Sheduler
			if(start==((input->size)+1)) break;	//An elegthoun ola ta zevgaria vges ap thn for
		}
		JSWaitalltasks(Sheduler);	//Perimene na teleiosoun ta threads
		limit=i;
		if(start==((input->size)+1)) limit++;
		for(i=0 ; i<model->array_size ; i++){	//arxikopieise to w kai to b
			w=0;
			for(j=0 ; j<limit ; j++){
				w+=array[curr][j].w[i];
			}
			w=w/limit;
			model->weight_array[i]=w;
		}
		b=0;
		for(i=0 ; i<limit ; i++){
			b+=array[curr][i].b;
		}
		b=b/limit;
		model->b=b;
		curr++;
	}
	for(int r=0 ; r<msize ; r++){	//Apodesmefse to array
		if(r<curr){
			for(int t=0 ; t<Sheduler->num ; t++){
				if((r==(curr-1)) && (t==limit)) break;
				free(array[r][t].w);
			}
			free(array[r]);
		}

	}
	free(array);
	return model;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r12
movq %rsi, %rbx
movq %rdi, -0x30(%rbp)
movl $0x50, %edi
callq 0x11a0
movq %rax, %r15
movq %rbx, -0x60(%rbp)
cmpl $0x0, 0x10(%rbx)
movq %r12, -0x58(%rbp)
jle 0x2541
xorl %r13d, %r13d
movl $0xa, %ecx
movl $0x0, -0x38(%rbp)
movq -0x60(%rbp), %rbx
movslq %ecx, %rax
cmpq %rax, %r13
jge 0x234d
movl %ecx, -0x44(%rbp)
jmp 0x2366
leal 0xa(%rax), %ecx
movl %ecx, -0x44(%rbp)
leaq 0x50(,%rax,8), %rsi
movq %r15, %rdi
callq 0x11c0
movq %rax, %r15
movslq 0xa8(%r12), %r14
movq %r14, %rdi
shlq $0x5, %rdi
callq 0x11a0
movq %rax, (%r15,%r13,8)
testq %r14, %r14
jle 0x2461
xorl %r14d, %r14d
movq %r13, -0x40(%rbp)
movq -0x30(%rbp), %rax
movslq 0x10(%rax), %r12
leaq (,%r12,8), %rdi
callq 0x11a0
movq %r14, %rcx
shlq $0x5, %rcx
movq (%r15,%r13,8), %rdx
movq %rax, 0x10(%rdx,%rcx)
movq (%r15,%r13,8), %rax
testq %r12, %r12
jle 0x23dc
movq -0x30(%rbp), %rdx
movq (%rdx), %rdx
movq 0x10(%rax,%rcx), %rsi
xorl %edi, %edi
movsd (%rdx,%rdi,8), %xmm0
movsd %xmm0, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %r12
jne 0x23ca
movq -0x30(%rbp), %rdx
movsd 0x8(%rdx), %xmm0
movsd %xmm0, 0x8(%rax,%rcx)
movq %rbx, 0x18(%rax,%rcx)
movq %r15, %r13
movq -0x40(%rbp), %rax
movq (%r15,%rax,8), %rax
leaq (%rax,%rcx), %rsi
movl -0x38(%rbp), %edi
movl %edi, (%rax,%rcx)
addl $0x3e8, %edi            # imm = 0x3E8
movl 0x10(%rbx), %edx
cmpl %edx, %edi
movl %edi, %r15d
cmovgel %edx, %r15d
movl %r15d, 0x4(%rax,%rcx)
leal 0x1(%r15), %eax
movl %eax, -0x38(%rbp)
leaq 0x1b7(%rip), %rdi       # 0x25e1
callq 0x543c
movq -0x58(%rbp), %r12
movq %r12, %rdi
movq %rax, %rsi
callq 0x5654
cmpl 0x10(%rbx), %r15d
je 0x2466
incq %r14
movslq 0xa8(%r12), %rax
cmpq %rax, %r14
movq %r13, %r15
movq -0x40(%rbp), %r13
jl 0x238e
jmp 0x246d
xorl %r14d, %r14d
jmp 0x246d
movq %r13, %r15
movq -0x40(%rbp), %r13
movq %r12, %rdi
callq 0x56a5
movq -0x60(%rbp), %rax
movl 0x10(%rax), %eax
leal 0x1(%rax), %edx
xorl %ecx, %ecx
cmpl %edx, -0x38(%rbp)
sete %cl
addl %r14d, %ecx
movq -0x30(%rbp), %rdx
movslq 0x10(%rdx), %rdx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movl %ecx, %esi
movq %rsi, -0x50(%rbp)
testq %rdx, %rdx
jle 0x24f1
movq -0x30(%rbp), %rsi
movq (%rsi), %rsi
movq -0x50(%rbp), %rdi
shlq $0x5, %rdi
xorl %r8d, %r8d
testl %ecx, %ecx
je 0x24db
movq (%r15,%r13,8), %r9
xorpd %xmm1, %xmm1
xorl %r10d, %r10d
movq 0x10(%r9,%r10), %r11
addsd (%r11,%r8,8), %xmm1
addq $0x20, %r10
cmpq %r10, %rdi
jne 0x24c5
jmp 0x24df
xorpd %xmm1, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsi,%r8,8)
incq %r8
cmpq %rdx, %r8
jne 0x24b6
testl %ecx, %ecx
je 0x2518
movq (%r15,%r13,8), %rcx
movq -0x50(%rbp), %rdx
shlq $0x5, %rdx
xorpd %xmm1, %xmm1
xorl %esi, %esi
addsd 0x8(%rcx,%rsi), %xmm1
addq $0x20, %rsi
cmpq %rsi, %rdx
jne 0x2507
jmp 0x251c
xorpd %xmm1, %xmm1
divsd %xmm0, %xmm1
movq -0x30(%rbp), %rcx
movsd %xmm1, 0x8(%rcx)
incq %r13
cmpl %eax, -0x38(%rbp)
movl -0x44(%rbp), %ecx
jl 0x2340
testl %ecx, %ecx
jg 0x2551
jmp 0x25c6
movl $0xa, %ecx
xorl %r13d, %r13d
movq $0x0, -0x50(%rbp)
movl %r13d, %eax
decl %r13d
movl %ecx, %ecx
xorl %r12d, %r12d
movq %rax, -0x38(%rbp)
movq %rcx, -0x40(%rbp)
cmpq %rax, %r12
jae 0x25be
movq -0x58(%rbp), %rax
cmpl $0x0, 0xa8(%rax)
jle 0x25ad
movl $0x10, %ebx
xorl %r14d, %r14d
cmpq %r13, %r12
jne 0x2589
cmpq %r14, -0x50(%rbp)
je 0x25ad
movq (%r15,%r12,8), %rax
movq (%rax,%rbx), %rdi
callq 0x1030
incq %r14
movq -0x58(%rbp), %rax
movslq 0xa8(%rax), %rax
addq $0x20, %rbx
cmpq %rax, %r14
jl 0x257e
movq (%r15,%r12,8), %rdi
callq 0x1030
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
incq %r12
cmpq %rcx, %r12
jne 0x2564
movq %r15, %rdi
callq 0x1030
movq -0x30(%rbp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq