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

#define MAX_POINTS 100000000
#define MAX_MEANS 1000
#define MAX_ITER 100

typedef struct {
  double *x, *y;
  int *membership;
} points;

typedef struct {
  double *x, *y;
  int *size;
  double *x_sum, *y_sum;
} centroids;

__managed__ int assignment_changed;

// reads n data points from input file
__host__ void read_data(int n, char *file_name, points P) {
  size_t i = 0;
  double x, y;
  FILE *file = fopen(file_name, "r");
  assert(file != NULL);

  while (!feof(file) && i < n) {
    if (fscanf(file, "%lf %lf", &x, &y) != 2)
      break;
    P.x[i] = x;
    P.y[i++] = y;

    if (i % (n / 100) == 0) {
      printf("\rReading input: %d%%", 100 * i / n);
      fflush(stdout);
    }
  }

  printf("Read %d points\n", i);
}

// selects k centers at random from n points
__host__ void init_centers(int n, int k, points P, centroids C) {
  for (int i = 0; i < k; ++i) {
    // not actually uniform random sampling, but good enough for testing
    int rand_idx = rand() % n;
    C.x[i] = P.x[rand_idx];
    C.y[i] = P.y[rand_idx];
  }
}

// computes ||p-c||^2 for a point p and center c
__device__ inline double norm_2D_sqr(double x1, double y1, double x2,
                                     double y2) {
  // sqrt is monotonic, so we may omit it in the distance calculation
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

__global__ void
assign_clusters(int n, int k, const double *__restrict__ Px,
                const double *__restrict__ Py, int *__restrict__ Pmembership,
                double *__restrict__ Cx, double *__restrict__ Cy,
                int *__restrict__ Csize, double *__restrict__ Cx_sum,
                double *__restrict__ Cy_sum) {
  int index = blockIdx.x * blockDim.x + threadIdx.x;

  if (index < n) {
    double min_dist = INFINITY;
    int membership = -1;

    for (int i = 0; i < k; ++i) {
      double current_dist = norm_2D_sqr(Px[index], Py[index], Cx[i], Cy[i]);
      if (current_dist < min_dist) {
        min_dist = current_dist;
        membership = i;
      }
    }

    if (membership != Pmembership[index])
      assignment_changed = 1;
    Pmembership[index] = membership;

    atomicAdd(&Cx_sum[membership], Px[index]);
    atomicAdd(&Cy_sum[membership], Py[index]);
    atomicAdd(&Csize[membership], 1);
  }
}

__global__ void update_clusters(int n, int k, double *__restrict__ Cx,
                                double *__restrict__ Cy,
                                double *__restrict__ Cx_sum,
                                double *__restrict__ Cy_sum,
                                int *__restrict__ Csize) {
  int index = blockIdx.x * blockDim.x + threadIdx.x;

  if (index < k && Csize[index]) {
    Cx[index] = Cx_sum[index] / Csize[index];
    Cy[index] = Cy_sum[index] / Csize[index];
  }
}

__global__ void zero_centroid_vals(int k, double *__restrict__ Cx_sum,
                                   double *__restrict__ Cy_sum,
                                   int *__restrict__ Csize) {
  int index = blockIdx.x * blockDim.x + threadIdx.x;

  if (index < k) {
    Cx_sum[index] = 0;
    Cy_sum[index] = 0;
    Csize[index] = 0;
  }
}

__host__ void print_results(int k, int n, int h, double t, points P,
                            centroids C) {
  printf("performed %d iterations in %.2f s, perf: %.2f billion\n", h, t,
         (double)k * n * h / t * 1e-9);

  for (int i = 0; i < k; ++i) {
    printf("cluster %d centered at (%f, %f) has size %d\n", i, C.x[i], C.y[i],
           C.size[i]);
  }
}

int main(int argc, char **argv) {
  int k, n, h;
  char *file_name;
  points P;
  centroids C;

  assert(argc >= 4);
  n = atoi(argv[1]);
  k = atoi(argv[2]);
  file_name = argv[3];
  assert(n <= MAX_POINTS && k <= MAX_MEANS);

  cudaMallocManaged(&P.x, sizeof(double) * n);
  cudaMallocManaged(&P.y, sizeof(double) * n);
  cudaMallocManaged(&P.membership, sizeof(int) * n);
  cudaMallocManaged(&C.x, sizeof(double) * k);
  cudaMallocManaged(&C.y, sizeof(double) * k);
  cudaMallocManaged(&C.size, sizeof(int) * k);
  cudaMallocManaged(&C.x_sum, sizeof(double) * k);
  cudaMallocManaged(&C.y_sum, sizeof(double) * k);

  read_data(n, file_name, P);
  init_centers(n, k, P, C);

  int blockSize = 256;
  int numBlocks = (n + blockSize - 1) / blockSize;

  clock_t start = clock();

  for (h = 0; h < MAX_ITER; ++h) {
    assignment_changed = 0;
    zero_centroid_vals<<<1, k>>>(k, C.x_sum, C.y_sum, C.size);
    cudaDeviceSynchronize();

    assign_clusters<<<numBlocks, blockSize>>>(n, k, P.x, P.y, P.membership, C.x,
                                              C.y, C.size, C.x_sum, C.y_sum);
    cudaDeviceSynchronize();

    if (!assignment_changed)
      break;

    update_clusters<<<1, k>>>(n, k, C.x, C.y, C.x_sum, C.y_sum, C.size);
    cudaDeviceSynchronize();
  }

  clock_t end = clock();
  double t = (double)(end - start) / CLOCKS_PER_SEC;

  print_results(k, n, h, t, P, C);
}

	.file	"tmpxft_00225b39_00000000-6_kmeans_atomic.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL20__nv_init_managed_rtv, @function
_ZL20__nv_init_managed_rtv:
.LFB1:
	.cfi_startproc
	movb	_ZL22__nv_inited_managed_rt(%rip), %al
	testb	%al, %al
	jne	.L4
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	_ZL32__nv_fatbinhandle_for_managed_rt(%rip), %rdi
	call	__cudaInitModule@PLT
	movb	%al, _ZL22__nv_inited_managed_rt(%rip)
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
.L4:
	movb	%al, _ZL22__nv_inited_managed_rt(%rip)
	ret
	.cfi_endproc
.LFE1:
	.size	_ZL20__nv_init_managed_rtv, .-_ZL20__nv_init_managed_rtv
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"r"
.LC1:
	.string	"\rReading input: %d%%"
.LC2:
	.string	"Read %d points\n"
.LC3:
	.string	"%lf %lf"
	.text
	.globl	_Z9read_dataiPc6points
	.type	_Z9read_dataiPc6points, @function
_Z9read_dataiPc6points:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movslq	%edi, %rbp
	movq	%rsi, %rdi
	leaq	.LC0(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	movl	$100, %ecx
	movq	%rax, %r12
	movl	%ebp, %eax
	cltd
	idivl	%ecx
	movslq	%eax, %r13
.L10:
	movq	%r12, %rdi
	call	feof@PLT
	testl	%eax, %eax
	je	.L12
.L13:
	xorl	%eax, %eax
	movq	%rbx, %rdx
	movl	$2, %edi
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L12:
	cmpq	%rbp, %rbx
	jnb	.L13
	xorl	%eax, %eax
	leaq	16(%rsp), %rcx
	leaq	8(%rsp), %rdx
	movq	%r12, %rdi
	leaq	.LC3(%rip), %rsi
	call	__isoc23_fscanf@PLT
	cmpl	$2, %eax
	jne	.L13
	movq	80(%rsp), %rdx
	movsd	8(%rsp), %xmm0
	leaq	0(,%rbx,8), %rax
	movsd	%xmm0, (%rdx,%rbx,8)
	movq	88(%rsp), %rdx
	movsd	16(%rsp), %xmm0
	incq	%rbx
	movsd	%xmm0, (%rdx,%rax)
	movq	%rbx, %rax
	xorl	%edx, %edx
	divq	%r13
	testq	%rdx, %rdx
	jne	.L10
	imulq	$100, %rbx, %rax
	xorl	%edx, %edx
	movl	$2, %edi
	leaq	.LC1(%rip), %rsi
	divq	%rbp
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
	jmp	.L10
.L15:
	addq	$40, %rsp
	.cfi_def_cfa_offset 40
	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_dataiPc6points, .-_Z9read_dataiPc6points
	.globl	_Z12init_centersii6points9centroids
	.type	_Z12init_centersii6points9centroids, @function
_Z12init_centersii6points9centroids:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
.L20:
	cmpl	%ebx, %r12d
	jle	.L23
	call	rand@PLT
	cltd
	idivl	%ebp
	movq	32(%rsp), %rax
	movslq	%edx, %rdx
	movsd	(%rax,%rdx,8), %xmm0
	movq	56(%rsp), %rax
	movsd	%xmm0, (%rax,%rbx,8)
	movq	40(%rsp), %rax
	movsd	(%rax,%rdx,8), %xmm0
	movq	64(%rsp), %rax
	movsd	%xmm0, (%rax,%rbx,8)
	incq	%rbx
	jmp	.L20
.L23:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z12init_centersii6points9centroids, .-_Z12init_centersii6points9centroids
	.section	.rodata.str1.1
.LC5:
	.string	"performed %d iterations in %.2f s, perf: %.2f billion\n"
.LC6:
	.string	"cluster %d centered at (%f, %f) has size %d\n"
	.text
	.globl	_Z13print_resultsiiid6points9centroids
	.type	_Z13print_resultsiiid6points9centroids, @function
_Z13print_resultsiiid6points9centroids:
.LFB2030:
	.cfi_startproc
	endbr64
	cvtsi2sdl	%esi, %xmm2
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC5(%rip), %rsi
	movb	$2, %al
	cvtsi2sdl	%edi, %xmm1
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%edi, %ebp
	movl	$2, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	leaq	.LC6(%rip), %r12
	xorl	%ebx, %ebx
	mulsd	%xmm2, %xmm1
	cvtsi2sdl	%edx, %xmm2
	mulsd	%xmm2, %xmm1
	divsd	%xmm0, %xmm1
	mulsd	.LC4(%rip), %xmm1
	call	__printf_chk@PLT
.L25:
	movl	%ebx, %edx
	cmpl	%ebx, %ebp
	jle	.L28
	movq	72(%rsp), %rax
	movq	%r12, %rsi
	movl	$2, %edi
	movl	(%rax,%rbx,4), %ecx
	movq	56(%rsp), %rax
	movsd	(%rax,%rbx,8), %xmm0
	movq	64(%rsp), %rax
	movsd	(%rax,%rbx,8), %xmm1
	movb	$2, %al
	incq	%rbx
	call	__printf_chk@PLT
	jmp	.L25
.L28:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z13print_resultsiiid6points9centroids, .-_Z13print_resultsiiid6points9centroids
	.globl	_Z57__device_stub__Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_iiPKdS0_PiPdS2_S1_S2_S2_
	.type	_Z57__device_stub__Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_iiPKdS0_PiPdS2_S1_S2_S2_, @function
_Z57__device_stub__Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_iiPKdS0_PiPdS2_S1_S2_S2_:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$248, %rsp
	.cfi_def_cfa_offset 256
	movl	%edi, 12(%rsp)
	leaq	104(%rsp), %rdi
	movl	%esi, 8(%rsp)
	leaq	116(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 232(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rax
	movq	%rdx, 24(%rsp)
	leaq	88(%rsp), %rdx
	movq	%rax, 152(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 192(%rsp)
	movq	256(%rsp), %rax
	movq	%rcx, 32(%rsp)
	leaq	96(%rsp), %rcx
	movq	%rax, 56(%rsp)
	leaq	56(%rsp), %rax
	movq	%rax, 200(%rsp)
	movq	264(%rsp), %rax
	movq	%r8, 40(%rsp)
	movq	%rax, 64(%rsp)
	leaq	64(%rsp), %rax
	movq	%rax, 208(%rsp)
	movq	272(%rsp), %rax
	movq	%r9, 48(%rsp)
	movq	%rax, 72(%rsp)
	leaq	72(%rsp), %rax
	movq	%rax, 216(%rsp)
	movq	280(%rsp), %rax
	movl	$1, 112(%rsp)
	movq	%rax, 80(%rsp)
	leaq	80(%rsp), %rax
	movq	%rax, 224(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 104(%rsp)
	movq	%rax, 116(%rsp)
	movl	$1, 124(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	pushq	96(%rsp)
	.cfi_def_cfa_offset 264
	leaq	_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_(%rip), %rdi
	pushq	96(%rsp)
	.cfi_def_cfa_offset 272
	movq	132(%rsp), %rcx
	movl	140(%rsp), %r8d
	movq	120(%rsp), %rsi
	movl	128(%rsp), %edx
	leaq	168(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 264
	popq	%rdx
	.cfi_def_cfa_offset 256
.L29:
	movq	232(%rsp), %rax
	subq	%fs:40, %rax
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$248, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z57__device_stub__Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_iiPKdS0_PiPdS2_S1_S2_S2_, .-_Z57__device_stub__Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_iiPKdS0_PiPdS2_S1_S2_S2_
	.globl	_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
	.type	_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_, @function
_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z57__device_stub__Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_iiPKdS0_PiPdS2_S1_S2_S2_
	.cfi_endproc
.LFE2057:
	.size	_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_, .-_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
	.globl	_Z45__device_stub__Z15update_clustersiiPdS_S_S_PiiiPdS_S_S_Pi
	.type	_Z45__device_stub__Z15update_clustersiiPdS_S_S_PiiiPdS_S_S_Pi, @function
_Z45__device_stub__Z15update_clustersiiPdS_S_S_PiiiPdS_S_S_Pi:
.LFB2058:
	.cfi_startproc
	endbr64
	subq	$200, %rsp
	.cfi_def_cfa_offset 208
	movl	%edi, 12(%rsp)
	leaq	80(%rsp), %rdi
	movl	%esi, 8(%rsp)
	leaq	92(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 184(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rax
	movq	%rdx, 24(%rsp)
	leaq	64(%rsp), %rdx
	movq	%rax, 128(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 168(%rsp)
	movq	208(%rsp), %rax
	movq	%rcx, 32(%rsp)
	leaq	72(%rsp), %rcx
	movq	%rax, 56(%rsp)
	leaq	56(%rsp), %rax
	movq	%rax, 176(%rsp)
	movabsq	$4294967297, %rax
	movq	%r8, 40(%rsp)
	movq	%r9, 48(%rsp)
	movq	%rax, 80(%rsp)
	movl	$1, 88(%rsp)
	movq	%rax, 92(%rsp)
	movl	$1, 100(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L34
	pushq	72(%rsp)
	.cfi_def_cfa_offset 216
	leaq	_Z15update_clustersiiPdS_S_S_Pi(%rip), %rdi
	pushq	72(%rsp)
	.cfi_def_cfa_offset 224
	movq	108(%rsp), %rcx
	movl	116(%rsp), %r8d
	movq	96(%rsp), %rsi
	movl	104(%rsp), %edx
	leaq	144(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 216
	popq	%rdx
	.cfi_def_cfa_offset 208
.L34:
	movq	184(%rsp), %rax
	subq	%fs:40, %rax
	je	.L36
	call	__stack_chk_fail@PLT
.L36:
	addq	$200, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z45__device_stub__Z15update_clustersiiPdS_S_S_PiiiPdS_S_S_Pi, .-_Z45__device_stub__Z15update_clustersiiPdS_S_S_PiiiPdS_S_S_Pi
	.globl	_Z15update_clustersiiPdS_S_S_Pi
	.type	_Z15update_clustersiiPdS_S_S_Pi, @function
_Z15update_clustersiiPdS_S_S_Pi:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z45__device_stub__Z15update_clustersiiPdS_S_S_PiiiPdS_S_S_Pi
	.cfi_endproc
.LFE2059:
	.size	_Z15update_clustersiiPdS_S_S_Pi, .-_Z15update_clustersiiPdS_S_S_Pi
	.globl	_Z43__device_stub__Z18zero_centroid_valsiPdS_PiiPdS_Pi
	.type	_Z43__device_stub__Z18zero_centroid_valsiPdS_PiiPdS_Pi, @function
_Z43__device_stub__Z18zero_centroid_valsiPdS_PiiPdS_Pi:
.LFB2060:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movl	%edi, 12(%rsp)
	leaq	56(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rax
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rdx, 24(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, 32(%rsp)
	leaq	48(%rsp), %rcx
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movl	$1, 64(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L39
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z18zero_centroid_valsiPdS_Pi(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L39:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L41
	call	__stack_chk_fail@PLT
.L41:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2060:
	.size	_Z43__device_stub__Z18zero_centroid_valsiPdS_PiiPdS_Pi, .-_Z43__device_stub__Z18zero_centroid_valsiPdS_PiiPdS_Pi
	.globl	_Z18zero_centroid_valsiPdS_Pi
	.type	_Z18zero_centroid_valsiPdS_Pi, @function
_Z18zero_centroid_valsiPdS_Pi:
.LFB2061:
	.cfi_startproc
	endbr64
	jmp	_Z43__device_stub__Z18zero_centroid_valsiPdS_PiiPdS_Pi
	.cfi_endproc
.LFE2061:
	.size	_Z18zero_centroid_valsiPdS_Pi, .-_Z18zero_centroid_valsiPdS_Pi
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	8(%rsi), %rdi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	call	atoi@PLT
	movq	16(%r12), %rdi
	movl	%eax, %ebp
	call	atoi@PLT
	movq	24(%r12), %r14
	movslq	%ebp, %r12
	leaq	40(%rsp), %rdi
	leaq	0(,%r12,8), %r13
	movl	$1, %edx
	movl	%eax, %ebx
	movq	%r13, %rsi
	call	cudaMallocManaged@PLT
	leaq	48(%rsp), %rdi
	movq	%r13, %rsi
	movl	$1, %edx
	call	cudaMallocManaged@PLT
	movslq	%ebx, %r13
	leaq	56(%rsp), %rdi
	leaq	0(,%r12,4), %rsi
	movl	$1, %edx
	leaq	0(,%r13,8), %r12
	call	cudaMallocManaged@PLT
	leaq	64(%rsp), %rax
	movq	%r12, %rsi
	movl	$1, %edx
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	cudaMallocManaged@PLT
	leaq	72(%rsp), %rdi
	movq	%r12, %rsi
	movl	$1, %edx
	call	cudaMallocManaged@PLT
	leaq	80(%rsp), %rdi
	movl	$1, %edx
	leaq	0(,%r13,4), %rsi
	call	cudaMallocManaged@PLT
	leaq	88(%rsp), %rdi
	movq	%r12, %rsi
	xorl	%r13d, %r13d
	movl	$1, %edx
	call	cudaMallocManaged@PLT
	movl	$1, %edx
	leaq	96(%rsp), %rdi
	movq	%r12, %rsi
	call	cudaMallocManaged@PLT
	subq	$32, %rsp
	.cfi_def_cfa_offset 208
	movl	%ebp, %edi
	movq	%r14, %rsi
	movups	72(%rsp), %xmm1
	movq	88(%rsp), %rax
	movabsq	$4294967297, %r12
	movups	%xmm1, (%rsp)
	movq	%rax, 16(%rsp)
	call	_Z9read_dataiPc6points
	movl	$10, %ecx
	pushq	%rdi
	.cfi_def_cfa_offset 216
	movq	48(%rsp), %rsi
	movq	%rsp, %rdi
	subq	$24, %rsp
	.cfi_def_cfa_offset 240
	rep movsl
	movl	%ebx, %esi
	movl	%ebp, %edi
	movups	104(%rsp), %xmm2
	movq	120(%rsp), %rax
	movups	%xmm2, (%rsp)
	movq	%rax, 16(%rsp)
	call	_Z12init_centersii6points9centroids
	leal	255(%rbp), %eax
	movl	$256, %ecx
	addq	$64, %rsp
	.cfi_def_cfa_offset 176
	cltd
	idivl	%ecx
	movl	%eax, %r14d
	call	clock@PLT
	movq	%rax, %r15
.L51:
	cmpb	$0, _ZL22__nv_inited_managed_rt(%rip)
	jne	.L45
	call	_ZL20__nv_init_managed_rtv
.L45:
	movq	_ZL18assignment_changed(%rip), %rax
	xorl	%esi, %esi
	movl	%ebx, 28(%rsp)
	xorl	%r9d, %r9d
	movq	%r12, 32(%rsp)
	movl	36(%rsp), %ecx
	xorl	%r8d, %r8d
	movq	%r12, %rdi
	movl	%esi, (%rax)
	movq	28(%rsp), %rdx
	movl	$1, %esi
	movq	%r12, 16(%rsp)
	movl	$1, 24(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L46
	movq	80(%rsp), %rcx
	movq	96(%rsp), %rdx
	movl	%ebx, %edi
	movq	88(%rsp), %rsi
	call	_Z43__device_stub__Z18zero_centroid_valsiPdS_PiiPdS_Pi
.L46:
	call	cudaDeviceSynchronize@PLT
	movq	%r12, 20(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	%r14d, 16(%rsp)
	movl	$16777217, %edx
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movl	24(%rsp), %esi
	salq	$8, %rdx
	movl	$1, 36(%rsp)
	movq	%rdx, 28(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L47
	pushq	96(%rsp)
	.cfi_def_cfa_offset 184
	movl	%ebx, %esi
	movl	%ebp, %edi
	pushq	96(%rsp)
	.cfi_def_cfa_offset 192
	pushq	96(%rsp)
	.cfi_def_cfa_offset 200
	pushq	96(%rsp)
	.cfi_def_cfa_offset 208
	movq	96(%rsp), %r9
	movq	88(%rsp), %r8
	movq	80(%rsp), %rcx
	movq	72(%rsp), %rdx
	call	_Z57__device_stub__Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_iiPKdS0_PiPdS2_S1_S2_S2_
	addq	$32, %rsp
	.cfi_def_cfa_offset 176
.L47:
	call	cudaDeviceSynchronize@PLT
	cmpb	$0, _ZL22__nv_inited_managed_rt(%rip)
	jne	.L48
	call	_ZL20__nv_init_managed_rtv
.L48:
	movq	_ZL18assignment_changed(%rip), %rax
	cmpl	$0, (%rax)
	je	.L49
	movq	%r12, 32(%rsp)
	movl	36(%rsp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	%ebx, 28(%rsp)
	movq	28(%rsp), %rdx
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r12, 16(%rsp)
	movl	$1, 24(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L50
	pushq	%rax
	.cfi_def_cfa_offset 184
	movl	%ebx, %esi
	movl	%ebp, %edi
	pushq	88(%rsp)
	.cfi_def_cfa_offset 192
	movq	112(%rsp), %r9
	movq	104(%rsp), %r8
	movq	88(%rsp), %rcx
	movq	80(%rsp), %rdx
	call	_Z45__device_stub__Z15update_clustersiiPdS_S_S_PiiiPdS_S_S_Pi
	popq	%rdx
	.cfi_def_cfa_offset 184
	popq	%rcx
	.cfi_def_cfa_offset 176
.L50:
	call	cudaDeviceSynchronize@PLT
	incl	%r13d
	cmpl	$100, %r13d
	jne	.L51
.L49:
	call	clock@PLT
	subq	$40, %rsp
	.cfi_def_cfa_offset 216
	movl	$10, %ecx
	movl	%r13d, %edx
	movq	48(%rsp), %rsi
	movq	%rsp, %rdi
	subq	%r15, %rax
	subq	$24, %rsp
	.cfi_def_cfa_offset 240
	rep movsl
	cvtsi2sdq	%rax, %xmm0
	movl	%ebp, %esi
	movl	%ebx, %edi
	divsd	.LC7(%rip), %xmm0
	movups	104(%rsp), %xmm3
	movq	120(%rsp), %rax
	movups	%xmm3, (%rsp)
	movq	%rax, 16(%rsp)
	call	_Z13print_resultsiiid6points9centroids
	addq	$64, %rsp
	.cfi_def_cfa_offset 176
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L52
	call	__stack_chk_fail@PLT
.L52:
	addq	$120, %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
.LFE2031:
	.size	main, .-main
	.section	.rodata.str1.1
.LC8:
	.string	"_Z18zero_centroid_valsiPdS_Pi"
.LC9:
	.string	"_Z15update_clustersiiPdS_S_S_Pi"
.LC10:
	.string	"_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_"
.LC11:
	.string	"assignment_changed"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2063:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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	.LC8(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z18zero_centroid_valsiPdS_Pi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	movq	%rax, _ZL32__nv_fatbinhandle_for_managed_rt(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC9(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z15update_clustersiiPdS_S_S_Pi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC10(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC11(%rip), %rdx
	movl	$4, %r9d
	leaq	_ZL18assignment_changed(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterManagedVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2063:
	.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	__nv_managed_data__,"aw"
	.align 8
	.type	_ZL18assignment_changed, @object
	.size	_ZL18assignment_changed, 8
_ZL18assignment_changed:
	.zero	8
	.local	_ZL32__nv_fatbinhandle_for_managed_rt
	.comm	_ZL32__nv_fatbinhandle_for_managed_rt,8,8
	.local	_ZL22__nv_inited_managed_rt
	.comm	_ZL22__nv_inited_managed_rt,1,1
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC4:
	.long	-400107883
	.long	1041313291
	.align 8
.LC7:
	.long	0
	.long	1093567616
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


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

#define MAX_POINTS 100000000
#define MAX_MEANS 1000
#define MAX_ITER 100

typedef struct {
  double *x, *y;
  int *membership;
} points;

typedef struct {
  double *x, *y;
  int *size;
  double *x_sum, *y_sum;
} centroids;

__managed__ int assignment_changed;

// reads n data points from input file
__host__ void read_data(int n, char *file_name, points P) {
  size_t i = 0;
  double x, y;
  FILE *file = fopen(file_name, "r");
  assert(file != NULL);

  while (!feof(file) && i < n) {
    if (fscanf(file, "%lf %lf", &x, &y) != 2)
      break;
    P.x[i] = x;
    P.y[i++] = y;

    if (i % (n / 100) == 0) {
      printf("\rReading input: %d%%", 100 * i / n);
      fflush(stdout);
    }
  }

  printf("Read %d points\n", i);
}

// selects k centers at random from n points
__host__ void init_centers(int n, int k, points P, centroids C) {
  for (int i = 0; i < k; ++i) {
    // not actually uniform random sampling, but good enough for testing
    int rand_idx = rand() % n;
    C.x[i] = P.x[rand_idx];
    C.y[i] = P.y[rand_idx];
  }
}

// computes ||p-c||^2 for a point p and center c
__device__ inline double norm_2D_sqr(double x1, double y1, double x2,
                                     double y2) {
  // sqrt is monotonic, so we may omit it in the distance calculation
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

__global__ void
assign_clusters(int n, int k, const double *__restrict__ Px,
                const double *__restrict__ Py, int *__restrict__ Pmembership,
                double *__restrict__ Cx, double *__restrict__ Cy,
                int *__restrict__ Csize, double *__restrict__ Cx_sum,
                double *__restrict__ Cy_sum) {
  int index = blockIdx.x * blockDim.x + threadIdx.x;

  if (index < n) {
    double min_dist = INFINITY;
    int membership = -1;

    for (int i = 0; i < k; ++i) {
      double current_dist = norm_2D_sqr(Px[index], Py[index], Cx[i], Cy[i]);
      if (current_dist < min_dist) {
        min_dist = current_dist;
        membership = i;
      }
    }

    if (membership != Pmembership[index])
      assignment_changed = 1;
    Pmembership[index] = membership;

    atomicAdd(&Cx_sum[membership], Px[index]);
    atomicAdd(&Cy_sum[membership], Py[index]);
    atomicAdd(&Csize[membership], 1);
  }
}

__global__ void update_clusters(int n, int k, double *__restrict__ Cx,
                                double *__restrict__ Cy,
                                double *__restrict__ Cx_sum,
                                double *__restrict__ Cy_sum,
                                int *__restrict__ Csize) {
  int index = blockIdx.x * blockDim.x + threadIdx.x;

  if (index < k && Csize[index]) {
    Cx[index] = Cx_sum[index] / Csize[index];
    Cy[index] = Cy_sum[index] / Csize[index];
  }
}

__global__ void zero_centroid_vals(int k, double *__restrict__ Cx_sum,
                                   double *__restrict__ Cy_sum,
                                   int *__restrict__ Csize) {
  int index = blockIdx.x * blockDim.x + threadIdx.x;

  if (index < k) {
    Cx_sum[index] = 0;
    Cy_sum[index] = 0;
    Csize[index] = 0;
  }
}

__host__ void print_results(int k, int n, int h, double t, points P,
                            centroids C) {
  printf("performed %d iterations in %.2f s, perf: %.2f billion\n", h, t,
         (double)k * n * h / t * 1e-9);

  for (int i = 0; i < k; ++i) {
    printf("cluster %d centered at (%f, %f) has size %d\n", i, C.x[i], C.y[i],
           C.size[i]);
  }
}

int main(int argc, char **argv) {
  int k, n, h;
  char *file_name;
  points P;
  centroids C;

  assert(argc >= 4);
  n = atoi(argv[1]);
  k = atoi(argv[2]);
  file_name = argv[3];
  assert(n <= MAX_POINTS && k <= MAX_MEANS);

  hipMallocManaged(&P.x, sizeof(double) * n);
  hipMallocManaged(&P.y, sizeof(double) * n);
  hipMallocManaged(&P.membership, sizeof(int) * n);
  hipMallocManaged(&C.x, sizeof(double) * k);
  hipMallocManaged(&C.y, sizeof(double) * k);
  hipMallocManaged(&C.size, sizeof(int) * k);
  hipMallocManaged(&C.x_sum, sizeof(double) * k);
  hipMallocManaged(&C.y_sum, sizeof(double) * k);

  read_data(n, file_name, P);
  init_centers(n, k, P, C);

  int blockSize = 256;
  int numBlocks = (n + blockSize - 1) / blockSize;

  clock_t start = clock();

  for (h = 0; h < MAX_ITER; ++h) {
    assignment_changed = 0;
    zero_centroid_vals<<<1, k>>>(k, C.x_sum, C.y_sum, C.size);
    hipDeviceSynchronize();

    assign_clusters<<<numBlocks, blockSize>>>(n, k, P.x, P.y, P.membership, C.x,
                                              C.y, C.size, C.x_sum, C.y_sum);
    hipDeviceSynchronize();

    if (!assignment_changed)
      break;

    update_clusters<<<1, k>>>(n, k, C.x, C.y, C.x_sum, C.y_sum, C.size);
    hipDeviceSynchronize();
  }

  clock_t end = clock();
  double t = (double)(end - start) / CLOCKS_PER_SEC;

  print_results(k, n, h, t, P, C);
}

	.text
	.file	"kmeans_atomic.hip"
	.globl	_Z9read_dataiPc6points          # -- Begin function _Z9read_dataiPc6points
	.type	_Z9read_dataiPc6points,@function
_Z9read_dataiPc6points:                 # @_Z9read_dataiPc6points
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rax
	movl	%edi, %ebp
	movl	$.L.str, %esi
	movq	%rax, %rdi
	callq	fopen
	movq	%rax, %rbx
	movq	%rax, %rdi
	callq	feof
	xorl	%r14d, %r14d
	testl	%ebp, %ebp
	je	.LBB0_8
# %bb.1:
	testl	%eax, %eax
	jne	.LBB0_8
# %bb.2:                                # %.lr.ph
	leaq	80(%rsp), %rax
	movslq	%ebp, %rbp
	movq	(%rax), %rcx
	movq	%rcx, (%rsp)                    # 8-byte Spill
	movq	8(%rax), %r13
	imulq	$1374389535, %rbp, %rax         # imm = 0x51EB851F
	movq	%rax, %rcx
	shrq	$63, %rcx
	sarq	$37, %rax
	addl	%ecx, %eax
	movslq	%eax, %r12
	movl	$100, %r15d
	xorl	%r14d, %r14d
.LBB0_3:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str.1, %esi
	movq	%rbx, %rdi
	leaq	16(%rsp), %rdx
	leaq	8(%rsp), %rcx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$2, %eax
	jne	.LBB0_8
# %bb.4:                                #   in Loop: Header=BB0_3 Depth=1
	movsd	16(%rsp), %xmm0                 # xmm0 = mem[0],zero
	movq	(%rsp), %rax                    # 8-byte Reload
	movsd	%xmm0, (%rax,%r14,8)
	movsd	8(%rsp), %xmm0                  # xmm0 = mem[0],zero
	movsd	%xmm0, (%r13,%r14,8)
	incq	%r14
	movq	%r14, %rax
	xorl	%edx, %edx
	divq	%r12
	testq	%rdx, %rdx
	jne	.LBB0_6
# %bb.5:                                #   in Loop: Header=BB0_3 Depth=1
	movq	%r15, %rax
	xorl	%edx, %edx
	divq	%rbp
	movl	$.L.str.2, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
	movq	stdout(%rip), %rdi
	callq	fflush
.LBB0_6:                                #   in Loop: Header=BB0_3 Depth=1
	movq	%rbx, %rdi
	callq	feof
	cmpq	%rbp, %r14
	jae	.LBB0_8
# %bb.7:                                #   in Loop: Header=BB0_3 Depth=1
	addq	$100, %r15
	testl	%eax, %eax
	je	.LBB0_3
.LBB0_8:                                # %._crit_edge
	movl	$.L.str.3, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	printf
	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_dataiPc6points, .Lfunc_end0-_Z9read_dataiPc6points
	.cfi_endproc
                                        # -- End function
	.globl	_Z12init_centersii6points9centroids # -- Begin function _Z12init_centersii6points9centroids
	.type	_Z12init_centersii6points9centroids,@function
_Z12init_centersii6points9centroids:    # @_Z12init_centersii6points9centroids
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB1_4
# %bb.1:                                # %.lr.ph
	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
	movl	%edi, %r14d
	leaq	88(%rsp), %rax
	leaq	64(%rsp), %rcx
	movq	(%rcx), %rdx
	movq	%rdx, (%rsp)                    # 8-byte Spill
	movq	8(%rcx), %r15
	movq	(%rax), %r12
	movq	8(%rax), %r13
	movl	%esi, %ebp
	xorl	%ebx, %ebx
.LBB1_2:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	cltd
	idivl	%r14d
	movslq	%edx, %rax
	movq	(%rsp), %rcx                    # 8-byte Reload
	movsd	(%rcx,%rax,8), %xmm0            # xmm0 = mem[0],zero
	movsd	%xmm0, (%r12,%rbx,8)
	movsd	(%r15,%rax,8), %xmm0            # xmm0 = mem[0],zero
	movsd	%xmm0, (%r13,%rbx,8)
	incq	%rbx
	cmpq	%rbx, %rbp
	jne	.LBB1_2
# %bb.3:
	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
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r13
	.cfi_restore %r14
	.cfi_restore %r15
	.cfi_restore %rbp
.LBB1_4:                                # %._crit_edge
	retq
.Lfunc_end1:
	.size	_Z12init_centersii6points9centroids, .Lfunc_end1-_Z12init_centersii6points9centroids
	.cfi_endproc
                                        # -- End function
	.globl	_Z30__device_stub__assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_ # -- Begin function _Z30__device_stub__assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
	.type	_Z30__device_stub__assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_,@function
_Z30__device_stub__assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_: # @_Z30__device_stub__assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
	.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	12(%rsp), %rax
	movl	%edi, (%rax)
	leaq	8(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	56(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	48(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	32(%rsp), %r8
	movq	%r9, (%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	$_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_, %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_end2:
	.size	_Z30__device_stub__assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_, .Lfunc_end2-_Z30__device_stub__assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
	.cfi_endproc
                                        # -- End function
	.globl	_Z30__device_stub__update_clustersiiPdS_S_S_Pi # -- Begin function _Z30__device_stub__update_clustersiiPdS_S_S_Pi
	.type	_Z30__device_stub__update_clustersiiPdS_S_S_Pi,@function
_Z30__device_stub__update_clustersiiPdS_S_S_Pi: # @_Z30__device_stub__update_clustersiiPdS_S_S_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	$160, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	12(%rsp), %rax
	movl	%edi, (%rax)
	leaq	8(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	56(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	48(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	32(%rsp), %r8
	movq	%r9, (%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	208(%rsp), %rax
	movq	%rax, 48(%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	$_Z15update_clustersiiPdS_S_S_Pi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$176, %rsp
	.cfi_adjust_cfa_offset -176
	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_end3:
	.size	_Z30__device_stub__update_clustersiiPdS_S_S_Pi, .Lfunc_end3-_Z30__device_stub__update_clustersiiPdS_S_S_Pi
	.cfi_endproc
                                        # -- End function
	.globl	_Z33__device_stub__zero_centroid_valsiPdS_Pi # -- Begin function _Z33__device_stub__zero_centroid_valsiPdS_Pi
	.type	_Z33__device_stub__zero_centroid_valsiPdS_Pi,@function
_Z33__device_stub__zero_centroid_valsiPdS_Pi: # @_Z33__device_stub__zero_centroid_valsiPdS_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	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	4(%rsp), %rax
	movl	%edi, (%rax)
	leaq	40(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	24(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%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	$_Z18zero_centroid_valsiPdS_Pi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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_end4:
	.size	_Z33__device_stub__zero_centroid_valsiPdS_Pi, .Lfunc_end4-_Z33__device_stub__zero_centroid_valsiPdS_Pi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z13print_resultsiiid6points9centroids
.LCPI5_0:
	.quad	0x3e112e0be826d695              # double 1.0000000000000001E-9
	.text
	.globl	_Z13print_resultsiiid6points9centroids
	.type	_Z13print_resultsiiid6points9centroids,@function
_Z13print_resultsiiid6points9centroids: # @_Z13print_resultsiiid6points9centroids
	.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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%edi, %ebx
	cvtsi2sd	%edi, %xmm1
	cvtsi2sd	%esi, %xmm2
	mulsd	%xmm1, %xmm2
	xorps	%xmm1, %xmm1
	cvtsi2sd	%edx, %xmm1
	mulsd	%xmm2, %xmm1
	divsd	%xmm0, %xmm1
	mulsd	.LCPI5_0(%rip), %xmm1
	movl	$.L.str.4, %edi
	movl	%edx, %esi
	movb	$2, %al
	callq	printf
	testl	%ebx, %ebx
	jle	.LBB5_3
# %bb.1:                                # %.lr.ph
	leaq	72(%rsp), %rax
	movq	(%rax), %r14
	movq	8(%rax), %r15
	movq	16(%rax), %r12
	movl	%ebx, %r13d
	xorl	%ebx, %ebx
.LBB5_2:                                # =>This Inner Loop Header: Depth=1
	movsd	(%r14,%rbx,8), %xmm0            # xmm0 = mem[0],zero
	movsd	(%r15,%rbx,8), %xmm1            # xmm1 = mem[0],zero
	movl	(%r12,%rbx,4), %edx
	movl	$.L.str.5, %edi
	movl	%ebx, %esi
	movb	$2, %al
	callq	printf
	incq	%rbx
	cmpq	%rbx, %r13
	jne	.LBB5_2
.LBB5_3:                                # %._crit_edge
	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_end5:
	.size	_Z13print_resultsiiid6points9centroids, .Lfunc_end5-_Z13print_resultsiiid6points9centroids
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI6_0:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	.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
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r14d
	movq	16(%rbx), %rdi
	callq	atoi
	movl	%eax, %ebp
	movq	24(%rbx), %rbx
	movq	%r14, 72(%rsp)                  # 8-byte Spill
	movslq	%r14d, %r14
	leaq	(,%r14,8), %r15
	leaq	120(%rsp), %rdi
	movq	%r15, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	leaq	128(%rsp), %rdi
	movq	%r15, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	leaq	136(%rsp), %r15
	leaq	(,%r14,4), %rsi
	movq	%r15, %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	movslq	%ebp, %r13
	leaq	(,%r13,8), %r12
	leaq	80(%rsp), %rdi
	movq	%r12, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	leaq	88(%rsp), %rdi
	movq	%r12, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	leaq	96(%rsp), %rdi
	leaq	(,%r13,4), %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	leaq	104(%rsp), %rdi
	movq	%r12, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	leaq	112(%rsp), %rdi
	movq	%r12, %rsi
	movl	$1, %edx
	callq	hipMallocManaged
	movq	(%r15), %rax
	movq	%rax, 16(%rsp)
	movups	-16(%r15), %xmm0
	movups	%xmm0, (%rsp)
	movl	%r14d, %edi
	movq	%rbx, %rsi
	callq	_Z9read_dataiPc6points
	movl	%r13d, %r12d
	testl	%r13d, %r13d
	jle	.LBB6_3
# %bb.1:                                # %.lr.ph.i.preheader
	movq	120(%rsp), %rbx
	movq	128(%rsp), %r14
	movq	80(%rsp), %r15
	movq	88(%rsp), %r13
	xorl	%ebp, %ebp
.LBB6_2:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltd
	idivl	72(%rsp)                        # 4-byte Folded Reload
	movslq	%edx, %rax
	movsd	(%rbx,%rax,8), %xmm0            # xmm0 = mem[0],zero
	movsd	%xmm0, (%r15,%rbp,8)
	movsd	(%r14,%rax,8), %xmm0            # xmm0 = mem[0],zero
	movsd	%xmm0, (%r13,%rbp,8)
	incq	%rbp
	cmpq	%rbp, %r12
	jne	.LBB6_2
.LBB6_3:                                # %_Z12init_centersii6points9centroids.exit
	movabsq	$4294967296, %r13               # imm = 0x100000000
	movq	72(%rsp), %rbp                  # 8-byte Reload
	leal	255(%rbp), %eax
                                        # kill: def $ebp killed $ebp killed $rbp def $rbp
	addl	$510, %ebp                      # imm = 0x1FE
	testl	%eax, %eax
	cmovnsl	%eax, %ebp
	sarl	$8, %ebp
	callq	clock
	movq	%rax, 144(%rsp)                 # 8-byte Spill
	movq	%r12, %r14
	btsq	$32, %r14
	btsq	$32, %rbp
	xorl	%r15d, %r15d
	leaq	1(%r13), %rbx
	addq	$256, %r13                      # imm = 0x100
.LBB6_4:                                # =>This Inner Loop Header: Depth=1
	movq	assignment_changed(%rip), %rax
	movl	$0, (%rax)
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_6
# %bb.5:                                #   in Loop: Header=BB6_4 Depth=1
	movq	96(%rsp), %rcx
	movq	104(%rsp), %rsi
	movq	112(%rsp), %rdx
	movl	%r12d, %edi
	callq	_Z33__device_stub__zero_centroid_valsiPdS_Pi
.LBB6_6:                                #   in Loop: Header=BB6_4 Depth=1
	callq	hipDeviceSynchronize
	movq	%rbp, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_8
# %bb.7:                                #   in Loop: Header=BB6_4 Depth=1
	movq	120(%rsp), %rdx
	movq	128(%rsp), %rcx
	movq	136(%rsp), %r8
	movq	80(%rsp), %r9
	movups	88(%rsp), %xmm0
	movups	104(%rsp), %xmm1
	movups	%xmm1, 16(%rsp)
	movups	%xmm0, (%rsp)
	movq	72(%rsp), %rdi                  # 8-byte Reload
                                        # kill: def $edi killed $edi killed $rdi
	movl	%r12d, %esi
	callq	_Z30__device_stub__assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
.LBB6_8:                                #   in Loop: Header=BB6_4 Depth=1
	callq	hipDeviceSynchronize
	movq	assignment_changed(%rip), %rax
	cmpl	$0, (%rax)
	je	.LBB6_13
# %bb.9:                                #   in Loop: Header=BB6_4 Depth=1
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_11
# %bb.10:                               #   in Loop: Header=BB6_4 Depth=1
	movq	80(%rsp), %rdx
	movq	88(%rsp), %rcx
	movq	104(%rsp), %r8
	movq	112(%rsp), %r9
	movq	96(%rsp), %rax
	movq	%rax, (%rsp)
	movq	72(%rsp), %rdi                  # 8-byte Reload
                                        # kill: def $edi killed $edi killed $rdi
	movl	%r12d, %esi
	callq	_Z30__device_stub__update_clustersiiPdS_S_S_Pi
.LBB6_11:                               #   in Loop: Header=BB6_4 Depth=1
	callq	hipDeviceSynchronize
	incl	%r15d
	cmpl	$100, %r15d
	jne	.LBB6_4
# %bb.12:
	movl	$100, %r15d
.LBB6_13:
	callq	clock
	subq	144(%rsp), %rax                 # 8-byte Folded Reload
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI6_0(%rip), %xmm0
	movq	112(%rsp), %rax
	movq	%rax, 56(%rsp)
	movups	80(%rsp), %xmm1
	movups	96(%rsp), %xmm2
	movups	%xmm2, 40(%rsp)
	movups	%xmm1, 24(%rsp)
	movq	136(%rsp), %rax
	movq	%rax, 16(%rsp)
	movups	120(%rsp), %xmm1
	movups	%xmm1, (%rsp)
	movl	%r12d, %edi
	movq	72(%rsp), %rsi                  # 8-byte Reload
                                        # kill: def $esi killed $esi killed $rsi
	movl	%r15d, %edx
	callq	_Z13print_resultsiiid6points9centroids
	xorl	%eax, %eax
	addq	$152, %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_end6:
	.size	main, .Lfunc_end6-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:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z15update_clustersiiPdS_S_S_Pi, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z18zero_centroid_valsiPdS_Pi, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$assignment_changed, %esi
	movl	$assignment_changed.managed, %edx
	movl	$.L__unnamed_4, %ecx
	movl	$4, %r8d
	movq	%rbx, %rdi
	movl	$4, %r9d
	callq	__hipRegisterManagedVar
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__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	.LBB8_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
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	assignment_changed.managed,@object # @assignment_changed.managed
	.local	assignment_changed.managed
	.comm	assignment_changed.managed,4,4
	.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	"%lf %lf"
	.size	.L.str.1, 8

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"\rReading input: %d%%"
	.size	.L.str.2, 21

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

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

	.type	_Z15update_clustersiiPdS_S_S_Pi,@object # @_Z15update_clustersiiPdS_S_S_Pi
	.globl	_Z15update_clustersiiPdS_S_S_Pi
	.p2align	3, 0x0
_Z15update_clustersiiPdS_S_S_Pi:
	.quad	_Z30__device_stub__update_clustersiiPdS_S_S_Pi
	.size	_Z15update_clustersiiPdS_S_S_Pi, 8

	.type	_Z18zero_centroid_valsiPdS_Pi,@object # @_Z18zero_centroid_valsiPdS_Pi
	.globl	_Z18zero_centroid_valsiPdS_Pi
	.p2align	3, 0x0
_Z18zero_centroid_valsiPdS_Pi:
	.quad	_Z33__device_stub__zero_centroid_valsiPdS_Pi
	.size	_Z18zero_centroid_valsiPdS_Pi, 8

	.type	.L.str.4,@object                # @.str.4
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.4:
	.asciz	"performed %d iterations in %.2f s, perf: %.2f billion\n"
	.size	.L.str.4, 55

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"cluster %d centered at (%f, %f) has size %d\n"
	.size	.L.str.5, 45

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_"
	.size	.L__unnamed_1, 44

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z15update_clustersiiPdS_S_S_Pi"
	.size	.L__unnamed_2, 32

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z18zero_centroid_valsiPdS_Pi"
	.size	.L__unnamed_3, 30

	.type	.L__unnamed_4,@object           # @3
.L__unnamed_4:
	.asciz	"assignment_changed"
	.size	.L__unnamed_4, 19

	.type	assignment_changed,@object      # @assignment_changed
	.local	assignment_changed
	.comm	assignment_changed,8,8
	.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

	.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 _Z30__device_stub__assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
	.addrsig_sym _Z30__device_stub__update_clustersiiPdS_S_S_Pi
	.addrsig_sym _Z33__device_stub__zero_centroid_valsiPdS_Pi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym assignment_changed.managed
	.addrsig_sym _Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
	.addrsig_sym _Z15update_clustersiiPdS_S_S_Pi
	.addrsig_sym _Z18zero_centroid_valsiPdS_Pi
	.addrsig_sym assignment_changed
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_ ; -- Begin function _Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
	.globl	_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
	.p2align	8
	.type	_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_,@function
_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_: ; @_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x54
	s_load_b64 s[16:17], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s16, v1
	s_cbranch_execz .LBB0_12
; %bb.1:                                ; %.preheader
	s_clause 0x3
	s_load_b128 s[8:11], s[0:1], 0x8
	s_load_b64 s[14:15], s[0:1], 0x18
	s_load_b64 s[12:13], s[0:1], 0x40
	s_load_b128 s[4:7], s[0:1], 0x30
	v_ashrrev_i32_e32 v2, 31, v1
	s_cmp_lt_i32 s17, 1
	s_delay_alu instid0(VALU_DEP_1)
	v_lshlrev_b64 v[6:7], 3, v[1:2]
	s_cbranch_scc1 .LBB0_4
; %bb.2:                                ; %.lr.ph
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s8, v6
	v_add_co_ci_u32_e32 v4, vcc_lo, s9, v7, vcc_lo
	v_add_co_u32 v10, vcc_lo, s10, v6
	v_add_co_ci_u32_e32 v11, vcc_lo, s11, v7, vcc_lo
	s_load_b128 s[0:3], s[0:1], 0x20
	global_load_b64 v[8:9], v[3:4], off
	global_load_b64 v[10:11], v[10:11], off
	v_mov_b32_e32 v12, 0
	v_dual_mov_b32 v13, 0x7ff00000 :: v_dual_mov_b32 v4, -1
	s_mov_b32 s16, 0
.LBB0_3:                                ; =>This Inner Loop Header: Depth=1
	s_waitcnt lgkmcnt(0)
	s_load_b64 s[18:19], s[2:3], 0x0
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_add_f64 v[14:15], v[10:11], -s[18:19]
	s_load_b64 s[18:19], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	v_add_f64 v[16:17], v[8:9], -s[18:19]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[14:15], v[14:15], v[14:15]
	v_fma_f64 v[14:15], v[16:17], v[16:17], v[14:15]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_lt_f64_e32 vcc_lo, v[14:15], v[12:13]
	v_cndmask_b32_e64 v4, v4, s16, vcc_lo
	s_add_i32 s16, s16, 1
	s_add_u32 s0, s0, 8
	s_addc_u32 s1, s1, 0
	v_dual_cndmask_b32 v13, v13, v15 :: v_dual_cndmask_b32 v12, v12, v14
	s_add_u32 s2, s2, 8
	s_addc_u32 s3, s3, 0
	s_cmp_eq_u32 s17, s16
	s_cbranch_scc0 .LBB0_3
	s_branch .LBB0_5
.LBB0_4:
	v_mov_b32_e32 v4, -1
.LBB0_5:                                ; %Flow61
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_mov_b32 s0, exec_lo
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s14, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s15, v1, vcc_lo
	global_load_b32 v2, v[0:1], off
	s_waitcnt vmcnt(0)
	v_cmpx_ne_u32_e64 v4, v2
	s_cbranch_execz .LBB0_7
; %bb.6:
	s_getpc_b64 s[2:3]
	s_add_u32 s2, s2, assignment_changed@rel32@lo+4
	s_addc_u32 s3, s3, assignment_changed@rel32@hi+12
	v_dual_mov_b32 v2, 0 :: v_dual_mov_b32 v3, 1
	s_load_b64 s[2:3], s[2:3], 0x0
	s_waitcnt lgkmcnt(0)
	global_store_b32 v2, v3, s[2:3]
.LBB0_7:
	s_or_b32 exec_lo, exec_lo, s0
	v_ashrrev_i32_e32 v5, 31, v4
	v_add_co_u32 v2, vcc_lo, s8, v6
	v_add_co_ci_u32_e32 v3, vcc_lo, s9, v7, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[8:9], 3, v[4:5]
	s_mov_b32 s0, 0
	v_add_co_u32 v10, vcc_lo, s6, v8
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v11, vcc_lo, s7, v9, vcc_lo
	global_load_b64 v[12:13], v[2:3], off
	global_load_b64 v[2:3], v[10:11], off
	global_store_b32 v[0:1], v4, off
.LBB0_8:                                ; %atomicrmw.start
                                        ; =>This Inner Loop Header: Depth=1
	s_waitcnt vmcnt(0)
	v_add_f64 v[0:1], v[2:3], v[12:13]
	global_atomic_cmpswap_b64 v[0:1], v[10:11], v[0:3], off glc
	s_waitcnt vmcnt(0)
	v_cmp_eq_u64_e32 vcc_lo, v[0:1], v[2:3]
	v_dual_mov_b32 v3, v1 :: v_dual_mov_b32 v2, v0
	s_or_b32 s0, vcc_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s0
	s_cbranch_execnz .LBB0_8
; %bb.9:                                ; %atomicrmw.end
	s_or_b32 exec_lo, exec_lo, s0
	v_add_co_u32 v0, vcc_lo, s10, v6
	v_add_co_ci_u32_e32 v1, vcc_lo, s11, v7, vcc_lo
	v_add_co_u32 v6, vcc_lo, s12, v8
	v_add_co_ci_u32_e32 v7, vcc_lo, s13, v9, vcc_lo
	s_mov_b32 s0, 0
	global_load_b64 v[8:9], v[0:1], off
	global_load_b64 v[2:3], v[6:7], off
.LBB0_10:                               ; %atomicrmw.start49
                                        ; =>This Inner Loop Header: Depth=1
	s_waitcnt vmcnt(0)
	v_add_f64 v[0:1], v[2:3], v[8:9]
	global_atomic_cmpswap_b64 v[0:1], v[6:7], v[0:3], off glc
	s_waitcnt vmcnt(0)
	v_cmp_eq_u64_e32 vcc_lo, v[0:1], v[2:3]
	v_dual_mov_b32 v3, v1 :: v_dual_mov_b32 v2, v0
	s_or_b32 s0, vcc_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s0
	s_cbranch_execnz .LBB0_10
; %bb.11:                               ; %atomicrmw.end48
	s_or_b32 exec_lo, exec_lo, s0
	v_lshlrev_b64 v[0:1], 2, v[4:5]
	v_mov_b32_e32 v2, 1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v0, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	global_atomic_add_u32 v[0:1], v2, off
.LBB0_12:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 328
		.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 18
		.amdhsa_next_free_sgpr 20
		.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	_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_, .Lfunc_end0-_Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 704
; NumSgprs: 22
; NumVgprs: 18
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 22
; NumVGPRsForWavesPerEU: 18
; Occupancy: 16
; WaveLimiterHint : 1
; 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
	.protected	_Z15update_clustersiiPdS_S_S_Pi ; -- Begin function _Z15update_clustersiiPdS_S_S_Pi
	.globl	_Z15update_clustersiiPdS_S_S_Pi
	.p2align	8
	.type	_Z15update_clustersiiPdS_S_S_Pi,@function
_Z15update_clustersiiPdS_S_S_Pi:        ; @_Z15update_clustersiiPdS_S_S_Pi
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x3c
	s_load_b32 s3, s[0:1], 0x4
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB1_3
; %bb.1:
	s_load_b64 s[2:3], s[0:1], 0x28
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v3, vcc_lo, s2, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s3, v4, vcc_lo
	global_load_b32 v0, v[3:4], off
	s_waitcnt vmcnt(0)
	v_cmp_ne_u32_e32 vcc_lo, 0, v0
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB1_3
; %bb.2:
	s_load_b256 s[4:11], s[0:1], 0x8
	v_lshlrev_b64 v[1:2], 3, v[1:2]
	v_cvt_f64_i32_e32 v[7:8], v0
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v3, vcc_lo, s8, v1
	v_add_co_ci_u32_e32 v4, vcc_lo, s9, v2, vcc_lo
	v_add_co_u32 v5, vcc_lo, s10, v1
	v_add_co_ci_u32_e32 v6, vcc_lo, s11, v2, vcc_lo
	global_load_b64 v[3:4], v[3:4], off
	global_load_b64 v[5:6], v[5:6], off
	s_waitcnt vmcnt(1)
	v_div_scale_f64 v[9:10], null, v[7:8], v[7:8], v[3:4]
	s_waitcnt vmcnt(0)
	v_div_scale_f64 v[11:12], null, v[7:8], v[7:8], v[5:6]
	v_div_scale_f64 v[21:22], vcc_lo, v[3:4], v[7:8], v[3:4]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_rcp_f64_e32 v[13:14], v[9:10]
	v_rcp_f64_e32 v[15:16], v[11:12]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[17:18], -v[9:10], v[13:14], 1.0
	v_fma_f64 v[19:20], -v[11:12], v[15:16], 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[13:14], v[13:14], v[17:18], v[13:14]
	v_fma_f64 v[15:16], v[15:16], v[19:20], v[15:16]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[17:18], -v[9:10], v[13:14], 1.0
	v_fma_f64 v[19:20], -v[11:12], v[15:16], 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_fma_f64 v[13:14], v[13:14], v[17:18], v[13:14]
	v_div_scale_f64 v[17:18], s0, v[5:6], v[7:8], v[5:6]
	v_fma_f64 v[15:16], v[15:16], v[19:20], v[15:16]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f64 v[19:20], v[21:22], v[13:14]
	v_mul_f64 v[23:24], v[17:18], v[15:16]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[9:10], -v[9:10], v[19:20], v[21:22]
	v_fma_f64 v[11:12], -v[11:12], v[23:24], v[17:18]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_fmas_f64 v[9:10], v[9:10], v[13:14], v[19:20]
	s_mov_b32 vcc_lo, s0
	v_div_fmas_f64 v[11:12], v[11:12], v[15:16], v[23:24]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fixup_f64 v[3:4], v[9:10], v[7:8], v[3:4]
	v_div_fixup_f64 v[5:6], v[11:12], v[7:8], v[5:6]
	v_add_co_u32 v7, vcc_lo, s4, v1
	v_add_co_ci_u32_e32 v8, vcc_lo, s5, v2, vcc_lo
	v_add_co_u32 v0, vcc_lo, s6, v1
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v2, vcc_lo
	global_store_b64 v[7:8], v[3:4], off
	global_store_b64 v[0:1], v[5:6], off
.LBB1_3:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15update_clustersiiPdS_S_S_Pi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 304
		.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 25
		.amdhsa_next_free_sgpr 16
		.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_end1:
	.size	_Z15update_clustersiiPdS_S_S_Pi, .Lfunc_end1-_Z15update_clustersiiPdS_S_S_Pi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 464
; NumSgprs: 18
; NumVgprs: 25
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 3
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 25
; 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
	.protected	_Z18zero_centroid_valsiPdS_Pi ; -- Begin function _Z18zero_centroid_valsiPdS_Pi
	.globl	_Z18zero_centroid_valsiPdS_Pi
	.p2align	8
	.type	_Z18zero_centroid_valsiPdS_Pi,@function
_Z18zero_centroid_valsiPdS_Pi:          ; @_Z18zero_centroid_valsiPdS_Pi
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b32 s3, s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB2_2
; %bb.1:
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x8
	s_load_b64 s[0:1], s[0:1], 0x18
	v_ashrrev_i32_e32 v2, 31, v1
	s_mov_b32 s2, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mov_b32 s3, s2
	v_dual_mov_b32 v9, 0 :: v_dual_mov_b32 v6, s3
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[3:4], 3, v[1:2]
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_mov_b32_e32 v5, s2
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v7, vcc_lo, s6, v3
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v8, vcc_lo, s7, v4, vcc_lo
	v_add_co_u32 v2, vcc_lo, s4, v3
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v4, vcc_lo
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b64 v[2:3], v[5:6], off
	global_store_b64 v[7:8], v[5:6], off
	global_store_b32 v[0:1], v9, off
.LBB2_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z18zero_centroid_valsiPdS_Pi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.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 10
		.amdhsa_next_free_sgpr 16
		.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_end2:
	.size	_Z18zero_centroid_valsiPdS_Pi, .Lfunc_end2-_Z18zero_centroid_valsiPdS_Pi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 208
; NumSgprs: 18
; NumVgprs: 10
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 10
; 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
	.protected	assignment_changed.managed ; @assignment_changed.managed
	.type	assignment_changed.managed,@object
	.section	.bss,"aw",@nobits
	.globl	assignment_changed.managed
	.p2align	2, 0x0
assignment_changed.managed:
	.long	0                               ; 0x0
	.size	assignment_changed.managed, 4

	.protected	assignment_changed      ; @assignment_changed
	.type	assignment_changed,@object
	.globl	assignment_changed
	.p2align	3, 0x0
assignment_changed:
	.quad	0
	.size	assignment_changed, 8

	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.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 assignment_changed.managed
	.addrsig_sym assignment_changed
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .offset:         4
        .size:           4
        .value_kind:     by_value
      - .actual_access:  read_only
        .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .actual_access:  read_only
        .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .actual_access:  read_only
        .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .actual_access:  read_only
        .address_space:  global
        .offset:         40
        .size:           8
        .value_kind:     global_buffer
      - .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
      - .offset:         72
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         76
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         80
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         84
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         86
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         88
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         90
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         92
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         94
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         112
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         120
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         128
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         136
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 328
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_
    .private_segment_fixed_size: 0
    .sgpr_count:     22
    .sgpr_spill_count: 0
    .symbol:         _Z15assign_clustersiiPKdS0_PiPdS2_S1_S2_S2_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     18
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .offset:         4
        .size:           4
        .value_kind:     by_value
      - .actual_access:  write_only
        .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .actual_access:  write_only
        .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .actual_access:  read_only
        .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .actual_access:  read_only
        .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .actual_access:  read_only
        .address_space:  global
        .offset:         40
        .size:           8
        .value_kind:     global_buffer
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         52
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         56
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         60
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         62
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         64
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         66
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         68
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         70
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         112
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 304
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z15update_clustersiiPdS_S_S_Pi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z15update_clustersiiPdS_S_S_Pi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     25
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .actual_access:  write_only
        .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .actual_access:  write_only
        .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .actual_access:  write_only
        .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z18zero_centroid_valsiPdS_Pi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z18zero_centroid_valsiPdS_Pi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     10
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
