#include <iostream>
#include <cstdlib>
#include <limits>
using namespace std;

#define Nparticles     30
#define T_MAX          1000
#define NFC_MAX        1000000
#define W_0            0.9
#define W_T            0.4
#define MAX_V          2.0
#define c1             2.0      
#define c2             2.0
#define Nvariables     30


#define Rand()     ((double)rand()/RAND_MAX);

__global__ void evalPlane(int n, double *x, double *fit) {
    int index = blockIdx.x * blockDim.x + threadIdx.x;
    int stride = blockDim.x * gridDim.x;
    for (int i = index; i < n; i += stride)
        fit[i] += x[i] * x[i];
}


class Particle {
    public:
        double *x;
        double *v;
        double fitness;
        double pBest;
        double *xBest;
};

class Swarm {
    private:
        
        int gBest; //index
        double gBestValue;
    public:
        Particle *P;
        Swarm();
        void setGBestIndex(int index);
        void setGBestValue(double gBestValue);
        void setParticleXV(int i, int j, double x, double v);
        void setParticleFitness(int i, double fit);
        void setParticlePBest(int i, double value, double *x);
        Particle getParticleValue(int i);
        int getGbest();
        double getGbestValue();
};

Swarm::Swarm() {
    gBest = 0;

    P = (Particle *)malloc(sizeof(Particle)*Nparticles);
    if (P==NULL) {
        fprintf(stderr, "Cannot allocate memory for %d Particles\n", Nparticles);
        exit (1);
    } 

    for(int i = 0; i < Nparticles; i++) {
        P[i].x = (double *)malloc(sizeof(double)*Nvariables);
        if (P[i].x==NULL) {
            fprintf(stderr, "Cannot allocate memory for %d x\n", Nvariables);
            exit (1);
        } 
        P[i].v = (double *)malloc(sizeof(double)*Nvariables);
        if (P[i].v==NULL) {
            fprintf(stderr, "Cannot allocate memory for %d v\n", Nvariables);
            exit (1);
        } 
        P[i].xBest = (double *)malloc(sizeof(double)*Nvariables);
        if (P[i].xBest==NULL) {
            fprintf(stderr, "Cannot allocate memory for %d xBest\n", Nvariables);
            exit (1);
        } 
    }
    
}

void Swarm::setGBestIndex(int index) {
    this->gBest = index;
}

void Swarm::setGBestValue(double gBestValue) {
    this->gBestValue = gBestValue;
}

void Swarm::setParticleXV(int i, int j, double x, double v) {
    if (x != NULL) P[i].x[j] = x;
    if (v != NULL) P[i].v[j] = v;
}

void Swarm::setParticleFitness(int i, double fit) {
    P[i].fitness = fit;
}

void Swarm::setParticlePBest(int i, double value, double *x) {
    P[i].pBest = value;
    for(int j = 0; j < Nvariables; j++)
    {
        P[i].xBest[j] = P[i].x[j];
    }    
}

Particle Swarm::getParticleValue(int i) {
    return P[i];
}

int Swarm::getGbest() {
    return gBest;
}

double Swarm::getGbestValue() {
    return gBestValue;
}

class PSO {
    private:
        int nfc;
        double w;
        double *maxV; 
    public:
        Swarm swarm;
        PSO();
        void initialize();
        void evolution();
        void updateBest(int i);
        void calculateVMax();
        void particleMovement();
        void evaluate(int i);
        void evaluateSwarm();
};

PSO::PSO() {
    maxV = (double *)malloc(sizeof(double)*Nvariables);
    if (maxV==NULL) {
        fprintf(stderr, "Cannot allocate memory for %d maxV\n", Nvariables);
        exit (1);
    } 
}

void PSO::evolution() {
    double dw = (W_0 - W_T) / (NFC_MAX / Nparticles);
    w = W_0;
    
    initialize();
    
    nfc = 0;
    while(nfc < NFC_MAX) {
        calculateVMax();
        particleMovement();  
        evaluateSwarm();
        w -= dw;     
    }

}

void PSO::initialize() {
    swarm.setGBestValue(numeric_limits<double>::max());

    for(int i = 0; i < Nparticles; i++) {
        for(int j = 0; j < Nvariables; j++) {
            double x = -5.12 + 10.24 * Rand();
            //double x = Rand();
            double v = 0.0;
            swarm.setParticleXV(i, j, x, v);
        }
        evaluate(i);
        updateBest(i);

        double fitness = swarm.getParticleValue(i).fitness;
        double gbest = swarm.getGbestValue();

        if (fitness < gbest) {
            swarm.setGBestValue(fitness);
            swarm.setGBestIndex(i);
        }

    }

    Particle best = swarm.getParticleValue(swarm.getGbest());
    printf("0 : ");
    for (int j = 0; j < Nvariables; j++)
        printf("%g ", best.xBest[j]);
    printf(" = %e\n", best.pBest);
}

void PSO::evaluate(int i) {
    //int index = i;

    int ThreadsInBlock = 8;
    int BlocksInGrid = (int)(Nvariables + ThreadsInBlock - 1) / ThreadsInBlock;
    double *fitness = (double *)malloc(sizeof(double));
    cudaMallocManaged((void **)&fitness, sizeof(double));

    cudaMallocManaged((void **)&swarm.P[i].x, sizeof(double)*Nvariables);

    evalPlane<<<BlocksInGrid, ThreadsInBlock>>>(Nvariables, swarm.P[i].x, fitness);
    cudaGetLastError();

    //if (cudaSuccess != cudaMemcpy())


    cudaDeviceSynchronize();

    // double fitness = 0.0;

    // for(int k = 0 ; k < Nvariables ; k++ ) {
    //     int x = swarm.getParticleValue(index).x[k];
    //     fitness +=  x * x;
    // }


    // double fitness = 0, temp = 0;
    // for(int k = 0 ; k < Nvariables ; k++ ) {
    //     for(int l = 0; l < k; l++)
    //     {
    //         double x = swarm.getParticleValue(index).x[l];
    //         temp += x;
    //     }
        
    //     fitness +=  temp * temp;
    // }

    cudaFree(fitness);
    cudaFree(swarm.P[i].x);
    //swarm.setParticleFitness(index, fitness);
}

void PSO::evaluateSwarm() {
    for(int i = 0; i < Nparticles; i++) {
        evaluate(i);    
        nfc++;

        if (nfc % 5000 == 0) {
            Particle best = swarm.getParticleValue(swarm.getGbest());
            printf("%d : ", nfc);
            // for (int j = 0; j < Nvariables; j++)
            //     printf("%g ", best.xBest[j]);
            printf(" = %g\n", best.pBest);
            //cout << "PSO SPHERE nfc" << nfc << " \tbestfit " << best.pBest << "\n";
        }
    }

    for(int n = 0; n < Nparticles; n++) {
        Particle par = swarm.getParticleValue(n);
        if (par.fitness < par.pBest ) {
            swarm.setParticlePBest(n, par.fitness, par.x);

            if (par.fitness < swarm.getGbestValue() ) {
                swarm.setGBestIndex(n);
                swarm.setGBestValue(par.fitness);
            }
        }
    }
}

void PSO::updateBest(int i) {
    Particle par = swarm.getParticleValue(i);
    swarm.setParticlePBest(i, par.fitness, par.x);
}

void PSO::calculateVMax() {
    double xmin[Nparticles], xmax[Nparticles];

    for (int d = 0; d < Nvariables; d++) {
        xmin[d] = xmax[d] = swarm.getParticleValue(0).x[d];
        for (int n = 1; n < Nparticles; n++) {
            double pos = swarm.getParticleValue(n).x[d];
            if (pos < xmin[d])
                xmin[d] = pos;
            if (pos > xmax[d])
                xmax[d] = pos;
        }
        maxV[d] = xmax[d] - xmin[d];
    }
}

void PSO::particleMovement() {
    int n, d;

    for (n = 0; n < Nparticles ; n++) {
        Particle par = swarm.getParticleValue(n);
        Particle bPar = swarm.getParticleValue(swarm.getGbest());
        // update velocities
        for(d = 0; d < Nvariables ; d++ ) {
            double r1 = Rand();
            double r2 = Rand();
            double newV = w * par.v[d] + c1 * r1 * (par.xBest[d] - par.x[d]) + c2 * r2 * (bPar.x[d] - par.x[d]);
            swarm.setParticleXV(n, d, NULL, newV);
            // check v with its dimensional maxV
            if ( swarm.getParticleValue(n).v[d] > maxV[d] ) swarm.setParticleXV(n, d, NULL, maxV[d]);
            else if ( swarm.getParticleValue(n).v[d] < -maxV[d] ) swarm.setParticleXV(n, d, NULL, -maxV[d]);
        }
        // update positions
        Particle newPar = swarm.getParticleValue(n);
        for (d = 0; d < Nvariables ; d++) {
            //newPar.x[d] = newPar.x[d] + newPar.v[d];
            swarm.setParticleXV(n, d, newPar.x[d] + newPar.v[d], NULL);
        }
    }
}

int main(int argc, char **argv) {
    //int threadCount = BlocksInGrid * ThreadsInBlock;
    //long size = threadCount * sizeof(double);
    PSO pso;
    pso.evolution();

    return 0;
}
	.file	"tmpxft_0033690a_00000000-6_CUDA_BPSO.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3659:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3659:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Cannot allocate memory for %d Particles\n"
.LC1:
	.string	"Cannot allocate memory for %d x\n"
.LC2:
	.string	"Cannot allocate memory for %d v\n"
.LC3:
	.string	"Cannot allocate memory for %d xBest\n"
	.text
	.align 2
	.globl	_ZN5SwarmC2Ev
	.type	_ZN5SwarmC2Ev, @function
_ZN5SwarmC2Ev:
.LFB3636:
	.cfi_startproc
	endbr64
	xorl	%ecx, %ecx
	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
	pushq	%rdx
	.cfi_def_cfa_offset 32
	movl	%ecx, (%rdi)
	movl	$1200, %edi
	call	malloc@PLT
	movq	%rax, 16(%rbp)
	testq	%rax, %rax
	jne	.L10
	movq	stderr(%rip), %rdi
	movl	$30, %ecx
	leaq	.LC0(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	jmp	.L12
.L10:
	movq	%rax, %rbx
	leaq	1200(%rax), %rbp
.L7:
	movl	$240, %edi
	call	malloc@PLT
	movq	%rax, (%rbx)
	testq	%rax, %rax
	jne	.L4
	movl	$30, %ecx
	leaq	.LC1(%rip), %rdx
.L13:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
.L12:
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L4:
	movl	$240, %edi
	call	malloc@PLT
	movq	%rax, 8(%rbx)
	testq	%rax, %rax
	jne	.L5
	movl	$30, %ecx
	leaq	.LC2(%rip), %rdx
	jmp	.L13
.L5:
	movl	$240, %edi
	call	malloc@PLT
	movq	%rax, 32(%rbx)
	testq	%rax, %rax
	jne	.L6
	movl	$30, %ecx
	leaq	.LC3(%rip), %rdx
	jmp	.L13
.L6:
	addq	$40, %rbx
	cmpq	%rbp, %rbx
	jne	.L7
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3636:
	.size	_ZN5SwarmC2Ev, .-_ZN5SwarmC2Ev
	.globl	_ZN5SwarmC1Ev
	.set	_ZN5SwarmC1Ev,_ZN5SwarmC2Ev
	.align 2
	.globl	_ZN5Swarm13setGBestIndexEi
	.type	_ZN5Swarm13setGBestIndexEi, @function
_ZN5Swarm13setGBestIndexEi:
.LFB3638:
	.cfi_startproc
	endbr64
	movl	%esi, (%rdi)
	ret
	.cfi_endproc
.LFE3638:
	.size	_ZN5Swarm13setGBestIndexEi, .-_ZN5Swarm13setGBestIndexEi
	.align 2
	.globl	_ZN5Swarm13setGBestValueEd
	.type	_ZN5Swarm13setGBestValueEd, @function
_ZN5Swarm13setGBestValueEd:
.LFB3639:
	.cfi_startproc
	endbr64
	movsd	%xmm0, 8(%rdi)
	ret
	.cfi_endproc
.LFE3639:
	.size	_ZN5Swarm13setGBestValueEd, .-_ZN5Swarm13setGBestValueEd
	.align 2
	.globl	_ZN5Swarm13setParticleXVEiidd
	.type	_ZN5Swarm13setParticleXVEiidd, @function
_ZN5Swarm13setParticleXVEiidd:
.LFB3640:
	.cfi_startproc
	endbr64
	xorps	%xmm2, %xmm2
	movq	%rdi, %rcx
	movslq	%edx, %rax
	ucomisd	%xmm2, %xmm0
	jp	.L22
	je	.L18
.L22:
	movslq	%esi, %rdx
	movslq	%eax, %rdi
	imulq	$40, %rdx, %rdx
	addq	16(%rcx), %rdx
	movq	(%rdx), %r8
	movsd	%xmm0, (%r8,%rdi,8)
.L18:
	xorps	%xmm0, %xmm0
	ucomisd	%xmm0, %xmm1
	jp	.L23
	je	.L17
.L23:
	movslq	%esi, %rsi
	imulq	$40, %rsi, %rsi
	addq	16(%rcx), %rsi
	movq	8(%rsi), %rdx
	movsd	%xmm1, (%rdx,%rax,8)
.L17:
	ret
	.cfi_endproc
.LFE3640:
	.size	_ZN5Swarm13setParticleXVEiidd, .-_ZN5Swarm13setParticleXVEiidd
	.align 2
	.globl	_ZN5Swarm18setParticleFitnessEid
	.type	_ZN5Swarm18setParticleFitnessEid, @function
_ZN5Swarm18setParticleFitnessEid:
.LFB3641:
	.cfi_startproc
	endbr64
	movslq	%esi, %rsi
	imulq	$40, %rsi, %rsi
	addq	16(%rdi), %rsi
	movsd	%xmm0, 16(%rsi)
	ret
	.cfi_endproc
.LFE3641:
	.size	_ZN5Swarm18setParticleFitnessEid, .-_ZN5Swarm18setParticleFitnessEid
	.align 2
	.globl	_ZN5Swarm16setParticlePBestEidPd
	.type	_ZN5Swarm16setParticlePBestEidPd, @function
_ZN5Swarm16setParticlePBestEidPd:
.LFB3642:
	.cfi_startproc
	endbr64
	movslq	%esi, %rsi
	xorl	%eax, %eax
	imulq	$40, %rsi, %rsi
	addq	16(%rdi), %rsi
	movq	(%rsi), %rcx
	movq	32(%rsi), %rdx
	movsd	%xmm0, 24(%rsi)
.L26:
	movsd	(%rcx,%rax), %xmm0
	movsd	%xmm0, (%rdx,%rax)
	addq	$8, %rax
	cmpq	$240, %rax
	jne	.L26
	ret
	.cfi_endproc
.LFE3642:
	.size	_ZN5Swarm16setParticlePBestEidPd, .-_ZN5Swarm16setParticlePBestEidPd
	.align 2
	.globl	_ZN5Swarm16getParticleValueEi
	.type	_ZN5Swarm16getParticleValueEi, @function
_ZN5Swarm16getParticleValueEi:
.LFB3643:
	.cfi_startproc
	endbr64
	movq	%rsi, %rcx
	movslq	%edx, %rsi
	movq	%rdi, %rax
	imulq	$40, %rsi, %rsi
	addq	16(%rcx), %rsi
	movl	$10, %ecx
	rep movsl
	ret
	.cfi_endproc
.LFE3643:
	.size	_ZN5Swarm16getParticleValueEi, .-_ZN5Swarm16getParticleValueEi
	.align 2
	.globl	_ZN5Swarm8getGbestEv
	.type	_ZN5Swarm8getGbestEv, @function
_ZN5Swarm8getGbestEv:
.LFB3644:
	.cfi_startproc
	endbr64
	movl	(%rdi), %eax
	ret
	.cfi_endproc
.LFE3644:
	.size	_ZN5Swarm8getGbestEv, .-_ZN5Swarm8getGbestEv
	.align 2
	.globl	_ZN5Swarm13getGbestValueEv
	.type	_ZN5Swarm13getGbestValueEv, @function
_ZN5Swarm13getGbestValueEv:
.LFB3645:
	.cfi_startproc
	endbr64
	movsd	8(%rdi), %xmm0
	ret
	.cfi_endproc
.LFE3645:
	.size	_ZN5Swarm13getGbestValueEv, .-_ZN5Swarm13getGbestValueEv
	.section	.rodata.str1.1
.LC5:
	.string	"Cannot allocate memory for %d maxV\n"
	.text
	.align 2
	.globl	_ZN3PSOC2Ev
	.type	_ZN3PSOC2Ev, @function
_ZN3PSOC2Ev:
.LFB3647:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	addq	$24, %rdi
	call	_ZN5SwarmC1Ev
	movl	$240, %edi
	call	malloc@PLT
	movq	%rax, 16(%rbx)
	testq	%rax, %rax
	jne	.L31
	movq	stderr(%rip), %rdi
	movl	$30, %ecx
	movl	$2, %esi
	leaq	.LC5(%rip), %rdx
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L31:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3647:
	.size	_ZN3PSOC2Ev, .-_ZN3PSOC2Ev
	.globl	_ZN3PSOC1Ev
	.set	_ZN3PSOC1Ev,_ZN3PSOC2Ev
	.align 2
	.globl	_ZN3PSO10updateBestEi
	.type	_ZN3PSO10updateBestEi, @function
_ZN3PSO10updateBestEi:
.LFB3653:
	.cfi_startproc
	endbr64
	subq	$56, %rsp
	.cfi_def_cfa_offset 64
	leaq	24(%rdi), %r8
	movl	%esi, %r9d
	movl	%esi, %edx
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rdi
	movq	%r8, %rsi
	call	_ZN5Swarm16getParticleValueEi
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	movq	(%rsp), %rdx
	movsd	16(%rsp), %xmm0
	movl	%r9d, %esi
	movq	%r8, %rdi
	addq	$56, %rsp
	.cfi_def_cfa_offset 8
	jmp	_ZN5Swarm16setParticlePBestEidPd
	.cfi_endproc
.LFE3653:
	.size	_ZN3PSO10updateBestEi, .-_ZN3PSO10updateBestEi
	.align 2
	.globl	_ZN3PSO13calculateVMaxEv
	.type	_ZN3PSO13calculateVMaxEv, @function
_ZN3PSO13calculateVMaxEv:
.LFB3654:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rdi, %r9
	xorl	%r8d, %r8d
	leaq	24(%rdi), %r10
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$536, %rsp
	.cfi_def_cfa_offset 560
	movq	%fs:40, %rax
	movq	%rax, 520(%rsp)
	xorl	%eax, %eax
.L44:
	movq	%rsp, %rbp
	xorl	%edx, %edx
	leaq	280(%rsp), %r11
	movq	%r10, %rsi
	movq	%rbp, %rdi
	leaq	40(%rsp), %rbx
	call	_ZN5Swarm16getParticleValueEi
	movq	(%rsp), %rax
	movl	$1, %edx
	movsd	(%rax,%r8), %xmm0
	movsd	%xmm0, 280(%rsp,%r8)
	movsd	%xmm0, 40(%rsp,%r8)
.L43:
	movq	%r10, %rsi
	movq	%rbp, %rdi
	call	_ZN5Swarm16getParticleValueEi
	movq	(%rsp), %rax
	incl	%edx
	movsd	(%rax,%r8), %xmm0
	movaps	%xmm0, %xmm1
	maxsd	(%r11,%r8), %xmm0
	minsd	(%rbx,%r8), %xmm1
	movsd	%xmm0, (%r11,%r8)
	movsd	%xmm1, (%rbx,%r8)
	cmpl	$30, %edx
	jne	.L43
	subsd	%xmm1, %xmm0
	movq	16(%r9), %rax
	movsd	%xmm0, (%rax,%r8)
	addq	$8, %r8
	cmpq	$240, %r8
	jne	.L44
	movq	520(%rsp), %rax
	subq	%fs:40, %rax
	je	.L45
	call	__stack_chk_fail@PLT
.L45:
	addq	$536, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3654:
	.size	_ZN3PSO13calculateVMaxEv, .-_ZN3PSO13calculateVMaxEv
	.align 2
	.globl	_ZN3PSO16particleMovementEv
	.type	_ZN3PSO16particleMovementEv, @function
_ZN3PSO16particleMovementEv:
.LFB3655:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$152, %rsp
	.cfi_def_cfa_offset 208
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
.L58:
	leaq	24(%r13), %r12
	leaq	16(%rsp), %rdi
	movl	%ebx, %edx
	xorl	%ebp, %ebp
	movq	%r12, %rsi
	call	_ZN5Swarm16getParticleValueEi
	movl	24(%r13), %edx
	leaq	56(%rsp), %rdi
	movq	%r12, %rsi
	movq	16(%rsp), %r15
	call	_ZN5Swarm16getParticleValueEi
.L56:
	call	rand@PLT
	movl	%ebp, %r14d
	cvtsi2sdl	%eax, %xmm1
	divsd	.LC6(%rip), %xmm1
	movsd	%xmm1, 8(%rsp)
	call	rand@PLT
	movq	48(%rsp), %rdx
	movl	%ebx, %esi
	movq	%r12, %rdi
	movsd	(%r15,%rbp,8), %xmm2
	movsd	8(%rsp), %xmm1
	leaq	96(%rsp), %r9
	movsd	(%rdx,%rbp,8), %xmm0
	movq	24(%rsp), %rdx
	addsd	%xmm1, %xmm1
	subsd	%xmm2, %xmm0
	mulsd	%xmm1, %xmm0
	movsd	(%rdx,%rbp,8), %xmm1
	movq	56(%rsp), %rdx
	mulsd	8(%r13), %xmm1
	addsd	%xmm1, %xmm0
	movsd	(%rdx,%rbp,8), %xmm1
	movl	%ebp, %edx
	subsd	%xmm2, %xmm1
	cvtsi2sdl	%eax, %xmm2
	divsd	.LC6(%rip), %xmm2
	addsd	%xmm2, %xmm2
	mulsd	%xmm2, %xmm1
	addsd	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	call	_ZN5Swarm13setParticleXVEiidd
	movl	%ebx, %edx
	movq	%r12, %rsi
	movq	%r9, %rdi
	call	_ZN5Swarm16getParticleValueEi
	movq	104(%rsp), %rax
	movsd	(%rax,%rbp,8), %xmm0
	movq	16(%r13), %rax
	movsd	(%rax,%rbp,8), %xmm1
	comisd	%xmm1, %xmm0
	ja	.L67
	movq	%r12, %rsi
	movq	%r9, %rdi
	call	_ZN5Swarm16getParticleValueEi
	movq	104(%rsp), %rax
	xorps	.LC7(%rip), %xmm1
	comisd	(%rax,%rbp,8), %xmm1
	jbe	.L54
.L67:
	xorps	%xmm0, %xmm0
	movl	%r14d, %edx
	movl	%ebx, %esi
	movq	%r12, %rdi
	call	_ZN5Swarm13setParticleXVEiidd
.L54:
	incq	%rbp
	cmpq	$30, %rbp
	jne	.L56
	movq	%r9, %rdi
	movl	%ebx, %edx
	movq	%r12, %rsi
	xorl	%r9d, %r9d
	call	_ZN5Swarm16getParticleValueEi
.L57:
	movq	96(%rsp), %rax
	movl	%r9d, %edx
	xorps	%xmm1, %xmm1
	movl	%ebx, %esi
	movq	%r12, %rdi
	movsd	(%rax,%r9,8), %xmm0
	movq	104(%rsp), %rax
	addsd	(%rax,%r9,8), %xmm0
	incq	%r9
	call	_ZN5Swarm13setParticleXVEiidd
	cmpq	$30, %r9
	jne	.L57
	incl	%ebx
	cmpl	$30, %ebx
	jne	.L58
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L59
	call	__stack_chk_fail@PLT
.L59:
	addq	$152, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3655:
	.size	_ZN3PSO16particleMovementEv, .-_ZN3PSO16particleMovementEv
	.globl	_Z31__device_stub__Z9evalPlaneiPdS_iPdS_
	.type	_Z31__device_stub__Z9evalPlaneiPdS_iPdS_, @function
_Z31__device_stub__Z9evalPlaneiPdS_iPdS_:
.LFB3681:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movl	%edi, 28(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L68
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z9evalPlaneiPdS_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L68:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L70
	call	__stack_chk_fail@PLT
.L70:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3681:
	.size	_Z31__device_stub__Z9evalPlaneiPdS_iPdS_, .-_Z31__device_stub__Z9evalPlaneiPdS_iPdS_
	.globl	_Z9evalPlaneiPdS_
	.type	_Z9evalPlaneiPdS_, @function
_Z9evalPlaneiPdS_:
.LFB3682:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z9evalPlaneiPdS_iPdS_
	.cfi_endproc
.LFE3682:
	.size	_Z9evalPlaneiPdS_, .-_Z9evalPlaneiPdS_
	.align 2
	.globl	_ZN3PSO8evaluateEi
	.type	_ZN3PSO8evaluateEi, @function
_ZN3PSO8evaluateEi:
.LFB3651:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rdi, %rbp
	movl	$8, %edi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movslq	%esi, %rbx
	imulq	$40, %rbx, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	leaq	8(%rsp), %rdi
	movl	$1, %edx
	movl	$8, %esi
	movq	%rax, 8(%rsp)
	call	cudaMallocManaged@PLT
	movq	40(%rbp), %rdi
	movl	$1, %edx
	movl	$240, %esi
	addq	%rbx, %rdi
	call	cudaMallocManaged@PLT
	movl	$536870913, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1073741825, %edi
	salq	$3, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	salq	$2, %rdi
	movq	%rdx, 28(%rsp)
	movl	$1, 36(%rsp)
	movq	%rdi, 16(%rsp)
	movl	$1, 24(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L74
	movq	40(%rbp), %rax
	movq	8(%rsp), %rdx
	movl	$30, %edi
	movq	(%rax,%rbx), %rsi
	call	_Z31__device_stub__Z9evalPlaneiPdS_iPdS_
.L74:
	call	cudaGetLastError@PLT
	call	cudaDeviceSynchronize@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rbp), %rax
	movq	(%rax,%rbx), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L75
	call	__stack_chk_fail@PLT
.L75:
	addq	$56, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3651:
	.size	_ZN3PSO8evaluateEi, .-_ZN3PSO8evaluateEi
	.section	.rodata.str1.1
.LC11:
	.string	"0 : "
.LC12:
	.string	"%g "
.LC13:
	.string	" = %e\n"
	.text
	.align 2
	.globl	_ZN3PSO10initializeEv
	.type	_ZN3PSO10initializeEv, @function
_ZN3PSO10initializeEv:
.LFB3650:
	.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
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	movq	.LC8(%rip), %rax
	movq	%rax, 32(%rdi)
.L78:
	xorl	%r12d, %r12d
.L79:
	call	rand@PLT
	leaq	24(%rbx), %r13
	movl	%r12d, %edx
	xorps	%xmm1, %xmm1
	cvtsi2sdl	%eax, %xmm0
	movl	%ebp, %esi
	movq	%r13, %rdi
	incl	%r12d
	divsd	.LC6(%rip), %xmm0
	mulsd	.LC9(%rip), %xmm0
	subsd	.LC10(%rip), %xmm0
	call	_ZN5Swarm13setParticleXVEiidd
	cmpl	$30, %r12d
	jne	.L79
	movl	%ebp, %esi
	movq	%rbx, %rdi
	call	_ZN3PSO8evaluateEi
	movl	%ebp, %esi
	movq	%rbx, %rdi
	call	_ZN3PSO10updateBestEi
	movq	%rsp, %r8
	movl	%ebp, %edx
	movq	%r13, %rsi
	movq	%r8, %rdi
	call	_ZN5Swarm16getParticleValueEi
	movsd	16(%rsp), %xmm0
	movsd	32(%rbx), %xmm1
	comisd	%xmm0, %xmm1
	jbe	.L80
	movl	%ebp, 24(%rbx)
	movsd	%xmm0, 32(%rbx)
.L80:
	incl	%ebp
	cmpl	$30, %ebp
	jne	.L78
	movl	24(%rbx), %edx
	movq	%r8, %rdi
	movq	%r13, %rsi
	xorl	%ebx, %ebx
	leaq	.LC12(%rip), %rbp
	call	_ZN5Swarm16getParticleValueEi
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L83:
	movq	32(%rsp), %rax
	movq	%rbp, %rsi
	movl	$2, %edi
	movsd	(%rax,%rbx), %xmm0
	movb	$1, %al
	addq	$8, %rbx
	call	__printf_chk@PLT
	cmpq	$240, %rbx
	jne	.L83
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L84
	call	__stack_chk_fail@PLT
.L84:
	movsd	24(%rsp), %xmm0
	addq	$56, %rsp
	.cfi_def_cfa_offset 40
	leaq	.LC13(%rip), %rsi
	movb	$1, %al
	popq	%rbx
	.cfi_def_cfa_offset 32
	movl	$2, %edi
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE3650:
	.size	_ZN3PSO10initializeEv, .-_ZN3PSO10initializeEv
	.section	.rodata.str1.1
.LC14:
	.string	"%d : "
.LC15:
	.string	" = %g\n"
	.text
	.align 2
	.globl	_ZN3PSO13evaluateSwarmEv
	.type	_ZN3PSO13evaluateSwarmEv, @function
_ZN3PSO13evaluateSwarmEv:
.LFB3652:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC14(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	subq	$48, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
.L92:
	movl	%ebp, %esi
	movq	%rbx, %rdi
	call	_ZN3PSO8evaluateEi
	movl	(%rbx), %eax
	movl	$5000, %ecx
	leal	1(%rax), %r8d
	movl	%r8d, %eax
	movl	%r8d, (%rbx)
	cltd
	idivl	%ecx
	testl	%edx, %edx
	jne	.L91
	movl	24(%rbx), %edx
	movq	%rsp, %rdi
	leaq	24(%rbx), %rsi
	call	_ZN5Swarm16getParticleValueEi
	movq	%r12, %rsi
	movl	$2, %edi
	movl	%r8d, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movsd	24(%rsp), %xmm0
	leaq	.LC15(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	call	__printf_chk@PLT
.L91:
	incl	%ebp
	cmpl	$30, %ebp
	jne	.L92
	xorl	%r8d, %r8d
	leaq	24(%rbx), %r9
.L97:
	movq	%rsp, %rdi
	movl	%r8d, %edx
	movq	%r9, %rsi
	call	_ZN5Swarm16getParticleValueEi
	movsd	16(%rsp), %xmm1
	movsd	24(%rsp), %xmm0
	comisd	%xmm1, %xmm0
	jbe	.L94
	movq	(%rsp), %rdx
	movaps	%xmm1, %xmm0
	movl	%r8d, %esi
	movq	%r9, %rdi
	call	_ZN5Swarm16setParticlePBestEidPd
	movsd	32(%rbx), %xmm0
	comisd	%xmm1, %xmm0
	jbe	.L94
	movl	%r8d, 24(%rbx)
	movsd	%xmm1, 32(%rbx)
.L94:
	incl	%r8d
	cmpl	$30, %r8d
	jne	.L97
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L98
	call	__stack_chk_fail@PLT
.L98:
	addq	$48, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3652:
	.size	_ZN3PSO13evaluateSwarmEv, .-_ZN3PSO13evaluateSwarmEv
	.align 2
	.globl	_ZN3PSO9evolutionEv
	.type	_ZN3PSO9evolutionEv, @function
_ZN3PSO9evolutionEv:
.LFB3649:
	.cfi_startproc
	endbr64
	movq	.LC16(%rip), %rax
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	movq	%rax, 8(%rdi)
	call	_ZN3PSO10initializeEv
	xorl	%eax, %eax
	movl	%eax, (%rbx)
.L104:
	cmpl	$999999, (%rbx)
	jg	.L107
	movq	%rbx, %rdi
	call	_ZN3PSO13calculateVMaxEv
	movq	%rbx, %rdi
	call	_ZN3PSO16particleMovementEv
	movq	%rbx, %rdi
	call	_ZN3PSO13evaluateSwarmEv
	movsd	8(%rbx), %xmm0
	subsd	.LC17(%rip), %xmm0
	movsd	%xmm0, 8(%rbx)
	jmp	.L104
.L107:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3649:
	.size	_ZN3PSO9evolutionEv, .-_ZN3PSO9evolutionEv
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3656:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	subq	$64, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rbx
	movq	%rbx, %rdi
	call	_ZN3PSOC1Ev
	movq	%rbx, %rdi
	call	_ZN3PSO9evolutionEv
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L109
	call	__stack_chk_fail@PLT
.L109:
	addq	$64, %rsp
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3656:
	.size	main, .-main
	.section	.rodata.str1.1
.LC18:
	.string	"_Z9evalPlaneiPdS_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3684:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC18(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z9evalPlaneiPdS_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3684:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC6:
	.long	-4194304
	.long	1105199103
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC7:
	.long	0
	.long	-2147483648
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC8:
	.long	-1
	.long	2146435071
	.align 8
.LC9:
	.long	1202590843
	.long	1076132577
	.align 8
.LC10:
	.long	1202590843
	.long	1075084001
	.align 8
.LC16:
	.long	-858993459
	.long	1072483532
	.align 8
.LC17:
	.long	-351632489
	.long	1055880484
	.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 <iostream>
#include <cstdlib>
#include <limits>
using namespace std;

#define Nparticles     30
#define T_MAX          1000
#define NFC_MAX        1000000
#define W_0            0.9
#define W_T            0.4
#define MAX_V          2.0
#define c1             2.0      
#define c2             2.0
#define Nvariables     30


#define Rand()     ((double)rand()/RAND_MAX);

__global__ void evalPlane(int n, double *x, double *fit) {
    int index = blockIdx.x * blockDim.x + threadIdx.x;
    int stride = blockDim.x * gridDim.x;
    for (int i = index; i < n; i += stride)
        fit[i] += x[i] * x[i];
}


class Particle {
    public:
        double *x;
        double *v;
        double fitness;
        double pBest;
        double *xBest;
};

class Swarm {
    private:
        
        int gBest; //index
        double gBestValue;
    public:
        Particle *P;
        Swarm();
        void setGBestIndex(int index);
        void setGBestValue(double gBestValue);
        void setParticleXV(int i, int j, double x, double v);
        void setParticleFitness(int i, double fit);
        void setParticlePBest(int i, double value, double *x);
        Particle getParticleValue(int i);
        int getGbest();
        double getGbestValue();
};

Swarm::Swarm() {
    gBest = 0;

    P = (Particle *)malloc(sizeof(Particle)*Nparticles);
    if (P==NULL) {
        fprintf(stderr, "Cannot allocate memory for %d Particles\n", Nparticles);
        exit (1);
    } 

    for(int i = 0; i < Nparticles; i++) {
        P[i].x = (double *)malloc(sizeof(double)*Nvariables);
        if (P[i].x==NULL) {
            fprintf(stderr, "Cannot allocate memory for %d x\n", Nvariables);
            exit (1);
        } 
        P[i].v = (double *)malloc(sizeof(double)*Nvariables);
        if (P[i].v==NULL) {
            fprintf(stderr, "Cannot allocate memory for %d v\n", Nvariables);
            exit (1);
        } 
        P[i].xBest = (double *)malloc(sizeof(double)*Nvariables);
        if (P[i].xBest==NULL) {
            fprintf(stderr, "Cannot allocate memory for %d xBest\n", Nvariables);
            exit (1);
        } 
    }
    
}

void Swarm::setGBestIndex(int index) {
    this->gBest = index;
}

void Swarm::setGBestValue(double gBestValue) {
    this->gBestValue = gBestValue;
}

void Swarm::setParticleXV(int i, int j, double x, double v) {
    if (x != NULL) P[i].x[j] = x;
    if (v != NULL) P[i].v[j] = v;
}

void Swarm::setParticleFitness(int i, double fit) {
    P[i].fitness = fit;
}

void Swarm::setParticlePBest(int i, double value, double *x) {
    P[i].pBest = value;
    for(int j = 0; j < Nvariables; j++)
    {
        P[i].xBest[j] = P[i].x[j];
    }    
}

Particle Swarm::getParticleValue(int i) {
    return P[i];
}

int Swarm::getGbest() {
    return gBest;
}

double Swarm::getGbestValue() {
    return gBestValue;
}

class PSO {
    private:
        int nfc;
        double w;
        double *maxV; 
    public:
        Swarm swarm;
        PSO();
        void initialize();
        void evolution();
        void updateBest(int i);
        void calculateVMax();
        void particleMovement();
        void evaluate(int i);
        void evaluateSwarm();
};

PSO::PSO() {
    maxV = (double *)malloc(sizeof(double)*Nvariables);
    if (maxV==NULL) {
        fprintf(stderr, "Cannot allocate memory for %d maxV\n", Nvariables);
        exit (1);
    } 
}

void PSO::evolution() {
    double dw = (W_0 - W_T) / (NFC_MAX / Nparticles);
    w = W_0;
    
    initialize();
    
    nfc = 0;
    while(nfc < NFC_MAX) {
        calculateVMax();
        particleMovement();  
        evaluateSwarm();
        w -= dw;     
    }

}

void PSO::initialize() {
    swarm.setGBestValue(numeric_limits<double>::max());

    for(int i = 0; i < Nparticles; i++) {
        for(int j = 0; j < Nvariables; j++) {
            double x = -5.12 + 10.24 * Rand();
            //double x = Rand();
            double v = 0.0;
            swarm.setParticleXV(i, j, x, v);
        }
        evaluate(i);
        updateBest(i);

        double fitness = swarm.getParticleValue(i).fitness;
        double gbest = swarm.getGbestValue();

        if (fitness < gbest) {
            swarm.setGBestValue(fitness);
            swarm.setGBestIndex(i);
        }

    }

    Particle best = swarm.getParticleValue(swarm.getGbest());
    printf("0 : ");
    for (int j = 0; j < Nvariables; j++)
        printf("%g ", best.xBest[j]);
    printf(" = %e\n", best.pBest);
}

void PSO::evaluate(int i) {
    //int index = i;

    int ThreadsInBlock = 8;
    int BlocksInGrid = (int)(Nvariables + ThreadsInBlock - 1) / ThreadsInBlock;
    double *fitness = (double *)malloc(sizeof(double));
    hipMallocManaged((void **)&fitness, sizeof(double));

    hipMallocManaged((void **)&swarm.P[i].x, sizeof(double)*Nvariables);

    evalPlane<<<BlocksInGrid, ThreadsInBlock>>>(Nvariables, swarm.P[i].x, fitness);
    hipGetLastError();

    //if (cudaSuccess != cudaMemcpy())


    hipDeviceSynchronize();

    // double fitness = 0.0;

    // for(int k = 0 ; k < Nvariables ; k++ ) {
    //     int x = swarm.getParticleValue(index).x[k];
    //     fitness +=  x * x;
    // }


    // double fitness = 0, temp = 0;
    // for(int k = 0 ; k < Nvariables ; k++ ) {
    //     for(int l = 0; l < k; l++)
    //     {
    //         double x = swarm.getParticleValue(index).x[l];
    //         temp += x;
    //     }
        
    //     fitness +=  temp * temp;
    // }

    hipFree(fitness);
    hipFree(swarm.P[i].x);
    //swarm.setParticleFitness(index, fitness);
}

void PSO::evaluateSwarm() {
    for(int i = 0; i < Nparticles; i++) {
        evaluate(i);    
        nfc++;

        if (nfc % 5000 == 0) {
            Particle best = swarm.getParticleValue(swarm.getGbest());
            printf("%d : ", nfc);
            // for (int j = 0; j < Nvariables; j++)
            //     printf("%g ", best.xBest[j]);
            printf(" = %g\n", best.pBest);
            //cout << "PSO SPHERE nfc" << nfc << " \tbestfit " << best.pBest << "\n";
        }
    }

    for(int n = 0; n < Nparticles; n++) {
        Particle par = swarm.getParticleValue(n);
        if (par.fitness < par.pBest ) {
            swarm.setParticlePBest(n, par.fitness, par.x);

            if (par.fitness < swarm.getGbestValue() ) {
                swarm.setGBestIndex(n);
                swarm.setGBestValue(par.fitness);
            }
        }
    }
}

void PSO::updateBest(int i) {
    Particle par = swarm.getParticleValue(i);
    swarm.setParticlePBest(i, par.fitness, par.x);
}

void PSO::calculateVMax() {
    double xmin[Nparticles], xmax[Nparticles];

    for (int d = 0; d < Nvariables; d++) {
        xmin[d] = xmax[d] = swarm.getParticleValue(0).x[d];
        for (int n = 1; n < Nparticles; n++) {
            double pos = swarm.getParticleValue(n).x[d];
            if (pos < xmin[d])
                xmin[d] = pos;
            if (pos > xmax[d])
                xmax[d] = pos;
        }
        maxV[d] = xmax[d] - xmin[d];
    }
}

void PSO::particleMovement() {
    int n, d;

    for (n = 0; n < Nparticles ; n++) {
        Particle par = swarm.getParticleValue(n);
        Particle bPar = swarm.getParticleValue(swarm.getGbest());
        // update velocities
        for(d = 0; d < Nvariables ; d++ ) {
            double r1 = Rand();
            double r2 = Rand();
            double newV = w * par.v[d] + c1 * r1 * (par.xBest[d] - par.x[d]) + c2 * r2 * (bPar.x[d] - par.x[d]);
            swarm.setParticleXV(n, d, NULL, newV);
            // check v with its dimensional maxV
            if ( swarm.getParticleValue(n).v[d] > maxV[d] ) swarm.setParticleXV(n, d, NULL, maxV[d]);
            else if ( swarm.getParticleValue(n).v[d] < -maxV[d] ) swarm.setParticleXV(n, d, NULL, -maxV[d]);
        }
        // update positions
        Particle newPar = swarm.getParticleValue(n);
        for (d = 0; d < Nvariables ; d++) {
            //newPar.x[d] = newPar.x[d] + newPar.v[d];
            swarm.setParticleXV(n, d, newPar.x[d] + newPar.v[d], NULL);
        }
    }
}

int main(int argc, char **argv) {
    //int threadCount = BlocksInGrid * ThreadsInBlock;
    //long size = threadCount * sizeof(double);
    PSO pso;
    pso.evolution();

    return 0;
}
	.text
	.file	"CUDA_BPSO.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z24__device_stub__evalPlaneiPdS_ # -- Begin function _Z24__device_stub__evalPlaneiPdS_
	.type	_Z24__device_stub__evalPlaneiPdS_,@function
_Z24__device_stub__evalPlaneiPdS_:      # @_Z24__device_stub__evalPlaneiPdS_
	.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	12(%rsp), %rax
	movl	%edi, (%rax)
	leaq	40(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	32(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%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	$_Z9evalPlaneiPdS_, %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_end0:
	.size	_Z24__device_stub__evalPlaneiPdS_, .Lfunc_end0-_Z24__device_stub__evalPlaneiPdS_
	.cfi_endproc
                                        # -- End function
	.globl	_ZN5SwarmC2Ev                   # -- Begin function _ZN5SwarmC2Ev
	.p2align	1, 0x90
	.type	_ZN5SwarmC2Ev,@function
_ZN5SwarmC2Ev:                          # @_ZN5SwarmC2Ev
	.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, %r14
	movl	$0, (%rdi)
	movl	$1200, %edi                     # imm = 0x4B0
	callq	malloc
	movq	%rax, 16(%r14)
	testq	%rax, %rax
	je	.LBB1_2
# %bb.1:                                # %.preheader.preheader
	movq	%rax, %rbx
	xorl	%r14d, %r14d
.LBB1_5:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	movl	$240, %edi
	callq	malloc
	movq	%rax, (%rbx,%r14)
	testq	%rax, %rax
	je	.LBB1_6
# %bb.7:                                #   in Loop: Header=BB1_5 Depth=1
	movl	$240, %edi
	callq	malloc
	movq	%rax, 8(%rbx,%r14)
	testq	%rax, %rax
	je	.LBB1_8
# %bb.9:                                #   in Loop: Header=BB1_5 Depth=1
	movl	$240, %edi
	callq	malloc
	movq	%rax, 32(%rbx,%r14)
	testq	%rax, %rax
	je	.LBB1_10
# %bb.4:                                #   in Loop: Header=BB1_5 Depth=1
	addq	$40, %r14
	cmpq	$1200, %r14                     # imm = 0x4B0
	jne	.LBB1_5
# %bb.11:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB1_10:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rdi
	movl	$.L.str.3, %esi
	jmp	.LBB1_3
.LBB1_6:
	movq	stderr(%rip), %rdi
	movl	$.L.str.1, %esi
	jmp	.LBB1_3
.LBB1_8:
	movq	stderr(%rip), %rdi
	movl	$.L.str.2, %esi
.LBB1_3:
	movl	$30, %edx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.LBB1_2:
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	jmp	.LBB1_3
.Lfunc_end1:
	.size	_ZN5SwarmC2Ev, .Lfunc_end1-_ZN5SwarmC2Ev
	.cfi_endproc
                                        # -- End function
	.globl	_ZN5Swarm13setGBestIndexEi      # -- Begin function _ZN5Swarm13setGBestIndexEi
	.p2align	1, 0x90
	.type	_ZN5Swarm13setGBestIndexEi,@function
_ZN5Swarm13setGBestIndexEi:             # @_ZN5Swarm13setGBestIndexEi
	.cfi_startproc
# %bb.0:
	movl	%esi, (%rdi)
	retq
.Lfunc_end2:
	.size	_ZN5Swarm13setGBestIndexEi, .Lfunc_end2-_ZN5Swarm13setGBestIndexEi
	.cfi_endproc
                                        # -- End function
	.globl	_ZN5Swarm13setGBestValueEd      # -- Begin function _ZN5Swarm13setGBestValueEd
	.p2align	1, 0x90
	.type	_ZN5Swarm13setGBestValueEd,@function
_ZN5Swarm13setGBestValueEd:             # @_ZN5Swarm13setGBestValueEd
	.cfi_startproc
# %bb.0:
	movsd	%xmm0, 8(%rdi)
	retq
.Lfunc_end3:
	.size	_ZN5Swarm13setGBestValueEd, .Lfunc_end3-_ZN5Swarm13setGBestValueEd
	.cfi_endproc
                                        # -- End function
	.globl	_ZN5Swarm13setParticleXVEiidd   # -- Begin function _ZN5Swarm13setParticleXVEiidd
	.p2align	1, 0x90
	.type	_ZN5Swarm13setParticleXVEiidd,@function
_ZN5Swarm13setParticleXVEiidd:          # @_ZN5Swarm13setParticleXVEiidd
	.cfi_startproc
# %bb.0:
	xorpd	%xmm2, %xmm2
	ucomisd	%xmm2, %xmm0
	movslq	%esi, %rcx
	movslq	%edx, %rax
	jne	.LBB4_1
	jnp	.LBB4_2
.LBB4_1:
	movq	16(%rdi), %rdx
	leaq	(%rcx,%rcx,4), %rsi
	movq	(%rdx,%rsi,8), %rdx
	movsd	%xmm0, (%rdx,%rax,8)
.LBB4_2:
	ucomisd	%xmm2, %xmm1
	jne	.LBB4_3
	jnp	.LBB4_4
.LBB4_3:
	movq	16(%rdi), %rdx
	leaq	(%rcx,%rcx,4), %rcx
	movq	8(%rdx,%rcx,8), %rcx
	movsd	%xmm1, (%rcx,%rax,8)
.LBB4_4:
	retq
.Lfunc_end4:
	.size	_ZN5Swarm13setParticleXVEiidd, .Lfunc_end4-_ZN5Swarm13setParticleXVEiidd
	.cfi_endproc
                                        # -- End function
	.globl	_ZN5Swarm18setParticleFitnessEid # -- Begin function _ZN5Swarm18setParticleFitnessEid
	.p2align	1, 0x90
	.type	_ZN5Swarm18setParticleFitnessEid,@function
_ZN5Swarm18setParticleFitnessEid:       # @_ZN5Swarm18setParticleFitnessEid
	.cfi_startproc
# %bb.0:
	movq	16(%rdi), %rax
	movslq	%esi, %rcx
	leaq	(%rcx,%rcx,4), %rcx
	movsd	%xmm0, 16(%rax,%rcx,8)
	retq
.Lfunc_end5:
	.size	_ZN5Swarm18setParticleFitnessEid, .Lfunc_end5-_ZN5Swarm18setParticleFitnessEid
	.cfi_endproc
                                        # -- End function
	.globl	_ZN5Swarm16setParticlePBestEidPd # -- Begin function _ZN5Swarm16setParticlePBestEidPd
	.p2align	1, 0x90
	.type	_ZN5Swarm16setParticlePBestEidPd,@function
_ZN5Swarm16setParticlePBestEidPd:       # @_ZN5Swarm16setParticlePBestEidPd
	.cfi_startproc
# %bb.0:
	movq	16(%rdi), %rcx
	movslq	%esi, %rax
	leaq	(%rax,%rax,4), %rdx
	movsd	%xmm0, 24(%rcx,%rdx,8)
	movq	(%rcx,%rdx,8), %rax
	movq	32(%rcx,%rdx,8), %rcx
	xorl	%edx, %edx
.LBB6_1:                                # =>This Inner Loop Header: Depth=1
	movsd	(%rax,%rdx,8), %xmm0            # xmm0 = mem[0],zero
	movsd	%xmm0, (%rcx,%rdx,8)
	incq	%rdx
	cmpq	$30, %rdx
	jne	.LBB6_1
# %bb.2:
	retq
.Lfunc_end6:
	.size	_ZN5Swarm16setParticlePBestEidPd, .Lfunc_end6-_ZN5Swarm16setParticlePBestEidPd
	.cfi_endproc
                                        # -- End function
	.globl	_ZN5Swarm16getParticleValueEi   # -- Begin function _ZN5Swarm16getParticleValueEi
	.p2align	1, 0x90
	.type	_ZN5Swarm16getParticleValueEi,@function
_ZN5Swarm16getParticleValueEi:          # @_ZN5Swarm16getParticleValueEi
	.cfi_startproc
# %bb.0:
	movq	%rdi, %rax
	movq	16(%rsi), %rcx
	movslq	%edx, %rdx
	leaq	(%rdx,%rdx,4), %rdx
	movq	32(%rcx,%rdx,8), %rsi
	movq	%rsi, 32(%rdi)
	movups	(%rcx,%rdx,8), %xmm0
	movups	16(%rcx,%rdx,8), %xmm1
	movups	%xmm1, 16(%rdi)
	movups	%xmm0, (%rdi)
	retq
.Lfunc_end7:
	.size	_ZN5Swarm16getParticleValueEi, .Lfunc_end7-_ZN5Swarm16getParticleValueEi
	.cfi_endproc
                                        # -- End function
	.globl	_ZN5Swarm8getGbestEv            # -- Begin function _ZN5Swarm8getGbestEv
	.p2align	1, 0x90
	.type	_ZN5Swarm8getGbestEv,@function
_ZN5Swarm8getGbestEv:                   # @_ZN5Swarm8getGbestEv
	.cfi_startproc
# %bb.0:
	movl	(%rdi), %eax
	retq
.Lfunc_end8:
	.size	_ZN5Swarm8getGbestEv, .Lfunc_end8-_ZN5Swarm8getGbestEv
	.cfi_endproc
                                        # -- End function
	.globl	_ZN5Swarm13getGbestValueEv      # -- Begin function _ZN5Swarm13getGbestValueEv
	.p2align	1, 0x90
	.type	_ZN5Swarm13getGbestValueEv,@function
_ZN5Swarm13getGbestValueEv:             # @_ZN5Swarm13getGbestValueEv
	.cfi_startproc
# %bb.0:
	movsd	8(%rdi), %xmm0                  # xmm0 = mem[0],zero
	retq
.Lfunc_end9:
	.size	_ZN5Swarm13getGbestValueEv, .Lfunc_end9-_ZN5Swarm13getGbestValueEv
	.cfi_endproc
                                        # -- End function
	.globl	_ZN3PSOC2Ev                     # -- Begin function _ZN3PSOC2Ev
	.p2align	1, 0x90
	.type	_ZN3PSOC2Ev,@function
_ZN3PSOC2Ev:                            # @_ZN3PSOC2Ev
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	addq	$24, %rdi
	callq	_ZN5SwarmC2Ev
	movl	$240, %edi
	callq	malloc
	movq	%rax, 16(%rbx)
	testq	%rax, %rax
	je	.LBB10_2
# %bb.1:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB10_2:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rdi
	movl	$.L.str.4, %esi
	movl	$30, %edx
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end10:
	.size	_ZN3PSOC2Ev, .Lfunc_end10-_ZN3PSOC2Ev
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _ZN3PSO9evolutionEv
.LCPI11_0:
	.quad	0xbeef7524eb0a8397              # double -1.5000150001500015E-5
	.text
	.globl	_ZN3PSO9evolutionEv
	.p2align	1, 0x90
	.type	_ZN3PSO9evolutionEv,@function
_ZN3PSO9evolutionEv:                    # @_ZN3PSO9evolutionEv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movabsq	$4606281698874543309, %rax      # imm = 0x3FECCCCCCCCCCCCD
	movq	%rax, 8(%rdi)
	callq	_ZN3PSO10initializeEv
	movl	$0, (%rbx)
.LBB11_1:                               # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	callq	_ZN3PSO13calculateVMaxEv
	movq	%rbx, %rdi
	callq	_ZN3PSO16particleMovementEv
	movq	%rbx, %rdi
	callq	_ZN3PSO13evaluateSwarmEv
	movsd	8(%rbx), %xmm0                  # xmm0 = mem[0],zero
	addsd	.LCPI11_0(%rip), %xmm0
	movsd	%xmm0, 8(%rbx)
	cmpl	$1000000, (%rbx)                # imm = 0xF4240
	jl	.LBB11_1
# %bb.2:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end11:
	.size	_ZN3PSO9evolutionEv, .Lfunc_end11-_ZN3PSO9evolutionEv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _ZN3PSO10initializeEv
.LCPI12_0:
	.quad	0x41dfffffffc00000              # double 2147483647
.LCPI12_1:
	.quad	0x40247ae147ae147b              # double 10.24
.LCPI12_2:
	.quad	0xc0147ae147ae147b              # double -5.1200000000000001
.LCPI12_3:
	.quad	0x0000000000000000              # double 0
	.text
	.globl	_ZN3PSO10initializeEv
	.p2align	1, 0x90
	.type	_ZN3PSO10initializeEv,@function
_ZN3PSO10initializeEv:                  # @_ZN3PSO10initializeEv
	.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
	movabsq	$9218868437227405311, %rax      # imm = 0x7FEFFFFFFFFFFFFF
	movq	%rax, 32(%rdi)
	xorl	%r14d, %r14d
.LBB12_1:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB12_2 Depth 2
                                        #     Child Loop BB12_6 Depth 2
	leaq	(%r14,%r14,4), %r15
	xorl	%r12d, %r12d
.LBB12_2:                               #   Parent Loop BB12_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI12_0(%rip), %xmm0
	mulsd	.LCPI12_1(%rip), %xmm0
	addsd	.LCPI12_2(%rip), %xmm0
	ucomisd	.LCPI12_3(%rip), %xmm0
	jne	.LBB12_3
	jnp	.LBB12_4
.LBB12_3:                               #   in Loop: Header=BB12_2 Depth=2
	movq	40(%rbx), %rax
	movq	(%rax,%r15,8), %rax
	movsd	%xmm0, (%rax,%r12,8)
.LBB12_4:                               # %_ZN5Swarm13setParticleXVEiidd.exit
                                        #   in Loop: Header=BB12_2 Depth=2
	incq	%r12
	cmpq	$30, %r12
	jne	.LBB12_2
# %bb.5:                                #   in Loop: Header=BB12_1 Depth=1
	movq	%rbx, %rdi
	movl	%r14d, %esi
	callq	_ZN3PSO8evaluateEi
	movq	40(%rbx), %rcx
	movsd	16(%rcx,%r15,8), %xmm0          # xmm0 = mem[0],zero
	movsd	%xmm0, 24(%rcx,%r15,8)
	movq	(%rcx,%r15,8), %rax
	movq	32(%rcx,%r15,8), %rcx
	xorl	%edx, %edx
.LBB12_6:                               #   Parent Loop BB12_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rax,%rdx,8), %xmm0            # xmm0 = mem[0],zero
	movsd	%xmm0, (%rcx,%rdx,8)
	incq	%rdx
	cmpq	$30, %rdx
	jne	.LBB12_6
# %bb.7:                                # %_ZN3PSO10updateBestEi.exit
                                        #   in Loop: Header=BB12_1 Depth=1
	movq	40(%rbx), %rax
	movsd	16(%rax,%r15,8), %xmm0          # xmm0 = mem[0],zero
	movsd	32(%rbx), %xmm1                 # xmm1 = mem[0],zero
	ucomisd	%xmm0, %xmm1
	jbe	.LBB12_9
# %bb.8:                                #   in Loop: Header=BB12_1 Depth=1
	movsd	%xmm0, 32(%rbx)
	movl	%r14d, 24(%rbx)
.LBB12_9:                               #   in Loop: Header=BB12_1 Depth=1
	incq	%r14
	cmpq	$30, %r14
	jne	.LBB12_1
# %bb.10:
	movslq	24(%rbx), %rcx
	leaq	(%rcx,%rcx,4), %rcx
	movsd	24(%rax,%rcx,8), %xmm0          # xmm0 = mem[0],zero
	movsd	%xmm0, (%rsp)                   # 8-byte Spill
	movq	32(%rax,%rcx,8), %rbx
	xorl	%r14d, %r14d
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
.LBB12_11:                              # =>This Inner Loop Header: Depth=1
	movsd	(%rbx,%r14,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	incq	%r14
	cmpq	$30, %r14
	jne	.LBB12_11
# %bb.12:
	movl	$.L.str.7, %edi
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	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	printf                          # TAILCALL
.Lfunc_end12:
	.size	_ZN3PSO10initializeEv, .Lfunc_end12-_ZN3PSO10initializeEv
	.cfi_endproc
                                        # -- End function
	.globl	_ZN3PSO13calculateVMaxEv        # -- Begin function _ZN3PSO13calculateVMaxEv
	.p2align	1, 0x90
	.type	_ZN3PSO13calculateVMaxEv,@function
_ZN3PSO13calculateVMaxEv:               # @_ZN3PSO13calculateVMaxEv
	.cfi_startproc
# %bb.0:
	movq	16(%rdi), %rax
	movq	40(%rdi), %rcx
	xorl	%edx, %edx
.LBB13_1:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB13_2 Depth 2
	movq	(%rcx), %rsi
	movsd	(%rsi,%rdx,8), %xmm0            # xmm0 = mem[0],zero
	movl	$40, %esi
	movapd	%xmm0, %xmm1
.LBB13_2:                               #   Parent Loop BB13_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movapd	%xmm1, %xmm2
	movapd	%xmm0, %xmm3
	movq	(%rcx,%rsi), %rdi
	movsd	(%rdi,%rdx,8), %xmm1            # xmm1 = mem[0],zero
	movapd	%xmm1, %xmm0
	minsd	%xmm3, %xmm0
	maxsd	%xmm2, %xmm1
	addq	$40, %rsi
	cmpq	$1200, %rsi                     # imm = 0x4B0
	jne	.LBB13_2
# %bb.3:                                #   in Loop: Header=BB13_1 Depth=1
	subsd	%xmm0, %xmm1
	movsd	%xmm1, (%rax,%rdx,8)
	incq	%rdx
	cmpq	$30, %rdx
	jne	.LBB13_1
# %bb.4:
	retq
.Lfunc_end13:
	.size	_ZN3PSO13calculateVMaxEv, .Lfunc_end13-_ZN3PSO13calculateVMaxEv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _ZN3PSO16particleMovementEv
.LCPI14_0:
	.quad	0x41dfffffffc00000              # double 2147483647
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI14_1:
	.quad	0x8000000000000000              # double -0
	.quad	0x8000000000000000              # double -0
	.text
	.globl	_ZN3PSO16particleMovementEv
	.p2align	1, 0x90
	.type	_ZN3PSO16particleMovementEv,@function
_ZN3PSO16particleMovementEv:            # @_ZN3PSO16particleMovementEv
	.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	%rdi, %rbx
	movq	40(%rdi), %rax
	xorl	%ecx, %ecx
.LBB14_1:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB14_2 Depth 2
                                        #     Child Loop BB14_12 Depth 2
	movq	%rcx, (%rsp)                    # 8-byte Spill
	leaq	(%rcx,%rcx,4), %r15
	movq	(%rax,%r15,8), %rcx
	movq	%rcx, 8(%rsp)                   # 8-byte Spill
	movq	8(%rax,%r15,8), %r13
	movq	32(%rax,%r15,8), %rbp
	movslq	24(%rbx), %rcx
	leaq	(%rcx,%rcx,4), %rcx
	movq	(%rax,%rcx,8), %r14
	xorl	%r12d, %r12d
.LBB14_2:                               #   Parent Loop BB14_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	xorps	%xmm1, %xmm1
	cvtsi2sd	%eax, %xmm1
	movsd	.LCPI14_0(%rip), %xmm0          # xmm0 = mem[0],zero
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 16(%rsp)                 # 8-byte Spill
	callq	rand
	xorps	%xmm1, %xmm1
	cvtsi2sd	%eax, %xmm1
	divsd	.LCPI14_0(%rip), %xmm1
	movsd	8(%rbx), %xmm0                  # xmm0 = mem[0],zero
	mulsd	(%r13,%r12), %xmm0
	movsd	16(%rsp), %xmm4                 # 8-byte Reload
                                        # xmm4 = mem[0],zero
	addsd	%xmm4, %xmm4
	movsd	(%rbp,%r12), %xmm2              # xmm2 = mem[0],zero
	movq	8(%rsp), %rax                   # 8-byte Reload
	movsd	(%rax,%r12), %xmm3              # xmm3 = mem[0],zero
	subsd	%xmm3, %xmm2
	mulsd	%xmm4, %xmm2
	addsd	%xmm0, %xmm2
	addsd	%xmm1, %xmm1
	movsd	(%r14,%r12), %xmm0              # xmm0 = mem[0],zero
	subsd	%xmm3, %xmm0
	xorpd	%xmm3, %xmm3
	mulsd	%xmm1, %xmm0
	addsd	%xmm2, %xmm0
	ucomisd	%xmm3, %xmm0
	movq	40(%rbx), %rax
	jne	.LBB14_3
	jnp	.LBB14_4
.LBB14_3:                               #   in Loop: Header=BB14_2 Depth=2
	movq	8(%rax,%r15,8), %rcx
	movsd	%xmm0, (%rcx,%r12)
.LBB14_4:                               # %_ZN5Swarm13setParticleXVEiidd.exit
                                        #   in Loop: Header=BB14_2 Depth=2
	movq	8(%rax,%r15,8), %rcx
	movsd	(%rcx,%r12), %xmm2              # xmm2 = mem[0],zero
	movq	16(%rbx), %rdx
	movsd	(%rdx,%r12), %xmm0              # xmm0 = mem[0],zero
	ucomisd	%xmm0, %xmm2
	jbe	.LBB14_6
# %bb.5:                                #   in Loop: Header=BB14_2 Depth=2
	ucomisd	%xmm3, %xmm0
	jne	.LBB14_9
	jp	.LBB14_9
	jmp	.LBB14_10
.LBB14_6:                               #   in Loop: Header=BB14_2 Depth=2
	movapd	%xmm0, %xmm1
	xorpd	.LCPI14_1(%rip), %xmm1
	ucomisd	%xmm2, %xmm1
	jbe	.LBB14_10
# %bb.7:                                #   in Loop: Header=BB14_2 Depth=2
	ucomisd	%xmm3, %xmm0
	jne	.LBB14_8
	jnp	.LBB14_10
.LBB14_8:                               #   in Loop: Header=BB14_2 Depth=2
	movapd	%xmm1, %xmm0
.LBB14_9:                               # %_ZN5Swarm13setParticleXVEiidd.exit35.sink.split
                                        #   in Loop: Header=BB14_2 Depth=2
	movsd	%xmm0, (%rcx,%r12)
.LBB14_10:                              # %_ZN5Swarm13setParticleXVEiidd.exit35
                                        #   in Loop: Header=BB14_2 Depth=2
	addq	$8, %r12
	cmpq	$240, %r12
	jne	.LBB14_2
# %bb.11:                               #   in Loop: Header=BB14_1 Depth=1
	movq	(%rax,%r15,8), %rcx
	movq	8(%rax,%r15,8), %rdx
	xorl	%esi, %esi
.LBB14_12:                              #   Parent Loop BB14_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rcx,%rsi,8), %xmm0            # xmm0 = mem[0],zero
	addsd	(%rdx,%rsi,8), %xmm0
	ucomisd	%xmm3, %xmm0
	jne	.LBB14_13
	jnp	.LBB14_14
.LBB14_13:                              #   in Loop: Header=BB14_12 Depth=2
	movsd	%xmm0, (%rcx,%rsi,8)
.LBB14_14:                              # %_ZN5Swarm13setParticleXVEiidd.exit37
                                        #   in Loop: Header=BB14_12 Depth=2
	incq	%rsi
	cmpq	$30, %rsi
	jne	.LBB14_12
# %bb.15:                               #   in Loop: Header=BB14_1 Depth=1
	movq	(%rsp), %rcx                    # 8-byte Reload
	incq	%rcx
	cmpq	$30, %rcx
	jne	.LBB14_1
# %bb.16:
	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_end14:
	.size	_ZN3PSO16particleMovementEv, .Lfunc_end14-_ZN3PSO16particleMovementEv
	.cfi_endproc
                                        # -- End function
	.globl	_ZN3PSO13evaluateSwarmEv        # -- Begin function _ZN3PSO13evaluateSwarmEv
	.p2align	1, 0x90
	.type	_ZN3PSO13evaluateSwarmEv,@function
_ZN3PSO13evaluateSwarmEv:               # @_ZN3PSO13evaluateSwarmEv
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.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 %rbp, -16
	movq	%rdi, %rbx
	xorl	%ebp, %ebp
.LBB15_1:                               # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	_ZN3PSO8evaluateEi
	movl	(%rbx), %esi
	incl	%esi
	movl	%esi, (%rbx)
	imull	$989560465, %esi, %eax          # imm = 0x3AFB7E91
	addl	$3435968, %eax                  # imm = 0x346DC0
	rorl	$3, %eax
	cmpl	$858992, %eax                   # imm = 0xD1B70
	ja	.LBB15_3
# %bb.2:                                #   in Loop: Header=BB15_1 Depth=1
	movslq	24(%rbx), %rax
	movq	40(%rbx), %rcx
	leaq	(%rax,%rax,4), %rax
	movsd	24(%rcx,%rax,8), %xmm0          # xmm0 = mem[0],zero
	movsd	%xmm0, (%rsp)                   # 8-byte Spill
	movl	$.L.str.8, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.9, %edi
	movsd	(%rsp), %xmm0                   # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
.LBB15_3:                               #   in Loop: Header=BB15_1 Depth=1
	incl	%ebp
	cmpl	$30, %ebp
	jne	.LBB15_1
# %bb.4:                                # %.preheader
	movq	40(%rbx), %rax
	xorl	%ecx, %ecx
.LBB15_5:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB15_7 Depth 2
	leaq	(%rcx,%rcx,4), %rdx
	movsd	16(%rax,%rdx,8), %xmm0          # xmm0 = mem[0],zero
	movsd	24(%rax,%rdx,8), %xmm1          # xmm1 = mem[0],zero
	ucomisd	%xmm0, %xmm1
	jbe	.LBB15_10
# %bb.6:                                #   in Loop: Header=BB15_5 Depth=1
	leaq	(%rax,%rdx,8), %rsi
	movsd	%xmm0, 24(%rsi)
	movq	(%rsi), %rdx
	movq	32(%rsi), %rsi
	xorl	%edi, %edi
.LBB15_7:                               #   Parent Loop BB15_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%rdx,%rdi,8), %xmm1            # xmm1 = mem[0],zero
	movsd	%xmm1, (%rsi,%rdi,8)
	incq	%rdi
	cmpq	$30, %rdi
	jne	.LBB15_7
# %bb.8:                                # %_ZN5Swarm16setParticlePBestEidPd.exit
                                        #   in Loop: Header=BB15_5 Depth=1
	movsd	32(%rbx), %xmm1                 # xmm1 = mem[0],zero
	ucomisd	%xmm0, %xmm1
	jbe	.LBB15_10
# %bb.9:                                #   in Loop: Header=BB15_5 Depth=1
	movl	%ecx, 24(%rbx)
	movsd	%xmm0, 32(%rbx)
.LBB15_10:                              #   in Loop: Header=BB15_5 Depth=1
	incq	%rcx
	cmpq	$30, %rcx
	jne	.LBB15_5
# %bb.11:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end15:
	.size	_ZN3PSO13evaluateSwarmEv, .Lfunc_end15-_ZN3PSO13evaluateSwarmEv
	.cfi_endproc
                                        # -- End function
	.globl	_ZN3PSO8evaluateEi              # -- Begin function _ZN3PSO8evaluateEi
	.p2align	1, 0x90
	.type	_ZN3PSO8evaluateEi,@function
_ZN3PSO8evaluateEi:                     # @_ZN3PSO8evaluateEi
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.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 %rbp, -16
	movl	%esi, %ebp
	movq	%rdi, %rbx
	movl	$8, %edi
	callq	malloc
	leaq	8(%rsp), %rdi
	movq	%rax, (%rdi)
	movl	$8, %esi
	movl	$1, %edx
	callq	hipMallocManaged
	movslq	%ebp, %rax
	leaq	(%rax,%rax,4), %r14
	leaq	(,%r14,8), %rdi
	addq	40(%rbx), %rdi
	movl	$240, %esi
	movl	$1, %edx
	callq	hipMallocManaged
	movabsq	$4294967300, %rdi               # imm = 0x100000004
	leaq	4(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB16_2
# %bb.1:
	movq	40(%rbx), %rax
	movq	(%rax,%r14,8), %rsi
	movq	8(%rsp), %rdx
	movl	$30, %edi
	callq	_Z24__device_stub__evalPlaneiPdS_
.LBB16_2:
	callq	hipGetLastError
	callq	hipDeviceSynchronize
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	40(%rbx), %rax
	movq	(%rax,%r14,8), %rdi
	callq	hipFree
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end16:
	.size	_ZN3PSO8evaluateEi, .Lfunc_end16-_ZN3PSO8evaluateEi
	.cfi_endproc
                                        # -- End function
	.globl	_ZN3PSO10updateBestEi           # -- Begin function _ZN3PSO10updateBestEi
	.p2align	1, 0x90
	.type	_ZN3PSO10updateBestEi,@function
_ZN3PSO10updateBestEi:                  # @_ZN3PSO10updateBestEi
	.cfi_startproc
# %bb.0:
	movq	40(%rdi), %rcx
	movslq	%esi, %rax
	leaq	(%rax,%rax,4), %rdx
	movsd	16(%rcx,%rdx,8), %xmm0          # xmm0 = mem[0],zero
	movsd	%xmm0, 24(%rcx,%rdx,8)
	movq	(%rcx,%rdx,8), %rax
	movq	32(%rcx,%rdx,8), %rcx
	xorl	%edx, %edx
.LBB17_1:                               # =>This Inner Loop Header: Depth=1
	movsd	(%rax,%rdx,8), %xmm0            # xmm0 = mem[0],zero
	movsd	%xmm0, (%rcx,%rdx,8)
	incq	%rdx
	cmpq	$30, %rdx
	jne	.LBB17_1
# %bb.2:                                # %_ZN5Swarm16setParticlePBestEidPd.exit
	retq
.Lfunc_end17:
	.size	_ZN3PSO10updateBestEi, .Lfunc_end17-_ZN3PSO10updateBestEi
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$48, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -16
	movq	%rsp, %rbx
	movq	%rbx, %rdi
	callq	_ZN3PSOC2Ev
	movq	%rbx, %rdi
	callq	_ZN3PSO9evolutionEv
	xorl	%eax, %eax
	addq	$48, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end18:
	.size	main, .Lfunc_end18-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB19_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB19_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9evalPlaneiPdS_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end19:
	.size	__hip_module_ctor, .Lfunc_end19-__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	.LBB20_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
.LBB20_2:
	retq
.Lfunc_end20:
	.size	__hip_module_dtor, .Lfunc_end20-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z9evalPlaneiPdS_,@object       # @_Z9evalPlaneiPdS_
	.section	.rodata,"a",@progbits
	.globl	_Z9evalPlaneiPdS_
	.p2align	3, 0x0
_Z9evalPlaneiPdS_:
	.quad	_Z24__device_stub__evalPlaneiPdS_
	.size	_Z9evalPlaneiPdS_, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Cannot allocate memory for %d Particles\n"
	.size	.L.str, 41

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Cannot allocate memory for %d x\n"
	.size	.L.str.1, 33

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Cannot allocate memory for %d v\n"
	.size	.L.str.2, 33

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Cannot allocate memory for %d xBest\n"
	.size	.L.str.3, 37

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Cannot allocate memory for %d maxV\n"
	.size	.L.str.4, 36

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"0 : "
	.size	.L.str.5, 5

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"%g "
	.size	.L.str.6, 4

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

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

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	" = %g\n"
	.size	.L.str.9, 7

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z9evalPlaneiPdS_"
	.size	.L__unnamed_1, 18

	.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

	.globl	_ZN5SwarmC1Ev
	.type	_ZN5SwarmC1Ev,@function
.set _ZN5SwarmC1Ev, _ZN5SwarmC2Ev
	.globl	_ZN3PSOC1Ev
	.type	_ZN3PSOC1Ev,@function
.set _ZN3PSOC1Ev, _ZN3PSOC2Ev
	.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 _Z24__device_stub__evalPlaneiPdS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z9evalPlaneiPdS_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z9evalPlaneiPdS_       ; -- Begin function _Z9evalPlaneiPdS_
	.globl	_Z9evalPlaneiPdS_
	.p2align	8
	.type	_Z9evalPlaneiPdS_,@function
_Z9evalPlaneiPdS_:                      ; @_Z9evalPlaneiPdS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x24
	s_load_b32 s10, s[0:1], 0x0
	s_add_u32 s2, s0, 24
	s_addc_u32 s3, s1, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s8, s4, 0xffff
	s_mov_b32 s4, exec_lo
	v_mad_u64_u32 v[1:2], null, s15, s8, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s10, v1
	s_cbranch_execz .LBB0_3
; %bb.1:                                ; %.lr.ph.preheader
	s_load_b32 s2, s[2:3], 0x0
	s_load_b128 s[4:7], s[0:1], 0x8
	v_ashrrev_i32_e32 v2, 31, v1
	s_mov_b32 s1, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	v_lshlrev_b64 v[2:3], 3, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s2, s2, s8
	s_ashr_i32 s3, s2, 31
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b64 s[8:9], s[2:3], 3
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_u32 v4, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v3, vcc_lo
	v_add_co_u32 v6, vcc_lo, s6, v2
	v_add_co_ci_u32_e32 v7, vcc_lo, s7, v3, vcc_lo
	v_add_nc_u32_e32 v1, s2, v1
	global_load_b64 v[4:5], v[4:5], off
	global_load_b64 v[8:9], v[6:7], off
	v_add_co_u32 v2, s0, v2, s8
	v_cmp_le_i32_e32 vcc_lo, s10, v1
	v_add_co_ci_u32_e64 v3, s0, s9, v3, s0
	s_or_b32 s1, vcc_lo, s1
	s_waitcnt vmcnt(0)
	v_fma_f64 v[4:5], v[4:5], v[4:5], v[8:9]
	global_store_b64 v[6:7], v[4:5], off
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB0_2
.LBB0_3:                                ; %Flow21
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9evalPlaneiPdS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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_end0:
	.size	_Z9evalPlaneiPdS_, .Lfunc_end0-_Z9evalPlaneiPdS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 236
; 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
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .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:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9evalPlaneiPdS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9evalPlaneiPdS_.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
