//Input-------------------------------------------------------------------------------------------------
#define WindowDimension 3						// this is the dimension of the window. 
#define PatchSigma 0.01                         // this is h squared , mentioned in the report
#define Sigma 0.05   							// this is the sigma squared , mentioned in the report
#define FILENAME "images/rasp_noise.csv"		// path to the csv of the image you want to use as input
//End of input------------------------------------------------------------------------------------------





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

//fast exp , sacrifising some accuracy
float expf_fastCPU(float a) {
  union { float f; int x; } u;
  u.x = (int) (12102203 * a + 1064866805);
  return u.f;
}

//Calculate the mean of each pixel , using the moving-window technique
void meansCPU(float* pixels , int *windowSize, int* iconLine, float *means){
	int xIndex = 0;
	for(xIndex = 0; xIndex<*iconLine*(*iconLine); xIndex++){


		int* index = &xIndex;
		int i, j;
		int lim = (*windowSize)/2;
		int dimension = *windowSize;

		float result[WindowDimension*WindowDimension];
		
		for(i=-lim; i<=lim; i++){
			for(j=-lim; j<=lim; j++){
				int location = (*index) + i +j*(*iconLine);

				bool outLeftorRight = (location/(*iconLine) != ((*index)/(*iconLine) + j) ) || location<0;
				bool outUpOrDown = location/(*iconLine) <0 || location/(*iconLine) >= (*iconLine);
				bool ifResult = !(outLeftorRight || outUpOrDown);
				int resultIndex = (j+lim)*(*windowSize) + (i+lim);

				//if the window is completely inside the image
				if(ifResult){
					result[resultIndex] = pixels[location];
				}
				
		 		//if part of the window is outside of the image
				else{
		

					location = (*index) - i -j*(*iconLine);
					
					outLeftorRight =location/(*iconLine) != ((*index)/(*iconLine) - j) || location<0;
					outUpOrDown = location/(*iconLine) <0 || location/(*iconLine) >= (*iconLine);

					if(!outLeftorRight && !outUpOrDown){
						result[resultIndex] = pixels[location];
						continue;
					}

					location = (*index) -i +j*(*iconLine);
					outLeftorRight =location/(*iconLine) != ((*index)/(*iconLine) + j) || location<0;
					outUpOrDown = location/(*iconLine) <0 || location/(*iconLine) >= (*iconLine);

					if(!outLeftorRight && !outUpOrDown){
						result[resultIndex] = pixels[location];
						continue;
					}

					location = (*index) +i -j*(*iconLine);
					result[resultIndex] = pixels[location];
				}

			}	
		}
		float mean=0;
		
		float patchSigma = PatchSigma;
		float tmp = 0;
		for(i=0; i<*windowSize*(*windowSize); i++){
			int x = i%dimension - dimension/2;
			int y = i/dimension - dimension/2;

			float fx = (float)x;
			float fy = (float)y;
			float arithmitis = fx*fx + fy*fy;
			float paronomastis = 2*M_PI*patchSigma;
			
			mean = mean + result[i]*expf_fastCPU(-arithmitis/paronomastis)*0.5;
			tmp = tmp+expf_fastCPU(-arithmitis/paronomastis)*0.5;
		
		}
		
		mean = mean/tmp;
		means[xIndex] = mean; 
	}
}
//denoise the image using the formulas mentioned in the report
void denoiseCPU(float* pixels, float* sigma, int* imageDimension,int* windowDimension,float* means, float* result){
	int xIndex =0;
	for(xIndex=0; xIndex<*imageDimension*(*imageDimension); xIndex++){
		int windowSize;
		int imageSize;
		imageSize = *imageDimension*(*imageDimension);
		windowSize = *windowDimension*(*windowDimension); 
		float mean1 = means[xIndex];
		int i=0;
		float sumW = 0 ;
		float sumP = 0;
		for(i=0; i<imageSize; i++){
			float mean2 = means[i];
		
			float tmp = (mean1 - mean2)*(mean1-mean2)*(-1);
			float weight = exp(tmp/(*sigma));

			sumW = sumW + weight;
			sumP = sumP + weight*pixels[i];

		}
	sumP = sumP/sumW;
	result[xIndex] = sumP;
	}
}



//read the csv and put it in a float array
float* readCSVfile(char* filename, int* dimension){
	FILE *file;
	file = fopen(filename, "r");
	int local_dimension = 256; 
	float* result = (float*)malloc(local_dimension*local_dimension*sizeof(float));  // dont forget to free the memory afterwards
	if(file == NULL){
		printf("The file could not be opened/ does not exits");
		exit(1);
	}

	char* line =NULL;
	size_t length = 0 ;
	ssize_t read;
	const char delimeters[] = ", ";

	char* number ;
	int outer_counter = 0;
	while ((read = getline(&line, &length, file) != -1)){
		
		number = strtok(line, delimeters);
		float fnumber = atof(number);
		int counter = 0;

		while( number !=NULL){
			result[counter + outer_counter*local_dimension] = fnumber;
			counter++;
			

			number = strtok(NULL, delimeters);
			if(number != NULL)	
				fnumber = atof(number);
		}

		if(counter != local_dimension){
			local_dimension = counter;
			
			result =  (float*)realloc(result, counter*counter*sizeof(float));
			
		}


		outer_counter++;
		

	}

	fclose(file);
	if(line)
		free(line);

	*dimension = local_dimension;
	return result;
}



//save a float array to csv
void floatToCSV(char* filename, int dimension, float* arr){
	int i;
	FILE* fileWriter;
	fileWriter = fopen(filename, "a");
	if(fileWriter == NULL){
		printf("something went wrong when saving");
		exit(1);
	}
	for(i=0; i<dimension*dimension ; i++){
	
		if(i!=0 && i%dimension==0)
			fputs("\n", fileWriter);
		if(arr[i]!=arr[i])
			arr[i]=0;
	

	 
		char stringFl[10];
		sprintf(stringFl, "%f", arr[i]);
		fputs( stringFl, fileWriter );
		fputs( ",", fileWriter );
	}
	fclose(fileWriter);
}
int main(void){

	
	float sigma = Sigma;
	int windowDimension = WindowDimension;
	int dimension ; 
	float *image ;
	image = readCSVfile(FILENAME, &dimension);

	float* means = (float*)malloc(dimension*dimension*sizeof(float));

	
	
	
	


	

	float* finalPixel = (float*)malloc(sizeof(float)*dimension*dimension);
	clock_t start, end;
    double cpu_time_used;
    start = clock();

    //the whole algorithm gets executed here
    meansCPU(image, &windowDimension, &dimension, means);

    denoiseCPU(image, &sigma, &dimension, &windowDimension, means, finalPixel);
	//-------------------------------------

	end = clock();
    cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
    printf("program took %f seconds to execute \n", cpu_time_used);

    floatToCSV("imageAfter.csv", dimension, finalPixel);
    
	








	

	return 0; 

}
	.file	"tmpxft_002347f6_00000000-6_mainCPU.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z12expf_fastCPUf
	.type	_Z12expf_fastCPUf, @function
