// File: /workspace/github_c_makefile_star2_O1/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, -0x38(%rbp)
movl $0x50, %edi
callq 0x11a0
movq %rax, %r15
movq %rbx, -0x40(%rbp)
cmpl $0x0, 0x10(%rbx)
movq %r12, -0x50(%rbp)
jle 0x257a
xorl %r13d, %r13d
movl $0xa, %r14d
xorl %r11d, %r11d
movslq %r14d, %rax
cmpq %rax, %r13
movl %r11d, -0x48(%rbp)
jl 0x238e
leal 0xa(%rax), %r14d
leaq 0x50(,%rax,8), %rsi
movq %r15, %rdi
callq 0x11c0
movq %rax, %r15
movslq 0xa8(%r12), %rbx
movq %rbx, %rdi
shlq $0x5, %rdi
callq 0x11a0
movq %rax, (%r15,%r13,8)
testq %rbx, %rbx
jle 0x2499
movl %r14d, -0x54(%rbp)
xorl %ebx, %ebx
movq -0x38(%rbp), %rax
movslq 0x10(%rax), %r12
leaq (,%r12,8), %rdi
callq 0x11a0
movq %rbx, -0x30(%rbp)
movq %rbx, %rcx
shlq $0x5, %rcx
movq (%r15,%r13,8), %rdx
movq %rax, 0x10(%rdx,%rcx)
testq %r12, %r12
jle 0x2407
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq (%r15,%r13,8), %rdx
movq 0x10(%rdx,%rcx), %rdx
xorl %esi, %esi
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %r12
jne 0x23f5
movq -0x38(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq (%r15,%r13,8), %rax
movsd %xmm0, 0x8(%rax,%rcx)
movq -0x40(%rbp), %rbx
movq %rbx, 0x18(%rax,%rcx)
movq %r13, %rax
movq %r15, %r13
movq %rax, %r14
movq (%r15,%rax,8), %rax
leaq (%rax,%rcx), %rsi
movl -0x48(%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, -0x48(%rbp)
leaq 0x1c2(%rip), %rdi       # 0x2621
callq 0x5434
movq -0x50(%rbp), %r12
movq %r12, %rdi
movq %rax, %rsi
callq 0x565c
cmpl 0x10(%rbx), %r15d
je 0x249d
movq -0x30(%rbp), %rbx
incq %rbx
movslq 0xa8(%r12), %rax
cmpq %rax, %rbx
movq %r13, %r15
movq %r14, %r13
jl 0x23b5
jmp 0x24a7
xorl %ebx, %ebx
jmp 0x24ab
movq %r13, %r15
movq %r14, %r13
movq -0x30(%rbp), %rbx
movl -0x54(%rbp), %r14d
movq %r12, %rdi
callq 0x56ad
movq -0x40(%rbp), %rax
movl 0x10(%rax), %ecx
incl %ecx
xorl %eax, %eax
movl -0x48(%rbp), %r11d
cmpl %ecx, %r11d
sete %al
addl %ebx, %eax
movq -0x38(%rbp), %rcx
movslq 0x10(%rcx), %rcx
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movl %eax, %edx
movq %rdx, -0x30(%rbp)
testq %rcx, %rcx
jle 0x252f
movq -0x38(%rbp), %rdx
movq (%rdx), %rdx
movq -0x30(%rbp), %rsi
shlq $0x5, %rsi
xorl %edi, %edi
testl %eax, %eax
je 0x251a
movq (%r15,%r13,8), %r8
xorpd %xmm1, %xmm1
xorl %r9d, %r9d
movq 0x10(%r8,%r9), %r10
addsd (%r10,%rdi,8), %xmm1
addq $0x20, %r9
cmpq %r9, %rsi
jne 0x2504
jmp 0x251e
xorpd %xmm1, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rdx,%rdi,8)
incq %rdi
cmpq %rcx, %rdi
jne 0x24f5
testl %eax, %eax
je 0x2556
movq (%r15,%r13,8), %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
xorpd %xmm1, %xmm1
xorl %edx, %edx
addsd 0x8(%rax,%rdx), %xmm1
addq $0x20, %rdx
cmpq %rdx, %rcx
jne 0x2545
jmp 0x255a
xorpd %xmm1, %xmm1
divsd %xmm0, %xmm1
movq -0x38(%rbp), %rax
movsd %xmm1, 0x8(%rax)
incq %r13
movq -0x40(%rbp), %rax
cmpl 0x10(%rax), %r11d
jl 0x236b
jmp 0x258b
movq $0x0, -0x30(%rbp)
movl $0xa, %r14d
xorl %r13d, %r13d
testl %r14d, %r14d
jle 0x2606
movl %r13d, %eax
decl %r13d
movl %r14d, %ecx
xorl %r12d, %r12d
movq %rax, -0x48(%rbp)
movq %rcx, -0x40(%rbp)
cmpq %rax, %r12
jae 0x25fe
movq -0x50(%rbp), %rax
cmpl $0x0, 0xa8(%rax)
jle 0x25ed
movl $0x10, %ebx
xorl %r14d, %r14d
cmpq %r13, %r12
jne 0x25c9
cmpq %r14, -0x30(%rbp)
je 0x25ed
movq (%r15,%r12,8), %rax
movq (%rax,%rbx), %rdi
callq 0x1030
incq %r14
movq -0x50(%rbp), %rax
movslq 0xa8(%rax), %rax
addq $0x20, %rbx
cmpq %rax, %r14
jl 0x25be
movq (%r15,%r12,8), %rdi
callq 0x1030
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
incq %r12
cmpq %rcx, %r12
jne 0x25a4
movq %r15, %rdi
callq 0x1030
movq -0x38(%rbp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq