// File: /workspace/github_c_makefile_star2_O2/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, %r14
movq %rdi, %rbx
pushq $0x50
popq %rdi
callq 0x11a0
movq %rax, %r15
movq %r14, -0x40(%rbp)
movl 0x10(%r14), %eax
pushq $0xa
popq %rcx
xorl %r13d, %r13d
movl $0x0, -0x30(%rbp)
movq %r12, -0x58(%rbp)
cmpl %eax, -0x30(%rbp)
jge 0x2402
movslq %ecx, %rax
cmpq %rax, %r13
jge 0x2228
movq %rcx, -0x48(%rbp)
jmp 0x2242
addl $0xa, %ecx
movq %rcx, -0x48(%rbp)
leaq 0x50(,%rax,8), %rsi
movq %r15, %rdi
callq 0x11c0
movq %rax, %r15
movslq 0xa8(%r12), %r12
movq %r12, %rdi
shlq $0x5, %rdi
callq 0x11a0
movq %rax, (%r15,%r13,8)
movq $0x0, -0x38(%rbp)
xorl %ecx, %ecx
movslq %r12d, %rax
cmpq %rax, %rcx
movq %rcx, -0x50(%rbp)
jge 0x234c
movq %rcx, %r14
movslq 0x10(%rbx), %r12
movq %r12, %rdi
shlq $0x3, %rdi
callq 0x11a0
movq (%r15,%r13,8), %rdx
movq %r14, %rcx
shlq $0x5, %rcx
movq %rax, 0x10(%rdx,%rcx)
testl %r12d, %r12d
movl $0x0, %eax
cmovgl %r12d, %eax
xorl %edx, %edx
cmpq %rdx, %rax
je 0x22c5
movq (%rbx), %rsi
movsd (%rsi,%rdx,8), %xmm0
movq (%r15,%r13,8), %rsi
movq 0x10(%rsi,%rcx), %rsi
movsd %xmm0, (%rsi,%rdx,8)
incq %rdx
jmp 0x22a5
movsd 0x8(%rbx), %xmm0
movq (%r15,%r13,8), %rax
movsd %xmm0, 0x8(%rax,%rcx)
movq -0x40(%rbp), %rdx
movq %rdx, 0x18(%rax,%rcx)
movq (%r15,%r13,8), %rax
leaq (%rax,%rcx), %rsi
movl -0x30(%rbp), %edi
movl %edi, (%rax,%rcx)
addl $0x3e8, %edi            # imm = 0x3E8
movl 0x10(%rdx), %edx
cmpl %edx, %edi
movl %edi, %r12d
cmovgel %edx, %r12d
movl %r12d, 0x4(%rax,%rcx)
leal 0x1(%r12), %eax
movl %eax, -0x30(%rbp)
leaq 0x19b(%rip), %rdi       # 0x24ac
callq 0x4ce8
movq -0x58(%rbp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x4edd
movq -0x40(%rbp), %rax
cmpl 0x10(%rax), %r12d
je 0x2352
movq -0x50(%rbp), %rcx
incq %rcx
movl 0xa8(%r14), %r12d
movq -0x38(%rbp), %rax
incl %eax
movq %rax, -0x38(%rbp)
jmp 0x2264
movq -0x58(%rbp), %r12
jmp 0x2355
movq %r14, %r12
movq %r12, %rdi
callq 0x4f2e
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
leal 0x1(%rax), %ecx
xorl %edx, %edx
cmpl %ecx, -0x30(%rbp)
sete %dl
movq -0x50(%rbp), %r9
addl %edx, %r9d
cvtsi2sd %r9d, %xmm0
movl 0x10(%rbx), %ecx
testl %ecx, %ecx
movl $0x0, %esi
cmovlel %esi, %ecx
movq -0x38(%rbp), %r10
addl %edx, %r10d
movq %r10, %rdx
shlq $0x5, %rdx
xorl %esi, %esi
cmpq %rcx, %rsi
je 0x23ce
xorpd %xmm1, %xmm1
xorl %edi, %edi
cmpq %rdi, %rdx
je 0x23bd
movq (%r15,%r13,8), %r8
movq 0x10(%r8,%rdi), %r8
addsd (%r8,%rsi,8), %xmm1
addq $0x20, %rdi
jmp 0x23a3
divsd %xmm0, %xmm1
movq (%rbx), %rdi
movsd %xmm1, (%rdi,%rsi,8)
incq %rsi
jmp 0x2398
shlq $0x5, %r10
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
cmpq %rcx, %r10
je 0x23ed
movq (%r15,%r13,8), %rdx
addsd 0x8(%rdx,%rcx), %xmm1
addq $0x20, %rcx
jmp 0x23d8
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rbx)
incq %r13
movq -0x48(%rbp), %rcx
jmp 0x2211
leal -0x1(%r13), %eax
movq %rax, -0x50(%rbp)
movl %r9d, %eax
movq %rax, -0x40(%rbp)
movl %r13d, %eax
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
movq %rcx, -0x48(%rbp)
movq %rax, -0x38(%rbp)
cmpq %rcx, %rdx
je 0x2492
cmpq %rax, %rdx
jae 0x248d
movq %rdx, %rax
xorq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
pushq $0x10
popq %r12
xorl %r13d, %r13d
movq -0x58(%rbp), %rax
movslq 0xa8(%rax), %rcx
movq -0x40(%rbp), %rax
xorq %r13, %rax
orq -0x30(%rbp), %rax
sete %al
movq %rdx, %r14
movq (%r15,%rdx,8), %rdi
cmpq %rcx, %r13
jge 0x247d
testb %al, %al
jne 0x247d
movq (%rdi,%r12), %rdi
callq 0x1030
incq %r13
addq $0x20, %r12
movq %r14, %rdx
jmp 0x243f
callq 0x1030
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %r14, %rdx
incq %rdx
jmp 0x2423
movq %r15, %rdi
callq 0x1030
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq