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

#include <cuda.h>
#include <curand.h>

typedef struct group {
    // array of pointer of points
    int *p;

    // how many points in the group
    unsigned int length;
}Group;

typedef struct cluster {
    // array of pointer of groups
    Group** g;
    int num_point;
}Cluster;
int N;
int blockNum;

/*
 funct: create group and allocate the memory it needs
 parms:
 id: the id of group

 return:
 a pointer of Group
 */
Group* Create_Group(unsigned int id){
    Group* g = (Group*) malloc(sizeof(Group));
    g->p = (int*) malloc(1 * sizeof(int));
    g->length = 1;
    g->p[0] = id;

    return g;
}


/*
 funct: create cluster and allocate the memory it needs
 parms:
 n: the amount of points

 return:
 a pointer of Cluster
 */
Cluster* Create_Cluster(unsigned int n){
    Cluster* c = (Cluster*) malloc(sizeof(Cluster));
    c->g = (Group**) malloc(n * sizeof(Group*));

    c->num_point = n;

    int i;
    for(i = 0; i < n; ++i){
        c->g[i] = Create_Group(i);
    }

    return c;
}


/*
 funct: merge two groups
 parms:
 self: the group that absorb the other group
 other: the group that is going to be absorbed
 return:
 none
 */
void Merge_Group(Group* self, Group* other){
    unsigned int insert_position = self->length;
    self->length += other->length;
    self->p = (int*) realloc(self->p, self->length * sizeof(int));

    int i;
    for(i = 0; i < other->length; ++i){
        self->p[insert_position + i] = other->p[i];
    }

    free(other->p);
    free(other);
}

/*
 funct: merge two group in the cluster given by two group id
 parms:
 c: the cluster
 g1: group id of the group that will absorb the other group
 g2: group id of the group that will be absorbed
 return:
 none
 */
void Merge(Cluster* c, unsigned int g1, unsigned int g2){
    Merge_Group(c->g[g1], c->g[g2]);
    c->g[g2] = NULL;
}

// CUDA
#define BLOCK_SIZE 1024

__constant__ int Num;

float *adj, *hadj;
int length;
int *gids, *rgids, *hgids;

int *gab, *hgab;


__device__ int index(const int i, const int j) {return (2*Num-i-1)*i/2+j-i-1;}
int hindex(const int i, const int j) {return (2*N-i-1)*i/2+j-i-1;}

void ShowAdj(const float* adj) {
    printf("============Adj============\n");
    for (int i = 0; i < N-1; i++) {
        for (int j = i+1; j < N; j++) {
            printf("%.4lf ", hadj[hindex(i, j)]);
        }
        printf("\n");
    }
    printf("===========================\n");
}

void ShowCluster(const Cluster* c, const int* gids) {
    printf("==========Cluster==========\n");
    printf("Groups=%d\n", length);
    for (int g = 0; g < length; g++) {
        int gid = hgids[g];
        printf("[");
        for (int i = 0; i < c->g[gid]->length; i++) {
            if (i) printf(" ");
            printf("%d", c->g[gid]->p[i]);
        }
        printf("]\n");
    }
    printf("===========================\n");
}

void Clear(Cluster* c){
    int i;
    for(i = 0; i < c->num_point; ++i){
        if(c->g[i] == NULL){
            continue;
        }
        else{
            free(c->g[i]->p);
            free(c->g[i]);
        }
    }

    cudaFree(gab);
    cudaFree(adj);
    cudaFree(gids);
    free(rgids);
    free(hgids);
    free(hgab);
    free(hadj);
}

void CheckError(const char name[]) {
    printf("%s\n", name);
    cudaError_t err = cudaGetLastError();
    if (err != cudaSuccess)
        printf("Error: %s\n", cudaGetErrorString(err));
}

double randn() {
    int sign = (rand()%10)>5?1:-1;
    return rand()%10000000/(double)10000000.*sign;
}

double matmul(double input1[], double input2[], int dim) {
    double dis = 0;
    for (int i=0; i<dim; i++) {
        dis += input1[i] * input2[i];
    }
    return dis;
}

__global__ void Update(float *adj, int *gids, int *gab, int length) {
    int idx = blockIdx.x * BLOCK_SIZE + threadIdx.x;
    if (idx >= length) return;
    int gid = gids[idx], ga = gab[0], gb = gab[1];
    if (gid < ga) {
        // printf("Update adj(%d, %d)\n", gid, ga);
        adj[index(gid, ga)] = max(adj[index(gid, ga)], adj[index(gid, gb)]);
    }
    else if (gid > ga && gid != gb) {
        // printf("Update adj(%d, %d)\n", gid, ga);
        int ra = min(gb, gid), rb = max(gb, gid);
        adj[index(ga, gid)] = max(adj[index(ga, gid)], adj[index(ra, rb)]);
    }
}

void Clusting() {
    double mind = 9999;
    for (int i = 0; i < length-1; i++) {
        for (int j = i+1; j < length; j++) {
            int gi = hgids[i], gj = hgids[j];
            double gd = hadj[hindex(gi, gj)];
            if (gd < mind) {
                mind = gd;
                hgab[0] = gi;
                hgab[1] = gj;
            }
        }
    }

    cudaMemcpy(gab, hgab, 2*sizeof(int), cudaMemcpyHostToDevice);
    cudaMemcpy(gids, hgids, N*sizeof(int), cudaMemcpyHostToDevice);
    // printf("Merge %d %d\n", hgab[0], hgab[1]);


    int BN = length/BLOCK_SIZE;
    if (length % BLOCK_SIZE) BN += 1;
    dim3 blockNum(BN);
    Update<<<blockNum, BLOCK_SIZE>>>(adj, gids, gab, length);
    // CheckError("update");
    cudaDeviceSynchronize();
    // printf("Check U\n");
    cudaMemcpy(hadj, adj, N*(N-1)/2*sizeof(float), cudaMemcpyDeviceToHost);

    hgids[rgids[hgab[1]]] = hgids[length-1];
    rgids[hgids[length-1]] = rgids[hgab[1]];
    length -= 1;
}

int main(int argc, char *argv[]){
    curandGenerator_t gen;
    curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT);
    curandSetPseudoRandomGeneratorSeed(gen, 1234ULL);
    N = atoi(argv[1]);
    cudaMemcpyToSymbol(Num, &N, sizeof(int));

    /*
     adjacent list, which store the distance
     ex. adj[0][1] is the distance between point 0 and point 1
     */
    cudaMalloc((void**) &adj, N*(N-1)/2*sizeof(float));
    curandGenerateUniform(gen, adj, N*(N-1)/2);
    cudaMalloc((void**) &gids, N*sizeof(int));
    cudaMalloc((void**) &gab, 2*sizeof(int));
    hadj = (float*) malloc(N*(N-1)/2*sizeof(float));
    cudaMemcpy(hadj, adj, N*(N-1)/2*sizeof(float), cudaMemcpyDeviceToHost);
    rgids = (int*) malloc(N*sizeof(int));
    hgids = (int*) malloc(N*sizeof(int));
    hgab = (int*) malloc(2*sizeof(int));
    length = N;

    for (int i=0; i<N; ++i) {
      hgids[i] = i;
      rgids[i] = i;
    }

    Cluster *cluster = Create_Cluster(N);
    // ShowAdj(adj);
    // ShowCluster(cluster, gids);

    int cluster_size=1;
    while (length > cluster_size) {
        Clusting();

        Merge(cluster, hgab[0], hgab[1]);
        // ShowAdj(adj);
        // ShowCluster(cluster, gids);
    }

    // ShowCluster(cluster, gids);
    curandDestroyGenerator(gen);
    Clear(cluster);
}

	.file	"tmpxft_0026124c_00000000-6_cluster.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2043:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2043:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z12Create_Groupj
	.type	_Z12Create_Groupj, @function
_Z12Create_Groupj:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%edi, %ebp
	movl	$16, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	pushq	%rax
	.cfi_def_cfa_offset 32
	call	malloc@PLT
	movl	$4, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	movl	$1, 8(%rbx)
	movq	%rax, (%rbx)
	movl	%ebp, (%rax)
	movq	%rbx, %rax
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z12Create_Groupj, .-_Z12Create_Groupj
	.globl	_Z14Create_Clusterj
	.type	_Z14Create_Clusterj, @function
_Z14Create_Clusterj:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%edi, %r13d
	movl	$16, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	pushq	%rcx
	.cfi_def_cfa_offset 48
	call	malloc@PLT
	leaq	0(,%r13,8), %rdi
	movq	%rax, %rbx
	call	malloc@PLT
	movl	%r13d, 8(%rbx)
	movq	%rax, (%rbx)
	movq	%rax, %r12
.L5:
	movl	%ebp, %edi
	cmpq	%rbp, %r13
	je	.L9
	call	_Z12Create_Groupj
	movq	%rax, (%r12,%rbp,8)
	incq	%rbp
	jmp	.L5
.L9:
	popq	%rdx
	.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
.LFE2028:
	.size	_Z14Create_Clusterj, .-_Z14Create_Clusterj
	.globl	_Z11Merge_GroupP5groupS0_
	.type	_Z11Merge_GroupP5groupS0_, @function
_Z11Merge_GroupP5groupS0_:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	8(%rdi), %r12d
	movq	%rsi, %rbx
	movl	%r12d, %esi
	addl	8(%rbx), %esi
	movl	%esi, 8(%rdi)
	movq	(%rdi), %rdi
	salq	$2, %rsi
	call	realloc@PLT
	xorl	%edx, %edx
	movq	%rax, 0(%rbp)
	movq	(%rbx), %rdi
.L11:
	cmpl	8(%rbx), %edx
	jnb	.L14
	movl	(%rdi,%rdx,4), %esi
	leal	(%r12,%rdx), %ecx
	incq	%rdx
	movl	%esi, (%rax,%rcx,4)
	jmp	.L11
.L14:
	call	free@PLT
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	free@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z11Merge_GroupP5groupS0_, .-_Z11Merge_GroupP5groupS0_
	.globl	_Z5MergeP7clusterjj
	.type	_Z5MergeP7clusterjj, @function
_Z5MergeP7clusterjj:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%esi, %esi
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movl	%edx, %ebx
	pushq	%rax
	.cfi_def_cfa_offset 32
	movq	(%rdi), %rax
	movq	(%rax,%rbx,8), %rdx
	movq	(%rax,%rsi,8), %rdi
	movq	%rdx, %rsi
	call	_Z11Merge_GroupP5groupS0_
	movq	0(%rbp), %rax
	xorl	%edx, %edx
	movq	%rdx, (%rax,%rbx,8)
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z5MergeP7clusterjj, .-_Z5MergeP7clusterjj
	.globl	_Z5indexii
	.type	_Z5indexii, @function
_Z5indexii:
.LFB2031:
	.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
.LFE2031:
	.size	_Z5indexii, .-_Z5indexii
	.globl	_Z6hindexii
	.type	_Z6hindexii, @function
_Z6hindexii:
.LFB2032:
	.cfi_startproc
	endbr64
	movl	N(%rip), %edx
	movl	%edi, %eax
	movl	$2, %ecx
	notl	%eax
	leal	(%rax,%rdx,2), %eax
	imull	%edi, %eax
	cltd
	idivl	%ecx
	addl	%esi, %eax
	subl	%edi, %eax
	decl	%eax
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z6hindexii, .-_Z6hindexii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"============Adj============\n"
.LC1:
	.string	"%.4lf "
.LC2:
	.string	"\n"
.LC3:
	.string	"===========================\n"
	.text
	.globl	_Z7ShowAdjPKf
	.type	_Z7ShowAdjPKf, @function
_Z7ShowAdjPKf:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	leaq	.LC1(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 48
	call	__printf_chk@PLT
.L21:
	movl	N(%rip), %eax
	decl	%eax
	cmpl	%ebx, %eax
	jle	.L26
	leal	1(%rbx), %r13d
	movl	%r13d, %ebp
.L22:
	cmpl	%ebp, N(%rip)
	jle	.L27
	movl	%ebp, %esi
	movl	%ebx, %edi
	incl	%ebp
	call	_Z6hindexii
	movq	hadj(%rip), %rdx
	movq	%r12, %rsi
	movl	$2, %edi
	cltq
	cvtss2sd	(%rdx,%rax,4), %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	jmp	.L22
.L27:
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	movl	%r13d, %ebx
	call	__printf_chk@PLT
	jmp	.L21
.L26:
	popq	%rdx
	.cfi_def_cfa_offset 40
	leaq	.LC3(%rip), %rsi
	popq	%rbx
	.cfi_def_cfa_offset 32
	movl	$2, %edi
	popq	%rbp
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2033:
	.size	_Z7ShowAdjPKf, .-_Z7ShowAdjPKf
	.section	.rodata.str1.1
.LC4:
	.string	"==========Cluster==========\n"
.LC5:
	.string	"Groups=%d\n"
.LC6:
	.string	"["
.LC7:
	.string	" "
.LC8:
	.string	"%d"
.LC9:
	.string	"]\n"
	.text
	.globl	_Z11ShowClusterPK7clusterPKi
	.type	_Z11ShowClusterPK7clusterPKi, @function
_Z11ShowClusterPK7clusterPKi:
.LFB2034:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC6(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	movl	$2, %edi
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	pushq	%rcx
	.cfi_def_cfa_offset 64
	call	__printf_chk@PLT
	movl	length(%rip), %edx
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
.L29:
	cmpl	%r12d, length(%rip)
	jle	.L38
	movq	hgids(%rip), %rax
	movq	%r14, %rsi
	movl	$2, %edi
	xorl	%ebp, %ebp
	leaq	.LC7(%rip), %r15
	movslq	(%rax,%r12,4), %rbx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	salq	$3, %rbx
.L30:
	movq	0(%r13), %rax
	movq	(%rax,%rbx), %rax
	cmpl	8(%rax), %ebp
	jnb	.L39
	testq	%rbp, %rbp
	je	.L31
	movq	%r15, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L31:
	movq	0(%r13), %rax
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	movq	(%rax,%rbx), %rax
	movq	(%rax), %rax
	movl	(%rax,%rbp,4), %edx
	xorl	%eax, %eax
	incq	%rbp
	call	__printf_chk@PLT
	jmp	.L30
.L39:
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%r12
	call	__printf_chk@PLT
	jmp	.L29
.L38:
	popq	%rdx
	.cfi_def_cfa_offset 56
	leaq	.LC3(%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
.LFE2034:
	.size	_Z11ShowClusterPK7clusterPKi, .-_Z11ShowClusterPK7clusterPKi
	.globl	_Z5ClearP7cluster
	.type	_Z5ClearP7cluster, @function
_Z5ClearP7cluster:
.LFB2035:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	xorl	%ebx, %ebx
	pushq	%rdx
	.cfi_def_cfa_offset 32
.L41:
	cmpl	%ebx, 8(%rbp)
	jle	.L48
	movq	0(%rbp), %rax
	movq	(%rax,%rbx,8), %rax
	testq	%rax, %rax
	je	.L42
	movq	(%rax), %rdi
	call	free@PLT
	movq	0(%rbp), %rax
	movq	(%rax,%rbx,8), %rdi
	call	free@PLT
.L42:
	incq	%rbx
	jmp	.L41
.L48:
	movq	gab(%rip), %rdi
	call	cudaFree@PLT
	movq	adj(%rip), %rdi
	call	cudaFree@PLT
	movq	gids(%rip), %rdi
	call	cudaFree@PLT
	movq	rgids(%rip), %rdi
	call	free@PLT
	movq	hgids(%rip), %rdi
	call	free@PLT
	movq	hgab(%rip), %rdi
	call	free@PLT
	movq	hadj(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	free@PLT
	.cfi_endproc
.LFE2035:
	.size	_Z5ClearP7cluster, .-_Z5ClearP7cluster
	.section	.rodata.str1.1
.LC10:
	.string	"%s\n"
.LC11:
	.string	"Error: %s\n"
	.text
	.globl	_Z10CheckErrorPKc
	.type	_Z10CheckErrorPKc, @function
_Z10CheckErrorPKc:
.LFB2036:
	.cfi_startproc
	endbr64
	pushq	%rsi
	.cfi_def_cfa_offset 16
	movq	%rdi, %rdx
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L49
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	popq	%rcx
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	movq	%rax, %rdx
	xorl	%eax, %eax
	jmp	__printf_chk@PLT
.L49:
	.cfi_restore_state
	popq	%rax
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2036:
	.size	_Z10CheckErrorPKc, .-_Z10CheckErrorPKc
	.globl	_Z5randnv
	.type	_Z5randnv, @function
_Z5randnv:
.LFB2037:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	xorl	%ebx, %ebx
	call	rand@PLT
	movl	$10, %ecx
	cltd
	idivl	%ecx
	cmpl	$6, %edx
	setge	%bl
	call	rand@PLT
	movl	$10000000, %ecx
	leal	-1(%rbx,%rbx), %ebx
	cltd
	cvtsi2sdl	%ebx, %xmm1
	popq	%rbx
	.cfi_def_cfa_offset 8
	idivl	%ecx
	cvtsi2sdl	%edx, %xmm0
	divsd	.LC12(%rip), %xmm0
	mulsd	%xmm1, %xmm0
	ret
	.cfi_endproc
.LFE2037:
	.size	_Z5randnv, .-_Z5randnv
	.globl	_Z6matmulPdS_i
	.type	_Z6matmulPdS_i, @function
_Z6matmulPdS_i:
.LFB2038:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
.L57:
	cmpl	%eax, %edx
	jle	.L59
	movsd	(%rdi,%rax,8), %xmm1
	mulsd	(%rsi,%rax,8), %xmm1
	incq	%rax
	addsd	%xmm1, %xmm0
	jmp	.L57
.L59:
	ret
	.cfi_endproc
.LFE2038:
	.size	_Z6matmulPdS_i, .-_Z6matmulPdS_i
	.globl	_Z31__device_stub__Z6UpdatePfPiS0_iPfPiS0_i
	.type	_Z31__device_stub__Z6UpdatePfPiS0_iPfPiS0_i, @function
_Z31__device_stub__Z6UpdatePfPiS0_iPfPiS0_i:
.LFB2065:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L60
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z6UpdatePfPiS0_i(%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
.L60:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L62
	call	__stack_chk_fail@PLT
.L62:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2065:
	.size	_Z31__device_stub__Z6UpdatePfPiS0_iPfPiS0_i, .-_Z31__device_stub__Z6UpdatePfPiS0_iPfPiS0_i
	.globl	_Z6UpdatePfPiS0_i
	.type	_Z6UpdatePfPiS0_i, @function
_Z6UpdatePfPiS0_i:
.LFB2066:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z6UpdatePfPiS0_iPfPiS0_i
	.cfi_endproc
.LFE2066:
	.size	_Z6UpdatePfPiS0_i, .-_Z6UpdatePfPiS0_i
	.globl	_Z8Clustingv
	.type	_Z8Clustingv, @function
_Z8Clustingv:
.LFB2039:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	$1, %r8d
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	movq	hgids(%rip), %r11
	movq	hadj(%rip), %rbx
	movq	hgab(%rip), %r10
	movsd	.LC14(%rip), %xmm0
.L66:
	movl	length(%rip), %eax
	leal	-1(%r8), %edx
	decl	%eax
	cmpl	%edx, %eax
	jle	.L78
	movq	%r8, %r9
.L70:
	cmpl	%r9d, length(%rip)
	jle	.L79
	movl	-4(%r11,%r8,4), %edi
	movl	(%r11,%r9,4), %esi
	call	_Z6hindexii
	cltq
	cvtss2sd	(%rbx,%rax,4), %xmm1
	comisd	%xmm1, %xmm0
	jbe	.L67
	movl	%edi, (%r10)
	movaps	%xmm1, %xmm0
	movl	%esi, 4(%r10)
.L67:
	incq	%r9
	jmp	.L70
.L79:
	incq	%r8
	jmp	.L66
.L78:
	movq	gab(%rip), %rdi
	movq	%r10, %rsi
	movl	$1, %ecx
	movl	$8, %edx
	call	cudaMemcpy@PLT
	movslq	N(%rip), %rdx
	movl	$1, %ecx
	movq	hgids(%rip), %rsi
	movq	gids(%rip), %rdi
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	length(%rip), %eax
	movl	$1024, %ecx
	movl	$1, 28(%rsp)
	cltd
	idivl	%ecx
	movl	length(%rip), %edx
	andl	$1023, %edx
	movl	$1, %ecx
	cmpl	$1, %edx
	movl	$4194305, %edx
	sbbl	$-1, %eax
	salq	$10, %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	%eax, 8(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 12(%rsp)
	movq	8(%rsp), %rdi
	movl	16(%rsp), %esi
	movq	%rdx, 20(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L72
	movl	length(%rip), %ecx
	movq	gab(%rip), %rdx
	movq	gids(%rip), %rsi
	movq	adj(%rip), %rdi
	call	_Z31__device_stub__Z6UpdatePfPiS0_iPfPiS0_i
.L72:
	call	cudaDeviceSynchronize@PLT
	movl	N(%rip), %edx
	movl	$2, %ecx
	movq	adj(%rip), %rsi
	movq	hadj(%rip), %rdi
	leal	-1(%rdx), %eax
	imull	%edx, %eax
	cltd
	idivl	%ecx
	cltq
	leaq	0(,%rax,4), %rdx
	call	cudaMemcpy@PLT
	movslq	length(%rip), %rsi
	movq	hgids(%rip), %rdx
	movq	hgab(%rip), %rcx
	movq	rgids(%rip), %rax
	movl	-4(%rdx,%rsi,4), %edi
	movslq	4(%rcx), %rsi
	movslq	(%rax,%rsi,4), %rsi
	movl	%edi, (%rdx,%rsi,4)
	movslq	length(%rip), %rsi
	movslq	4(%rcx), %rcx
	movslq	-4(%rdx,%rsi,4), %rdx
	movl	(%rax,%rcx,4), %ecx
	movl	%ecx, (%rax,%rdx,4)
	decl	length(%rip)
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2039:
	.size	_Z8Clustingv, .-_Z8Clustingv
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2040:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rsi, %rbx
	movl	$100, %esi
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	call	curandCreateGenerator@PLT
	movq	(%rsp), %rdi
	movl	$1234, %esi
	call	curandSetPseudoRandomGeneratorSeed@PLT
	movq	8(%rbx), %rdi
	movl	$2, %ebx
	call	atoi@PLT
	movl	$1, %r8d
	xorl	%ecx, %ecx
	movl	$4, %edx
	leaq	N(%rip), %rsi
	leaq	_ZL3Num(%rip), %rdi
	movl	%eax, N(%rip)
	call	cudaMemcpyToSymbol@PLT
	movl	N(%rip), %edx
	leaq	adj(%rip), %rdi
	leal	-1(%rdx), %eax
	imull	%edx, %eax
	cltd
	idivl	%ebx
	cltq
	leaq	0(,%rax,4), %rsi
	call	cudaMalloc@PLT
	movl	N(%rip), %edx
	movq	adj(%rip), %rsi
	movq	(%rsp), %rdi
	leal	-1(%rdx), %eax
	imull	%edx, %eax
	cltd
	idivl	%ebx
	movslq	%eax, %rdx
	call	curandGenerateUniform@PLT
	movslq	N(%rip), %rsi
	leaq	gids(%rip), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	$8, %esi
	leaq	gab(%rip), %rdi
	call	cudaMalloc@PLT
	movl	N(%rip), %edx
	leal	-1(%rdx), %eax
	imull	%edx, %eax
	cltd
	idivl	%ebx
	cltq
	leaq	0(,%rax,4), %rbx
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	adj(%rip), %rsi
	movq	%rbx, %rdx
	movl	$2, %ecx
	movq	%rax, %rdi
	movq	%rax, hadj(%rip)
	call	cudaMemcpy@PLT
	movslq	N(%rip), %r12
	movq	%r12, %rbx
	salq	$2, %r12
	movq	%r12, %rdi
	call	malloc@PLT
	movq	%r12, %rdi
	movq	%rax, rgids(%rip)
	movq	%rax, %rbp
	call	malloc@PLT
	movl	$8, %edi
	movq	%rax, hgids(%rip)
	movq	%rax, %r12
	call	malloc@PLT
	movl	%ebx, length(%rip)
	xorl	%edx, %edx
	movq	%rax, hgab(%rip)
.L81:
	cmpl	%edx, %ebx
	jle	.L87
	movl	%edx, (%r12,%rdx,4)
	movl	%edx, 0(%rbp,%rdx,4)
	incq	%rdx
	jmp	.L81
.L87:
	movl	%ebx, %edi
	call	_Z14Create_Clusterj
	movq	%rax, %rbx
.L83:
	cmpl	$1, length(%rip)
	jle	.L88
	call	_Z8Clustingv
	movq	hgab(%rip), %rax
	movq	%rbx, %rdi
	movl	4(%rax), %edx
	movl	(%rax), %esi
	call	_Z5MergeP7clusterjj
	jmp	.L83
.L88:
	movq	(%rsp), %rdi
	call	curandDestroyGenerator@PLT
	movq	%rbx, %rdi
	call	_Z5ClearP7cluster
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L85
	call	__stack_chk_fail@PLT
.L85:
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2040:
	.size	main, .-main
	.section	.rodata.str1.1
.LC15:
	.string	"_Z6UpdatePfPiS0_i"
.LC16:
	.string	"Num"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2068:
	.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	.LC15(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z6UpdatePfPiS0_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	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	.LC16(%rip), %rdx
	movl	$4, %r9d
	leaq	_ZL3Num(%rip), %rsi
	pushq	$1
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@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
.LFE2068:
	.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
	.globl	hgab
	.bss
	.align 8
	.type	hgab, @object
	.size	hgab, 8
hgab:
	.zero	8
	.globl	gab
	.align 8
	.type	gab, @object
	.size	gab, 8
gab:
	.zero	8
	.globl	hgids
	.align 8
	.type	hgids, @object
	.size	hgids, 8
hgids:
	.zero	8
	.globl	rgids
	.align 8
	.type	rgids, @object
	.size	rgids, 8
rgids:
	.zero	8
	.globl	gids
	.align 8
	.type	gids, @object
	.size	gids, 8
gids:
	.zero	8
	.globl	length
	.align 4
	.type	length, @object
	.size	length, 4
length:
	.zero	4
	.globl	hadj
	.align 8
	.type	hadj, @object
	.size	hadj, 8
hadj:
	.zero	8
	.globl	adj
	.align 8
	.type	adj, @object
	.size	adj, 8
adj:
	.zero	8
	.local	_ZL3Num
	.comm	_ZL3Num,4,4
	.globl	blockNum
	.align 4
	.type	blockNum, @object
	.size	blockNum, 4
blockNum:
	.zero	4
	.globl	N
	.align 4
	.type	N, @object
	.size	N, 4
N:
	.zero	4
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC12:
	.long	0
	.long	1097011920
	.align 8
.LC14:
	.long	0
	.long	1086556032
	.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 <stdio.h>
#include <stdlib.h>

#include <hip/hip_runtime.h>
#include <hiprand/hiprand.h>

typedef struct group {
    // array of pointer of points
    int *p;

    // how many points in the group
    unsigned int length;
}Group;

typedef struct cluster {
    // array of pointer of groups
    Group** g;
    int num_point;
}Cluster;
int N;
int blockNum;

/*
 funct: create group and allocate the memory it needs
 parms:
 id: the id of group

 return:
 a pointer of Group
 */
Group* Create_Group(unsigned int id){
    Group* g = (Group*) malloc(sizeof(Group));
    g->p = (int*) malloc(1 * sizeof(int));
    g->length = 1;
    g->p[0] = id;

    return g;
}


/*
 funct: create cluster and allocate the memory it needs
 parms:
 n: the amount of points

 return:
 a pointer of Cluster
 */
Cluster* Create_Cluster(unsigned int n){
    Cluster* c = (Cluster*) malloc(sizeof(Cluster));
    c->g = (Group**) malloc(n * sizeof(Group*));

    c->num_point = n;

    int i;
    for(i = 0; i < n; ++i){
        c->g[i] = Create_Group(i);
    }

    return c;
}


/*
 funct: merge two groups
 parms:
 self: the group that absorb the other group
 other: the group that is going to be absorbed
 return:
 none
 */
void Merge_Group(Group* self, Group* other){
    unsigned int insert_position = self->length;
    self->length += other->length;
    self->p = (int*) realloc(self->p, self->length * sizeof(int));

    int i;
    for(i = 0; i < other->length; ++i){
        self->p[insert_position + i] = other->p[i];
    }

    free(other->p);
    free(other);
}

/*
 funct: merge two group in the cluster given by two group id
 parms:
 c: the cluster
 g1: group id of the group that will absorb the other group
 g2: group id of the group that will be absorbed
 return:
 none
 */
void Merge(Cluster* c, unsigned int g1, unsigned int g2){
    Merge_Group(c->g[g1], c->g[g2]);
    c->g[g2] = NULL;
}

// CUDA
#define BLOCK_SIZE 1024

__constant__ int Num;

float *adj, *hadj;
int length;
int *gids, *rgids, *hgids;

int *gab, *hgab;


__device__ int index(const int i, const int j) {return (2*Num-i-1)*i/2+j-i-1;}
int hindex(const int i, const int j) {return (2*N-i-1)*i/2+j-i-1;}

void ShowAdj(const float* adj) {
    printf("============Adj============\n");
    for (int i = 0; i < N-1; i++) {
        for (int j = i+1; j < N; j++) {
            printf("%.4lf ", hadj[hindex(i, j)]);
        }
        printf("\n");
    }
    printf("===========================\n");
}

void ShowCluster(const Cluster* c, const int* gids) {
    printf("==========Cluster==========\n");
    printf("Groups=%d\n", length);
    for (int g = 0; g < length; g++) {
        int gid = hgids[g];
        printf("[");
        for (int i = 0; i < c->g[gid]->length; i++) {
            if (i) printf(" ");
            printf("%d", c->g[gid]->p[i]);
        }
        printf("]\n");
    }
    printf("===========================\n");
}

void Clear(Cluster* c){
    int i;
    for(i = 0; i < c->num_point; ++i){
        if(c->g[i] == NULL){
            continue;
        }
        else{
            free(c->g[i]->p);
            free(c->g[i]);
        }
    }

    hipFree(gab);
    hipFree(adj);
    hipFree(gids);
    free(rgids);
    free(hgids);
    free(hgab);
    free(hadj);
}

void CheckError(const char name[]) {
    printf("%s\n", name);
    hipError_t err = hipGetLastError();
    if (err != hipSuccess)
        printf("Error: %s\n", hipGetErrorString(err));
}

double randn() {
    int sign = (rand()%10)>5?1:-1;
    return rand()%10000000/(double)10000000.*sign;
}

double matmul(double input1[], double input2[], int dim) {
    double dis = 0;
    for (int i=0; i<dim; i++) {
        dis += input1[i] * input2[i];
    }
    return dis;
}

__global__ void Update(float *adj, int *gids, int *gab, int length) {
    int idx = blockIdx.x * BLOCK_SIZE + threadIdx.x;
    if (idx >= length) return;
    int gid = gids[idx], ga = gab[0], gb = gab[1];
    if (gid < ga) {
        // printf("Update adj(%d, %d)\n", gid, ga);
        adj[index(gid, ga)] = max(adj[index(gid, ga)], adj[index(gid, gb)]);
    }
    else if (gid > ga && gid != gb) {
        // printf("Update adj(%d, %d)\n", gid, ga);
        int ra = min(gb, gid), rb = max(gb, gid);
        adj[index(ga, gid)] = max(adj[index(ga, gid)], adj[index(ra, rb)]);
    }
}

void Clusting() {
    double mind = 9999;
    for (int i = 0; i < length-1; i++) {
        for (int j = i+1; j < length; j++) {
            int gi = hgids[i], gj = hgids[j];
            double gd = hadj[hindex(gi, gj)];
            if (gd < mind) {
                mind = gd;
                hgab[0] = gi;
                hgab[1] = gj;
            }
        }
    }

    hipMemcpy(gab, hgab, 2*sizeof(int), hipMemcpyHostToDevice);
    hipMemcpy(gids, hgids, N*sizeof(int), hipMemcpyHostToDevice);
    // printf("Merge %d %d\n", hgab[0], hgab[1]);


    int BN = length/BLOCK_SIZE;
    if (length % BLOCK_SIZE) BN += 1;
    dim3 blockNum(BN);
    Update<<<blockNum, BLOCK_SIZE>>>(adj, gids, gab, length);
    // CheckError("update");
    hipDeviceSynchronize();
    // printf("Check U\n");
    hipMemcpy(hadj, adj, N*(N-1)/2*sizeof(float), hipMemcpyDeviceToHost);

    hgids[rgids[hgab[1]]] = hgids[length-1];
    rgids[hgids[length-1]] = rgids[hgab[1]];
    length -= 1;
}

int main(int argc, char *argv[]){
    hiprandGenerator_t gen;
    hiprandCreateGenerator(&gen, HIPRAND_RNG_PSEUDO_DEFAULT);
    hiprandSetPseudoRandomGeneratorSeed(gen, 1234ULL);
    N = atoi(argv[1]);
    hipMemcpyToSymbol(HIP_SYMBOL(Num), &N, sizeof(int));

    /*
     adjacent list, which store the distance
     ex. adj[0][1] is the distance between point 0 and point 1
     */
    hipMalloc((void**) &adj, N*(N-1)/2*sizeof(float));
    hiprandGenerateUniform(gen, adj, N*(N-1)/2);
    hipMalloc((void**) &gids, N*sizeof(int));
    hipMalloc((void**) &gab, 2*sizeof(int));
    hadj = (float*) malloc(N*(N-1)/2*sizeof(float));
    hipMemcpy(hadj, adj, N*(N-1)/2*sizeof(float), hipMemcpyDeviceToHost);
    rgids = (int*) malloc(N*sizeof(int));
    hgids = (int*) malloc(N*sizeof(int));
    hgab = (int*) malloc(2*sizeof(int));
    length = N;

    for (int i=0; i<N; ++i) {
      hgids[i] = i;
      rgids[i] = i;
    }

    Cluster *cluster = Create_Cluster(N);
    // ShowAdj(adj);
    // ShowCluster(cluster, gids);

    int cluster_size=1;
    while (length > cluster_size) {
        Clusting();

        Merge(cluster, hgab[0], hgab[1]);
        // ShowAdj(adj);
        // ShowCluster(cluster, gids);
    }

    // ShowCluster(cluster, gids);
    hiprandDestroyGenerator(gen);
    Clear(cluster);
}

	.text
	.file	"cluster.hip"
	.globl	_Z12Create_Groupj               # -- Begin function _Z12Create_Groupj
	.type	_Z12Create_Groupj,@function
_Z12Create_Groupj:                      # @_Z12Create_Groupj
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	%edi, %ebx
	movl	$16, %edi
	callq	malloc
	movq	%rax, %r14
	movl	$4, %edi
	callq	malloc
	movq	%rax, (%r14)
	movl	$1, 8(%r14)
	movl	%ebx, (%rax)
	movq	%r14, %rax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z12Create_Groupj, .Lfunc_end0-_Z12Create_Groupj
	.cfi_endproc
                                        # -- End function
	.globl	_Z14Create_Clusterj             # -- Begin function _Z14Create_Clusterj
	.type	_Z14Create_Clusterj,@function
_Z14Create_Clusterj:                    # @_Z14Create_Clusterj
	.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
	movl	%edi, %ebp
	movl	$16, %edi
	callq	malloc
	movq	%rax, %rbx
	movl	%ebp, %r12d
	leaq	(,%r12,8), %rdi
	callq	malloc
	movq	%rax, (%rbx)
	movl	%ebp, 8(%rbx)
	testl	%ebp, %ebp
	je	.LBB1_3
# %bb.1:                                # %.lr.ph.preheader
	movq	%rax, %r14
	xorl	%r13d, %r13d
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$16, %edi
	callq	malloc
	movq	%rax, %r15
	movl	$4, %edi
	callq	malloc
	movq	%rax, (%r15)
	movl	$1, 8(%r15)
	movl	%r13d, (%rax)
	movq	%r15, (%r14,%r13,8)
	incq	%r13
	cmpq	%r13, %r12
	jne	.LBB1_2
.LBB1_3:                                # %._crit_edge
	movq	%rbx, %rax
	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_end1:
	.size	_Z14Create_Clusterj, .Lfunc_end1-_Z14Create_Clusterj
	.cfi_endproc
                                        # -- End function
	.globl	_Z11Merge_GroupP5groupS0_       # -- Begin function _Z11Merge_GroupP5groupS0_
	.type	_Z11Merge_GroupP5groupS0_,@function
_Z11Merge_GroupP5groupS0_:              # @_Z11Merge_GroupP5groupS0_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movl	8(%rdi), %r15d
	movl	8(%rsi), %esi
	addl	%r15d, %esi
	movl	%esi, 8(%rdi)
	movq	(%rdi), %rdi
	shlq	$2, %rsi
	callq	realloc
	movq	%rax, (%r14)
	movl	8(%rbx), %ecx
	movq	(%rbx), %rdi
	testq	%rcx, %rcx
	je	.LBB2_3
# %bb.1:                                # %.lr.ph
	xorl	%edx, %edx
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
	movl	(%rdi,%rdx,4), %esi
	leal	(%r15,%rdx), %r8d
	movl	%esi, (%rax,%r8,4)
	incq	%rdx
	cmpq	%rdx, %rcx
	jne	.LBB2_2
.LBB2_3:                                # %._crit_edge
	callq	free
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	free                            # TAILCALL
.Lfunc_end2:
	.size	_Z11Merge_GroupP5groupS0_, .Lfunc_end2-_Z11Merge_GroupP5groupS0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z5MergeP7clusterjj             # -- Begin function _Z5MergeP7clusterjj
	.type	_Z5MergeP7clusterjj,@function
_Z5MergeP7clusterjj:                    # @_Z5MergeP7clusterjj
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %rbx
	movq	(%rdi), %rax
	movl	%esi, %ecx
	movq	(%rax,%rcx,8), %rdi
	movl	%edx, %r14d
	movq	(%rax,%r14,8), %rsi
	callq	_Z11Merge_GroupP5groupS0_
	movq	(%rbx), %rax
	movq	$0, (%rax,%r14,8)
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z5MergeP7clusterjj, .Lfunc_end3-_Z5MergeP7clusterjj
	.cfi_endproc
                                        # -- End function
	.globl	_Z6hindexii                     # -- Begin function _Z6hindexii
	.type	_Z6hindexii,@function
_Z6hindexii:                            # @_Z6hindexii
	.cfi_startproc
# %bb.0:
	movl	N(%rip), %ecx
	movl	%edi, %eax
	notl	%eax
	leal	(%rax,%rcx,2), %ecx
	imull	%edi, %ecx
	movl	%ecx, %edx
	shrl	$31, %edx
	addl	%ecx, %edx
	sarl	%edx
	addl	%esi, %eax
	addl	%edx, %eax
                                        # kill: def $eax killed $eax killed $rax
	retq
.Lfunc_end4:
	.size	_Z6hindexii, .Lfunc_end4-_Z6hindexii
	.cfi_endproc
                                        # -- End function
	.globl	_Z7ShowAdjPKf                   # -- Begin function _Z7ShowAdjPKf
	.type	_Z7ShowAdjPKf,@function
_Z7ShowAdjPKf:                          # @_Z7ShowAdjPKf
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	N(%rip), %eax
	cmpl	$2, %eax
	jl	.LBB5_6
# %bb.1:                                # %.lr.ph12.preheader
	xorl	%r14d, %r14d
	movl	$1, %ebx
.LBB5_2:                                # %.lr.ph12
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_4 Depth 2
	leal	1(%r14), %ebp
	cmpl	%eax, %ebp
	jge	.LBB5_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB5_2 Depth=1
	movl	%r14d, %r15d
	notl	%r15d
	xorl	%r12d, %r12d
.LBB5_4:                                #   Parent Loop BB5_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	hadj(%rip), %rcx
	leal	(%r15,%rax,2), %eax
	imull	%r14d, %eax
	movl	%eax, %edx
	shrl	$31, %edx
	addl	%eax, %edx
	sarl	%edx
	addl	%r12d, %edx
	movslq	%edx, %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rcx,%rax,4), %xmm0
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	movl	N(%rip), %eax
	leal	(%rbx,%r12), %ecx
	incl	%ecx
	movl	%r12d, %edx
	incl	%edx
	movl	%edx, %r12d
	cmpl	%eax, %ecx
	jl	.LBB5_4
.LBB5_5:                                # %._crit_edge
                                        #   in Loop: Header=BB5_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	movl	N(%rip), %eax
	leal	-1(%rax), %ecx
	incl	%ebx
	movl	%ebp, %r14d
	cmpl	%ecx, %ebp
	jl	.LBB5_2
.LBB5_6:                                # %._crit_edge13
	movl	$.Lstr.3, %edi
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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	puts@PLT                        # TAILCALL
.Lfunc_end5:
	.size	_Z7ShowAdjPKf, .Lfunc_end5-_Z7ShowAdjPKf
	.cfi_endproc
                                        # -- End function
	.globl	_Z11ShowClusterPK7clusterPKi    # -- Begin function _Z11ShowClusterPK7clusterPKi
	.type	_Z11ShowClusterPK7clusterPKi,@function
_Z11ShowClusterPK7clusterPKi:           # @_Z11ShowClusterPK7clusterPKi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	length(%rip), %esi
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	cmpl	$0, length(%rip)
	jle	.LBB6_8
# %bb.1:                                # %.lr.ph17.preheader
	xorl	%r14d, %r14d
.LBB6_2:                                # %.lr.ph17
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_4 Depth 2
	movq	hgids(%rip), %rax
	movslq	(%rax,%r14,4), %r15
	movl	$91, %edi
	callq	putchar@PLT
	movq	(%rbx), %rax
	movq	(%rax,%r15,8), %rcx
	cmpl	$0, 8(%rcx)
	je	.LBB6_7
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB6_2 Depth=1
	xorl	%r12d, %r12d
.LBB6_4:                                # %.lr.ph
                                        #   Parent Loop BB6_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	testq	%r12, %r12
	je	.LBB6_6
# %bb.5:                                #   in Loop: Header=BB6_4 Depth=2
	movl	$32, %edi
	callq	putchar@PLT
	movq	(%rbx), %rax
.LBB6_6:                                #   in Loop: Header=BB6_4 Depth=2
	movq	(%rax,%r15,8), %rax
	movq	(%rax), %rax
	movl	(%rax,%r12,4), %esi
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r12
	movq	(%rbx), %rax
	movq	(%rax,%r15,8), %rcx
	movl	8(%rcx), %ecx
	cmpq	%rcx, %r12
	jb	.LBB6_4
.LBB6_7:                                # %._crit_edge
                                        #   in Loop: Header=BB6_2 Depth=1
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	incq	%r14
	movslq	length(%rip), %rax
	cmpq	%rax, %r14
	jl	.LBB6_2
.LBB6_8:                                # %._crit_edge18
	movl	$.Lstr.3, %edi
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end6:
	.size	_Z11ShowClusterPK7clusterPKi, .Lfunc_end6-_Z11ShowClusterPK7clusterPKi
	.cfi_endproc
                                        # -- End function
	.globl	_Z5ClearP7cluster               # -- Begin function _Z5ClearP7cluster
	.type	_Z5ClearP7cluster,@function
_Z5ClearP7cluster:                      # @_Z5ClearP7cluster
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	8(%rdi), %eax
	testl	%eax, %eax
	jle	.LBB7_5
# %bb.1:                                # %.lr.ph.preheader
	movq	%rdi, %rbx
	xorl	%r14d, %r14d
.LBB7_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	(%rbx), %rcx
	movq	(%rcx,%r14,8), %rcx
	testq	%rcx, %rcx
	je	.LBB7_4
# %bb.3:                                #   in Loop: Header=BB7_2 Depth=1
	movq	(%rcx), %rdi
	callq	free
	movq	(%rbx), %rax
	movq	(%rax,%r14,8), %rdi
	callq	free
	movl	8(%rbx), %eax
.LBB7_4:                                #   in Loop: Header=BB7_2 Depth=1
	incq	%r14
	movslq	%eax, %rcx
	cmpq	%rcx, %r14
	jl	.LBB7_2
.LBB7_5:                                # %._crit_edge
	movq	gab(%rip), %rdi
	callq	hipFree
	movq	adj(%rip), %rdi
	callq	hipFree
	movq	gids(%rip), %rdi
	callq	hipFree
	movq	rgids(%rip), %rdi
	callq	free
	movq	hgids(%rip), %rdi
	callq	free
	movq	hgab(%rip), %rdi
	callq	free
	movq	hadj(%rip), %rdi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	free                            # TAILCALL
.Lfunc_end7:
	.size	_Z5ClearP7cluster, .Lfunc_end7-_Z5ClearP7cluster
	.cfi_endproc
                                        # -- End function
	.globl	_Z10CheckErrorPKc               # -- Begin function _Z10CheckErrorPKc
	.type	_Z10CheckErrorPKc,@function
_Z10CheckErrorPKc:                      # @_Z10CheckErrorPKc
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	puts@PLT
	callq	hipGetLastError
	testl	%eax, %eax
	je	.LBB8_1
# %bb.2:
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.LBB8_1:
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end8:
	.size	_Z10CheckErrorPKc, .Lfunc_end8-_Z10CheckErrorPKc
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z5randnv
.LCPI9_0:
	.quad	0x416312d000000000              # double 1.0E+7
	.text
	.globl	_Z5randnv
	.type	_Z5randnv,@function
_Z5randnv:                              # @_Z5randnv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	callq	rand
	cltq
	imulq	$1717986919, %rax, %rcx         # imm = 0x66666667
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$34, %rcx
	addl	%edx, %ecx
	addl	%ecx, %ecx
	leal	(%rcx,%rcx,4), %ecx
	subl	%ecx, %eax
	xorl	%ecx, %ecx
	cmpl	$6, %eax
	setge	%cl
	leal	-1(,%rcx,2), %ebx
	callq	rand
	cltq
	imulq	$1801439851, %rax, %rcx         # imm = 0x6B5FCA6B
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$54, %rcx
	addl	%edx, %ecx
	imull	$10000000, %ecx, %ecx           # imm = 0x989680
	subl	%ecx, %eax
	cvtsi2sd	%eax, %xmm1
	divsd	.LCPI9_0(%rip), %xmm1
	cvtsi2sd	%ebx, %xmm0
	mulsd	%xmm1, %xmm0
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end9:
	.size	_Z5randnv, .Lfunc_end9-_Z5randnv
	.cfi_endproc
                                        # -- End function
	.globl	_Z6matmulPdS_i                  # -- Begin function _Z6matmulPdS_i
	.type	_Z6matmulPdS_i,@function
_Z6matmulPdS_i:                         # @_Z6matmulPdS_i
	.cfi_startproc
# %bb.0:
	testl	%edx, %edx
	jle	.LBB10_1
# %bb.3:                                # %.lr.ph.preheader
	movl	%edx, %eax
	xorpd	%xmm0, %xmm0
	xorl	%ecx, %ecx
.LBB10_4:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movsd	(%rdi,%rcx,8), %xmm1            # xmm1 = mem[0],zero
	mulsd	(%rsi,%rcx,8), %xmm1
	addsd	%xmm1, %xmm0
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB10_4
# %bb.2:                                # %._crit_edge
	retq
.LBB10_1:
	xorps	%xmm0, %xmm0
	retq
.Lfunc_end10:
	.size	_Z6matmulPdS_i, .Lfunc_end10-_Z6matmulPdS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z21__device_stub__UpdatePfPiS0_i # -- Begin function _Z21__device_stub__UpdatePfPiS0_i
	.type	_Z21__device_stub__UpdatePfPiS0_i,@function
_Z21__device_stub__UpdatePfPiS0_i:      # @_Z21__device_stub__UpdatePfPiS0_i
	.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	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%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	$_Z6UpdatePfPiS0_i, %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_end11:
	.size	_Z21__device_stub__UpdatePfPiS0_i, .Lfunc_end11-_Z21__device_stub__UpdatePfPiS0_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z8Clustingv
.LCPI12_0:
	.quad	0x40c3878000000000              # double 9999
	.text
	.globl	_Z8Clustingv
	.type	_Z8Clustingv,@function
_Z8Clustingv:                           # @_Z8Clustingv
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	length(%rip), %eax
	cmpl	$2, %eax
	jl	.LBB12_4
# %bb.1:                                # %.lr.ph29
	movq	hgids(%rip), %rcx
	movsd	.LCPI12_0(%rip), %xmm0          # xmm0 = mem[0],zero
	movl	$1, %edx
	movq	hadj(%rip), %rsi
	xorl	%edi, %edi
.LBB12_2:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB12_8 Depth 2
	movq	%rdi, %r8
	incq	%rdi
	movslq	%eax, %r9
	cmpq	%r9, %rdi
	jge	.LBB12_3
# %bb.7:                                # %.lr.ph
                                        #   in Loop: Header=BB12_2 Depth=1
	movq	hgab(%rip), %r9
	movl	N(%rip), %r10d
	movq	%rdx, %r11
.LBB12_8:                               #   Parent Loop BB12_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%rcx,%r8,4), %ebx
	movl	(%rcx,%r11,4), %ebp
	movl	%ebx, %r14d
	notl	%r14d
	leal	(%r14,%r10,2), %r15d
	imull	%ebx, %r15d
	movl	%r15d, %r12d
	shrl	$31, %r12d
	addl	%r15d, %r12d
	sarl	%r12d
	addl	%ebp, %r14d
	addl	%r12d, %r14d
	movslq	%r14d, %r14
	xorps	%xmm1, %xmm1
	cvtss2sd	(%rsi,%r14,4), %xmm1
	ucomisd	%xmm1, %xmm0
	jbe	.LBB12_10
# %bb.9:                                #   in Loop: Header=BB12_8 Depth=2
	movl	%ebx, (%r9)
	movl	%ebp, 4(%r9)
	movl	N(%rip), %r10d
	movl	length(%rip), %eax
	movapd	%xmm1, %xmm0
.LBB12_10:                              #   in Loop: Header=BB12_8 Depth=2
	incq	%r11
	movslq	%eax, %rbx
	cmpq	%rbx, %r11
	jl	.LBB12_8
.LBB12_3:                               # %.loopexit
                                        #   in Loop: Header=BB12_2 Depth=1
	leal	-1(%rax), %r8d
	movslq	%r8d, %r8
	incq	%rdx
	cmpq	%r8, %rdi
	jl	.LBB12_2
.LBB12_4:                               # %._crit_edge
	movq	gab(%rip), %rdi
	movq	hgab(%rip), %rsi
	movl	$8, %edx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	gids(%rip), %rdi
	movq	hgids(%rip), %rsi
	movslq	N(%rip), %rdx
	shlq	$2, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	length(%rip), %eax
	movl	$1023, %ecx                     # imm = 0x3FF
	leal	(%rax,%rcx), %edi
	testl	%eax, %eax
	cmovnsl	%eax, %edi
	sarl	$10, %edi
	andl	%ecx, %eax
	cmpl	$1, %eax
	sbbl	$-1, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$1024, %rdx                     # imm = 0x400
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB12_6
# %bb.5:
	movq	adj(%rip), %rdi
	movq	gids(%rip), %rsi
	movq	gab(%rip), %rdx
	movl	length(%rip), %ecx
	callq	_Z21__device_stub__UpdatePfPiS0_i
.LBB12_6:
	callq	hipDeviceSynchronize
	movq	hadj(%rip), %rdi
	movq	adj(%rip), %rsi
	movl	N(%rip), %eax
	leal	-1(%rax), %ecx
	imull	%eax, %ecx
	movl	%ecx, %eax
	shrl	$31, %eax
	addl	%ecx, %eax
	sarl	%eax
	movslq	%eax, %rdx
	shlq	$2, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	hgids(%rip), %rax
	movslq	length(%rip), %rcx
	movl	-4(%rax,%rcx,4), %ecx
	movq	rgids(%rip), %rdx
	movq	hgab(%rip), %rsi
	movslq	4(%rsi), %rdi
	movslq	(%rdx,%rdi,4), %rdi
	movl	%ecx, (%rax,%rdi,4)
	movslq	4(%rsi), %rcx
	movl	(%rdx,%rcx,4), %ecx
	movslq	length(%rip), %rsi
	movslq	-4(%rax,%rsi,4), %rax
	movl	%ecx, (%rdx,%rax,4)
	decl	length(%rip)
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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_end12:
	.size	_Z8Clustingv, .Lfunc_end12-_Z8Clustingv
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %r14
	leaq	8(%rsp), %rbx
	movq	%rbx, %rdi
	movl	$400, %esi                      # imm = 0x190
	callq	hiprandCreateGenerator
	movq	(%rbx), %rdi
	movl	$1234, %esi                     # imm = 0x4D2
	callq	hiprandSetPseudoRandomGeneratorSeed
	movq	8(%r14), %rdi
	callq	atoi
	movl	%eax, N(%rip)
	movl	$Num, %edi
	movl	$N, %esi
	movl	$4, %edx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	movl	N(%rip), %eax
	leal	-1(%rax), %ecx
	imull	%eax, %ecx
	movl	%ecx, %eax
	shrl	$31, %eax
	addl	%ecx, %eax
	sarl	%eax
	movslq	%eax, %rsi
	shlq	$2, %rsi
	movl	$adj, %edi
	callq	hipMalloc
	movq	(%rbx), %rdi
	movq	adj(%rip), %rsi
	movl	N(%rip), %eax
	leal	-1(%rax), %ecx
	imull	%eax, %ecx
	movl	%ecx, %eax
	shrl	$31, %eax
	addl	%ecx, %eax
	sarl	%eax
	movslq	%eax, %rdx
	callq	hiprandGenerateUniform
	movslq	N(%rip), %rsi
	shlq	$2, %rsi
	movl	$gids, %edi
	callq	hipMalloc
	movl	$gab, %edi
	movl	$8, %esi
	callq	hipMalloc
	movl	N(%rip), %eax
	leal	-1(%rax), %ecx
	imull	%eax, %ecx
	movl	%ecx, %eax
	shrl	$31, %eax
	addl	%ecx, %eax
	sarl	%eax
	movslq	%eax, %rbx
	shlq	$2, %rbx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, hadj(%rip)
	movq	adj(%rip), %rsi
	movq	%rax, %rdi
	movq	%rbx, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movslq	N(%rip), %r15
	leaq	(,%r15,4), %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %rbx
	movq	%rax, rgids(%rip)
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	%rax, hgids(%rip)
	movl	$8, %edi
	callq	malloc
	movl	%r15d, %edi
	movq	%rax, hgab(%rip)
	movl	%r15d, length(%rip)
	testq	%r15, %r15
	jle	.LBB13_3
# %bb.1:                                # %.lr.ph.preheader
	xorl	%eax, %eax
.LBB13_2:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%eax, (%r14,%rax,4)
	movl	%eax, (%rbx,%rax,4)
	incq	%rax
	cmpq	%rax, %rdi
	jne	.LBB13_2
.LBB13_3:                               # %._crit_edge
                                        # kill: def $edi killed $edi killed $rdi
	callq	_Z14Create_Clusterj
	movq	%rax, %rbx
	cmpl	$2, length(%rip)
	jl	.LBB13_5
.LBB13_4:                               # %.lr.ph13
                                        # =>This Inner Loop Header: Depth=1
	callq	_Z8Clustingv
	movq	hgab(%rip), %rax
	movl	(%rax), %ecx
	movl	4(%rax), %r14d
	movq	(%rbx), %r15
	movq	(%r15,%rcx,8), %rdi
	movq	(%r15,%r14,8), %rsi
	callq	_Z11Merge_GroupP5groupS0_
	movq	$0, (%r15,%r14,8)
	cmpl	$1, length(%rip)
	jg	.LBB13_4
.LBB13_5:                               # %._crit_edge14
	movq	8(%rsp), %rdi
	callq	hiprandDestroyGenerator
	movq	%rbx, %rdi
	callq	_Z5ClearP7cluster
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end13:
	.size	main, .Lfunc_end13-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	.LBB14_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB14_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6UpdatePfPiS0_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$0, 8(%rsp)
	movl	$1, (%rsp)
	movl	$Num, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movl	$4, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	callq	__hipRegisterVar
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end14:
	.size	__hip_module_ctor, .Lfunc_end14-__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	.LBB15_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
.LBB15_2:
	retq
.Lfunc_end15:
	.size	__hip_module_dtor, .Lfunc_end15-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	N,@object                       # @N
	.bss
	.globl	N
	.p2align	2, 0x0
N:
	.long	0                               # 0x0
	.size	N, 4

	.type	blockNum,@object                # @blockNum
	.globl	blockNum
	.p2align	2, 0x0
blockNum:
	.long	0                               # 0x0
	.size	blockNum, 4

	.type	Num,@object                     # @Num
	.local	Num
	.comm	Num,4,4
	.type	adj,@object                     # @adj
	.globl	adj
	.p2align	3, 0x0
adj:
	.quad	0
	.size	adj, 8

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

	.type	length,@object                  # @length
	.globl	length
	.p2align	2, 0x0
length:
	.long	0                               # 0x0
	.size	length, 4

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

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

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

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

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

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"%.4lf "
	.size	.L.str.1, 7

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Groups=%d\n"
	.size	.L.str.5, 11

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"%d"
	.size	.L.str.8, 3

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Error: %s\n"
	.size	.L.str.11, 11

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

	.type	.L__unnamed_1,@object           # @0
	.section	.rodata.str1.1,"aMS",@progbits,1
.L__unnamed_1:
	.asciz	"_Z6UpdatePfPiS0_i"
	.size	.L__unnamed_1, 18

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"Num"
	.size	.L__unnamed_2, 4

	.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	"============Adj============"
	.size	.Lstr, 28

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"==========Cluster=========="
	.size	.Lstr.2, 28

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"==========================="
	.size	.Lstr.3, 28

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"]"
	.size	.Lstr.4, 2

	.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 _Z21__device_stub__UpdatePfPiS0_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym N
	.addrsig_sym Num
	.addrsig_sym adj
	.addrsig_sym gids
	.addrsig_sym gab
	.addrsig_sym _Z6UpdatePfPiS0_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6UpdatePfPiS0_i       ; -- Begin function _Z6UpdatePfPiS0_i
	.globl	_Z6UpdatePfPiS0_i
	.p2align	8
	.type	_Z6UpdatePfPiS0_i,@function
_Z6UpdatePfPiS0_i:                      ; @_Z6UpdatePfPiS0_i
; %bb.0:
	s_load_b32 s2, s[0:1], 0x18
	v_lshl_or_b32 v0, s15, 10, v0
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_gt_i32_e32 vcc_lo, s2, v0
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB0_9
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_ashrrev_i32_e32 v1, 31, v0
	s_load_b64 s[0:1], s[0:1], 0x10
                                        ; implicit-def: $vgpr2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s6, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	s_load_b64 s[2:3], s[0:1], 0x0
	s_mov_b32 s0, 0
	s_mov_b32 s1, exec_lo
	global_load_b32 v1, v[0:1], off
                                        ; implicit-def: $vgpr0
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_cmpx_le_i32_e64 s2, v1
	s_xor_b32 s1, exec_lo, s1
	s_cbranch_execz .LBB0_5
; %bb.2:
	v_cmp_lt_i32_e32 vcc_lo, s2, v1
	v_cmp_ne_u32_e64 s0, s3, v1
                                        ; implicit-def: $vgpr0
                                        ; implicit-def: $vgpr2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_and_b32 s6, vcc_lo, s0
	s_mov_b32 s0, 0
	s_and_saveexec_b32 s7, s6
	s_xor_b32 s6, exec_lo, s7
	s_cbranch_execz .LBB0_4
; %bb.3:
	s_getpc_b64 s[8:9]
	s_add_u32 s8, s8, Num@rel32@lo+4
	s_addc_u32 s9, s9, Num@rel32@hi+12
	v_min_i32_e32 v0, s3, v1
	s_load_b32 s7, s[8:9], 0x0
	s_not_b32 s8, s2
	s_mov_b32 s0, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_not_b32_e32 v2, v0
	s_waitcnt lgkmcnt(0)
	s_lshl_b32 s7, s7, 1
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_add_nc_u32_e32 v3, s7, v2
	s_add_i32 s7, s7, s8
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s7, s7, s2
	s_lshr_b32 s9, s7, 31
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_mul_lo_u32 v0, v3, v0
	s_add_i32 s7, s7, s9
	s_ashr_i32 s7, s7, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshrrev_b32_e32 v3, 31, v0
	v_add_nc_u32_e32 v0, v0, v3
	v_max_i32_e32 v3, s3, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v4, 1, v0
	v_add3_u32 v0, s7, s8, v1
	v_add3_u32 v2, v3, v2, v4
.LBB0_4:                                ; %Flow55
	s_or_b32 exec_lo, exec_lo, s6
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 s0, s0, exec_lo
                                        ; implicit-def: $vgpr1
.LBB0_5:                                ; %Flow
	s_and_not1_saveexec_b32 s1, s1
	s_cbranch_execz .LBB0_7
; %bb.6:
	s_getpc_b64 s[6:7]
	s_add_u32 s6, s6, Num@rel32@lo+4
	s_addc_u32 s7, s7, Num@rel32@hi+12
	v_not_b32_e32 v2, v1
	s_load_b32 s6, s[6:7], 0x0
	s_or_b32 s0, s0, exec_lo
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshl_add_u32 v0, s6, 1, v2
	v_mul_lo_u32 v0, v0, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshrrev_b32_e32 v1, 31, v0
	v_add_nc_u32_e32 v0, v0, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v1, 1, v0
	v_add3_u32 v0, s2, v2, v1
	v_add3_u32 v2, s3, v2, v1
.LBB0_7:                                ; %Flow56
	s_or_b32 exec_lo, exec_lo, s1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 exec_lo, exec_lo, s0
	s_cbranch_execz .LBB0_9
; %bb.8:                                ; %.sink.split
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v3, 31, v2
	v_ashrrev_i32_e32 v1, 31, v0
	v_lshlrev_b64 v[2:3], 2, v[2:3]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_add_co_u32 v2, vcc_lo, s4, v2
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	v_add_co_u32 v0, vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	s_clause 0x1
	global_load_b32 v2, v[2:3], off
	global_load_b32 v3, v[0:1], off
	s_waitcnt vmcnt(0)
	v_dual_max_f32 v2, v2, v2 :: v_dual_max_f32 v3, v3, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_max_f32_e32 v2, v3, v2
	global_store_b32 v[0:1], v2, off
.LBB0_9:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6UpdatePfPiS0_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 28
		.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 5
		.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_end0:
	.size	_Z6UpdatePfPiS0_i, .Lfunc_end0-_Z6UpdatePfPiS0_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 564
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; 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	Num                     ; @Num
	.type	Num,@object
	.section	.bss,"aw",@nobits
	.globl	Num
	.p2align	2, 0x0
Num:
	.long	0                               ; 0x0
	.size	Num, 4

	.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 Num
	.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
      - .offset:         24
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 28
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6UpdatePfPiS0_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z6UpdatePfPiS0_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
