#include <cuda.h>
#include <float.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

typedef struct Data {
	float* x;
        float* y;
	int num_node;
} data;

data* read_data(const char* file) {
	data* d = NULL;
	FILE* f = fopen (file, "r");

	int num_node;
	if (fscanf(f, "%5d\n", &num_node) == 0) {
		printf("read inputfile failed.\n");
		return NULL;
	}
	printf("num_node = %d\n", num_node);
	
	d = (data*) malloc(sizeof(data));
	d->num_node = num_node;
	d->x = (float*)malloc(num_node * sizeof(float));
	d->y = (float*)malloc(num_node * sizeof(float));
	for (int i = 0; i < num_node; i++) {
		fscanf(f, "%f %f\n", &(d->x[i]), &(d->y[i]));
	}

	for (int i = 0; i < d->num_node; i++) {
		printf("%d: x = %f, y = %f\n", i, d->x[i], d->y[i]);
	}
	
	fclose(f);
	
	return d;
}		

/*
__device__ float dist(const float x, const float y, const float cx, const float cy) {
	return sqrt(pow(x - cx, 2.0) + pow(y - cy, 2.0));
}
*/
__device__ float dist(const float x, const float y, const float cx, const float cy) {
	return sqrtf(powf(x - cx, 2.0) + powf(y - cy, 2.0));
}

__global__ void kmeans_kernel(const float* x, const float* y, float* cx, float* cy, int num_nodes, int num_cent, int iter, float* cx_result, float* cy_result, int* result) {
	
	__shared__ bool done;
	__shared__ float* tmp_cx;
	__shared__ float* tmp_cy;
	__shared__ int* tmp_label;
	__shared__ int* count;
	__shared__ float* dist_c;

		

	unsigned int id = blockIdx.x * blockDim.x + threadIdx.x;
	
	for (int i = 0; i < iter; i++) {
	// calculate the closest centroid
		done = true;
		for (int jj = 0; jj < num_cent; jj++) {
			count[jj] = 0;
		}
		float tmp_min = 9999;
		for (int jj = 0; jj < num_cent; jj++) {
			if (tmp_min >  dist(x[id], y[id], cx[jj], cy[jj])) {
				tmp_label[id] = jj;
				atomicAdd(count + jj, 1);
			}
		}
	// update centroid
	// calculate new centroids
	// add all x, all y of the same label, then divide by the nubmer of same label nodes.
		for (int jj = 0; jj < num_cent; jj++) {
			tmp_cx[jj] = cx[jj];
			tmp_cy[jj] = cy[jj];
			cx[jj] = 0;
			cy[jj] = 0;
		}
	
		for (int jj = 0; jj < num_cent; jj++) {
			if (tmp_label[id] == jj) {
				atomicAdd(&(cx[jj]), x[id]);
				atomicAdd(&(cy[jj]), y[id]);
			}
		}

		for (int jj = 0; jj < num_cent; jj++) {
			cx[jj] /= count[jj];
			cy[jj] /= count[jj];
		}

	// calculate distance from prev_centroid to cur_centroid
		for (int jj = 0; jj < num_cent; jj++) {
			dist_c[jj] = dist(cx[jj], tmp_cx[jj], cy[jj], tmp_cy[jj]);
			if (dist_c[jj] > 0.001) {
				done = false;
			}
		}

	// if the change of dist < 0.01, then break
	// cx_result = tmp_cx
	// cy_result = tmp_cy
	// result = tmp_label;
	//
		if (done) {
			for (int jj = 0; jj < num_cent; jj++) {
				cx_result[jj] = tmp_cx[jj];
				cy_result[jj] = tmp_cy[jj];
				result[id] = tmp_label[id];
			}
			break;
		}
	}
}

void kmeans(const float* x, const float* y, const float* cx, const float* cy, int num_nodes, int num_cent, int iter, float* cx_result, float* cy_result, int* result) {   				// memory alloc and hac execute
	
	int Dim = num_nodes;				// TODO

	float* d_in_x;						// for cudamalloc in 'nodes data'
	float* d_in_y;
	float* d_in_cx;
	float* d_in_cy;
	float* d_out_cx_result;						// result centroid
	float* d_out_cy_result;
	int* d_out_label_result;

	cudaMalloc((void**) &d_in_x, num_nodes * sizeof(float));				
	cudaMalloc((void**) &d_in_y, num_nodes * sizeof(float));				
	cudaMalloc((void**) &d_in_cx, num_cent * sizeof(float));				
	cudaMalloc((void**) &d_in_cy, num_cent * sizeof(float));				
	cudaMalloc((void**) &d_out_cx_result, num_cent * sizeof(float));				
	cudaMalloc((void**) &d_out_cy_result, num_cent * sizeof(float));				
	cudaMalloc((void**) &d_out_label_result, num_nodes * sizeof(int));				
	
	cudaMemcpy(d_in_x, x, num_nodes * sizeof(float), cudaMemcpyHostToDevice);	// node memcpy
	cudaMemcpy(d_in_y, y, num_nodes * sizeof(float), cudaMemcpyHostToDevice);		// centroid memcpy
	cudaMemcpy(d_in_cx, cx, num_cent * sizeof(float), cudaMemcpyHostToDevice);	// node memcpy
	cudaMemcpy(d_in_cy, cy, num_cent * sizeof(float), cudaMemcpyHostToDevice);		// centroid memcpy
	
	kmeans_kernel<<<1, Dim>>>(d_in_x, d_in_y, d_in_cx, d_in_cy, num_nodes, num_cent, iter, d_out_cx_result, d_out_cy_result, d_out_label_result);			
	
	cudaMemcpy(result, d_out_label_result, num_nodes * sizeof(int), cudaMemcpyDeviceToHost);	// cuda memcopy d to h 
	cudaMemcpy(cx_result, d_out_cx_result, num_cent * sizeof(float), cudaMemcpyDeviceToHost);
	cudaMemcpy(cy_result, d_out_cy_result, num_cent * sizeof(float), cudaMemcpyDeviceToHost);

	cudaFree(d_in_x);
	cudaFree(d_in_y);	
	cudaFree(d_in_cx);
	cudaFree(d_in_cy);
	cudaFree(d_out_cx_result);	
	cudaFree(d_out_cy_result);	
	cudaFree(d_out_label_result);	

	return;
}

// TODO
void free_data(data* d) {

}

// TODO
void print_result (const int num_node, const int num_cent, const float* cx, const float* cy, const int* label) {
	printf("\t");
	for (int i = 0; i < num_node; i++) {
		printf("\5 %d", i);
	}
	printf("\nLabel : ");
	for (int i = 0; i < num_node; i++) {
		printf("\5 %d", label[i]);
	}
	for (int i = 0; i < num_cent; i++) {
		printf("\ncentroid %d\t : %5f  %5f", i, cx[i], cy[i]);
	}
	printf("\n");
}

int main (int argc, char** argv) {
	if (argc != 3) {
		printf("Usage: %s <nodes file> <centroids file>\n", argv[0]);
		return 0;
	} else {
		data* d = read_data(argv[1]);
		data* c = read_data(argv[2]);
	
		float* cx_result = (float*)malloc(c->num_node * sizeof(float));;
		float* cy_result = (float*)malloc(c->num_node * sizeof(float));;
		int* result = (int*) malloc(d->num_node * sizeof(int));
		int iter = 100;

		if (d->num_node && c->num_node) {
			printf("Let's do CLUSTER!\n");
			kmeans(d->x, d->y, c->x, c->y, d->num_node, c->num_node, iter, cx_result, cy_result, result);		// cuda
			
			printf("print the result!\n");
			print_result(d->num_node, c->num_node, cx_result, cy_result, result);
	
//			free(d);
//			free(c);
			free(cx_result);
			free(cy_result);
			free(result);
		} else {
			printf("empty file.\n");
		}
	}
	return 0;
}



	.file	"tmpxft_002a843c_00000000-6_kmeans.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
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"r"
.LC1:
	.string	"%5d\n"
.LC2:
	.string	"read inputfile failed.\n"
.LC3:
	.string	"num_node = %d\n"
.LC4:
	.string	"%f %f\n"
.LC5:
	.string	"%d: x = %f, y = %f\n"
	.text
	.globl	_Z9read_dataPKc
	.type	_Z9read_dataPKc, @function
_Z9read_dataPKc:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %rsi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	leaq	4(%rsp), %rdx
	leaq	.LC1(%rip), %rsi
	movq	%rax, %r12
	movq	%rax, %rdi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	testl	%eax, %eax
	jne	.L3
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
	jmp	.L2
.L3:
	movl	4(%rsp), %edx
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC4(%rip), %r13
	call	__printf_chk@PLT
	movl	$24, %edi
	call	malloc@PLT
	movslq	4(%rsp), %rbp
	movq	%rax, %rbx
	movl	%ebp, 16(%rax)
	salq	$2, %rbp
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rbp, %rdi
	xorl	%ebp, %ebp
	movq	%rax, (%rbx)
	call	malloc@PLT
	movq	%rax, 8(%rbx)
.L5:
	cmpl	%ebp, 4(%rsp)
	jle	.L12
	movq	8(%rbx), %rcx
	movq	%r13, %rsi
	movq	%r12, %rdi
	xorl	%eax, %eax
	leaq	0(,%rbp,4), %rdx
	incq	%rbp
	addq	%rdx, %rcx
	addq	(%rbx), %rdx
	call	__isoc23_fscanf@PLT
	jmp	.L5
.L12:
	xorl	%ebp, %ebp
	leaq	.LC5(%rip), %r13
.L7:
	movl	%ebp, %edx
	cmpl	%ebp, 16(%rbx)
	jle	.L13
	movq	8(%rbx), %rax
	movq	(%rbx), %rcx
	movq	%r13, %rsi
	movl	$2, %edi
	cvtss2sd	(%rax,%rbp,4), %xmm1
	movb	$2, %al
	cvtss2sd	(%rcx,%rbp,4), %xmm0
	incq	%rbp
	call	__printf_chk@PLT
	jmp	.L7
.L13:
	movq	%r12, %rdi
	call	fclose@PLT
.L2:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z9read_dataPKc, .-_Z9read_dataPKc
	.globl	_Z4distffff
	.type	_Z4distffff, @function
_Z4distffff:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z4distffff, .-_Z4distffff
	.globl	_Z9free_dataP4Data
	.type	_Z9free_dataP4Data, @function
_Z9free_dataP4Data:
.LFB2030:
	.cfi_startproc
	endbr64
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z9free_dataP4Data, .-_Z9free_dataP4Data
	.section	.rodata.str1.1
.LC6:
	.string	"\t"
.LC7:
	.string	"\005 %d"
.LC8:
	.string	"\nLabel : "
.LC9:
	.string	"\ncentroid %d\t : %5f  %5f"
.LC10:
	.string	"\n"
	.text
	.globl	_Z12print_resultiiPKfS0_PKi
	.type	_Z12print_resultiiPKfS0_PKi, @function
