#include "SerializeDeserialize.cuh"

void serializeNeuralNet(NeuralNet* nn, char* fileName){
	// Opens the file for writing
	FILE* file=fopen(fileName, "w");

	// Writes the layer data
	fprintf(file, "%d\n", nn->layers);

	// Writes the neuron data
	for(int layer=0; layer<nn->layers; layer++){
		fprintf(file, "%d\n", nn->neurons[layer]);
	}

	// Writes the weight data
	for(int layer=0; layer<nn->layers-1; layer++){
		for(int neuron1=0; neuron1<nn->neurons[layer]; neuron1++){
			for(int neuron2=0; neuron2<nn->neurons[layer+1]; neuron2++){
				fprintf(file, "%lf\n", nn->weights[layer][neuron1][neuron2]);
			}
		}
	}

	// Writes the bias data
	for(int layer=0; layer<nn->layers-1; layer++){
		for(int neuron=0; neuron<nn->neurons[layer+1]; neuron++){
			fprintf(file, "%lf\n", nn->biases[layer][neuron]);
		}
	}

	// Writes the activation data
	for(int layer=0; layer<nn->layers-1; layer++){
		for(int neuron=0; neuron<nn->neurons[layer+1]; neuron++){
			fprintf(file, "%d\n", nn->activations[layer][neuron]);
		}
	}

	fclose(file);
}

NeuralNet* deserializeNeuralNet(char* fileName){
	FILE* file=fopen(fileName, "r");

	NeuralNet* nn;
	cudaMallocManaged(&nn, 1*sizeof(NeuralNet));

	// Gets the layers
	fscanf(file, "%d\n", &nn->layers);

	// Gets the neuron data
	cudaMallocManaged(&nn->neurons, nn->layers*sizeof(int));
	for(int layer=0; layer<nn->layers; layer++){
		fscanf(file, "%d\n", &nn->neurons[layer]);
	}

	// Gets the weight data
	cudaMallocManaged(&nn->weights, (nn->layers-1)*sizeof(double**));
	for(int layer=0; layer<nn->layers-1; layer++){
		cudaMallocManaged(&nn->weights[layer], nn->neurons[layer]*sizeof(double*));
		for(int neuron1=0; neuron1<nn->neurons[layer]; neuron1++){
			cudaMallocManaged(&nn->weights[layer][neuron1], 
				nn->neurons[layer+1]*sizeof(double));
			for(int neuron2=0; neuron2<nn->neurons[layer+1]; neuron2++){
				fscanf(file, "%lf\n", &nn->weights[layer][neuron1][neuron2]);
				//printf("Layer=%d\tNeuron1=%d\tNeuron2=%d\tWeight=%lf\n", layer, neuron1, neuron2, nn->weights[layer][neuron1][neuron2]);
			}
		}
	}

	// Gets the bias data
	cudaMallocManaged(&nn->biases, (nn->layers-1)*sizeof(double*));
	for(int layer=0; layer<nn->layers-1; layer++){
		cudaMallocManaged(&nn->biases[layer], nn->neurons[layer+1]*sizeof(double));
		for(int neuron=0; neuron<nn->neurons[layer+1]; neuron++){
			fscanf(file, "%lf\n", &nn->biases[layer][neuron]);
		}
	}

	// Gets the activation function data
	cudaMallocManaged(&nn->activations, (nn->layers-1)*sizeof(activation*));
	for(int layer=0; layer<nn->layers-1; layer++){
		cudaMallocManaged(&nn->activations[layer], nn->neurons[layer+1]*sizeof(activation));
		for(int neuron=0; neuron<nn->neurons[layer+1]; neuron++){
			fscanf(file, "%d\n", &nn->activations[layer][neuron]);
		}
	}

	fclose(file);

	return nn;
}