_Z12expf_fastCPUf:
.LFB2027:
	.cfi_startproc
	endbr64
	mulss	.LC0(%rip), %xmm0
	addss	.LC1(%rip), %xmm0
	cvttss2sil	%xmm0, %eax
	movd	%eax, %xmm0
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z12expf_fastCPUf, .-_Z12expf_fastCPUf
	.globl	_Z8meansCPUPfPiS0_S_
	.type	_Z8meansCPUPfPiS0_S_, @function
_Z8meansCPUPfPiS0_S_:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r10
	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
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	movss	.LC4(%rip), %xmm4
	movss	.LC0(%rip), %xmm5
	movq	%rsi, 72(%rsp)
	movss	.LC1(%rip), %xmm6
	xorl	%esi, %esi
	movss	.LC3(%rip), %xmm3
	movq	%rcx, 80(%rsp)
	movl	(%rdx), %ecx
	movsd	.LC5(%rip), %xmm2
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	movl	%ecx, %eax
	imull	%ecx, %eax
	movl	%eax, 40(%rsp)
	movslq	%ecx, %rax
	salq	$2, %rax
	movq	%rax, 56(%rsp)
.L4:
	movl	%esi, 64(%rsp)
	cmpl	%esi, 40(%rsp)
	jle	.L20
	movq	72(%rsp), %rax
	movl	$2, %edi
	movl	(%rax), %r8d
	movl	%r8d, %eax
	cltd
	idivl	%edi
	movl	%ecx, %edx
	cltq
	movl	%eax, %edi
	movq	%rax, %r11
	negl	%edi
	imull	%edi, %edx
	movslq	%edi, %r13
	addq	%r13, %rax
	leaq	100(%rsp,%rax,4), %rax
	movq	%rax, 16(%rsp)
	movslq	%edx, %rax
	addq	%r13, %rax
	addq	%rsi, %rax
	leaq	(%r10,%rax,4), %rax
	movq	%rax, 24(%rsp)
	movslq	%r8d, %rax
	salq	$2, %rax
	movq	%rax, 48(%rsp)
	movl	%esi, %eax
	subl	%edx, %eax
	movl	%eax, 68(%rsp)
	leal	(%rdx,%rsi), %eax
	movl	%eax, 88(%rsp)
.L5:
	cmpl	%r11d, %edi
	jg	.L11
	leal	(%rdi,%rdi), %eax
	movl	68(%rsp), %r14d
	movl	88(%rsp), %r9d
	movq	%r13, %rbx
	movl	%eax, 36(%rsp)
	movq	24(%rsp), %rax
	movq	16(%rsp), %r15
	subl	%edi, %r14d
	subl	%edi, %r9d
	movq	%rax, 8(%rsp)
.L12:
	movl	%ebx, 44(%rsp)
	cmpl	%ebx, %r11d
	jl	.L21
	movl	36(%rsp), %eax
	leal	(%r9,%rax), %ebp
	movl	%ebp, %eax
	cltd
	idivl	%ecx
	movl	%eax, 4(%rsp)
	movl	64(%rsp), %eax
	cltd
	idivl	%ecx
	cmpl	%ecx, 4(%rsp)
	setge	95(%rsp)
	movl	%eax, %r12d
	leal	(%rax,%rbx), %eax
	cmpl	%eax, 4(%rsp)
	movl	%eax, 32(%rsp)
	movb	95(%rsp), %al
	setne	%dl
	shrl	$31, %ebp
	orl	%edx, %eax
	orb	%bpl, %al
	jne	.L6
	cmpl	$0, 4(%rsp)
	js	.L6
	movq	8(%rsp), %rax
	movss	(%rax), %xmm0
	jmp	.L7
.L6:
	movl	%r14d, %eax
	cltd
	idivl	%ecx
	cmpl	%ecx, %eax
	movl	%eax, %edx
	setge	%bpl
	shrl	$31, %edx
	orl	%ebp, %edx
	movl	%r14d, %ebp
	shrl	$31, %ebp
	orb	%dl, %bpl
	jne	.L8
	movl	44(%rsp), %edx
	subl	%edx, %r12d
	cmpl	%eax, %r12d
	jne	.L8
	movl	%r14d, %eax
	jmp	.L18
.L8:
	movl	%r9d, %eax
	cltd
	idivl	%ecx
	cmpl	%ecx, %eax
	movl	%eax, %edx
	setge	%bpl
	shrl	$31, %edx
	orl	%ebp, %edx
	movl	%r9d, %ebp
	shrl	$31, %ebp
	orb	%dl, %bpl
	jne	.L9
	cmpl	%eax, 32(%rsp)
	jne	.L9
	movl	%r9d, %eax
	jmp	.L18
.L9:
	movl	36(%rsp), %eax
	addl	%r14d, %eax
	cltq
.L18:
	movss	(%r10,%rax,4), %xmm0
.L7:
	movq	48(%rsp), %rax
	movq	56(%rsp), %rdx
	incq	%rbx
	subl	%ecx, %r14d
	movss	%xmm0, (%r15)
	addl	%ecx, %r9d
	addq	%rdx, 8(%rsp)
	addq	%rax, %r15
	jmp	.L12
.L21:
	addq	$4, 16(%rsp)
	incl	%edi
	addq	$4, 24(%rsp)
	jmp	.L5
.L11:
	movl	%r8d, %r9d
	xorps	%xmm7, %xmm7
	leaq	100(%rsp), %rbx
	xorl	%edi, %edi
	imull	%r8d, %r9d
	movaps	%xmm7, %xmm1
.L13:
	movl	%edi, %eax
	cmpl	%edi, %r9d
	jle	.L22
	cltd
	cvtss2sd	%xmm1, %xmm1
	cvtss2sd	%xmm7, %xmm7
	idivl	%r8d
	subl	%r11d, %eax
	subl	%r11d, %edx
	cvtsi2ssl	%eax, %xmm8
	cvtsi2ssl	%edx, %xmm0
	mulss	%xmm8, %xmm8
	mulss	%xmm0, %xmm0
	addss	%xmm8, %xmm0
	movss	(%rbx,%rdi,4), %xmm8
	incq	%rdi
	xorps	%xmm3, %xmm0
	divss	%xmm4, %xmm0
	mulss	%xmm5, %xmm0
	addss	%xmm6, %xmm0
	cvttss2sil	%xmm0, %eax
	movd	%eax, %xmm0
	mulss	%xmm0, %xmm8
	cvtss2sd	%xmm0, %xmm0
	mulsd	%xmm2, %xmm0
	cvtss2sd	%xmm8, %xmm8
	mulsd	%xmm2, %xmm8
	addsd	%xmm0, %xmm7
	cvtsd2ss	%xmm7, %xmm7
	addsd	%xmm8, %xmm1
	cvtsd2ss	%xmm1, %xmm1
	jmp	.L13
.L22:
	divss	%xmm7, %xmm1
	movq	80(%rsp), %rax
	movss	%xmm1, (%rax,%rsi,4)
	incq	%rsi
	jmp	.L4
.L20:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$152, %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	_Z8meansCPUPfPiS0_S_, .-_Z8meansCPUPfPiS0_S_
	.globl	_Z10denoiseCPUPfS_PiS0_S_S_
	.type	_Z10denoiseCPUPfS_PiS0_S_S_, @function
_Z10denoiseCPUPfS_PiS0_S_S_:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rsi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%r8, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
.L24:
	movl	(%rdx), %ebp
	imull	%ebp, %ebp
	cmpl	%ebx, %ebp
	jle	.L29
	xorps	%xmm1, %xmm1
	movss	0(%r13,%rbx,4), %xmm3
	xorl	%r12d, %r12d
	movaps	%xmm1, %xmm2
.L25:
	movaps	%xmm3, %xmm0
	subss	0(%r13,%r12,4), %xmm0
	movq	%r9, 24(%rsp)
	movq	%rdx, 16(%rsp)
	movss	%xmm1, 12(%rsp)
	mulss	%xmm0, %xmm0
	movss	%xmm2, 8(%rsp)
	xorps	.LC3(%rip), %xmm0
	movss	%xmm3, 4(%rsp)
	divss	(%r15), %xmm0
	call	expf@PLT
	movss	8(%rsp), %xmm2
	movss	12(%rsp), %xmm1
	movss	4(%rsp), %xmm3
	movq	16(%rsp), %rdx
	addss	%xmm0, %xmm2
	mulss	(%r14,%r12,4), %xmm0
	incq	%r12
	movq	24(%rsp), %r9
	cmpl	%r12d, %ebp
	addss	%xmm0, %xmm1
	jg	.L25
	divss	%xmm2, %xmm1
	movss	%xmm1, (%r9,%rbx,4)
	incq	%rbx
	jmp	.L24
.L29:
	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
.LFE2029:
	.size	_Z10denoiseCPUPfS_PiS0_S_S_, .-_Z10denoiseCPUPfS_PiS0_S_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC6:
	.string	"r"
.LC7:
	.string	"The file could not be opened/ does not exits"
	.text
	.globl	_Z11readCSVfilePcPi
	.type	_Z11readCSVfilePcPi, @function
_Z11readCSVfilePcPi:
.LFB2030:
	.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
	movq	%rsi, %r13
	leaq	.LC6(%rip), %rsi
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	movl	$262144, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	testq	%rbp, %rbp
	jne	.L31
	movl	$2, %edi
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L31:
	movq	%rax, %rbx
	xorl	%eax, %eax
	movw	$8236, 53(%rsp)
	xorl	%r14d, %r14d
	movq	%rax, 32(%rsp)
	movl	$256, %r12d
	movq	%rax, 40(%rsp)
	leaq	40(%rsp), %rax
	movb	$0, 55(%rsp)
	movq	%rax, 24(%rsp)
.L32:
	movq	24(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%rbp, %rdx
	call	getline@PLT
	incq	%rax
	je	.L43
	leaq	53(%rsp), %rax
	movq	32(%rsp), %rdi
	movq	%rax, %rsi
	movq	%rax, 8(%rsp)
	call	strtok@PLT
	movq	%rax, %rdi
	call	atof@PLT
	movl	%r12d, %eax
	movl	$1, %edx
	imull	%r14d, %eax
	cvtsd2ss	%xmm0, %xmm0
	cltq
	leaq	(%rbx,%rax,4), %r15
.L34:
	movq	8(%rsp), %rsi
	movss	%xmm0, -4(%r15,%rdx,4)
	xorl	%edi, %edi
	movq	%rdx, 16(%rsp)
	call	strtok@PLT
	movq	16(%rsp), %rdx
	movq	%rax, %rdi
	leaq	1(%rdx), %rax
	movq	%rax, 16(%rsp)
	testq	%rdi, %rdi
	je	.L33
	call	atof@PLT
	movq	16(%rsp), %rdx
	cvtsd2ss	%xmm0, %xmm0
	jmp	.L34
.L33:
	movl	%edx, %r15d
	cmpl	%edx, %r12d
	je	.L35
	imull	%edx, %edx
	movq	%rbx, %rdi
	movslq	%edx, %rsi
	salq	$2, %rsi
	call	realloc@PLT
	movq	%rax, %rbx
.L35:
	incl	%r14d
	movl	%r15d, %r12d
	jmp	.L32
.L43:
	movq	%rbp, %rdi
	call	fclose@PLT
	movq	32(%rsp), %rdi
	testq	%rdi, %rdi
	je	.L37
	call	free@PLT
.L37:
	movl	%r12d, 0(%r13)
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L38
	call	__stack_chk_fail@PLT
.L38:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	movq	%rbx, %rax
	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
.LFE2030:
	.size	_Z11readCSVfilePcPi, .-_Z11readCSVfilePcPi
	.section	.rodata.str1.1
.LC8:
	.string	"a"
.LC9:
	.string	"something went wrong when saving"
.LC10:
	.string	"%f"
	.text
	.globl	_Z10floatToCSVPciPf
	.type	_Z10floatToCSVPciPf, @function
_Z10floatToCSVPciPf:
.LFB2031:
	.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
	movq	%rdx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%esi, %r12d
	leaq	.LC8(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	testq	%rax, %rax
	je	.L45
	movl	%r12d, %r14d
	movq	%rax, %rbp
	leaq	.LC10(%rip), %r15
	xorl	%ebx, %ebx
	imull	%r12d, %r14d
	jmp	.L46
.L45:
	movl	$2, %edi
	leaq	.LC9(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L50:
	testq	%rbx, %rbx
	jne	.L58
.L47:
	movss	0(%r13,%rbx,4), %xmm0
	ucomiss	%xmm0, %xmm0
	jnp	.L48
	movl	$0x00000000, 0(%r13,%rbx,4)
.L48:
	leaq	30(%rsp), %rdi
	movq	%r15, %rcx
	movl	$10, %edx
	movb	$1, %al
	movl	$2, %esi
	cvtss2sd	0(%r13,%rbx,4), %xmm0
	movq	%rdi, 8(%rsp)
	incq	%rbx
	call	__sprintf_chk@PLT
	movq	8(%rsp), %rdi
	movq	%rbp, %rsi
	call	fputs@PLT
	movq	%rbp, %rsi
	movl	$44, %edi
	call	fputc@PLT
.L46:
	cmpl	%ebx, %r14d
	jg	.L50
	jmp	.L59
.L58:
	movl	%ebx, %eax
	cltd
	idivl	%r12d
	testl	%edx, %edx
	jne	.L47
	movq	%rbp, %rsi
	movl	$10, %edi
	call	fputc@PLT
	jmp	.L47
.L59:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L51
	call	__stack_chk_fail@PLT
.L51:
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	movq	%rbp, %rdi
	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
.LFE2031:
	.size	_Z10floatToCSVPciPf, .-_Z10floatToCSVPciPf
	.section	.rodata.str1.1
.LC12:
	.string	"images/rasp_noise.csv"
.LC14:
	.string	"program took %f seconds to execute \n"
.LC15:
	.string	"imageAfter.csv"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC12(%rip), %rdi
	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
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	36(%rsp), %r13
	movl	$0x3d4ccccd, 28(%rsp)
	leaq	32(%rsp), %r15
	movq	%r13, %rsi
	movl	$3, 32(%rsp)
	call	_Z11readCSVfilePcPi
	movl	36(%rsp), %ebx
	movq	%rax, 8(%rsp)
	movl	%ebx, %edi
	imull	%ebx, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movslq	%ebx, %rdi
	imulq	%rdi, %rdi
	movq	%rax, %r12
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %r14
	call	clock@PLT
	movq	8(%rsp), %rdi
	movq	%r12, %rcx
	movq	%r13, %rdx
	movq	%r15, %rsi
	movq	%rax, %rbp
	call	_Z8meansCPUPfPiS0_S_
	movq	8(%rsp), %rdi
	movq	%r13, %rdx
	movq	%r14, %r9
	leaq	28(%rsp), %rsi
	movq	%r12, %r8
	movq	%r15, %rcx
	call	_Z10denoiseCPUPfS_PiS0_S_S_
	call	clock@PLT
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	subq	%rbp, %rax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC13(%rip), %xmm0
	call	__printf_chk@PLT
	movq	%r14, %rdx
	movl	%ebx, %esi
	leaq	.LC15(%rip), %rdi
	call	_Z10floatToCSVPciPf
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L61
	call	__stack_chk_fail@PLT
.L61:
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.LFE2032:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2058:
	.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
.LFE2058:
	.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
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	1262004795
	.align 4
.LC1:
	.long	1316872784
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC3:
	.long	-2147483648
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst4
	.align 4
.LC4:
	.long	1031843324
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC5:
	.long	0
	.long	1071644672
	.align 8
.LC13:
	.long	0
	.long	1093567616
	.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:

//Input-------------------------------------------------------------------------------------------------
#define WindowDimension 3						// this is the dimension of the window. 
#define PatchSigma 0.01                         // this is h squared , mentioned in the report
#define Sigma 0.05   							// this is the sigma squared , mentioned in the report
#define FILENAME "images/rasp_noise.csv"		// path to the csv of the image you want to use as input
//End of input------------------------------------------------------------------------------------------






#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

//fast exp , sacrifising some accuracy
float expf_fastCPU(float a) {
  union { float f; int x; } u;
  u.x = (int) (12102203 * a + 1064866805);
  return u.f;
}

//Calculate the mean of each pixel , using the moving-window technique
void meansCPU(float* pixels , int *windowSize, int* iconLine, float *means){
	int xIndex = 0;
	for(xIndex = 0; xIndex<*iconLine*(*iconLine); xIndex++){


		int* index = &xIndex;
		int i, j;
		int lim = (*windowSize)/2;
		int dimension = *windowSize;

		float result[WindowDimension*WindowDimension];
		
		for(i=-lim; i<=lim; i++){
			for(j=-lim; j<=lim; j++){
				int location = (*index) + i +j*(*iconLine);

				bool outLeftorRight = (location/(*iconLine) != ((*index)/(*iconLine) + j) ) || location<0;
				bool outUpOrDown = location/(*iconLine) <0 || location/(*iconLine) >= (*iconLine);
				bool ifResult = !(outLeftorRight || outUpOrDown);
				int resultIndex = (j+lim)*(*windowSize) + (i+lim);

				//if the window is completely inside the image
				if(ifResult){
					result[resultIndex] = pixels[location];
				}
				
		 		//if part of the window is outside of the image
				else{
		

					location = (*index) - i -j*(*iconLine);
					
					outLeftorRight =location/(*iconLine) != ((*index)/(*iconLine) - j) || location<0;
					outUpOrDown = location/(*iconLine) <0 || location/(*iconLine) >= (*iconLine);

					if(!outLeftorRight && !outUpOrDown){
						result[resultIndex] = pixels[location];
						continue;
					}

					location = (*index) -i +j*(*iconLine);
					outLeftorRight =location/(*iconLine) != ((*index)/(*iconLine) + j) || location<0;
					outUpOrDown = location/(*iconLine) <0 || location/(*iconLine) >= (*iconLine);

					if(!outLeftorRight && !outUpOrDown){
						result[resultIndex] = pixels[location];
						continue;
					}

					location = (*index) +i -j*(*iconLine);
					result[resultIndex] = pixels[location];
				}

			}	
		}
		float mean=0;
		
		float patchSigma = PatchSigma;
		float tmp = 0;
		for(i=0; i<*windowSize*(*windowSize); i++){
			int x = i%dimension - dimension/2;
			int y = i/dimension - dimension/2;

			float fx = (float)x;
			float fy = (float)y;
			float arithmitis = fx*fx + fy*fy;
			float paronomastis = 2*M_PI*patchSigma;
			
			mean = mean + result[i]*expf_fastCPU(-arithmitis/paronomastis)*0.5;
			tmp = tmp+expf_fastCPU(-arithmitis/paronomastis)*0.5;
		
		}
		
		mean = mean/tmp;
		means[xIndex] = mean; 
	}
}
//denoise the image using the formulas mentioned in the report
void denoiseCPU(float* pixels, float* sigma, int* imageDimension,int* windowDimension,float* means, float* result){
	int xIndex =0;
	for(xIndex=0; xIndex<*imageDimension*(*imageDimension); xIndex++){
		int windowSize;
		int imageSize;
		imageSize = *imageDimension*(*imageDimension);
		windowSize = *windowDimension*(*windowDimension); 
		float mean1 = means[xIndex];
		int i=0;
		float sumW = 0 ;
		float sumP = 0;
		for(i=0; i<imageSize; i++){
			float mean2 = means[i];
		
			float tmp = (mean1 - mean2)*(mean1-mean2)*(-1);
			float weight = exp(tmp/(*sigma));

			sumW = sumW + weight;
			sumP = sumP + weight*pixels[i];

		}
	sumP = sumP/sumW;
	result[xIndex] = sumP;
	}
}



//read the csv and put it in a float array
float* readCSVfile(char* filename, int* dimension){
	FILE *file;
	file = fopen(filename, "r");
	int local_dimension = 256; 
	float* result = (float*)malloc(local_dimension*local_dimension*sizeof(float));  // dont forget to free the memory afterwards
	if(file == NULL){
		printf("The file could not be opened/ does not exits");
		exit(1);
	}

	char* line =NULL;
	size_t length = 0 ;
	ssize_t read;
	const char delimeters[] = ", ";

	char* number ;
	int outer_counter = 0;
	while ((read = getline(&line, &length, file) != -1)){
		
		number = strtok(line, delimeters);
		float fnumber = atof(number);
		int counter = 0;

		while( number !=NULL){
			result[counter + outer_counter*local_dimension] = fnumber;
			counter++;
			

			number = strtok(NULL, delimeters);
			if(number != NULL)	
				fnumber = atof(number);
		}

		if(counter != local_dimension){
			local_dimension = counter;
			
			result =  (float*)realloc(result, counter*counter*sizeof(float));
			
		}


		outer_counter++;
		

	}

	fclose(file);
	if(line)
		free(line);

	*dimension = local_dimension;
	return result;
}



//save a float array to csv
void floatToCSV(char* filename, int dimension, float* arr){
	int i;
	FILE* fileWriter;
	fileWriter = fopen(filename, "a");
	if(fileWriter == NULL){
		printf("something went wrong when saving");
		exit(1);
	}
	for(i=0; i<dimension*dimension ; i++){
	
		if(i!=0 && i%dimension==0)
			fputs("\n", fileWriter);
		if(arr[i]!=arr[i])
			arr[i]=0;
	

	 
		char stringFl[10];
		sprintf(stringFl, "%f", arr[i]);
		fputs( stringFl, fileWriter );
		fputs( ",", fileWriter );
	}
	fclose(fileWriter);
}
int main(void){

	
	float sigma = Sigma;
	int windowDimension = WindowDimension;
	int dimension ; 
	float *image ;
	image = readCSVfile(FILENAME, &dimension);

	float* means = (float*)malloc(dimension*dimension*sizeof(float));

	
	
	
	


	

	float* finalPixel = (float*)malloc(sizeof(float)*dimension*dimension);
	clock_t start, end;
    double cpu_time_used;
    start = clock();

    //the whole algorithm gets executed here
    meansCPU(image, &windowDimension, &dimension, means);

    denoiseCPU(image, &sigma, &dimension, &windowDimension, means, finalPixel);
	//-------------------------------------

	end = clock();
    cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
    printf("program took %f seconds to execute \n", cpu_time_used);

    floatToCSV("imageAfter.csv", dimension, finalPixel);
    
	








	

	return 0; 

}
	.text
	.file	"mainCPU.hip"
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z12expf_fastCPUf
.LCPI0_0:
	.long	0x4b38aa3b                      # float 12102203
.LCPI0_1:
	.long	0x4e7de250                      # float 1.06486682E+9
	.text
	.globl	_Z12expf_fastCPUf
	.type	_Z12expf_fastCPUf,@function
_Z12expf_fastCPUf:                      # @_Z12expf_fastCPUf
	.cfi_startproc
# %bb.0:
	mulss	.LCPI0_0(%rip), %xmm0
	addss	.LCPI0_1(%rip), %xmm0
	cvttss2si	%xmm0, %eax
	movd	%eax, %xmm0
	retq
.Lfunc_end0:
	.size	_Z12expf_fastCPUf, .Lfunc_end0-_Z12expf_fastCPUf
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z8meansCPUPfPiS0_S_
.LCPI1_0:
	.long	0x7fc00000                      # float NaN
.LCPI1_1:
	.long	0xbd80adfc                      # float -0.0628318488
.LCPI1_2:
	.long	0x4b38aa3b                      # float 12102203
.LCPI1_3:
	.long	0x4e7de250                      # float 1.06486682E+9
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI1_4:
	.quad	0x3fe0000000000000              # double 0.5
	.text
	.globl	_Z8meansCPUPfPiS0_S_
	.type	_Z8meansCPUPfPiS0_S_,@function
_Z8meansCPUPfPiS0_S_:                   # @_Z8meansCPUPfPiS0_S_
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdi, -128(%rsp)                # 8-byte Spill
	movslq	(%rdx), %rbx
	testq	%rbx, %rbx
	je	.LBB1_15
# %bb.1:                                # %.lr.ph148
	movl	%ebx, %edi
	imull	%edi, %edi
	movslq	(%rsi), %r9
	movl	%r9d, %r12d
	shrl	$31, %r12d
	addl	%r9d, %r12d
	sarl	%r12d
	movl	%r9d, %r10d
	imull	%r10d, %r10d
	movl	%r12d, %eax
	negl	%eax
	movl	%eax, -116(%rsp)                # 4-byte Spill
	movslq	%eax, %r8
	movl	%r12d, %eax
	cmovnsl	%r8d, %eax
	incl	%eax
	movl	%eax, -100(%rsp)                # 4-byte Spill
	cmpl	$1, %r10d
	adcl	$0, %r10d
	movslq	%r12d, %rax
	cmpl	$1, %edi
	adcl	$0, %edi
	movq	%r9, %rdx
	shlq	$2, %rdx
	movq	%rdx, 24(%rsp)                  # 8-byte Spill
	leaq	-1(%rbx), %rdx
	imulq	%rax, %rdx
	movq	-128(%rsp), %rsi                # 8-byte Reload
	leaq	(%rsi,%rdx,4), %r11
	leaq	(,%rbx,4), %rdx
	negq	%rdx
	movq	%rdx, 16(%rsp)                  # 8-byte Spill
	movl	$1, %ebp
	subl	%ebx, %ebp
	imull	%r12d, %ebp
	leal	1(%rbx), %r15d
	imull	%r12d, %r15d
	movq	%rbx, %r14
	notq	%r14
	imulq	%rax, %r14
	leaq	(%rsi,%r14,4), %r13
	cmpl	%r8d, %eax
	movq	%r8, -80(%rsp)                  # 8-byte Spill
	movl	%r8d, %eax
	cmovgl	%r12d, %eax
	notl	%eax
	movl	%eax, -104(%rsp)                # 4-byte Spill
	movss	.LCPI1_1(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	.LCPI1_2(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	movss	.LCPI1_3(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	movsd	.LCPI1_4(%rip), %xmm3           # xmm3 = mem[0],zero
	movss	.LCPI1_0(%rip), %xmm4           # xmm4 = mem[0],zero,zero,zero
	xorl	%esi, %esi
	movq	%rcx, -48(%rsp)                 # 8-byte Spill
	movq	%rdi, -56(%rsp)                 # 8-byte Spill
	movq	%r9, -64(%rsp)                  # 8-byte Spill
	movq	%r10, -72(%rsp)                 # 8-byte Spill
.LBB1_2:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
                                        #       Child Loop BB1_5 Depth 3
                                        #     Child Loop BB1_12 Depth 2
	cmpl	$-1, %r9d
	jl	.LBB1_11
# %bb.3:                                # %.preheader.preheader
                                        #   in Loop: Header=BB1_2 Depth=1
	movq	%rsi, -40(%rsp)                 # 8-byte Spill
	movl	%esi, %eax
	cltd
	idivl	%ebx
	movl	%eax, -92(%rsp)                 # 4-byte Spill
	addl	-116(%rsp), %eax                # 4-byte Folded Reload
	movl	%eax, -96(%rsp)                 # 4-byte Spill
	movq	%r14, -24(%rsp)                 # 8-byte Spill
	movq	%r14, %rsi
	movq	%r13, -32(%rsp)                 # 8-byte Spill
	movq	%r13, %r14
	movl	%r15d, -112(%rsp)               # 4-byte Spill
	movl	%r15d, %r10d
	movl	%ebp, -108(%rsp)                # 4-byte Spill
	movl	%ebp, %ecx
	movq	%r11, -16(%rsp)                 # 8-byte Spill
	movq	%r11, %r13
	leaq	32(%rsp), %rdi
	movq	-80(%rsp), %rax                 # 8-byte Reload
.LBB1_4:                                # %.preheader
                                        #   Parent Loop BB1_2 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_5 Depth 3
	movq	%rax, -8(%rsp)                  # 8-byte Spill
	movl	-104(%rsp), %ebp                # 4-byte Reload
	movl	%esi, %r9d
	xorl	%r8d, %r8d
	movl	%r10d, -84(%rsp)                # 4-byte Spill
	movl	%ecx, -88(%rsp)                 # 4-byte Spill
	movl	%ecx, %r11d
	movq	%r13, 8(%rsp)                   # 8-byte Spill
	movq	%rdi, (%rsp)                    # 8-byte Spill
	movl	-96(%rsp), %r15d                # 4-byte Reload
	movl	-92(%rsp), %eax                 # 4-byte Reload
	movl	%eax, %ecx
.LBB1_5:                                #   Parent Loop BB1_2 Depth=1
                                        #     Parent Loop BB1_4 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	%r9d, %eax
	cltd
	idivl	%ebx
	testl	%eax, %eax
	js	.LBB1_16
# %bb.6:                                #   in Loop: Header=BB1_5 Depth=3
	cmpl	%ebx, %eax
	jge	.LBB1_16
# %bb.7:                                #   in Loop: Header=BB1_5 Depth=3
	movq	%rsi, %rdx
	addq	%r8, %rdx
	js	.LBB1_16
# %bb.8:                                #   in Loop: Header=BB1_5 Depth=3
	cmpl	%eax, %r15d
	jne	.LBB1_16
# %bb.9:                                #   in Loop: Header=BB1_5 Depth=3
	movss	(%r14,%r8,4), %xmm5             # xmm5 = mem[0],zero,zero,zero
	jmp	.LBB1_28
.LBB1_16:                               #   in Loop: Header=BB1_5 Depth=3
	movl	%r10d, %eax
	cltd
	idivl	%ebx
	testl	%r10d, %r10d
	js	.LBB1_22
# %bb.17:                               #   in Loop: Header=BB1_5 Depth=3
	leal	(%r12,%rcx), %edx
	cmpl	%eax, %edx
	jne	.LBB1_22
# %bb.18:                               #   in Loop: Header=BB1_5 Depth=3
	testl	%eax, %eax
	js	.LBB1_22
# %bb.19:                               #   in Loop: Header=BB1_5 Depth=3
	cmpl	%ebx, %eax
	jge	.LBB1_22
# %bb.20:                               #   in Loop: Header=BB1_5 Depth=3
	movl	%r10d, %eax
	jmp	.LBB1_21
.LBB1_22:                               #   in Loop: Header=BB1_5 Depth=3
	movl	%r11d, %eax
	cltd
	idivl	%ebx
	testl	%r11d, %r11d
	js	.LBB1_27
# %bb.23:                               #   in Loop: Header=BB1_5 Depth=3
	cmpl	%eax, %r15d
	jne	.LBB1_27
# %bb.24:                               #   in Loop: Header=BB1_5 Depth=3
	testl	%eax, %eax
	js	.LBB1_27
# %bb.25:                               #   in Loop: Header=BB1_5 Depth=3
	cmpl	%ebx, %eax
	jge	.LBB1_27
# %bb.26:                               #   in Loop: Header=BB1_5 Depth=3
	movl	%r11d, %eax
.LBB1_21:                               #   in Loop: Header=BB1_5 Depth=3
	movq	-128(%rsp), %rdx                # 8-byte Reload
	movss	(%rdx,%rax,4), %xmm5            # xmm5 = mem[0],zero,zero,zero
	jmp	.LBB1_28
.LBB1_27:                               #   in Loop: Header=BB1_5 Depth=3
	movss	(%r13), %xmm5                   # xmm5 = mem[0],zero,zero,zero
.LBB1_28:                               #   in Loop: Header=BB1_5 Depth=3
	movss	%xmm5, (%rdi)
	decl	%ecx
	incl	%r15d
	addq	24(%rsp), %rdi                  # 8-byte Folded Reload
	addq	16(%rsp), %r13                  # 8-byte Folded Reload
	addl	%ebx, %r11d
	subl	%ebx, %r10d
	addq	%rbx, %r8
	addl	%ebx, %r9d
	incl	%ebp
	cmpl	%ebp, %r12d
	jne	.LBB1_5
# %bb.29:                               # %._crit_edge
                                        #   in Loop: Header=BB1_4 Depth=2
	movq	-8(%rsp), %rax                  # 8-byte Reload
	incq	%rax
	movq	(%rsp), %rdi                    # 8-byte Reload
	addq	$4, %rdi
	movq	8(%rsp), %r13                   # 8-byte Reload
	addq	$4, %r13
	movl	-88(%rsp), %ecx                 # 4-byte Reload
	decl	%ecx
	movl	-84(%rsp), %r10d                # 4-byte Reload
	decl	%r10d
	addq	$4, %r14
	incq	%rsi
	cmpl	%eax, -100(%rsp)                # 4-byte Folded Reload
	jne	.LBB1_4
# %bb.10:                               # %.preheader135
                                        #   in Loop: Header=BB1_2 Depth=1
	movaps	%xmm4, %xmm6
	movq	-64(%rsp), %r9                  # 8-byte Reload
	testl	%r9d, %r9d
	movq	-48(%rsp), %rcx                 # 8-byte Reload
	movq	-56(%rsp), %rdi                 # 8-byte Reload
	movq	-72(%rsp), %r10                 # 8-byte Reload
	movq	-16(%rsp), %r11                 # 8-byte Reload
	movl	-108(%rsp), %ebp                # 4-byte Reload
	movl	-112(%rsp), %r15d               # 4-byte Reload
	movq	-24(%rsp), %r14                 # 8-byte Reload
	movq	-32(%rsp), %r13                 # 8-byte Reload
	movq	-40(%rsp), %rsi                 # 8-byte Reload
	je	.LBB1_14
.LBB1_11:                               # %.lr.ph143.preheader
                                        #   in Loop: Header=BB1_2 Depth=1
	xorps	%xmm5, %xmm5
	xorl	%r8d, %r8d
	xorps	%xmm6, %xmm6
.LBB1_12:                               # %.lr.ph143
                                        #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%r8d, %eax
	cltd
	idivl	%r9d
	subl	%r12d, %edx
	xorps	%xmm7, %xmm7
	cvtsi2ss	%edx, %xmm7
	subl	%r12d, %eax
	xorps	%xmm8, %xmm8
	cvtsi2ss	%eax, %xmm8
	mulss	%xmm7, %xmm7
	mulss	%xmm8, %xmm8
	addss	%xmm7, %xmm8
	cvtss2sd	%xmm6, %xmm6
	divss	%xmm0, %xmm8
	mulss	%xmm1, %xmm8
	addss	%xmm2, %xmm8
	cvttss2si	%xmm8, %eax
	movd	%eax, %xmm7
	xorps	%xmm8, %xmm8
	cvtss2sd	%xmm7, %xmm8
	mulss	32(%rsp,%r8,4), %xmm7
	cvtss2sd	%xmm7, %xmm7
	mulsd	%xmm3, %xmm7
	addsd	%xmm6, %xmm7
	xorps	%xmm6, %xmm6
	cvtsd2ss	%xmm7, %xmm6
	cvtss2sd	%xmm5, %xmm5
	mulsd	%xmm3, %xmm8
	addsd	%xmm5, %xmm8
	xorps	%xmm5, %xmm5
	cvtsd2ss	%xmm8, %xmm5
	incq	%r8
	cmpq	%r8, %r10
	jne	.LBB1_12
# %bb.13:                               # %._crit_edge144.loopexit
                                        #   in Loop: Header=BB1_2 Depth=1
	divss	%xmm5, %xmm6
.LBB1_14:                               # %._crit_edge144
                                        #   in Loop: Header=BB1_2 Depth=1
	movss	%xmm6, (%rcx,%rsi,4)
	incq	%rsi
	addq	$4, %r11
	incl	%ebp
	incl	%r15d
	addq	$4, %r13
	incq	%r14
	cmpq	%rdi, %rsi
	jne	.LBB1_2
.LBB1_15:                               # %._crit_edge149
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z8meansCPUPfPiS0_S_, .Lfunc_end1-_Z8meansCPUPfPiS0_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z10denoiseCPUPfS_PiS0_S_S_
.LCPI2_0:
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.long	0x80000000                      # float -0
	.text
	.globl	_Z10denoiseCPUPfS_PiS0_S_S_
	.type	_Z10denoiseCPUPfS_PiS0_S_S_,@function
_Z10denoiseCPUPfS_PiS0_S_S_:            # @_Z10denoiseCPUPfS_PiS0_S_S_
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%r9, 32(%rsp)                   # 8-byte Spill
	movq	%rdx, 24(%rsp)                  # 8-byte Spill
	movl	(%rdx), %ebp
	testl	%ebp, %ebp
	je	.LBB2_5
# %bb.1:                                # %.lr.ph.preheader
	movq	%r8, %r14
	movq	%rsi, %r12
	movq	%rdi, %r13
	imull	%ebp, %ebp
	xorl	%ebx, %ebx
	movaps	.LCPI2_0(%rip), %xmm2           # xmm2 = [-0.0E+0,-0.0E+0,-0.0E+0,-0.0E+0]
.LBB2_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_3 Depth 2
	cmpl	$1, %ebp
	adcl	$0, %ebp
	movss	(%r14,%rbx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, 16(%rsp)                 # 4-byte Spill
	xorps	%xmm1, %xmm1
	xorl	%r15d, %r15d
	xorps	%xmm0, %xmm0
.LBB2_3:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	%xmm0, 12(%rsp)                 # 4-byte Spill
	movss	%xmm1, 20(%rsp)                 # 4-byte Spill
	movss	16(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	subss	(%r14,%r15,4), %xmm1
	movaps	%xmm1, %xmm0
	xorps	%xmm2, %xmm0
	mulss	%xmm1, %xmm0
	divss	(%r12), %xmm0
	callq	expf
	movss	20(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
	movaps	.LCPI2_0(%rip), %xmm2           # xmm2 = [-0.0E+0,-0.0E+0,-0.0E+0,-0.0E+0]
	addss	%xmm0, %xmm1
	mulss	(%r13,%r15,4), %xmm0
	movss	12(%rsp), %xmm3                 # 4-byte Reload
                                        # xmm3 = mem[0],zero,zero,zero
	addss	%xmm0, %xmm3
	movss	%xmm3, 12(%rsp)                 # 4-byte Spill
	movss	12(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	incq	%r15
	cmpq	%r15, %rbp
	jne	.LBB2_3
# %bb.4:                                #   in Loop: Header=BB2_2 Depth=1
	divss	%xmm1, %xmm0
	movq	32(%rsp), %rax                  # 8-byte Reload
	movss	%xmm0, (%rax,%rbx,4)
	incq	%rbx
	movq	24(%rsp), %rax                  # 8-byte Reload
	movl	(%rax), %ebp
	imull	%ebp, %ebp
	cmpq	%rbp, %rbx
	jb	.LBB2_2
.LBB2_5:                                # %._crit_edge
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z10denoiseCPUPfS_PiS0_S_S_, .Lfunc_end2-_Z10denoiseCPUPfS_PiS0_S_S_
	.cfi_endproc
                                        # -- End function
	.globl	_Z11readCSVfilePcPi             # -- Begin function _Z11readCSVfilePcPi
	.type	_Z11readCSVfilePcPi,@function
_Z11readCSVfilePcPi:                    # @_Z11readCSVfilePcPi
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %r14
	movl	$262144, %edi                   # imm = 0x40000
	callq	malloc
	testq	%r14, %r14
	je	.LBB3_17
# %bb.1:
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movq	%rbx, 24(%rsp)                  # 8-byte Spill
	xorl	%ebx, %ebx
	leaq	16(%rsp), %rdi
	movq	%rbx, (%rdi)
	leaq	32(%rsp), %rsi
	movq	%rbx, (%rsi)
	movw	$8236, 5(%rsp)                  # imm = 0x202C
	movb	$0, 7(%rsp)
	movq	%r14, %rdx
	callq	getline
	cmpq	$-1, %rax
	je	.LBB3_2
# %bb.3:                                # %.lr.ph47.preheader
	movl	$256, %r13d                     # imm = 0x100
	leaq	5(%rsp), %r12
.LBB3_4:                                # %.lr.ph47
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_9 Depth 2
	movq	16(%rsp), %rdi
	movq	%r12, %rsi
	callq	strtok
	testq	%rax, %rax
	je	.LBB3_5
# %bb.6:                                # %.lr.ph
                                        #   in Loop: Header=BB3_4 Depth=1
	movq	%rax, %rdi
	callq	atof
	movl	%ebx, %eax
	imull	%r13d, %eax
	movslq	%eax, %r15
	cvtsd2ss	%xmm0, %xmm0
	movq	8(%rsp), %rbp                   # 8-byte Reload
	movss	%xmm0, (%rbp,%r15,4)
	xorl	%edi, %edi
	movq	%r12, %rsi
	callq	strtok
	testq	%rax, %rax
	je	.LBB3_7
# %bb.8:                                # %.lr.ph56.preheader
                                        #   in Loop: Header=BB3_4 Depth=1
	leaq	(,%r15,4), %r15
	addq	%rbp, %r15
	movl	$1, %ebp
.LBB3_9:                                # %.lr.ph56
                                        #   Parent Loop BB3_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%rax, %rdi
	callq	atof
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r15,%rbp,4)
	incq	%rbp
	xorl	%edi, %edi
	movq	%r12, %rsi
	callq	strtok
	testq	%rax, %rax
	jne	.LBB3_9
	jmp	.LBB3_10
.LBB3_5:                                #   in Loop: Header=BB3_4 Depth=1
	xorl	%ebp, %ebp
	jmp	.LBB3_10
.LBB3_7:                                #   in Loop: Header=BB3_4 Depth=1
	movl	$1, %ebp
.LBB3_10:                               # %._crit_edge
                                        #   in Loop: Header=BB3_4 Depth=1
	cmpl	%r13d, %ebp
	jne	.LBB3_12
# %bb.11:                               #   in Loop: Header=BB3_4 Depth=1
	movl	%r13d, %ebp
	jmp	.LBB3_13
.LBB3_12:                               #   in Loop: Header=BB3_4 Depth=1
	movl	%ebp, %esi
	imull	%esi, %esi
	shlq	$2, %rsi
	movq	8(%rsp), %rdi                   # 8-byte Reload
	callq	realloc
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movl	%ebp, %r13d
.LBB3_13:                               #   in Loop: Header=BB3_4 Depth=1
	incl	%ebx
	leaq	16(%rsp), %rdi
	leaq	32(%rsp), %rsi
	movq	%r14, %rdx
	callq	getline
	cmpq	$-1, %rax
	jne	.LBB3_4
	jmp	.LBB3_14
.LBB3_2:
	movl	$256, %ebp                      # imm = 0x100
.LBB3_14:                               # %._crit_edge48
	movq	%r14, %rdi
	callq	fclose
	movq	16(%rsp), %rdi
	testq	%rdi, %rdi
	je	.LBB3_16
# %bb.15:
	callq	free
.LBB3_16:
	movq	24(%rsp), %rax                  # 8-byte Reload
	movl	%ebp, (%rax)
	movq	8(%rsp), %rax                   # 8-byte Reload
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB3_17:
	.cfi_def_cfa_offset 96
	movl	$.L.str.1, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	_Z11readCSVfilePcPi, .Lfunc_end3-_Z11readCSVfilePcPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10floatToCSVPciPf             # -- Begin function _Z10floatToCSVPciPf
	.type	_Z10floatToCSVPciPf,@function
_Z10floatToCSVPciPf:                    # @_Z10floatToCSVPciPf
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdx, %rbx
	movl	%esi, %ebp
	movl	$.L.str.2, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB4_10
# %bb.1:                                # %.preheader
	movq	%rax, %r14
	testl	%ebp, %ebp
	je	.LBB4_9
# %bb.2:                                # %.lr.ph.preheader
	movl	%ebp, %r13d
	imull	%r13d, %r13d
	cmpl	$1, %r13d
	adcl	$0, %r13d
	xorl	%r15d, %r15d
	leaq	14(%rsp), %r12
.LBB4_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	testq	%r15, %r15
	je	.LBB4_6
# %bb.4:                                #   in Loop: Header=BB4_3 Depth=1
	movl	%r15d, %eax
	cltd
	idivl	%ebp
	testl	%edx, %edx
	jne	.LBB4_6
# %bb.5:                                #   in Loop: Header=BB4_3 Depth=1
	movl	$.L.str.4, %edi
	movq	%r14, %rsi
	callq	fputs
.LBB4_6:                                #   in Loop: Header=BB4_3 Depth=1
	movss	(%rbx,%r15,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm0
	jp	.LBB4_7
.LBB4_8:                                #   in Loop: Header=BB4_3 Depth=1
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.5, %esi
	movq	%r12, %rdi
	movb	$1, %al
	callq	sprintf
	movq	%r12, %rdi
	movq	%r14, %rsi
	callq	fputs
	movl	$.L.str.6, %edi
	movq	%r14, %rsi
	callq	fputs
	incq	%r15
	cmpq	%r15, %r13
	jne	.LBB4_3
	jmp	.LBB4_9
.LBB4_7:                                #   in Loop: Header=BB4_3 Depth=1
	movl	$0, (%rbx,%r15,4)
	xorps	%xmm0, %xmm0
	jmp	.LBB4_8
.LBB4_9:                                # %._crit_edge
	movq	%r14, %rdi
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	fclose                          # TAILCALL
.LBB4_10:
	.cfi_def_cfa_offset 80
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end4:
	.size	_Z10floatToCSVPciPf, .Lfunc_end4-_Z10floatToCSVPciPf
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI5_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	16(%rsp), %rax
	movl	$1028443341, (%rax)             # imm = 0x3D4CCCCD
	leaq	12(%rsp), %rax
	movl	$3, (%rax)
	leaq	20(%rsp), %r15
	movl	$.L.str.7, %edi
	movq	%r15, %rsi
	callq	_Z11readCSVfilePcPi
	movq	%rax, %rbp
	movslq	(%r15), %rbx
	movl	%ebx, %edi
	imull	%edi, %edi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	%rbx, %rdi
	imulq	%rbx, %rdi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, %r12
	callq	clock
	movq	%rax, %r13
	movq	%rbp, %rdi
	leaq	12(%rsp), %rsi
	movq	%r15, %rdx
	movq	%r14, %rcx
	callq	_Z8meansCPUPfPiS0_S_
	movq	%rbp, %rdi
	leaq	16(%rsp), %rsi
	movq	%r15, %rdx
	movq	%r14, %r8
	movq	%r12, %r9
	callq	_Z10denoiseCPUPfS_PiS0_S_S_
	callq	clock
	subq	%r13, %rax
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI5_0(%rip), %xmm0
	movl	$.L.str.8, %edi
	movb	$1, %al
	callq	printf
	movl	$.L.str.9, %edi
	movl	%ebx, %esi
	movq	%r12, %rdx
	callq	_Z10floatToCSVPciPf
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"r"
	.size	.L.str, 2

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"The file could not be opened/ does not exits"
	.size	.L.str.1, 45

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"a"
	.size	.L.str.2, 2

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"something went wrong when saving"
	.size	.L.str.3, 33

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"\n"
	.size	.L.str.4, 2

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%f"
	.size	.L.str.5, 3

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	","
	.size	.L.str.6, 2

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"images/rasp_noise.csv"
	.size	.L.str.7, 22

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"program took %f seconds to execute \n"
	.size	.L.str.8, 37

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"imageAfter.csv"
	.size	.L.str.9, 15

	.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