_Z12print_resultiiPKfS0_PKi:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%eax, %eax
	xorl	%r15d, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%r8, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rcx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%esi, %ebp
	leaq	.LC6(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edi, %ebx
	movl	$2, %edi
	pushq	%r9
	.cfi_def_cfa_offset 64
	call	__printf_chk@PLT
.L18:
	cmpl	%ebx, %r15d
	jge	.L25
	movl	%r15d, %edx
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	incl	%r15d
	jmp	.L18
.L25:
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%r15d, %r15d
	call	__printf_chk@PLT
.L20:
	cmpl	%r15d, %ebx
	jle	.L26
	movl	(%r14,%r15,4), %edx
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%r15
	call	__printf_chk@PLT
	jmp	.L20
.L26:
	xorl	%ebx, %ebx
	leaq	.LC9(%rip), %r14
.L22:
	movl	%ebx, %edx
	cmpl	%ebx, %ebp
	jle	.L27
	movq	%r14, %rsi
	movl	$2, %edi
	movb	$2, %al
	cvtss2sd	(%r12,%rbx,4), %xmm0
	cvtss2sd	0(%r13,%rbx,4), %xmm1
	call	__printf_chk@PLT
	incq	%rbx
	jmp	.L22
.L27:
	popq	%rdx
	.cfi_def_cfa_offset 56
	leaq	.LC10(%rip), %rsi
	popq	%rbx
	.cfi_def_cfa_offset 48
	movl	$2, %edi
	popq	%rbp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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	__printf_chk@PLT
	.cfi_endproc
.LFE2031:
	.size	_Z12print_resultiiPKfS0_PKi, .-_Z12print_resultiiPKfS0_PKi
	.globl	_Z53__device_stub__Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_PiPKfS0_PfS1_iiiS1_S1_Pi
	.type	_Z53__device_stub__Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_PiPKfS0_PfS1_iiiS1_S1_Pi, @function
_Z53__device_stub__Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_PiPKfS0_PfS1_iiiS1_S1_Pi:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$232, %rsp
	.cfi_def_cfa_offset 240
	movq	248(%rsp), %rax
	movq	%rdi, 56(%rsp)
	leaq	88(%rsp), %rdi
	movq	%rsi, 48(%rsp)
	leaq	100(%rsp), %rsi
	movq	%rax, 16(%rsp)
	movq	256(%rsp), %rax
	movq	%rdx, 40(%rsp)
	leaq	72(%rsp), %rdx
	movq	%rax, 8(%rsp)
	movq	264(%rsp), %rax
	movq	%rcx, 32(%rsp)
	leaq	80(%rsp), %rcx
	movl	%r8d, 28(%rsp)
	movl	%r9d, 24(%rsp)
	movq	%rax, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 216(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rax
	movl	$1, 96(%rsp)
	movq	%rax, 136(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	240(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 192(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 200(%rsp)
	movq	%rsp, %rax
	movq	%rax, 208(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 88(%rsp)
	movq	%rax, 100(%rsp)
	movl	$1, 108(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L28
	pushq	80(%rsp)
	.cfi_def_cfa_offset 248
	leaq	_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi(%rip), %rdi
	pushq	80(%rsp)
	.cfi_def_cfa_offset 256
	movq	116(%rsp), %rcx
	movl	124(%rsp), %r8d
	movq	104(%rsp), %rsi
	movl	112(%rsp), %edx
	leaq	152(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 248
	popq	%rdx
	.cfi_def_cfa_offset 240
.L28:
	movq	216(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$232, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z53__device_stub__Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_PiPKfS0_PfS1_iiiS1_S1_Pi, .-_Z53__device_stub__Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_PiPKfS0_PfS1_iiiS1_S1_Pi
	.globl	_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
	.type	_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi, @function
_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z53__device_stub__Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_PiPKfS0_PfS1_iiiS1_S1_Pi
	.cfi_endproc
.LFE2058:
	.size	_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi, .-_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
	.globl	_Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi
	.type	_Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi, @function
_Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	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
	movq	%rcx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%r9d, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%r8d, %ebx
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	movq	216(%rsp), %rax
	leaq	56(%rsp), %rdi
	movq	%rax, 24(%rsp)
	movq	224(%rsp), %rax
	movq	%rax, 32(%rsp)
	movq	232(%rsp), %rax
	movq	%rax, 40(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	movslq	%r8d, %rax
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, 16(%rsp)
	call	cudaMalloc@PLT
	movq	16(%rsp), %rsi
	leaq	64(%rsp), %rdi
	call	cudaMalloc@PLT
	movslq	%ebp, %rax
	leaq	72(%rsp), %rdi
	salq	$2, %rax
	movq	%rax, %rsi
	movq	%rax, 8(%rsp)
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	80(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	88(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	96(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rsi
	leaq	104(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdx
	movq	56(%rsp), %rdi
	movq	%r15, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdx
	movq	64(%rsp), %rdi
	movq	%r14, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	72(%rsp), %rdi
	movq	%r13, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	80(%rsp), %rdi
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%ebx, 124(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movq	%rdi, 128(%rsp)
	movl	132(%rsp), %ecx
	movq	124(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L34
	pushq	104(%rsp)
	.cfi_def_cfa_offset 216
	movl	%ebp, %r9d
	movl	%ebx, %r8d
	pushq	104(%rsp)
	.cfi_def_cfa_offset 224
	pushq	104(%rsp)
	.cfi_def_cfa_offset 232
	movl	232(%rsp), %eax
	pushq	%rax
	.cfi_def_cfa_offset 240
	movq	112(%rsp), %rcx
	movq	104(%rsp), %rdx
	movq	96(%rsp), %rsi
	movq	88(%rsp), %rdi
	call	_Z53__device_stub__Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_PiPKfS0_PfS1_iiiS1_S1_Pi
	addq	$32, %rsp
	.cfi_def_cfa_offset 208
.L34:
	movq	16(%rsp), %rdx
	movq	104(%rsp), %rsi
	movl	$2, %ecx
	movq	40(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	88(%rsp), %rsi
	movl	$2, %ecx
	movq	24(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	96(%rsp), %rsi
	movl	$2, %ecx
	movq	32(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rdi
	call	cudaFree@PLT
	movq	96(%rsp), %rdi
	call	cudaFree@PLT
	movq	104(%rsp), %rdi
	call	cudaFree@PLT
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	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
.LFE2029:
	.size	_Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi, .-_Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi
	.section	.rodata.str1.1
.LC11:
	.string	"Usage: %s <nodes file> <centroids file>\n"
.LC12:
	.string	"Let's do CLUSTER!\n"
.LC13:
	.string	"print the result!\n"
.LC14:
	.string	"empty file.\n"
	.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
	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
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	cmpl	$3, %edi
	je	.L38
	movq	(%rsi), %rdx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC11(%rip), %rsi
	call	__printf_chk@PLT
	jmp	.L39
.L38:
	movq	8(%rsi), %rdi
	call	_Z9read_dataPKc
	movq	16(%rbp), %rdi
	movq	%rax, %rbx
	call	_Z9read_dataPKc
	movslq	16(%rax), %r12
	movq	%rax, %rbp
	movl	%r12d, 12(%rsp)
	salq	$2, %r12
	movq	%r12, %rdi
	call	malloc@PLT
	movq	%r12, %rdi
	movq	%rax, %r14
	call	malloc@PLT
	movslq	16(%rbx), %rdi
	movq	%rax, %r13
	movq	%rdi, %r15
	salq	$2, %rdi
	call	malloc@PLT
	movl	12(%rsp), %edx
	movq	%rax, %r12
	testl	%edx, %edx
	je	.L40
	testl	%r15d, %r15d
	je	.L40
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	16(%rbp), %r9d
	movl	16(%rbx), %r8d
	movq	8(%rbp), %rcx
	movq	8(%rbx), %rsi
	pushq	%r12
	.cfi_def_cfa_offset 88
	pushq	%r13
	.cfi_def_cfa_offset 96
	pushq	%r14
	.cfi_def_cfa_offset 104
	movq	0(%rbp), %rdx
	pushq	$100
	.cfi_def_cfa_offset 112
	movq	(%rbx), %rdi
	call	_Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi
	addq	$32, %rsp
	.cfi_def_cfa_offset 80
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC13(%rip), %rsi
	call	__printf_chk@PLT
	movl	16(%rbp), %esi
	movl	16(%rbx), %edi
	movq	%r12, %r8
	movq	%r13, %rcx
	movq	%r14, %rdx
	call	_Z12print_resultiiPKfS0_PKi
	movq	%r14, %rdi
	call	free@PLT
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	jmp	.L39
.L40:
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L39:
	addq	$24, %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
	.section	.rodata.str1.1
.LC15:
	.string	"_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC15(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2060:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

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

typedef struct Data {
	float* x;
        float* y;
	int num_node;
} data;

data* read_data(const char* file) {
	data* d = NULL;
	FILE* f = fopen (file, "r");

	int num_node;
	if (fscanf(f, "%5d\n", &num_node) == 0) {
		printf("read inputfile failed.\n");
		return NULL;
	}
	printf("num_node = %d\n", num_node);
	
	d = (data*) malloc(sizeof(data));
	d->num_node = num_node;
	d->x = (float*)malloc(num_node * sizeof(float));
	d->y = (float*)malloc(num_node * sizeof(float));
	for (int i = 0; i < num_node; i++) {
		fscanf(f, "%f %f\n", &(d->x[i]), &(d->y[i]));
	}

	for (int i = 0; i < d->num_node; i++) {
		printf("%d: x = %f, y = %f\n", i, d->x[i], d->y[i]);
	}
	
	fclose(f);
	
	return d;
}		

/*
__device__ float dist(const float x, const float y, const float cx, const float cy) {
	return sqrt(pow(x - cx, 2.0) + pow(y - cy, 2.0));
}
*/
__device__ float dist(const float x, const float y, const float cx, const float cy) {
	return sqrtf(powf(x - cx, 2.0) + powf(y - cy, 2.0));
}

__global__ void kmeans_kernel(const float* x, const float* y, float* cx, float* cy, int num_nodes, int num_cent, int iter, float* cx_result, float* cy_result, int* result) {
	
	__shared__ bool done;
	__shared__ float* tmp_cx;
	__shared__ float* tmp_cy;
	__shared__ int* tmp_label;
	__shared__ int* count;
	__shared__ float* dist_c;

		

	unsigned int id = blockIdx.x * blockDim.x + threadIdx.x;
	
	for (int i = 0; i < iter; i++) {
	// calculate the closest centroid
		done = true;
		for (int jj = 0; jj < num_cent; jj++) {
			count[jj] = 0;
		}
		float tmp_min = 9999;
		for (int jj = 0; jj < num_cent; jj++) {
			if (tmp_min >  dist(x[id], y[id], cx[jj], cy[jj])) {
				tmp_label[id] = jj;
				atomicAdd(count + jj, 1);
			}
		}
	// update centroid
	// calculate new centroids
	// add all x, all y of the same label, then divide by the nubmer of same label nodes.
		for (int jj = 0; jj < num_cent; jj++) {
			tmp_cx[jj] = cx[jj];
			tmp_cy[jj] = cy[jj];
			cx[jj] = 0;
			cy[jj] = 0;
		}
	
		for (int jj = 0; jj < num_cent; jj++) {
			if (tmp_label[id] == jj) {
				atomicAdd(&(cx[jj]), x[id]);
				atomicAdd(&(cy[jj]), y[id]);
			}
		}

		for (int jj = 0; jj < num_cent; jj++) {
			cx[jj] /= count[jj];
			cy[jj] /= count[jj];
		}

	// calculate distance from prev_centroid to cur_centroid
		for (int jj = 0; jj < num_cent; jj++) {
			dist_c[jj] = dist(cx[jj], tmp_cx[jj], cy[jj], tmp_cy[jj]);
			if (dist_c[jj] > 0.001) {
				done = false;
			}
		}

	// if the change of dist < 0.01, then break
	// cx_result = tmp_cx
	// cy_result = tmp_cy
	// result = tmp_label;
	//
		if (done) {
			for (int jj = 0; jj < num_cent; jj++) {
				cx_result[jj] = tmp_cx[jj];
				cy_result[jj] = tmp_cy[jj];
				result[id] = tmp_label[id];
			}
			break;
		}
	}
}

void kmeans(const float* x, const float* y, const float* cx, const float* cy, int num_nodes, int num_cent, int iter, float* cx_result, float* cy_result, int* result) {   				// memory alloc and hac execute
	
	int Dim = num_nodes;				// TODO

	float* d_in_x;						// for cudamalloc in 'nodes data'
	float* d_in_y;
	float* d_in_cx;
	float* d_in_cy;
	float* d_out_cx_result;						// result centroid
	float* d_out_cy_result;
	int* d_out_label_result;

	hipMalloc((void**) &d_in_x, num_nodes * sizeof(float));				
	hipMalloc((void**) &d_in_y, num_nodes * sizeof(float));				
	hipMalloc((void**) &d_in_cx, num_cent * sizeof(float));				
	hipMalloc((void**) &d_in_cy, num_cent * sizeof(float));				
	hipMalloc((void**) &d_out_cx_result, num_cent * sizeof(float));				
	hipMalloc((void**) &d_out_cy_result, num_cent * sizeof(float));				
	hipMalloc((void**) &d_out_label_result, num_nodes * sizeof(int));				
	
	hipMemcpy(d_in_x, x, num_nodes * sizeof(float), hipMemcpyHostToDevice);	// node memcpy
	hipMemcpy(d_in_y, y, num_nodes * sizeof(float), hipMemcpyHostToDevice);		// centroid memcpy
	hipMemcpy(d_in_cx, cx, num_cent * sizeof(float), hipMemcpyHostToDevice);	// node memcpy
	hipMemcpy(d_in_cy, cy, num_cent * sizeof(float), hipMemcpyHostToDevice);		// centroid memcpy
	
	kmeans_kernel<<<1, Dim>>>(d_in_x, d_in_y, d_in_cx, d_in_cy, num_nodes, num_cent, iter, d_out_cx_result, d_out_cy_result, d_out_label_result);			
	
	hipMemcpy(result, d_out_label_result, num_nodes * sizeof(int), hipMemcpyDeviceToHost);	// cuda memcopy d to h 
	hipMemcpy(cx_result, d_out_cx_result, num_cent * sizeof(float), hipMemcpyDeviceToHost);
	hipMemcpy(cy_result, d_out_cy_result, num_cent * sizeof(float), hipMemcpyDeviceToHost);

	hipFree(d_in_x);
	hipFree(d_in_y);	
	hipFree(d_in_cx);
	hipFree(d_in_cy);
	hipFree(d_out_cx_result);	
	hipFree(d_out_cy_result);	
	hipFree(d_out_label_result);	

	return;
}

// TODO
void free_data(data* d) {

}

// TODO
void print_result (const int num_node, const int num_cent, const float* cx, const float* cy, const int* label) {
	printf("\t");
	for (int i = 0; i < num_node; i++) {
		printf("\5 %d", i);
	}
	printf("\nLabel : ");
	for (int i = 0; i < num_node; i++) {
		printf("\5 %d", label[i]);
	}
	for (int i = 0; i < num_cent; i++) {
		printf("\ncentroid %d\t : %5f  %5f", i, cx[i], cy[i]);
	}
	printf("\n");
}

int main (int argc, char** argv) {
	if (argc != 3) {
		printf("Usage: %s <nodes file> <centroids file>\n", argv[0]);
		return 0;
	} else {
		data* d = read_data(argv[1]);
		data* c = read_data(argv[2]);
	
		float* cx_result = (float*)malloc(c->num_node * sizeof(float));;
		float* cy_result = (float*)malloc(c->num_node * sizeof(float));;
		int* result = (int*) malloc(d->num_node * sizeof(int));
		int iter = 100;

		if (d->num_node && c->num_node) {
			printf("Let's do CLUSTER!\n");
			kmeans(d->x, d->y, c->x, c->y, d->num_node, c->num_node, iter, cx_result, cy_result, result);		// cuda
			
			printf("print the result!\n");
			print_result(d->num_node, c->num_node, cx_result, cy_result, result);
	
//			free(d);
//			free(c);
			free(cx_result);
			free(cy_result);
			free(result);
		} else {
			printf("empty file.\n");
		}
	}
	return 0;
}



	.text
	.file	"kmeans.hip"
	.globl	_Z9read_dataPKc                 # -- Begin function _Z9read_dataPKc
	.type	_Z9read_dataPKc,@function
_Z9read_dataPKc:                        # @_Z9read_dataPKc
	.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
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %rbx
	leaq	4(%rsp), %rdx
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	testl	%eax, %eax
	je	.LBB0_1
# %bb.2:
	movl	4(%rsp), %esi
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$24, %edi
	callq	malloc
	movq	%rax, %r15
	movslq	4(%rsp), %r14
	movl	%r14d, 16(%rax)
	leaq	(,%r14,4), %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r13
	movq	%rax, (%r15)
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, 8(%r15)
	testq	%r14, %r14
	jle	.LBB0_8
# %bb.3:                                # %.lr.ph.preheader
	movq	%rax, %r12
	movq	%r15, 16(%rsp)                  # 8-byte Spill
	movl	%r14d, %r14d
	movq	%r13, 8(%rsp)                   # 8-byte Spill
	movq	%rax, %rbp
	xorl	%r15d, %r15d
.LBB0_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.4, %esi
	movq	%rbx, %rdi
	movq	%r13, %rdx
	movq	%rbp, %rcx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	incq	%r15
	movslq	4(%rsp), %rax
	addq	$4, %rbp
	addq	$4, %r13
	cmpq	%rax, %r15
	jl	.LBB0_4
# %bb.5:                                # %.preheader
	testl	%r14d, %r14d
	movq	16(%rsp), %r15                  # 8-byte Reload
	movq	8(%rsp), %rbp                   # 8-byte Reload
	jle	.LBB0_8
# %bb.6:                                # %.lr.ph26.preheader
	xorl	%r13d, %r13d
.LBB0_7:                                # %.lr.ph26
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbp,%r13,4), %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	(%r12,%r13,4), %xmm1
	movl	$.L.str.5, %edi
	movl	%r13d, %esi
	movb	$2, %al
	callq	printf
	incq	%r13
	cmpq	%r13, %r14
	jne	.LBB0_7
.LBB0_8:                                # %._crit_edge
	movq	%rbx, %rdi
	callq	fclose
	jmp	.LBB0_9
.LBB0_1:
	movl	$.Lstr, %edi
	callq	puts@PLT
	xorl	%r15d, %r15d
.LBB0_9:
	movq	%r15, %rax
	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_end0:
	.size	_Z9read_dataPKc, .Lfunc_end0-_Z9read_dataPKc
	.cfi_endproc
                                        # -- End function
	.globl	_Z28__device_stub__kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi # -- Begin function _Z28__device_stub__kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
	.type	_Z28__device_stub__kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi,@function
_Z28__device_stub__kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi: # @_Z28__device_stub__kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$176, %rsp
	.cfi_def_cfa_offset 224
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	12(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	8(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	224(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	232(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	240(%rsp), %rax
	movq	%rax, 64(%rbx)
	leaq	248(%rsp), %rax
	movq	%rax, 72(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$192, %rsp
	.cfi_adjust_cfa_offset -192
	popq	%rbx
	.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
	retq
.Lfunc_end1:
	.size	_Z28__device_stub__kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi, .Lfunc_end1-_Z28__device_stub__kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
	.cfi_endproc
                                        # -- End function
	.globl	_Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi # -- Begin function _Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi
	.type	_Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi,@function
_Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi:        # @_Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi
	.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	$88, %rsp
	.cfi_def_cfa_offset 144
	.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	%r9d, %r15d
	movq	%rcx, 80(%rsp)                  # 8-byte Spill
	movq	%rdx, 72(%rsp)                  # 8-byte Spill
	movq	%rsi, %rbp
	movq	%rdi, %rbx
	movl	%r8d, 56(%rsp)                  # 4-byte Spill
	movslq	%r8d, %r14
	leaq	(,%r14,4), %r13
	leaq	64(%rsp), %r12
	movq	%r12, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	48(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movl	%r15d, 60(%rsp)                 # 4-byte Spill
	movslq	%r15d, %r15
	shlq	$2, %r15
	leaq	40(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	32(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%r12), %rdi
	movq	%rbx, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	48(%rsp), %rax
	movq	(%rax), %rdi
	movq	%rbp, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	40(%rsp), %rax
	movq	(%rax), %rdi
	movq	72(%rsp), %rsi                  # 8-byte Reload
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	32(%rsp), %rax
	movq	(%rax), %rdi
	movq	80(%rsp), %rsi                  # 8-byte Reload
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%r14d, %edx
	btsq	$32, %rdx
	movabsq	$4294967296, %rdi               # imm = 0x100000000
	orq	$1, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_2
# %bb.1:
	movl	144(%rsp), %eax
	movq	64(%rsp), %rdi
	movq	48(%rsp), %rsi
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rcx
	movl	56(%rsp), %r8d                  # 4-byte Reload
	movl	60(%rsp), %r9d                  # 4-byte Reload
	pushq	8(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	24(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	40(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	callq	_Z28__device_stub__kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
.LBB2_2:
	movq	8(%rsp), %rsi
	movq	168(%rsp), %rdi
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	24(%rsp), %rsi
	movq	152(%rsp), %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rsi
	movq	160(%rsp), %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	64(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	addq	$88, %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	_Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi, .Lfunc_end2-_Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi
	.cfi_endproc
                                        # -- End function
	.globl	_Z9free_dataP4Data              # -- Begin function _Z9free_dataP4Data
	.type	_Z9free_dataP4Data,@function
_Z9free_dataP4Data:                     # @_Z9free_dataP4Data
	.cfi_startproc
# %bb.0:
	retq
.Lfunc_end3:
	.size	_Z9free_dataP4Data, .Lfunc_end3-_Z9free_dataP4Data
	.cfi_endproc
                                        # -- End function
	.globl	_Z12print_resultiiPKfS0_PKi     # -- Begin function _Z12print_resultiiPKfS0_PKi
	.type	_Z12print_resultiiPKfS0_PKi,@function
_Z12print_resultiiPKfS0_PKi:            # @_Z12print_resultiiPKfS0_PKi
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.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	%r8, %r15
	movq	%rcx, %rbx
	movq	%rdx, %r14
	movl	%esi, %ebp
	movl	%edi, %r12d
	movl	$9, %edi
	callq	putchar@PLT
	testl	%r12d, %r12d
	jle	.LBB4_6
# %bb.1:                                # %.lr.ph.preheader
	xorl	%r13d, %r13d
.LBB4_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.7, %edi
	movl	%r13d, %esi
	xorl	%eax, %eax
	callq	printf
	incl	%r13d
	cmpl	%r13d, %r12d
	jne	.LBB4_2
# %bb.3:                                # %._crit_edge
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	testl	%r12d, %r12d
	jle	.LBB4_7
# %bb.4:                                # %.lr.ph23.preheader
	movl	%r12d, %r12d
	xorl	%r13d, %r13d
.LBB4_5:                                # %.lr.ph23
                                        # =>This Inner Loop Header: Depth=1
	movl	(%r15,%r13,4), %esi
	movl	$.L.str.7, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB4_5
	jmp	.LBB4_7
.LBB4_6:                                # %._crit_edge.thread
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
.LBB4_7:                                # %.preheader
	testl	%ebp, %ebp
	jle	.LBB4_10
# %bb.8:                                # %.lr.ph25.preheader
	movl	%ebp, %r12d
	xorl	%r15d, %r15d
.LBB4_9:                                # %.lr.ph25
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%r15,4), %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	(%rbx,%r15,4), %xmm1
	movl	$.L.str.9, %edi
	movl	%r15d, %esi
	movb	$2, %al
	callq	printf
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB4_9
.LBB4_10:                               # %._crit_edge26
	movl	$10, %edi
	addq	$8, %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	putchar@PLT                     # TAILCALL
.Lfunc_end4:
	.size	_Z12print_resultiiPKfS0_PKi, .Lfunc_end4-_Z12print_resultiiPKfS0_PKi
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function 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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.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
	cmpl	$3, %edi
	jne	.LBB5_1
# %bb.2:
	movq	8(%rbx), %rdi
	callq	_Z9read_dataPKc
	movq	%rax, %rbp
	movq	16(%rbx), %rdi
	callq	_Z9read_dataPKc
	movq	%rax, %rbx
	movslq	16(%rax), %r15
	leaq	(,%r15,4), %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, (%rsp)                    # 8-byte Spill
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r14
	movslq	16(%rbp), %r13
	leaq	(,%r13,4), %rdi
	callq	malloc
	testq	%r15, %r15
	je	.LBB5_5
# %bb.3:
	testl	%r13d, %r13d
	je	.LBB5_5
# %bb.4:
	movq	%rax, %r12
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movq	(%rbp), %rdi
	movq	8(%rbp), %rsi
	movq	(%rbx), %rdx
	movq	8(%rbx), %rcx
	movl	%r13d, %r8d
	movl	%r15d, %r9d
	pushq	%r12
	.cfi_adjust_cfa_offset 8
	pushq	%r14
	.cfi_adjust_cfa_offset 8
	movq	16(%rsp), %rbx                  # 8-byte Reload
	pushq	%rbx
	.cfi_adjust_cfa_offset 8
	pushq	$100
	.cfi_adjust_cfa_offset 8
	callq	_Z6kmeansPKfS0_S0_S0_iiiPfS1_Pi
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	movl	%r13d, %edi
	movl	%r15d, %esi
	movq	%rbx, %rdx
	movq	%r14, %rcx
	movq	%r12, %r8
	callq	_Z12print_resultiiPKfS0_PKi
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%r12, %rdi
	callq	free
	jmp	.LBB5_6
.LBB5_1:
	movq	(%rbx), %rsi
	movl	$.L.str.11, %edi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB5_6
.LBB5_5:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
.LBB5_6:
	xorl	%eax, %eax
	addq	$8, %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
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB7_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.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	"%5d\n"
	.size	.L.str.1, 5

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"num_node = %d\n"
	.size	.L.str.3, 15

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%d: x = %f, y = %f\n"
	.size	.L.str.5, 20

	.type	_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi,@object # @_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
	.section	.rodata,"a",@progbits
	.globl	_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
	.p2align	3, 0x0
_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi:
	.quad	_Z28__device_stub__kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
	.size	_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi, 8

	.type	.L.str.7,@object                # @.str.7
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.7:
	.asciz	"\005 %d"
	.size	.L.str.7, 5

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"\nLabel : "
	.size	.L.str.8, 10

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"\ncentroid %d\t : %5f  %5f"
	.size	.L.str.9, 25

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Usage: %s <nodes file> <centroids file>\n"
	.size	.L.str.11, 41

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi"
	.size	.L__unnamed_1, 40

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"read inputfile failed."
	.size	.Lstr, 23

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"empty file."
	.size	.Lstr.1, 12

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Let's do CLUSTER!"
	.size	.Lstr.2, 18

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"print the result!"
	.size	.Lstr.3, 18

	.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 _Z28__device_stub__kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi ; -- Begin function _Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
	.globl	_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
	.p2align	8
	.type	_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi,@function
_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi: ; @_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
; %bb.0:
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 72
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 1
		.amdhsa_next_free_sgpr 1
		.amdhsa_reserve_vcc 0
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi, .Lfunc_end0-_Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 4
; NumSgprs: 0
; NumVgprs: 0
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 0
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 1
; NumVGPRsForWavesPerEU: 1
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.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_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         36
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         48
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         56
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         64
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 72
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi
    .private_segment_fixed_size: 0
    .sgpr_count:     0
    .sgpr_spill_count: 0
    .symbol:         _Z13kmeans_kernelPKfS0_PfS1_iiiS1_S1_Pi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     0
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