void serializeChessBoard(Piece** board, char* filename){
	FILE* file=fopen(filename, "w");
	
	fprintf(file, "\t");

	for(int col=0; col<DIM; col++){
		fprintf(file, "%c\t", ((int)'A')+col);
	}

	fprintf(file, "\n");

	for(int row=0; row<DIM; row++){

		fprintf(file, "%d\t", row);

		for(int col=0; col<DIM; col++){
			
			if(board[row][col].numberConversion==0){
				fprintf(file, "______\t");
			}

			else{
				fprintf(file, "__");

				if(board[row][col].piece.color==0){
					fprintf(file, "W");
				}
				else{
					fprintf(file, "B");
				}

				if(board[row][col].piece.isPawn){
					fprintf(file, "P");
				}
				else if(board[row][col].piece.isRook){
					fprintf(file, "R");
				}
				else if(board[row][col].piece.isKnight){
					fprintf(file, "N");
				}
				else if(board[row][col].piece.isBishop){
					fprintf(file, "B");
				}
				else if(board[row][col].piece.isQueen){
					fprintf(file, "Q");
				}
				else{
					fprintf(file, "K");
				}

				fprintf(file, "__\t");
			}
		}

		fprintf(file, "\n");
	}

	fprintf(file, "\n======================================================\n\n");

	for(int row=0; row<DIM; row++){
		for(int col=0; col<DIM; col++){
			fprintf(file, "Row %d, Col %d, Num %d, clr %d, fst %d, Pwn %d, Rk %d, Knt %d, Bshp %d, Qn %d, Kng %d\n", row, col, board[row][col].numberConversion, board[row][col].piece.color, board[row][col].piece.isFirstMove, board[row][col].piece.isPawn, board[row][col].piece.isRook, board[row][col].piece.isKnight, board[row][col].piece.isBishop, board[row][col].piece.isQueen, board[row][col].piece.isKing);
		}
	}

	fclose(file);
}

	.file	"tmpxft_002f69f4_00000000-6_SerializeDeserialize.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.type	_Z17cudaMallocManagedI2nnE9cudaErrorPPT_mj.constprop.0.isra.0, @function
_Z17cudaMallocManagedI2nnE9cudaErrorPPT_mj.constprop.0.isra.0:
.LFB2178:
	.cfi_startproc
	movl	$1, %edx
	jmp	cudaMallocManaged@PLT
	.cfi_endproc
.LFE2178:
	.size	_Z17cudaMallocManagedI2nnE9cudaErrorPPT_mj.constprop.0.isra.0, .-_Z17cudaMallocManagedI2nnE9cudaErrorPPT_mj.constprop.0.isra.0
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"w"
.LC1:
	.string	"%d\n"
.LC2:
	.string	"%lf\n"
	.text
	.globl	_Z18serializeNeuralNetP2nnPc
	.type	_Z18serializeNeuralNetP2nnPc, @function
_Z18serializeNeuralNetP2nnPc:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	movq	%rsi, %rdi
	leaq	.LC0(%rip), %rsi
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	call	fopen@PLT
	movl	(%rbx), %ecx
	movl	$2, %esi
	leaq	.LC1(%rip), %rdx
	movq	%rax, 8(%rsp)
	movq	%rax, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L4:
	cmpl	%r12d, (%rbx)
	jle	.L22
	movq	8(%rbx), %rax
	movq	8(%rsp), %rdi
	movl	$2, %esi
	leaq	.LC1(%rip), %rdx
	movl	(%rax,%r12,4), %ecx
	xorl	%eax, %eax
	incq	%r12
	call	__fprintf_chk@PLT
	jmp	.L4
.L22:
	xorl	%r12d, %r12d
	xorl	%r15d, %r15d
.L6:
	movl	(%rbx), %eax
	decl	%eax
	cmpl	%r15d, %eax
	jle	.L18
	leaq	4(%r12), %r13
	leaq	(%r12,%r12), %rbp
	xorl	%r14d, %r14d
.L11:
	movq	8(%rbx), %rax
	cmpl	%r14d, (%rax,%r12)
	jle	.L8
	leaq	0(,%r14,8), %r11
	xorl	%ecx, %ecx
.L9:
	movq	8(%rbx), %rax
	cmpl	%ecx, (%rax,%r13)
	jle	.L23
	movq	24(%rbx), %rax
	movq	8(%rsp), %rdi
	movl	$2, %esi
	leaq	.LC2(%rip), %rdx
	movq	%r11, 24(%rsp)
	movq	(%rax,%rbp), %rax
	movq	%rcx, 16(%rsp)
	movq	(%rax,%r11), %rax
	movsd	(%rax,%rcx,8), %xmm0
	movb	$1, %al
	call	__fprintf_chk@PLT
	movq	16(%rsp), %rcx
	movq	24(%rsp), %r11
	incq	%rcx
	jmp	.L9
.L23:
	incq	%r14
	jmp	.L11
.L8:
	incl	%r15d
	movq	%r13, %r12
	jmp	.L6
.L18:
	xorl	%eax, %eax
	leaq	.LC2(%rip), %r14
.L10:
	movl	(%rbx), %edx
	decl	%edx
	cmpl	%eax, %edx
	jle	.L19
	leaq	1(%rax), %r13
	leaq	0(,%rax,8), %r15
	xorl	%r12d, %r12d
	leaq	0(,%r13,4), %rbp
.L14:
	movq	8(%rbx), %rax
	cmpl	%r12d, (%rax,%rbp)
	jle	.L24
	movq	16(%rbx), %rax
	movq	8(%rsp), %rdi
	movq	%r14, %rdx
	movl	$2, %esi
	movq	(%rax,%r15), %rax
	movsd	(%rax,%r12,8), %xmm0
	movb	$1, %al
	incq	%r12
	call	__fprintf_chk@PLT
	jmp	.L14
.L24:
	movq	%r13, %rax
	jmp	.L10
.L19:
	xorl	%eax, %eax
.L13:
	movl	(%rbx), %edx
	decl	%edx
	cmpl	%eax, %edx
	jle	.L16
	leaq	1(%rax), %r15
	leaq	0(,%rax,8), %r14
	xorl	%r12d, %r12d
	leaq	0(,%r15,4), %rbp
.L17:
	movq	8(%rbx), %rax
	cmpl	%r12d, (%rax,%rbp)
	jle	.L25
	movq	32(%rbx), %rax
	movq	8(%rsp), %rdi
	movl	$2, %esi
	leaq	.LC1(%rip), %rdx
	movq	(%rax,%r14), %rax
	movl	(%rax,%r12,4), %ecx
	xorl	%eax, %eax
	incq	%r12
	call	__fprintf_chk@PLT
	jmp	.L17
.L25:
	movq	%r15, %rax
	jmp	.L13
.L16:
	movq	8(%rsp), %rdi
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	fclose@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z18serializeNeuralNetP2nnPc, .-_Z18serializeNeuralNetP2nnPc
	.section	.rodata.str1.1
.LC3:
	.string	"r"
	.text
	.globl	_Z20deserializeNeuralNetPc
	.type	_Z20deserializeNeuralNetPc, @function
_Z20deserializeNeuralNetPc:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC3(%rip), %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	leaq	16(%rsp), %rdi
	movl	$40, %esi
	movq	%rax, (%rsp)
	call	_Z17cudaMallocManagedI2nnE9cudaErrorPPT_mj.constprop.0.isra.0
	movq	16(%rsp), %rdx
	movq	(%rsp), %rdi
	xorl	%eax, %eax
	leaq	.LC1(%rip), %rsi
	call	__isoc23_fscanf@PLT
	movq	16(%rsp), %rdi
	movslq	(%rdi), %rsi
	addq	$8, %rdi
	salq	$2, %rsi
	call	_Z17cudaMallocManagedI2nnE9cudaErrorPPT_mj.constprop.0.isra.0
.L27:
	movq	16(%rsp), %rdi
	movl	(%rdi), %esi
	cmpl	%ebp, %esi
	jle	.L45
	movq	8(%rdi), %rax
	movq	(%rsp), %rdi
	leaq	.LC1(%rip), %rsi
	leaq	(%rax,%rbp,4), %rdx
	xorl	%eax, %eax
	incq	%rbp
	call	__isoc23_fscanf@PLT
	jmp	.L27
.L45:
	decl	%esi
	addq	$24, %rdi
	xorl	%ebx, %ebx
	movslq	%esi, %rsi
	salq	$3, %rsi
	call	_Z17cudaMallocManagedI2nnE9cudaErrorPPT_mj.constprop.0.isra.0
.L29:
	movq	16(%rsp), %rdi
	movl	(%rdi), %eax
	leal	-1(%rax), %esi
	cmpl	%ebx, %esi
	jle	.L46
	movq	8(%rdi), %rax
	leaq	0(,%rbx,8), %rbp
	leaq	0(,%rbx,4), %r12
	xorl	%r15d, %r15d
	leaq	4(%r12), %r13
	movslq	(%rax,%rbx,4), %rsi
	movq	24(%rdi), %rax
	addq	%rbp, %rax
	salq	$3, %rsi
	movq	%rax, %rdi
	call	_Z17cudaMallocManagedI2nnE9cudaErrorPPT_mj.constprop.0.isra.0
.L30:
	movq	16(%rsp), %rdx
	movq	8(%rdx), %rax
	cmpl	%r15d, (%rax,%r12)
	jle	.L47
	movslq	(%rax,%r13), %rsi
	movq	24(%rdx), %rax
	leaq	0(,%r15,8), %r14
	movq	(%rax,%rbp), %rdi
	salq	$3, %rsi
	addq	%r14, %rdi
	call	_Z17cudaMallocManagedI2nnE9cudaErrorPPT_mj.constprop.0.isra.0
	xorl	%r9d, %r9d
.L31:
	movq	16(%rsp), %rax
	movq	8(%rax), %rdx
	cmpl	%r9d, (%rdx,%r13)
	jle	.L48
	movq	24(%rax), %rax
	movq	(%rsp), %rdi
	movq	%r9, 8(%rsp)
	leaq	.LC2(%rip), %rsi
	movq	(%rax,%rbp), %rax
	movq	(%rax,%r14), %rax
	leaq	(%rax,%r9,8), %rdx
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	8(%rsp), %r9
	incq	%r9
	jmp	.L31
.L48:
	incq	%r15
	jmp	.L30
.L47:
	incq	%rbx
	jmp	.L29
.L46:
	movslq	%esi, %rsi
	addq	$16, %rdi
	leaq	.LC2(%rip), %r12
	salq	$3, %rsi
	call	_Z17cudaMallocManagedI2nnE9cudaErrorPPT_mj.constprop.0.isra.0
	xorl	%eax, %eax
.L35:
	movq	16(%rsp), %rdi
	movl	(%rdi), %ecx
	leal	-1(%rcx), %esi
	cmpl	%eax, %esi
	jle	.L49
	leaq	1(%rax), %rbp
	leaq	0(,%rax,8), %r14
	movq	8(%rdi), %rax
	xorl	%r15d, %r15d
	leaq	0(,%rbp,4), %r13
	movslq	(%rax,%rbp,4), %rsi
	movq	16(%rdi), %rax
	addq	%r14, %rax
	salq	$3, %rsi
	movq	%rax, %rdi
	call	_Z17cudaMallocManagedI2nnE9cudaErrorPPT_mj.constprop.0.isra.0
.L36:
	movq	16(%rsp), %rax
	movq	8(%rax), %rdx
	cmpl	%r15d, (%rdx,%r13)
	jle	.L50
	movq	16(%rax), %rax
	movq	(%rsp), %rdi
	movq	%r12, %rsi
	movq	(%rax,%r14), %rax
	leaq	(%rax,%r15,8), %rdx
	xorl	%eax, %eax
	incq	%r15
	call	__isoc23_fscanf@PLT
	jmp	.L36
.L50:
	movq	%rbp, %rax
	jmp	.L35
.L49:
	movslq	%esi, %rsi
	addq	$32, %rdi
	salq	$3, %rsi
	call	_Z17cudaMallocManagedI2nnE9cudaErrorPPT_mj.constprop.0.isra.0
	xorl	%eax, %eax
.L39:
	movq	16(%rsp), %rcx
	movl	(%rcx), %ebx
	leal	-1(%rbx), %edx
	cmpl	%eax, %edx
	jle	.L51
	leaq	1(%rax), %r12
	leaq	0(,%rax,8), %rbp
	movq	8(%rcx), %rax
	movq	32(%rcx), %rdi
	leaq	0(,%r12,4), %r13
	xorl	%r14d, %r14d
	movslq	(%rax,%r12,4), %rsi
	addq	%rbp, %rdi
	salq	$2, %rsi
	call	_Z17cudaMallocManagedI2nnE9cudaErrorPPT_mj.constprop.0.isra.0
.L40:
	movq	16(%rsp), %rax
	movq	8(%rax), %rdx
	cmpl	%r14d, (%rdx,%r13)
	jle	.L52
	movq	32(%rax), %rax
	movq	(%rsp), %rdi
	leaq	.LC1(%rip), %rsi
	movq	(%rax,%rbp), %rax
	leaq	(%rax,%r14,4), %rdx
	xorl	%eax, %eax
	incq	%r14
	call	__isoc23_fscanf@PLT
	jmp	.L40
.L52:
	movq	%r12, %rax
	jmp	.L39
.L51:
	movq	(%rsp), %rdi
	call	fclose@PLT
	movq	16(%rsp), %rax
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L43
	call	__stack_chk_fail@PLT
.L43:
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z20deserializeNeuralNetPc, .-_Z20deserializeNeuralNetPc
	.section	.rodata.str1.1
.LC4:
	.string	"\t"
.LC5:
	.string	"%c\t"
.LC6:
	.string	"\n"
.LC7:
	.string	"%d\t"
.LC8:
	.string	"______\t"
.LC9:
	.string	"__"
.LC10:
	.string	"W"
.LC11:
	.string	"B"
.LC12:
	.string	"P"
.LC13:
	.string	"R"
.LC14:
	.string	"N"
.LC15:
	.string	"Q"
.LC16:
	.string	"K"
.LC17:
	.string	"__\t"
.LC18:
	.string	"\n======================================================\n\n"
.LC19:
	.string	"Row %d, Col %d, Num %d, clr %d, fst %d, Pwn %d, Rk %d, Knt %d, Bshp %d, Qn %d, Kng %d\n"
	.text
	.globl	_Z19serializeChessBoardPP1pPc
	.type	_Z19serializeChessBoardPP1pPc, @function
