#include <stdio.h>
#include <math.h>
#include <float.h>
#include <limits.h>

#define XSIZE 	1201
#define YSIZE	801



#define RADIUS		100
#define	RADSTEP		1
#define ANGLESIZE	36	


#define PI 3.141592653589793

int main()
{
	FILE *datTxt,*outputAnisotropy00,*outputAnisotropy09,*outputAnisotropy49,*outputAnisotropy99;
	FILE *outputAzimuth00,*outputAzimuth09,*outputAzimuth49,*outputAzimuth99; 
	int data[YSIZE][XSIZE];

	FILE * inpCheck;
	inpCheck = fopen("inpCheck.txt","w");
	if(inpCheck == NULL) {
		perror("Cannot open dat.txt file");
		return (-1);
	}
	//1200 ints in a row which are max of 5 digits
	//with a space in the front and the back and space
	//between each number 
	char line[1200 * 5 +2+1200];
	memset(line, '\0', sizeof(line));
	char *startPtr,*endPtr;
	
	datTxt = fopen("dat.txt","r");
	if(datTxt == NULL) {
		perror("Cannot open dat.txt file");
		return (-1);
	}

	outputAnisotropy00 = fopen("outputDataAni00.txt","w");
	outputAnisotropy09 = fopen("outputDataAni09.txt","w");
	outputAnisotropy49 = fopen("outputDataAni49.txt","w");
	outputAnisotropy99 = fopen("outputDataAni99.txt","w");
	if((outputAnisotropy00 == NULL)||(outputAnisotropy09 == NULL)||(outputAnisotropy49 == NULL)||(outputAnisotropy99 == NULL)) {
		perror("Cannot open Anisotropy file");
		return (-1);
	}

	outputAzimuth00 = fopen("outputDataAzi00.txt","w");
	outputAzimuth09 = fopen("outputDataAzi09.txt","w");
	outputAzimuth49 = fopen("outputDataAzi49.txt","w");
	outputAzimuth99 = fopen("outputDataAzi99.txt","w");

	if((outputAzimuth00 == NULL)||(outputAzimuth09 == NULL)||(outputAzimuth49 == NULL)||(outputAzimuth99 == NULL)) {
		perror("Cannot open Azimuth file");
		return (-1);
	}

	int i,j,Value;
	j = 0;
	char tempVal[5];
	memset(tempVal,'\0',sizeof(tempVal));

	while(fgets(line,1200 *5 + 2 + 1200,datTxt)!=NULL) {	
		startPtr = line;	
		for(i=0;i<XSIZE;i++) {
			Value = 0;
			memset(tempVal,'\0',sizeof(tempVal));		
			if(i != (XSIZE - 1)) {	
				endPtr = strchr(startPtr,' ');
				strncpy(tempVal,startPtr,endPtr-startPtr); 
				Value = atoi(tempVal);
				data[j][i] = Value;
				fprintf(inpCheck,"%d ",Value);

				endPtr = endPtr + 1;
				startPtr = endPtr;
			}	
			else if(i == (XSIZE - 1)){
				strcpy(tempVal,startPtr);
				Value = atoi(tempVal);
				data[j][i] = Value;
				fprintf(inpCheck,"%d\n",Value);
			}
		}
		
		j++;
	}	
	
	//Fine
	float angle[ANGLESIZE];
	for(int i=0;i<ANGLESIZE;i++) {
		angle[i] = i * 5 * PI/180;
	}
	
	//Initializing 3D matrix anisotropy
	float*** anisotropy;
	anisotropy = (float***)malloc(YSIZE * sizeof(float**));
	for(i = 0;i<YSIZE;i++) {
		anisotropy[i] = (float**)malloc(XSIZE * sizeof(float *));
		for(j = 0; j<XSIZE;j++) {
			anisotropy[i][j] = (float*)malloc(RADIUS * sizeof(float));
		}
	}

	//Initializing 3D matrix anzimuth
	float*** azimuth;
	azimuth = (float***)malloc(YSIZE * sizeof(float**));
	for(i = 0;i<YSIZE;i++) {
		azimuth[i] = (float**)malloc(XSIZE * sizeof(float *));
		for(j = 0; j<XSIZE;j++) {
			azimuth[i][j] = (float*)malloc(RADIUS * sizeof(float));
		}
	}

	//Actual computation
	int xrad,yrad,x,y,xradOrtho,yradOrtho,xradOneEighty,yradOneEighty,valueOneEighty;
	float variance[100];
	float orientation[100];
	float ortho[100];
	float value,sum_value,avg_value;
	float valueOrtho,sum_valueOrtho,avg_valueOrtho;
	sum_value = 0;
	avg_value = 0;
	sum_valueOrtho = 0;
	avg_valueOrtho = 0;

	

	//y = 0;
	for(y=0;y<YSIZE;y++) {
		for(x = 0;x<XSIZE;x++) {
		/*for(x = 0;x<XSIZE+1;x++) {
			if(x==XSIZE) {
				y++;	
				if(y==YSIZE){
					x = XSIZE;
					continue;
				}
				x=0;
				continue;
			
			}
			*/
			if((y>(YSIZE - RADIUS - 1))||(y<(RADIUS + 1))) continue;
			if((x>(XSIZE - RADIUS - 1))||(x<(RADIUS + 1))) continue;	

			for(i=0;i<100;i++){
				variance[i] = FLT_MAX;
				ortho[i] = FLT_MAX;
			}
			
			
			//Flipped
			for(i=0;i<ANGLESIZE;i++) {
				sum_value = 0;
				sum_valueOrtho = 0;
				for(j = 0;j<RADIUS;j+=RADSTEP) {
		
					xrad = (int)round(cos(angle[i]) * (j+1) + x);	
					yrad = (int)round(sin(angle[i]) * (j+1) + y);	

					value = data[y][x] - data[yrad][xrad];
					value = value * value * 0.5;

					//sum_value = sum_value + value;
					//avg_value = sum_value/(j+1);


					//Ortho computation
					xradOrtho = (int)round(cos(angle[i]+PI/2) * (j+1) + x);	
					yradOrtho = (int)round(sin(angle[i]+PI/2) * (j+1) + y);	

					valueOrtho = data[y][x] - data[yradOrtho][xradOrtho];
					valueOrtho = valueOrtho * valueOrtho *0.5;

					sum_valueOrtho = sum_valueOrtho + valueOrtho;
					avg_valueOrtho = sum_valueOrtho/(j+1);

					
					//One eighty angle computation
					xradOneEighty = (int)round(cos(angle[i]+PI) * (j+1) + x);	
					yradOneEighty = (int)round(sin(angle[i]+PI) * (j+1) + y);	
					
					valueOneEighty = data[y][x] - data[yradOneEighty][xradOneEighty];
					valueOneEighty = valueOneEighty * valueOneEighty * 0.5;

					sum_value = sum_value + value + valueOneEighty;
					avg_value = sum_value/(2*(j+1));
	
					//Fail safe to ensure there is no nan or inf			
					if(avg_value == 0) {
							if((avg_valueOrtho < 1) && (avg_valueOrtho > 0)) {
								avg_value = avg_valueOrtho;
							}
							else {
								avg_value = 1;
							}
					}

					if(avg_valueOrtho == 0) {
						avg_valueOrtho = 1;
					}


					//printf("1(%d,%d)	%f	%f\n",(j+1),(i+1),variance[j],avg_value);
					if(avg_value < variance[j]) {
						//	printf("2(%d)	%f	%f\n",j,variance[j],avg_value);
							variance[j] = avg_value;
							orientation[j] = angle[i];
							ortho[j] = avg_valueOrtho;		
					}	
				}
			}
			
			for(j=0;j<RADIUS;j+=RADSTEP){
				anisotropy[y][x][j] = ortho[j]/variance[j];
				azimuth[y][x][j] = orientation[j] * 180/PI ;
				
				//printf("%f	%f\n",variance[j],anisotropy[y][x][j]);	
			}

			
//			Writing to files
			

			if (x == (XSIZE - RADIUS - 1)) {
				fprintf(outputAnisotropy00,"%f",anisotropy[y][x][0]);
				fprintf(outputAzimuth00,"%f",azimuth[y][x][0]);
				fprintf(outputAnisotropy00,"\n");
				fprintf(outputAzimuth00,"\n");

				fprintf(outputAnisotropy09,"%f",anisotropy[y][x][9]);
				fprintf(outputAzimuth09,"%f",azimuth[y][x][9]);
				fprintf(outputAnisotropy09,"\n");
				fprintf(outputAzimuth09,"\n");

				fprintf(outputAnisotropy49,"%f",anisotropy[y][x][49]);
				fprintf(outputAzimuth49,"%f",azimuth[y][x][49]);
				fprintf(outputAnisotropy49,"\n");
				fprintf(outputAzimuth49,"\n");

				fprintf(outputAnisotropy99,"%f",anisotropy[y][x][99]);
				fprintf(outputAzimuth99,"%f",azimuth[y][x][99]);
				fprintf(outputAnisotropy99,"\n");
				fprintf(outputAzimuth99,"\n");
			}
			else {
				fprintf(outputAnisotropy00,"%f",anisotropy[y][x][0]);
				fprintf(outputAzimuth00,"%f",azimuth[y][x][0]);
				fprintf(outputAnisotropy00,"\t");
				fprintf(outputAzimuth00,"\t");
				
				fprintf(outputAnisotropy09,"%f",anisotropy[y][x][9]);
				fprintf(outputAzimuth09,"%f",azimuth[y][x][9]);
				fprintf(outputAnisotropy09,"\t");
				fprintf(outputAzimuth09,"\t");

				fprintf(outputAnisotropy49,"%f",anisotropy[y][x][49]);
				fprintf(outputAzimuth49,"%f",azimuth[y][x][49]);	
				fprintf(outputAnisotropy49,"\t");
				fprintf(outputAzimuth49,"\t");

				fprintf(outputAnisotropy99,"%f",anisotropy[y][x][99]);
				fprintf(outputAzimuth99,"%f",azimuth[y][x][99]);
				fprintf(outputAnisotropy99,"\t");
				fprintf(outputAzimuth99,"\t");
				
			}					
		}			
			
	}


		
	
	


	fclose(datTxt);
	fclose(inpCheck);
	fclose(outputAnisotropy00);
	fclose(outputAnisotropy09);
	fclose(outputAnisotropy49);
	fclose(outputAnisotropy99);

	fclose(outputAzimuth00);
	fclose(outputAzimuth09);
	fclose(outputAzimuth49);
	fclose(outputAzimuth99);

	//Freeing 3D matrix anisotropy
	for(i = 0;i<YSIZE;i++) {
		for(j=0;j<XSIZE;j++) {
			free(anisotropy[i][j]);
		}
		free(anisotropy[i]);
	}
	free(anisotropy);

	//Freeing 3D matrix azimuth
	for(i = 0;i<YSIZE;i++) {
		for(j=0;j<XSIZE;j++) {
			free(azimuth[i][j]);
		}
		free(azimuth[i]);
	}
	free(azimuth);
	
	return 0;
}

	.file	"tmpxft_00259c5b_00000000-6_topographic_anisotropy_NewMethod.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"w"
.LC3:
	.string	"inpCheck.txt"
.LC4:
	.string	"Cannot open dat.txt file"
.LC5:
	.string	"r"
.LC6:
	.string	"dat.txt"
.LC7:
	.string	"outputDataAni00.txt"
.LC8:
	.string	"outputDataAni09.txt"
.LC9:
	.string	"outputDataAni49.txt"
.LC10:
	.string	"outputDataAni99.txt"
.LC11:
	.string	"Cannot open Anisotropy file"
.LC12:
	.string	"outputDataAzi00.txt"
.LC13:
	.string	"outputDataAzi09.txt"
.LC14:
	.string	"outputDataAzi49.txt"
.LC15:
	.string	"outputDataAzi99.txt"
.LC16:
	.string	"Cannot open Azimuth file"
.LC17:
	.string	"%d "
.LC18:
	.string	"%d\n"
.LC26:
	.string	"%f"
.LC27:
	.string	"\n"
.LC28:
	.string	"\t"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-3854336(%rsp), %r11
	.cfi_def_cfa 11, 3854392
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$2504, %rsp
	.cfi_def_cfa_offset 3856896
	leaq	.LC2(%rip), %rbx
	leaq	.LC3(%rip), %rdi
	movq	%rbx, %rsi
	movq	%fs:40, %rax
	movq	%rax, 3856824(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	movq	%rax, 72(%rsp)
	testq	%rax, %rax
	jne	.L3
.L5:
	leaq	.LC4(%rip), %rdi
	jmp	.L70
.L3:
	leaq	3849622(%rsp), %rdx
	xorl	%eax, %eax
	movl	$7202, %ecx
	movq	%rdx, %rdi
	leaq	.LC5(%rip), %rsi
	rep stosb
	leaq	.LC6(%rip), %rdi
	call	fopen@PLT
	movq	%rax, 104(%rsp)
	testq	%rax, %rax
	je	.L5
	movq	%rbx, %rsi
	leaq	.LC7(%rip), %rdi
	call	fopen@PLT
	movq	%rbx, %rsi
	leaq	.LC8(%rip), %rdi
	movq	%rax, 8(%rsp)
	call	fopen@PLT
	movq	%rbx, %rsi
	leaq	.LC9(%rip), %rdi
	movq	%rax, 16(%rsp)
	call	fopen@PLT
	movq	%rbx, %rsi
	leaq	.LC10(%rip), %rdi
	movq	%rax, 24(%rsp)
	call	fopen@PLT
	cmpq	$0, 8(%rsp)
	movq	%rax, 32(%rsp)
	je	.L6
	cmpq	$0, 16(%rsp)
	je	.L6
	cmpq	$0, 24(%rsp)
	je	.L6
	testq	%rax, %rax
	jne	.L7
.L6:
	leaq	.LC11(%rip), %rdi
.L70:
	call	perror@PLT
	orl	$-1, %eax
	jmp	.L2
.L7:
	movq	%rbx, %rsi
	leaq	.LC12(%rip), %rdi
	call	fopen@PLT
	movq	%rbx, %rsi
	leaq	.LC13(%rip), %rdi
	movq	%rax, 40(%rsp)
	call	fopen@PLT
	movq	%rbx, %rsi
	leaq	.LC14(%rip), %rdi
	movq	%rax, 48(%rsp)
	call	fopen@PLT
	movq	%rbx, %rsi
	leaq	.LC15(%rip), %rdi
	movq	%rax, 56(%rsp)
	call	fopen@PLT
	cmpq	$0, 40(%rsp)
	movq	%rax, 64(%rsp)
	je	.L10
	cmpq	$0, 48(%rsp)
	je	.L10
	cmpq	$0, 56(%rsp)
	je	.L10
	testq	%rax, %rax
	jne	.L11
.L10:
	leaq	.LC16(%rip), %rdi
	jmp	.L70
.L11:
	leaq	1612(%rsp), %rax
	xorl	%edx, %edx
	movb	$0, 3849621(%rsp)
	leaq	.LC18(%rip), %r14
	movl	%edx, 3849617(%rsp)
	movq	%rax, %r12
	movq	%rax, 136(%rsp)
.L13:
	movq	104(%rsp), %rcx
	movl	$7202, %edx
	movl	$7202, %esi
	leaq	3849622(%rsp), %rbx
	movq	%rbx, %rdi
	call	__fgets_chk@PLT
	testq	%rax, %rax
	je	.L72
	xorl	%ebp, %ebp
.L16:
	xorl	%eax, %eax
	movb	$0, 3849621(%rsp)
	leaq	3849617(%rsp), %r13
	movl	%eax, 3849617(%rsp)
	cmpq	$1200, %rbp
	je	.L14
	movq	%rbx, %rdi
	movl	$32, %esi
	call	strchr@PLT
	movq	%rbx, %rsi
	movl	$5, %ecx
	movq	%r13, %rdi
	movq	%rax, %rdx
	movq	%rax, %r15
	subq	%rbx, %rdx
	leaq	1(%r15), %rbx
	call	__strncpy_chk@PLT
	movq	%r13, %rdi
	call	atoi@PLT
	movq	72(%rsp), %rdi
	movl	$2, %esi
	leaq	.LC17(%rip), %rdx
	movl	%eax, (%r12,%rbp,4)
	movl	%eax, %ecx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L15
.L14:
	movl	$5, %edx
	movq	%rbx, %rsi
	movq	%r13, %rdi
	call	__strcpy_chk@PLT
	movq	%r13, %rdi
	call	atoi@PLT
	movq	72(%rsp), %rdi
	movq	%r14, %rdx
	movl	$2, %esi
	movl	%eax, 4800(%r12)
	movl	%eax, %ecx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L15:
	incq	%rbp
	cmpq	$1201, %rbp
	jne	.L16
	addq	$4804, %r12
	jmp	.L13
.L72:
	movsd	.LC20(%rip), %xmm1
	leaq	268(%rsp), %rdx
.L17:
	cvtsi2sdl	%eax, %xmm0
	mulsd	.LC19(%rip), %xmm0
	addl	$5, %eax
	addq	$4, %rdx
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, -4(%rdx)
	cmpl	$180, %eax
	jne	.L17
	movl	$6408, %edi
	xorl	%ebx, %ebx
	call	malloc@PLT
	movq	%rax, 80(%rsp)
.L19:
	movl	$9608, %edi
	xorl	%ebp, %ebp
	call	malloc@PLT
	movq	%rax, %r12
	movq	80(%rsp), %rax
	movq	%r12, (%rax,%rbx,8)
.L18:
	movl	$400, %edi
	call	malloc@PLT
	movq	%rax, (%r12,%rbp,8)
	incq	%rbp
	cmpq	$1201, %rbp
	jne	.L18
	incq	%rbx
	cmpq	$801, %rbx
	jne	.L19
	movl	$6408, %edi
	xorl	%ebx, %ebx
	call	malloc@PLT
	movq	%rax, 88(%rsp)
.L21:
	movl	$9608, %edi
	xorl	%ebp, %ebp
	call	malloc@PLT
	movq	%rax, %r12
	movq	88(%rsp), %rax
	movq	%r12, (%rax,%rbx,8)
.L20:
	movl	$400, %edi
	call	malloc@PLT
	movq	%rax, (%r12,%rbp,8)
	incq	%rbp
	cmpq	$1201, %rbp
	jne	.L20
	incq	%rbx
	cmpq	$801, %rbx
	jne	.L21
	xorl	%ebx, %ebx
.L22:
	imulq	$4804, %rbx, %rax
	movq	136(%rsp), %rcx
	xorl	%r13d, %r13d
	movl	%ebx, 164(%rsp)
	movl	%ebx, 160(%rsp)
	addq	%rcx, %rax
	movq	%rax, 168(%rsp)
.L39:
	movl	164(%rsp), %eax
	subl	$101, %eax
	cmpl	$599, %eax
	ja	.L23
	leal	-101(%r13), %eax
	cmpl	$999, %eax
	ja	.L23
	xorl	%eax, %eax
.L24:
	movl	$0x7f7fffff, 412(%rsp,%rax)
	movl	$0x7f7fffff, 1212(%rsp,%rax)
	addq	$4, %rax
	cmpq	$400, %rax
	jne	.L24
	movq	168(%rsp), %rax
	movl	%r13d, %r14d
	xorl	%ebp, %ebp
	movl	(%rax,%r13,4), %r12d
.L25:
	leaq	252(%rsp), %rdi
	leaq	248(%rsp), %rsi
	movss	268(%rsp,%rbp,4), %xmm3
	leaq	240(%rsp), %r15
	movaps	%xmm3, %xmm0
	movss	%xmm3, 100(%rsp)
	call	sincosf@PLT
	cvtss2sd	100(%rsp), %xmm1
	movaps	%xmm1, %xmm0
	addsd	.LC24(%rip), %xmm0
	movss	248(%rsp), %xmm4
	leaq	232(%rsp), %rsi
	movq	%r15, %rdi
	movss	252(%rsp), %xmm5
	movq	%rsi, 112(%rsp)
	movss	%xmm4, 176(%rsp)
	movss	%xmm5, 180(%rsp)
	movsd	%xmm1, 120(%rsp)
	call	sincos@PLT
	movsd	.LC19(%rip), %xmm0
	movq	112(%rsp), %rsi
	movq	%r15, %rdi
	movsd	120(%rsp), %xmm1
	movl	$1, %r15d
	movsd	232(%rsp), %xmm6
	movsd	240(%rsp), %xmm7
	movsd	%xmm6, 200(%rsp)
	addsd	%xmm1, %xmm0
	movsd	%xmm7, 208(%rsp)
	call	sincos@PLT
	cvtsi2ssl	%r14d, %xmm4
	movsd	240(%rsp), %xmm3
	movsd	232(%rsp), %xmm2
	cvtsi2sdl	%r14d, %xmm6
	movl	$0x00000000, 112(%rsp)
	cvtsi2ssl	160(%rsp), %xmm5
	movsd	%xmm3, 192(%rsp)
	xorps	%xmm3, %xmm3
	cvtsi2sdl	160(%rsp), %xmm7
	movsd	%xmm2, 184(%rsp)
	movss	%xmm4, 216(%rsp)
	movsd	%xmm6, 120(%rsp)
	movss	%xmm5, 220(%rsp)
	movsd	%xmm7, 128(%rsp)
.L33:
	movss	176(%rsp), %xmm0
	cvtsi2ssl	%r15d, %xmm7
	movss	%xmm3, 228(%rsp)
	movss	%xmm7, 144(%rsp)
	mulss	%xmm7, %xmm0
	addss	216(%rsp), %xmm0
	call	roundf@PLT
	movss	%xmm0, 152(%rsp)
	cvtsi2ssl	%r15d, %xmm0
	mulss	180(%rsp), %xmm0
	addss	220(%rsp), %xmm0
	call	roundf@PLT
	movl	%r12d, %eax
	cvtsi2sdl	%r15d, %xmm7
	movss	152(%rsp), %xmm1
	cvttss2sil	%xmm0, %edx
	cvttss2sil	%xmm1, %esi
	movsd	%xmm7, 152(%rsp)
	movslq	%edx, %rdx
	imulq	$1201, %rdx, %rdx
	movslq	%esi, %rsi
	addq	%rsi, %rdx
	subl	1612(%rsp,%rdx,4), %eax
	cvtsi2ssl	%eax, %xmm0
	movaps	%xmm0, %xmm2
	mulss	%xmm0, %xmm2
	movsd	200(%rsp), %xmm0
	mulsd	%xmm7, %xmm0
	addsd	120(%rsp), %xmm0
	movss	%xmm2, 224(%rsp)
	call	round@PLT
	movsd	%xmm0, 152(%rsp)
	cvtsi2sdl	%r15d, %xmm0
	mulsd	208(%rsp), %xmm0
	addsd	128(%rsp), %xmm0
	call	round@PLT
	movl	%r12d, %eax
	movsd	152(%rsp), %xmm1
	cvttsd2sil	%xmm0, %edx
	cvttsd2sil	%xmm1, %esi
	movslq	%edx, %rdx
	imulq	$1201, %rdx, %rdx
	movslq	%esi, %rsi
	addq	%rsi, %rdx
	subl	1612(%rsp,%rdx,4), %eax
	cvtsi2ssl	%eax, %xmm0
	mulss	%xmm0, %xmm0
	mulss	.LC22(%rip), %xmm0
	addss	112(%rsp), %xmm0
	movss	%xmm0, 112(%rsp)
	movaps	%xmm0, %xmm1
	cvtsi2sdl	%r15d, %xmm0
	divss	144(%rsp), %xmm1
	mulsd	184(%rsp), %xmm0
	movss	%xmm1, 152(%rsp)
	addsd	120(%rsp), %xmm0
	call	round@PLT
	movsd	%xmm0, 144(%rsp)
	cvtsi2sdl	%r15d, %xmm0
	mulsd	192(%rsp), %xmm0
	addsd	128(%rsp), %xmm0
	call	round@PLT
	movl	%r12d, %eax
	xorps	%xmm5, %xmm5
	movsd	144(%rsp), %xmm6
	movss	224(%rsp), %xmm2
	cvttsd2sil	%xmm0, %edx
	movss	.LC22(%rip), %xmm0
	movss	228(%rsp), %xmm3
	cvttsd2sil	%xmm6, %esi
	movss	152(%rsp), %xmm1
	mulss	%xmm2, %xmm0
	movslq	%edx, %rdx
	imulq	$1201, %rdx, %rdx
	movslq	%esi, %rsi
	addss	%xmm3, %xmm0
	addq	%rsi, %rdx
	subl	1612(%rsp,%rdx,4), %eax
	movl	%eax, %edx
	imull	%eax, %edx
	cvtsi2sdl	%edx, %xmm6
	mulsd	.LC23(%rip), %xmm6
	movss	.LC1(%rip), %xmm4
	cvttsd2sil	%xmm6, %edx
	cvtsi2ssl	%edx, %xmm3
	leal	(%r15,%r15), %edx
	cvtsi2ssl	%edx, %xmm2
	addss	%xmm0, %xmm3
	movaps	%xmm3, %xmm0
	divss	%xmm2, %xmm0
	ucomiss	%xmm5, %xmm0
	jp	.L26
	jne	.L26
	comiss	%xmm1, %xmm4
	movaps	%xmm4, %xmm0
	jbe	.L28
	comiss	%xmm5, %xmm1
	movaps	%xmm1, %xmm0
	ja	.L28
	movaps	%xmm4, %xmm0
.L26:
	ucomiss	%xmm5, %xmm1
	jp	.L28
	movl	.LC1(%rip), %ecx
	movd	%xmm1, %eax
	cmove	%ecx, %eax
	movd	%eax, %xmm1
.L28:
	movss	408(%rsp,%r15,4), %xmm2
	comiss	%xmm0, %xmm2
	jbe	.L31
	movss	%xmm0, 408(%rsp,%r15,4)
	movss	100(%rsp), %xmm2
	movss	%xmm1, 1208(%rsp,%r15,4)
	movss	%xmm2, 808(%rsp,%r15,4)
.L31:
	incq	%r15
	cmpq	$101, %r15
	jne	.L33
	incq	%rbp
	cmpq	$36, %rbp
	jne	.L25
	movq	80(%rsp), %rax
	movss	.LC25(%rip), %xmm1
	leaq	412(%rsp), %rsi
	movq	(%rax,%rbx,8), %rdx
	movq	88(%rsp), %rax
	movq	(%rax,%rbx,8), %rbp
	movq	(%rdx,%r13,8), %r15
	xorl	%eax, %eax
	movq	0(%rbp,%r13,8), %r14
.L35:
	movss	1212(%rsp,%rax), %xmm0
	divss	(%rax,%rsi), %xmm0
	movss	%xmm0, (%r15,%rax)
	movss	812(%rsp,%rax), %xmm0
	mulss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	divsd	.LC19(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r14,%rax)
	addq	$4, %rax
	cmpq	$400, %rax
	jne	.L35
	cmpq	$1100, %r13
	jne	.L36
	leaq	.LC26(%rip), %r12
	movq	8800(%rdx), %r15
	movq	8(%rsp), %rdi
	movb	$1, %al
	movq	%r12, %rdx
	movl	$2, %esi
	movl	$1101, %r13d
	cvtss2sd	(%r15), %xmm0
	call	__fprintf_chk@PLT
	movq	%r12, %rdx
	movb	$1, %al
	movq	8800(%rbp), %r14
	movq	40(%rsp), %rdi
	movl	$2, %esi
	leaq	.LC27(%rip), %rbp
	cvtss2sd	(%r14), %xmm0
	call	__fprintf_chk@PLT
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movq	8(%rsp), %rdi
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	40(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	16(%rsp), %rdi
	movq	%r12, %rdx
	movb	$1, %al
	movl	$2, %esi
	cvtss2sd	36(%r15), %xmm0
	call	__fprintf_chk@PLT
	movq	48(%rsp), %rdi
	movq	%r12, %rdx
	movb	$1, %al
	movl	$2, %esi
	cvtss2sd	36(%r14), %xmm0
	call	__fprintf_chk@PLT
	movq	16(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	48(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	24(%rsp), %rdi
	movq	%r12, %rdx
	movb	$1, %al
	cvtss2sd	196(%r15), %xmm0
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	56(%rsp), %rdi
	movq	%r12, %rdx
	movb	$1, %al
	cvtss2sd	196(%r14), %xmm0
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	24(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	56(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	32(%rsp), %rdi
	movq	%r12, %rdx
	movb	$1, %al
	cvtss2sd	396(%r15), %xmm0
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	64(%rsp), %rdi
	movq	%r12, %rdx
	movb	$1, %al
	cvtss2sd	396(%r14), %xmm0
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	32(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	64(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L39
.L36:
	leaq	.LC26(%rip), %r12
	movq	8(%rsp), %rdi
	movl	$2, %esi
	movb	$1, %al
	movq	%r12, %rdx
	cvtss2sd	(%r15), %xmm0
	leaq	.LC28(%rip), %rbp
	call	__fprintf_chk@PLT
	movq	40(%rsp), %rdi
	movq	%r12, %rdx
	movb	$1, %al
	movl	$2, %esi
	cvtss2sd	(%r14), %xmm0
	call	__fprintf_chk@PLT
	movq	8(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	40(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	16(%rsp), %rdi
	movq	%r12, %rdx
	movb	$1, %al
	movl	$2, %esi
	cvtss2sd	36(%r15), %xmm0
	call	__fprintf_chk@PLT
	movq	48(%rsp), %rdi
	movq	%r12, %rdx
	movb	$1, %al
	movl	$2, %esi
	cvtss2sd	36(%r14), %xmm0
	call	__fprintf_chk@PLT
	movq	16(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	48(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	24(%rsp), %rdi
	movq	%r12, %rdx
	movb	$1, %al
	cvtss2sd	196(%r15), %xmm0
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	56(%rsp), %rdi
	movq	%r12, %rdx
	movb	$1, %al
	cvtss2sd	196(%r14), %xmm0
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	24(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	56(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	32(%rsp), %rdi
	movq	%r12, %rdx
	movb	$1, %al
	cvtss2sd	396(%r15), %xmm0
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	64(%rsp), %rdi
	movq	%r12, %rdx
	movb	$1, %al
	cvtss2sd	396(%r14), %xmm0
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	32(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	64(%rsp), %rdi
	movq	%rbp, %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
.L23:
	incq	%r13
	cmpq	$1201, %r13
	jne	.L39
	incq	%rbx
	cmpq	$801, %rbx
	jne	.L22
	movq	104(%rsp), %rdi
	xorl	%ebp, %ebp
	call	fclose@PLT
	movq	72(%rsp), %rdi
	call	fclose@PLT
	movq	8(%rsp), %rdi
	call	fclose@PLT
	movq	16(%rsp), %rdi
	call	fclose@PLT
	movq	24(%rsp), %rdi
	call	fclose@PLT
	movq	32(%rsp), %rdi
	call	fclose@PLT
	movq	40(%rsp), %rdi
	call	fclose@PLT
	movq	48(%rsp), %rdi
	call	fclose@PLT
	movq	56(%rsp), %rdi
	call	fclose@PLT
	movq	64(%rsp), %rdi
	call	fclose@PLT
.L40:
	xorl	%ebx, %ebx
.L41:
	movq	80(%rsp), %rax
	movq	(%rax,%rbp,8), %r12
	movq	(%r12,%rbx), %rdi
	addq	$8, %rbx
	call	free@PLT
	cmpq	$9608, %rbx
	jne	.L41
	movq	%r12, %rdi
	incq	%rbp
	call	free@PLT
	cmpq	$801, %rbp
	jne	.L40
	movq	80(%rsp), %rdi
	xorl	%ebp, %ebp
	call	free@PLT
.L43:
	xorl	%ebx, %ebx
.L44:
	movq	88(%rsp), %rax
	movq	(%rax,%rbp,8), %r12
	movq	(%r12,%rbx), %rdi
	addq	$8, %rbx
	call	free@PLT
	cmpq	$9608, %rbx
	jne	.L44
	movq	%r12, %rdi
	incq	%rbp
	call	free@PLT
	cmpq	$801, %rbp
	jne	.L43
	movq	88(%rsp), %rdi
	call	free@PLT
	xorl	%eax, %eax
.L2:
	movq	3856824(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L46
	call	__stack_chk_fail@PLT
.L46:
	addq	$3856840, %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
.LFE2027:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2053:
	.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
.LFE2053:
	.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
.LC1:
	.long	1065353216
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC19:
	.long	1413754136
	.long	1074340347
	.align 8
.LC20:
	.long	0
	.long	1080459264
	.section	.rodata.cst4
	.align 4
.LC22:
	.long	1056964608
	.section	.rodata.cst8
	.align 8
.LC23:
	.long	0
	.long	1071644672
	.align 8
.LC24:
	.long	1413754136
	.long	1073291771
	.section	.rodata.cst4
	.align 4
.LC25:
	.long	1127481344
	.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:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <math.h>
#include <float.h>
#include <limits.h>

#define XSIZE 	1201
#define YSIZE	801



#define RADIUS		100
#define	RADSTEP		1
#define ANGLESIZE	36	


#define PI 3.141592653589793

int main()
{
	FILE *datTxt,*outputAnisotropy00,*outputAnisotropy09,*outputAnisotropy49,*outputAnisotropy99;
	FILE *outputAzimuth00,*outputAzimuth09,*outputAzimuth49,*outputAzimuth99; 
	int data[YSIZE][XSIZE];

	FILE * inpCheck;
	inpCheck = fopen("inpCheck.txt","w");
	if(inpCheck == NULL) {
		perror("Cannot open dat.txt file");
		return (-1);
	}
	//1200 ints in a row which are max of 5 digits
	//with a space in the front and the back and space
	//between each number 
	char line[1200 * 5 +2+1200];
	memset(line, '\0', sizeof(line));
	char *startPtr,*endPtr;
	
	datTxt = fopen("dat.txt","r");
	if(datTxt == NULL) {
		perror("Cannot open dat.txt file");
		return (-1);
	}

	outputAnisotropy00 = fopen("outputDataAni00.txt","w");
	outputAnisotropy09 = fopen("outputDataAni09.txt","w");
	outputAnisotropy49 = fopen("outputDataAni49.txt","w");
	outputAnisotropy99 = fopen("outputDataAni99.txt","w");
	if((outputAnisotropy00 == NULL)||(outputAnisotropy09 == NULL)||(outputAnisotropy49 == NULL)||(outputAnisotropy99 == NULL)) {
		perror("Cannot open Anisotropy file");
		return (-1);
	}

	outputAzimuth00 = fopen("outputDataAzi00.txt","w");
	outputAzimuth09 = fopen("outputDataAzi09.txt","w");
	outputAzimuth49 = fopen("outputDataAzi49.txt","w");
	outputAzimuth99 = fopen("outputDataAzi99.txt","w");

	if((outputAzimuth00 == NULL)||(outputAzimuth09 == NULL)||(outputAzimuth49 == NULL)||(outputAzimuth99 == NULL)) {
		perror("Cannot open Azimuth file");
		return (-1);
	}

	int i,j,Value;
	j = 0;
	char tempVal[5];
	memset(tempVal,'\0',sizeof(tempVal));

	while(fgets(line,1200 *5 + 2 + 1200,datTxt)!=NULL) {	
		startPtr = line;	
		for(i=0;i<XSIZE;i++) {
			Value = 0;
			memset(tempVal,'\0',sizeof(tempVal));		
			if(i != (XSIZE - 1)) {	
				endPtr = strchr(startPtr,' ');
				strncpy(tempVal,startPtr,endPtr-startPtr); 
				Value = atoi(tempVal);
				data[j][i] = Value;
				fprintf(inpCheck,"%d ",Value);

				endPtr = endPtr + 1;
				startPtr = endPtr;
			}	
			else if(i == (XSIZE - 1)){
				strcpy(tempVal,startPtr);
				Value = atoi(tempVal);
				data[j][i] = Value;
				fprintf(inpCheck,"%d\n",Value);
			}
		}
		
		j++;
	}	
	
	//Fine
	float angle[ANGLESIZE];
	for(int i=0;i<ANGLESIZE;i++) {
		angle[i] = i * 5 * PI/180;
	}
	
	//Initializing 3D matrix anisotropy
	float*** anisotropy;
	anisotropy = (float***)malloc(YSIZE * sizeof(float**));
	for(i = 0;i<YSIZE;i++) {
		anisotropy[i] = (float**)malloc(XSIZE * sizeof(float *));
		for(j = 0; j<XSIZE;j++) {
			anisotropy[i][j] = (float*)malloc(RADIUS * sizeof(float));
		}
	}

	//Initializing 3D matrix anzimuth
	float*** azimuth;
	azimuth = (float***)malloc(YSIZE * sizeof(float**));
	for(i = 0;i<YSIZE;i++) {
		azimuth[i] = (float**)malloc(XSIZE * sizeof(float *));
		for(j = 0; j<XSIZE;j++) {
			azimuth[i][j] = (float*)malloc(RADIUS * sizeof(float));
		}
	}

	//Actual computation
	int xrad,yrad,x,y,xradOrtho,yradOrtho,xradOneEighty,yradOneEighty,valueOneEighty;
	float variance[100];
	float orientation[100];
	float ortho[100];
	float value,sum_value,avg_value;
	float valueOrtho,sum_valueOrtho,avg_valueOrtho;
	sum_value = 0;
	avg_value = 0;
	sum_valueOrtho = 0;
	avg_valueOrtho = 0;

	

	//y = 0;
	for(y=0;y<YSIZE;y++) {
		for(x = 0;x<XSIZE;x++) {
		/*for(x = 0;x<XSIZE+1;x++) {
			if(x==XSIZE) {
				y++;	
				if(y==YSIZE){
					x = XSIZE;
					continue;
				}
				x=0;
				continue;
			
			}
			*/
			if((y>(YSIZE - RADIUS - 1))||(y<(RADIUS + 1))) continue;
			if((x>(XSIZE - RADIUS - 1))||(x<(RADIUS + 1))) continue;	

			for(i=0;i<100;i++){
				variance[i] = FLT_MAX;
				ortho[i] = FLT_MAX;
			}
			
			
			//Flipped
			for(i=0;i<ANGLESIZE;i++) {
				sum_value = 0;
				sum_valueOrtho = 0;
				for(j = 0;j<RADIUS;j+=RADSTEP) {
		
					xrad = (int)round(cos(angle[i]) * (j+1) + x);	
					yrad = (int)round(sin(angle[i]) * (j+1) + y);	

					value = data[y][x] - data[yrad][xrad];
					value = value * value * 0.5;

					//sum_value = sum_value + value;
					//avg_value = sum_value/(j+1);


					//Ortho computation
					xradOrtho = (int)round(cos(angle[i]+PI/2) * (j+1) + x);	
					yradOrtho = (int)round(sin(angle[i]+PI/2) * (j+1) + y);	

					valueOrtho = data[y][x] - data[yradOrtho][xradOrtho];
					valueOrtho = valueOrtho * valueOrtho *0.5;

					sum_valueOrtho = sum_valueOrtho + valueOrtho;
					avg_valueOrtho = sum_valueOrtho/(j+1);

					
					//One eighty angle computation
					xradOneEighty = (int)round(cos(angle[i]+PI) * (j+1) + x);	
					yradOneEighty = (int)round(sin(angle[i]+PI) * (j+1) + y);	
					
					valueOneEighty = data[y][x] - data[yradOneEighty][xradOneEighty];
					valueOneEighty = valueOneEighty * valueOneEighty * 0.5;

					sum_value = sum_value + value + valueOneEighty;
					avg_value = sum_value/(2*(j+1));
	
					//Fail safe to ensure there is no nan or inf			
					if(avg_value == 0) {
							if((avg_valueOrtho < 1) && (avg_valueOrtho > 0)) {
								avg_value = avg_valueOrtho;
							}
							else {
								avg_value = 1;
							}
					}

					if(avg_valueOrtho == 0) {
						avg_valueOrtho = 1;
					}


					//printf("1(%d,%d)	%f	%f\n",(j+1),(i+1),variance[j],avg_value);
					if(avg_value < variance[j]) {
						//	printf("2(%d)	%f	%f\n",j,variance[j],avg_value);
							variance[j] = avg_value;
							orientation[j] = angle[i];
							ortho[j] = avg_valueOrtho;		
					}	
				}
			}
			
			for(j=0;j<RADIUS;j+=RADSTEP){
				anisotropy[y][x][j] = ortho[j]/variance[j];
				azimuth[y][x][j] = orientation[j] * 180/PI ;
				
				//printf("%f	%f\n",variance[j],anisotropy[y][x][j]);	
			}

			
//			Writing to files
			

			if (x == (XSIZE - RADIUS - 1)) {
				fprintf(outputAnisotropy00,"%f",anisotropy[y][x][0]);
				fprintf(outputAzimuth00,"%f",azimuth[y][x][0]);
				fprintf(outputAnisotropy00,"\n");
				fprintf(outputAzimuth00,"\n");

				fprintf(outputAnisotropy09,"%f",anisotropy[y][x][9]);
				fprintf(outputAzimuth09,"%f",azimuth[y][x][9]);
				fprintf(outputAnisotropy09,"\n");
				fprintf(outputAzimuth09,"\n");

				fprintf(outputAnisotropy49,"%f",anisotropy[y][x][49]);
				fprintf(outputAzimuth49,"%f",azimuth[y][x][49]);
				fprintf(outputAnisotropy49,"\n");
				fprintf(outputAzimuth49,"\n");

				fprintf(outputAnisotropy99,"%f",anisotropy[y][x][99]);
				fprintf(outputAzimuth99,"%f",azimuth[y][x][99]);
				fprintf(outputAnisotropy99,"\n");
				fprintf(outputAzimuth99,"\n");
			}
			else {
				fprintf(outputAnisotropy00,"%f",anisotropy[y][x][0]);
				fprintf(outputAzimuth00,"%f",azimuth[y][x][0]);
				fprintf(outputAnisotropy00,"\t");
				fprintf(outputAzimuth00,"\t");
				
				fprintf(outputAnisotropy09,"%f",anisotropy[y][x][9]);
				fprintf(outputAzimuth09,"%f",azimuth[y][x][9]);
				fprintf(outputAnisotropy09,"\t");
				fprintf(outputAzimuth09,"\t");

				fprintf(outputAnisotropy49,"%f",anisotropy[y][x][49]);
				fprintf(outputAzimuth49,"%f",azimuth[y][x][49]);	
				fprintf(outputAnisotropy49,"\t");
				fprintf(outputAzimuth49,"\t");

				fprintf(outputAnisotropy99,"%f",anisotropy[y][x][99]);
				fprintf(outputAzimuth99,"%f",azimuth[y][x][99]);
				fprintf(outputAnisotropy99,"\t");
				fprintf(outputAzimuth99,"\t");
				
			}					
		}			
			
	}


		
	
	


	fclose(datTxt);
	fclose(inpCheck);
	fclose(outputAnisotropy00);
	fclose(outputAnisotropy09);
	fclose(outputAnisotropy49);
	fclose(outputAnisotropy99);

	fclose(outputAzimuth00);
	fclose(outputAzimuth09);
	fclose(outputAzimuth49);
	fclose(outputAzimuth99);

	//Freeing 3D matrix anisotropy
	for(i = 0;i<YSIZE;i++) {
		for(j=0;j<XSIZE;j++) {
			free(anisotropy[i][j]);
		}
		free(anisotropy[i]);
	}
	free(anisotropy);

	//Freeing 3D matrix azimuth
	for(i = 0;i<YSIZE;i++) {
		for(j=0;j<XSIZE;j++) {
			free(azimuth[i][j]);
		}
		free(azimuth[i]);
	}
	free(azimuth);
	
	return 0;
}

	.text
	.file	"topographic_anisotropy_NewMethod.hip"
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI0_0:
	.quad	0x400921fb54442d18              # double 3.1415926535897931
.LCPI0_1:
	.quad	0x4066800000000000              # double 180
.LCPI0_2:
	.quad	0x3ff921fb54442d18              # double 1.5707963267948966
.LCPI0_4:
	.quad	0x3fe0000000000000              # double 0.5
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI0_3:
	.long	0x3f000000                      # float 0.5
.LCPI0_5:
	.long	0x3f800000                      # float 1
.LCPI0_6:
	.long	0x43340000                      # float 180
.LCPI0_7:
	.long	0x00000000                      # float 0
	.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	$3856792, %rsp                  # imm = 0x3AD998
	.cfi_def_cfa_offset 3856848
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_2
# %bb.1:
	movq	%rax, 144(%rsp)                 # 8-byte Spill
	leaq	1568(%rsp), %rdi
	movl	$7202, %edx                     # imm = 0x1C22
	xorl	%esi, %esi
	callq	memset@PLT
	movl	$.L.str.3, %edi
	movl	$.L.str.4, %esi
	callq	fopen
	movq	%rax, 56(%rsp)                  # 8-byte Spill
	testq	%rax, %rax
	je	.LBB0_2
# %bb.4:
	movl	$.L.str.5, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, %rbx
	movl	$.L.str.6, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, 104(%rsp)                 # 8-byte Spill
	movl	$.L.str.7, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, 96(%rsp)                  # 8-byte Spill
	movl	$.L.str.8, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, 88(%rsp)                  # 8-byte Spill
	testq	%rbx, %rbx
	je	.LBB0_8
# %bb.5:
	cmpq	$0, 104(%rsp)                   # 8-byte Folded Reload
	je	.LBB0_8
# %bb.6:
	cmpq	$0, 96(%rsp)                    # 8-byte Folded Reload
	je	.LBB0_8
# %bb.7:
	cmpq	$0, 88(%rsp)                    # 8-byte Folded Reload
	je	.LBB0_8
# %bb.9:
	movl	$.L.str.10, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, %r14
	movl	$.L.str.11, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, 80(%rsp)                  # 8-byte Spill
	movl	$.L.str.12, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	movl	$.L.str.13, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	movq	%r14, 160(%rsp)                 # 8-byte Spill
	testq	%r14, %r14
	je	.LBB0_13
# %bb.10:
	cmpq	$0, 80(%rsp)                    # 8-byte Folded Reload
	je	.LBB0_13
# %bb.11:
	cmpq	$0, 72(%rsp)                    # 8-byte Folded Reload
	je	.LBB0_13
# %bb.12:
	cmpq	$0, 64(%rsp)                    # 8-byte Folded Reload
	je	.LBB0_13
# %bb.14:
	movq	%rbx, 152(%rsp)                 # 8-byte Spill
	movb	$0, 4(%rsp)
	movl	$0, (%rsp)
	leaq	1568(%rsp), %rbp
	movq	%rbp, %rdi
	movl	$7202, %esi                     # imm = 0x1C22
	movq	56(%rsp), %rdx                  # 8-byte Reload
	callq	fgets
	testq	%rax, %rax
	je	.LBB0_19
# %bb.15:                               # %.preheader324.preheader
	leaq	8784(%rsp), %rbx
	movq	%rsp, %r13
	xorl	%r14d, %r14d
	movq	144(%rsp), %r15                 # 8-byte Reload
.LBB0_16:                               # %.preheader324
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_17 Depth 2
	movq	%r14, 32(%rsp)                  # 8-byte Spill
	imulq	$4804, %r14, %rax               # imm = 0x12C4
	addq	%rsp, %rax
	addq	$13584, %rax                    # imm = 0x3510
	movq	%rax, 128(%rsp)                 # 8-byte Spill
	movb	$0, 4(%rsp)
	movl	$0, (%rsp)
	xorl	%r12d, %r12d
.LBB0_17:                               #   Parent Loop BB0_16 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%rbp, %rdi
	movl	$32, %esi
	callq	strchr
	movq	%rax, %r14
	movq	%rax, %rdx
	subq	%rbp, %rdx
	movq	%r13, %rdi
	movq	%rbp, %rsi
	callq	strncpy
	movq	%r13, %rdi
	callq	atoi
	movl	%eax, (%rbx,%r12,4)
	movl	$.L.str.15, %esi
	movq	%r15, %rdi
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	fprintf
	movq	%r14, %rbp
	incq	%rbp
	incq	%r12
	movl	$0, (%rsp)
	movb	$0, 4(%rsp)
	cmpq	$1200, %r12                     # imm = 0x4B0
	jne	.LBB0_17
# %bb.18:                               #   in Loop: Header=BB0_16 Depth=1
	movq	%r13, %rdi
	movq	%rbp, %rsi
	callq	strcpy
	movq	%r13, %rdi
	callq	atoi
	movq	128(%rsp), %rcx                 # 8-byte Reload
	movl	%eax, (%rcx)
	movl	$.L.str.16, %esi
	movq	%r15, %rdi
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	fprintf
	movq	32(%rsp), %r14                  # 8-byte Reload
	incq	%r14
	leaq	1568(%rsp), %rbp
	movq	%rbp, %rdi
	movl	$7202, %esi                     # imm = 0x1C22
	movq	56(%rsp), %rdx                  # 8-byte Reload
	callq	fgets
	addq	$4804, %rbx                     # imm = 0x12C4
	testq	%rax, %rax
	jne	.LBB0_16
.LBB0_19:                               # %._crit_edge
	leaq	224(%rsp), %rax
	xorl	%ecx, %ecx
	movsd	.LCPI0_1(%rip), %xmm0           # xmm0 = mem[0],zero
.LBB0_20:                               # =>This Inner Loop Header: Depth=1
	xorps	%xmm1, %xmm1
	cvtsi2sd	%ecx, %xmm1
	mulsd	.LCPI0_0(%rip), %xmm1
	divsd	%xmm0, %xmm1
	cvtsd2ss	%xmm1, %xmm1
	movss	%xmm1, (%rax)
	addq	$5, %rcx
	addq	$4, %rax
	cmpq	$180, %rcx
	jne	.LBB0_20
# %bb.21:
	movl	$6408, %edi                     # imm = 0x1908
	callq	malloc
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	xorl	%ebx, %ebx
	movq	152(%rsp), %rbp                 # 8-byte Reload
.LBB0_22:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_23 Depth 2
	movl	$9608, %edi                     # imm = 0x2588
	callq	malloc
	movq	%rax, %r13
	movq	24(%rsp), %rax                  # 8-byte Reload
	movq	%r13, (%rax,%rbx,8)
	xorl	%r14d, %r14d
.LBB0_23:                               #   Parent Loop BB0_22 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$400, %edi                      # imm = 0x190
	callq	malloc
	movq	%rax, (%r13,%r14,8)
	incq	%r14
	cmpq	$1201, %r14                     # imm = 0x4B1
	jne	.LBB0_23
# %bb.24:                               #   in Loop: Header=BB0_22 Depth=1
	incq	%rbx
	cmpq	$801, %rbx                      # imm = 0x321
	jne	.LBB0_22
# %bb.25:
	movl	$6408, %edi                     # imm = 0x1908
	callq	malloc
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	xorl	%ebx, %ebx
.LBB0_26:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_27 Depth 2
	movl	$9608, %edi                     # imm = 0x2588
	callq	malloc
	movq	%rax, %r13
	movq	16(%rsp), %rax                  # 8-byte Reload
	movq	%r13, (%rax,%rbx,8)
	xorl	%r14d, %r14d
.LBB0_27:                               #   Parent Loop BB0_26 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$400, %edi                      # imm = 0x190
	callq	malloc
	movq	%rax, (%r13,%r14,8)
	incq	%r14
	cmpq	$1201, %r14                     # imm = 0x4B1
	jne	.LBB0_27
# %bb.28:                               #   in Loop: Header=BB0_26 Depth=1
	incq	%rbx
	cmpq	$801, %rbx                      # imm = 0x321
	jne	.LBB0_26
# %bb.29:
	xorl	%eax, %eax
	movl	$2139095039, %ecx               # imm = 0x7F7FFFFF
	movsd	.LCPI0_0(%rip), %xmm1           # xmm1 = mem[0],zero
.LBB0_30:                               # %.preheader323
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_31 Depth 2
                                        #       Child Loop BB0_34 Depth 3
                                        #       Child Loop BB0_36 Depth 3
                                        #         Child Loop BB0_37 Depth 4
                                        #       Child Loop BB0_44 Depth 3
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, 116(%rsp)                # 4-byte Spill
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	%xmm0, 184(%rsp)                # 8-byte Spill
	leal	-701(%rax), %edx
	movq	%rax, 168(%rsp)                 # 8-byte Spill
	imulq	$4804, %rax, %rax               # imm = 0x12C4
	addq	%rsp, %rax
	addq	$8784, %rax                     # imm = 0x2250
	movq	%rax, 216(%rsp)                 # 8-byte Spill
	xorl	%esi, %esi
	movl	%edx, 112(%rsp)                 # 4-byte Spill
.LBB0_31:                               #   Parent Loop BB0_30 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB0_34 Depth 3
                                        #       Child Loop BB0_36 Depth 3
                                        #         Child Loop BB0_37 Depth 4
                                        #       Child Loop BB0_44 Depth 3
	cmpl	$-600, %edx                     # imm = 0xFDA8
	jb	.LBB0_49
# %bb.32:                               #   in Loop: Header=BB0_31 Depth=2
	leal	-1101(%rsi), %eax
	cmpl	$-1000, %eax                    # imm = 0xFC18
	jb	.LBB0_49
# %bb.33:                               # %.preheader322.preheader
                                        #   in Loop: Header=BB0_31 Depth=2
	xorl	%eax, %eax
.LBB0_34:                               # %.preheader322
                                        #   Parent Loop BB0_30 Depth=1
                                        #     Parent Loop BB0_31 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	%ecx, 368(%rsp,%rax,4)
	movl	%ecx, 768(%rsp,%rax,4)
	incq	%rax
	cmpq	$100, %rax
	jne	.LBB0_34
# %bb.35:                               # %.preheader321
                                        #   in Loop: Header=BB0_31 Depth=2
	xorps	%xmm0, %xmm0
	cvtsi2ss	%esi, %xmm0
	movss	%xmm0, 120(%rsp)                # 4-byte Spill
	movq	216(%rsp), %rax                 # 8-byte Reload
	movl	(%rax,%rsi,4), %r13d
	movq	%rsi, 176(%rsp)                 # 8-byte Spill
	xorps	%xmm0, %xmm0
	cvtsi2sd	%esi, %xmm0
	movsd	%xmm0, 192(%rsp)                # 8-byte Spill
	xorl	%r12d, %r12d
.LBB0_36:                               # %.preheader319
                                        #   Parent Loop BB0_30 Depth=1
                                        #     Parent Loop BB0_31 Depth=2
                                        # =>    This Loop Header: Depth=3
                                        #         Child Loop BB0_37 Depth 4
	movss	224(%rsp,%r12,4), %xmm0         # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, 12(%rsp)                 # 4-byte Spill
	cvtss2sd	%xmm0, %xmm0
	movaps	%xmm0, %xmm2
	addsd	.LCPI0_2(%rip), %xmm2
	movsd	%xmm2, 200(%rsp)                # 8-byte Spill
	addsd	%xmm1, %xmm0
	movsd	%xmm0, 208(%rsp)                # 8-byte Spill
	xorpd	%xmm0, %xmm0
	movl	$2, %ebx
	xorl	%r14d, %r14d
	xorps	%xmm4, %xmm4
.LBB0_37:                               #   Parent Loop BB0_30 Depth=1
                                        #     Parent Loop BB0_31 Depth=2
                                        #       Parent Loop BB0_36 Depth=3
                                        # =>      This Inner Loop Header: Depth=4
	movaps	%xmm4, 32(%rsp)                 # 16-byte Spill
	movss	%xmm0, 8(%rsp)                  # 4-byte Spill
	movss	12(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	callq	cosf
	leaq	1(%r14), %r15
	xorps	%xmm1, %xmm1
	cvtsi2ss	%r15d, %xmm1
	movss	%xmm1, 128(%rsp)                # 4-byte Spill
	mulss	%xmm1, %xmm0
	addss	120(%rsp), %xmm0                # 4-byte Folded Reload
	callq	roundf@PLT
	cvttss2si	%xmm0, %ebp
	movss	12(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	callq	sinf
	mulss	128(%rsp), %xmm0                # 4-byte Folded Reload
	addss	116(%rsp), %xmm0                # 4-byte Folded Reload
	callq	roundf@PLT
	cvttss2si	%xmm0, %eax
	cltq
	movslq	%ebp, %rcx
	imulq	$4804, %rax, %rax               # imm = 0x12C4
	addq	%rsp, %rax
	addq	$8784, %rax                     # imm = 0x2250
	movl	%r13d, %edx
	subl	(%rax,%rcx,4), %edx
	xorps	%xmm1, %xmm1
	cvtsi2ss	%edx, %xmm1
	mulss	%xmm1, %xmm1
	movss	.LCPI0_3(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	mulss	%xmm0, %xmm1
	addss	32(%rsp), %xmm1                 # 16-byte Folded Reload
	movss	%xmm1, 124(%rsp)                # 4-byte Spill
	movsd	200(%rsp), %xmm0                # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	cos
	xorps	%xmm1, %xmm1
	cvtsi2sd	%r15d, %xmm1
	movsd	%xmm1, 32(%rsp)                 # 8-byte Spill
	mulsd	%xmm1, %xmm0
	addsd	192(%rsp), %xmm0                # 8-byte Folded Reload
	callq	round@PLT
	cvttsd2si	%xmm0, %ebp
	movsd	200(%rsp), %xmm0                # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	sin
	mulsd	32(%rsp), %xmm0                 # 8-byte Folded Reload
	addsd	184(%rsp), %xmm0                # 8-byte Folded Reload
	callq	round@PLT
	cvttsd2si	%xmm0, %eax
	cltq
	movslq	%ebp, %rcx
	imulq	$4804, %rax, %rax               # imm = 0x12C4
	addq	%rsp, %rax
	addq	$8784, %rax                     # imm = 0x2250
	movl	%r13d, %edx
	subl	(%rax,%rcx,4), %edx
	xorps	%xmm0, %xmm0
	cvtsi2ss	%edx, %xmm0
	mulss	%xmm0, %xmm0
	mulss	.LCPI0_3(%rip), %xmm0
	addss	8(%rsp), %xmm0                  # 4-byte Folded Reload
	movss	%xmm0, 8(%rsp)                  # 4-byte Spill
	divss	128(%rsp), %xmm0                # 4-byte Folded Reload
	movaps	%xmm0, 128(%rsp)                # 16-byte Spill
	movsd	208(%rsp), %xmm0                # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	cos
	mulsd	32(%rsp), %xmm0                 # 8-byte Folded Reload
	addsd	192(%rsp), %xmm0                # 8-byte Folded Reload
	callq	round@PLT
	cvttsd2si	%xmm0, %ebp
	movsd	208(%rsp), %xmm0                # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	sin
	mulsd	32(%rsp), %xmm0                 # 8-byte Folded Reload
	addsd	184(%rsp), %xmm0                # 8-byte Folded Reload
	callq	round@PLT
	movaps	128(%rsp), %xmm5                # 16-byte Reload
	cvttsd2si	%xmm0, %eax
	cltq
	movslq	%ebp, %rcx
	imulq	$4804, %rax, %rax               # imm = 0x12C4
	addq	%rsp, %rax
	addq	$8784, %rax                     # imm = 0x2250
	movl	%r13d, %edx
	subl	(%rax,%rcx,4), %edx
	imull	%edx, %edx
	xorps	%xmm0, %xmm0
	cvtsi2sd	%edx, %xmm0
	mulsd	.LCPI0_4(%rip), %xmm0
	cvttpd2dq	%xmm0, %xmm0
	cvtdq2ps	%xmm0, %xmm4
	addss	124(%rsp), %xmm4                # 4-byte Folded Reload
	xorps	%xmm1, %xmm1
	cvtsi2ss	%ebx, %xmm1
	movaps	%xmm4, %xmm0
	divss	%xmm1, %xmm0
	ucomiss	.LCPI0_7(%rip), %xmm0
	jne	.LBB0_39
	jp	.LBB0_39
# %bb.38:                               #   in Loop: Header=BB0_37 Depth=4
	xorps	%xmm1, %xmm1
	cmpltss	%xmm5, %xmm1
	movaps	%xmm1, %xmm0
	andps	%xmm5, %xmm0
	movss	.LCPI0_5(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	andnps	%xmm2, %xmm1
	orps	%xmm0, %xmm1
	movaps	%xmm5, %xmm0
	cmpltss	%xmm2, %xmm0
	andps	%xmm0, %xmm1
	andnps	%xmm2, %xmm0
	orps	%xmm1, %xmm0
.LBB0_39:                               #   in Loop: Header=BB0_37 Depth=4
	movss	368(%rsp,%r14,4), %xmm1         # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jbe	.LBB0_41
# %bb.40:                               #   in Loop: Header=BB0_37 Depth=4
	movaps	%xmm5, %xmm1
	cmpeqss	.LCPI0_7(%rip), %xmm1
	movaps	%xmm1, %xmm2
	movss	.LCPI0_5(%rip), %xmm3           # xmm3 = mem[0],zero,zero,zero
	andps	%xmm3, %xmm2
	andnps	%xmm5, %xmm1
	orps	%xmm2, %xmm1
	movss	%xmm0, 368(%rsp,%r14,4)
	movss	12(%rsp), %xmm0                 # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	movss	%xmm0, 1168(%rsp,%r14,4)
	movss	%xmm1, 768(%rsp,%r14,4)
.LBB0_41:                               #   in Loop: Header=BB0_37 Depth=4
	addl	$2, %ebx
	movq	%r15, %r14
	cmpq	$100, %r15
	movss	8(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	jne	.LBB0_37
# %bb.42:                               #   in Loop: Header=BB0_36 Depth=3
	incq	%r12
	cmpq	$36, %r12
	movsd	.LCPI0_0(%rip), %xmm1           # xmm1 = mem[0],zero
	jne	.LBB0_36
# %bb.43:                               # %.preheader320
                                        #   in Loop: Header=BB0_31 Depth=2
	movq	24(%rsp), %rax                  # 8-byte Reload
	movq	168(%rsp), %rdx                 # 8-byte Reload
	movq	(%rax,%rdx,8), %r15
	movq	176(%rsp), %rsi                 # 8-byte Reload
	leaq	(%r15,%rsi,8), %r14
	movq	(%r14), %rax
	movq	16(%rsp), %rcx                  # 8-byte Reload
	movq	(%rcx,%rdx,8), %r12
	leaq	(%r12,%rsi,8), %rbx
	movq	(%rbx), %rcx
	xorl	%edx, %edx
	movss	.LCPI0_6(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
.LBB0_44:                               #   Parent Loop BB0_30 Depth=1
                                        #     Parent Loop BB0_31 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	768(%rsp,%rdx,4), %xmm0         # xmm0 = mem[0],zero,zero,zero
	divss	368(%rsp,%rdx,4), %xmm0
	movss	%xmm0, (%rax,%rdx,4)
	movss	1168(%rsp,%rdx,4), %xmm0        # xmm0 = mem[0],zero,zero,zero
	mulss	%xmm2, %xmm0
	cvtss2sd	%xmm0, %xmm0
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rcx,%rdx,4)
	incq	%rdx
	cmpq	$100, %rdx
	jne	.LBB0_44
# %bb.45:                               #   in Loop: Header=BB0_31 Depth=2
	cmpq	$1100, %rsi                     # imm = 0x44C
	movq	152(%rsp), %rbp                 # 8-byte Reload
	jne	.LBB0_47
# %bb.46:                               #   in Loop: Header=BB0_31 Depth=2
	movq	8800(%r15), %rax
	movl	$8800, %ebx                     # imm = 0x2260
	addq	%rbx, %r15
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rax), %xmm0
	movl	$.L.str.17, %esi
	movq	%rbp, %rdi
	movb	$1, %al
	callq	fprintf
	addq	%rbx, %r12
	movl	$10, %r13d
	movq	%r12, %rbx
	movq	%r15, %r14
	jmp	.LBB0_48
.LBB0_47:                               #   in Loop: Header=BB0_31 Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rax), %xmm0
	movl	$.L.str.17, %esi
	movq	%rbp, %rdi
	movb	$1, %al
	callq	fprintf
	movl	$9, %r13d
.LBB0_48:                               # %.sink.split
                                        #   in Loop: Header=BB0_31 Depth=2
	movq	(%rbx), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rax), %xmm0
	movl	$.L.str.17, %esi
	movq	160(%rsp), %r15                 # 8-byte Reload
	movq	%r15, %rdi
	movb	$1, %al
	callq	fprintf
	movl	%r13d, %edi
	movq	%rbp, %rsi
	callq	fputc@PLT
	movl	%r13d, %edi
	movq	%r15, %rsi
	callq	fputc@PLT
	movq	(%r14), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	36(%rax), %xmm0
	movl	$.L.str.17, %esi
	movq	104(%rsp), %r15                 # 8-byte Reload
	movq	%r15, %rdi
	movb	$1, %al
	callq	fprintf
	movq	(%rbx), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	36(%rax), %xmm0
	movl	$.L.str.17, %esi
	movq	80(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rdi
	movb	$1, %al
	callq	fprintf
	movl	%r13d, %edi
	movq	%r15, %rsi
	callq	fputc@PLT
	movl	%r13d, %edi
	movq	%r12, %rsi
	callq	fputc@PLT
	movq	(%r14), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	196(%rax), %xmm0
	movl	$.L.str.17, %esi
	movq	96(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rdi
	movb	$1, %al
	callq	fprintf
	movq	(%rbx), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	196(%rax), %xmm0
	movl	$.L.str.17, %esi
	movq	72(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rdi
	movb	$1, %al
	callq	fprintf
	movl	%r13d, %edi
	movq	%r15, %rsi
	callq	fputc@PLT
	movl	%r13d, %edi
	movq	%r12, %rsi
	callq	fputc@PLT
	movq	(%r14), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	396(%rax), %xmm0
	movl	$.L.str.17, %esi
	movq	88(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdi
	movb	$1, %al
	callq	fprintf
	movq	(%rbx), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	396(%rax), %xmm0
	movl	$.L.str.17, %esi
	movq	64(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rdi
	movb	$1, %al
	callq	fprintf
	movl	%r13d, %edi
	movq	%r14, %rsi
	callq	fputc@PLT
	movl	%r13d, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	movsd	.LCPI0_0(%rip), %xmm1           # xmm1 = mem[0],zero
	movl	$2139095039, %ecx               # imm = 0x7F7FFFFF
	movl	112(%rsp), %edx                 # 4-byte Reload
	movq	176(%rsp), %rsi                 # 8-byte Reload
.LBB0_49:                               #   in Loop: Header=BB0_31 Depth=2
	incq	%rsi
	cmpq	$1201, %rsi                     # imm = 0x4B1
	jne	.LBB0_31
# %bb.50:                               #   in Loop: Header=BB0_30 Depth=1
	movq	168(%rsp), %rax                 # 8-byte Reload
	incq	%rax
	cmpq	$801, %rax                      # imm = 0x321
	jne	.LBB0_30
# %bb.51:
	movq	56(%rsp), %rdi                  # 8-byte Reload
	callq	fclose
	movq	144(%rsp), %rdi                 # 8-byte Reload
	callq	fclose
	movq	%rbp, %rdi
	callq	fclose
	movq	104(%rsp), %rdi                 # 8-byte Reload
	callq	fclose
	movq	96(%rsp), %rdi                  # 8-byte Reload
	callq	fclose
	movq	88(%rsp), %rdi                  # 8-byte Reload
	callq	fclose
	movq	160(%rsp), %rdi                 # 8-byte Reload
	callq	fclose
	movq	80(%rsp), %rdi                  # 8-byte Reload
	callq	fclose
	movq	72(%rsp), %rdi                  # 8-byte Reload
	callq	fclose
	movq	64(%rsp), %rdi                  # 8-byte Reload
	callq	fclose
	xorl	%r14d, %r14d
.LBB0_52:                               # %.preheader318
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_53 Depth 2
	movq	24(%rsp), %rax                  # 8-byte Reload
	movq	(%rax,%r14,8), %rbx
	xorl	%r15d, %r15d
.LBB0_53:                               #   Parent Loop BB0_52 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	(%rbx,%r15,8), %rdi
	callq	free
	incq	%r15
	cmpq	$1201, %r15                     # imm = 0x4B1
	jne	.LBB0_53
# %bb.54:                               #   in Loop: Header=BB0_52 Depth=1
	movq	%rbx, %rdi
	callq	free
	incq	%r14
	cmpq	$801, %r14                      # imm = 0x321
	jne	.LBB0_52
# %bb.55:
	movq	24(%rsp), %rdi                  # 8-byte Reload
	callq	free
	xorl	%r14d, %r14d
.LBB0_56:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_57 Depth 2
	movq	16(%rsp), %rax                  # 8-byte Reload
	movq	(%rax,%r14,8), %rbx
	xorl	%r15d, %r15d
.LBB0_57:                               #   Parent Loop BB0_56 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	(%rbx,%r15,8), %rdi
	callq	free
	incq	%r15
	cmpq	$1201, %r15                     # imm = 0x4B1
	jne	.LBB0_57
# %bb.58:                               #   in Loop: Header=BB0_56 Depth=1
	movq	%rbx, %rdi
	callq	free
	incq	%r14
	cmpq	$801, %r14                      # imm = 0x321
	jne	.LBB0_56
# %bb.59:
	movq	16(%rsp), %rdi                  # 8-byte Reload
	callq	free
	xorl	%eax, %eax
	jmp	.LBB0_60
.LBB0_2:
	movl	$.L.str.2, %edi
	jmp	.LBB0_3
.LBB0_8:
	movl	$.L.str.9, %edi
	jmp	.LBB0_3
.LBB0_13:
	movl	$.L.str.14, %edi
.LBB0_3:
	callq	perror
	movl	$-1, %eax
.LBB0_60:
	addq	$3856792, %rsp                  # imm = 0x3AD998
	.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_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"inpCheck.txt"
	.size	.L.str, 13

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

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Cannot open dat.txt file"
	.size	.L.str.2, 25

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"dat.txt"
	.size	.L.str.3, 8

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"outputDataAni00.txt"
	.size	.L.str.5, 20

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"outputDataAni09.txt"
	.size	.L.str.6, 20

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"outputDataAni49.txt"
	.size	.L.str.7, 20

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"outputDataAni99.txt"
	.size	.L.str.8, 20

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Cannot open Anisotropy file"
	.size	.L.str.9, 28

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"outputDataAzi00.txt"
	.size	.L.str.10, 20

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"outputDataAzi09.txt"
	.size	.L.str.11, 20

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"outputDataAzi49.txt"
	.size	.L.str.12, 20

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"outputDataAzi99.txt"
	.size	.L.str.13, 20

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"Cannot open Azimuth file"
	.size	.L.str.14, 25

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"%d "
	.size	.L.str.15, 4

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"%d\n"
	.size	.L.str.16, 4

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

	.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