_Z19serializeChessBoardPP1pPc:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	.LC5(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	movq	%rsi, %rdi
	leaq	.LC0(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	$65, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	fopen@PLT
	leaq	.LC4(%rip), %rdx
	movl	$2, %esi
	movq	%rax, 8(%rsp)
	movq	%rax, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L54:
	movq	8(%rsp), %rdi
	movl	%ebx, %ecx
	movq	%r12, %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	incl	%ebx
	call	__fprintf_chk@PLT
	cmpl	$73, %ebx
	jne	.L54
	movq	8(%rsp), %rdi
	leaq	.LC6(%rip), %r13
	xorl	%eax, %eax
	xorl	%ebx, %ebx
	movq	%r13, %rdx
	movl	$2, %esi
	leaq	.LC7(%rip), %r14
	call	__fprintf_chk@PLT
.L66:
	movq	8(%rsp), %rdi
	movl	%ebx, %ecx
	movq	%r14, %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	xorl	%r12d, %r12d
	leaq	.LC9(%rip), %r15
	call	__fprintf_chk@PLT
.L65:
	movq	0(%rbp,%rbx,8), %rax
	leaq	.LC8(%rip), %rdx
	cmpl	$0, (%rax,%r12)
	je	.L77
	movq	8(%rsp), %rdi
	movq	%r15, %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	0(%rbp,%rbx,8), %rax
	leaq	.LC10(%rip), %rdx
	testb	$1, (%rax,%r12)
	je	.L75
	leaq	.LC11(%rip), %rdx
.L75:
	movq	8(%rsp), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	0(%rbp,%rbx,8), %rax
	leaq	.LC12(%rip), %rdx
	movb	(%rax,%r12), %al
	testb	$4, %al
	jne	.L76
	leaq	.LC13(%rip), %rdx
	testb	$8, %al
	jne	.L76
	leaq	.LC14(%rip), %rdx
	testb	$16, %al
	jne	.L76
	leaq	.LC11(%rip), %rdx
	testb	$32, %al
	jne	.L76
	leaq	.LC15(%rip), %rdx
	testb	$64, %al
	jne	.L76
	leaq	.LC16(%rip), %rdx
.L76:
	movq	8(%rsp), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	leaq	.LC17(%rip), %rdx
.L77:
	movq	8(%rsp), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	addq	$4, %r12
	call	__fprintf_chk@PLT
	cmpq	$32, %r12
	jne	.L65
	movq	8(%rsp), %rdi
	movq	%r13, %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	incq	%rbx
	call	__fprintf_chk@PLT
	cmpq	$8, %rbx
	jne	.L66
	movq	8(%rsp), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	xorl	%r14d, %r14d
	leaq	.LC18(%rip), %rdx
	leaq	.LC19(%rip), %r13
	call	__fprintf_chk@PLT
.L67:
	movl	%r14d, %r12d
	xorl	%ebx, %ebx
.L68:
	movq	0(%rbp,%r14,8), %rax
	movl	%ebx, %r8d
	movl	%r12d, %ecx
	movl	$2, %esi
	leaq	(%rax,%rbx,4), %rax
	incq	%rbx
	movb	(%rax), %dl
	shrb	$7, %dl
	movzbl	%dl, %edx
	pushq	%rdx
	.cfi_def_cfa_offset 88
	movb	(%rax), %dl
	shrb	$6, %dl
	andl	$1, %edx
	pushq	%rdx
	.cfi_def_cfa_offset 96
	movb	(%rax), %dl
	shrb	$5, %dl
	andl	$1, %edx
	pushq	%rdx
	.cfi_def_cfa_offset 104
	movb	(%rax), %dl
	shrb	$4, %dl
	andl	$1, %edx
	pushq	%rdx
	.cfi_def_cfa_offset 112
	movb	(%rax), %dl
	shrb	$3, %dl
	andl	$1, %edx
	pushq	%rdx
	.cfi_def_cfa_offset 120
	movb	(%rax), %dl
	shrb	$2, %dl
	andl	$1, %edx
	pushq	%rdx
	.cfi_def_cfa_offset 128
	movb	(%rax), %dl
	shrb	%dl
	andl	$1, %edx
	pushq	%rdx
	.cfi_def_cfa_offset 136
	movb	(%rax), %dl
	andl	$1, %edx
	pushq	%rdx
	.cfi_def_cfa_offset 144
	movl	(%rax), %r9d
	movq	%r13, %rdx
	xorl	%eax, %eax
	movq	72(%rsp), %rdi
	call	__fprintf_chk@PLT
	addq	$64, %rsp
	.cfi_def_cfa_offset 80
	cmpq	$8, %rbx
	jne	.L68
	incq	%r14
	cmpq	$8, %r14
	jne	.L67
	movq	8(%rsp), %rdi
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	fclose@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z19serializeChessBoardPP1pPc, .-_Z19serializeChessBoardPP1pPc
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2055:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2055:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#ifndef SERIALIZEDESERIALIZE
#define SERIALIZEDESERIALIZE

#include <stdio.h>
#include <stdlib.h>

#include "./../Chess/Piece.cuh"
#include "./../NeuralNetwork/NeuralNetwork.cuh"

#define DIM 8

void serializeNeuralNet(NeuralNet* nn, char* fileName);

NeuralNet* deserializeNeuralNet(char* fileName);

void serializeChessBoard(Piece** board, char* filename);

#endif

	.text
	.file	"SerializeDeserialize.hip"
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
