#include <iostream>
#include <cuda_runtime.h>
#include <curand_kernel.h>

#define NUM_PARTICLES 128
#define DIM 2
#define MAX_ITERATIONS 1000
#define LEARNING_RATE 0.5
#define SOCIAL_FACTOR 0.3
#define COGNITIVE_FACTOR 0.4

__device__ float global_best_position[DIM];
__device__ float global_best_fitness = 1e30;

__global__ void initializeParticles(float *positions, float *velocities, float *personal_best_positions, float *personal_best_fitnesses, curandState *states) {
    int idx = threadIdx.x + blockIdx.x * blockDim.x;
    if (idx < NUM_PARTICLES) {
        curandState localState = states[idx];
        for (int d = 0; d < DIM; ++d) {
            positions[idx * DIM + d] = curand_uniform(&localState) * 10.0f - 5.0f; // Random position between -5 and 5
            velocities[idx * DIM + d] = curand_uniform(&localState) * 2.0f - 1.0f; // Random velocity between -1 and 1
            personal_best_positions[idx * DIM + d] = positions[idx * DIM + d];
        }
        personal_best_fitnesses[idx] = 1e30;
        states[idx] = localState;
    }
}

__device__ float evaluateFitness(float *position) {
    // Sphere function: f(x, y) = x^2 + y^2
    return position[0] * position[0] + position[1] * position[1];
}

__global__ void updateParticles(float *positions, float *velocities, float *personal_best_positions, float *personal_best_fitnesses) {
    int idx = threadIdx.x + blockIdx.x * blockDim.x;
    if (idx < NUM_PARTICLES) {
        float position[DIM];
        float velocity[DIM];
        float fitness;

        // Load data
        for (int d = 0; d < DIM; ++d) {
            position[d] = positions[idx * DIM + d];
            velocity[d] = velocities[idx * DIM + d];
        }

        // Evaluate fitness
        fitness = evaluateFitness(position);

        // Update personal best
        if (fitness < personal_best_fitnesses[idx]) {
            for (int d = 0; d < DIM; ++d) {
                personal_best_positions[idx * DIM + d] = position[d];
            }
            personal_best_fitnesses[idx] = fitness;
        }

        // Update global best
        if (fitness < global_best_fitness) {
            atomicMin(reinterpret_cast<unsigned int*>(&global_best_fitness), __float_as_uint(fitness));
            for (int d = 0; d < DIM; ++d) {
                atomicExch(reinterpret_cast<unsigned int*>(&global_best_position[d]), __float_as_uint(position[d]));
            }
        }

        // Update velocity and position
        curandState localState;
        curand_init(idx, 0, 0, &localState);
        for (int d = 0; d < DIM; ++d) {
            float r1 = curand_uniform(&localState);
            float r2 = curand_uniform(&localState);
            velocity[d] = LEARNING_RATE * velocity[d] +
                          SOCIAL_FACTOR * r1 * (global_best_position[d] - position[d]) +
                          COGNITIVE_FACTOR * r2 * (personal_best_positions[idx * DIM + d] - position[d]);
            position[d] += velocity[d];
        }

        // Store updated data
        for (int d = 0; d < DIM; ++d) {
            positions[idx * DIM + d] = position[d];
            velocities[idx * DIM + d] = velocity[d];
        }
    }
}

int main() {
    float *h_positions, *h_velocities, *h_personal_best_positions, *h_personal_best_fitnesses;
    float *d_positions, *d_velocities, *d_personal_best_positions, *d_personal_best_fitnesses;
    curandState *d_states;

    // Allocate host memory
    h_positions = (float *)malloc(NUM_PARTICLES * DIM * sizeof(float));
    h_velocities = (float *)malloc(NUM_PARTICLES * DIM * sizeof(float));
    h_personal_best_positions = (float *)malloc(NUM_PARTICLES * DIM * sizeof(float));
    h_personal_best_fitnesses = (float *)malloc(NUM_PARTICLES * sizeof(float));

    // Allocate device memory
    cudaMalloc(&d_positions, NUM_PARTICLES * DIM * sizeof(float));
    cudaMalloc(&d_velocities, NUM_PARTICLES * DIM * sizeof(float));
    cudaMalloc(&d_personal_best_positions, NUM_PARTICLES * DIM * sizeof(float));
    cudaMalloc(&d_personal_best_fitnesses, NUM_PARTICLES * sizeof(float));
    cudaMalloc(&d_states, NUM_PARTICLES * sizeof(curandState));

    // Initialize particles on device
    initializeParticles<<<(NUM_PARTICLES + 255) / 256, 256>>>(d_positions, d_velocities, d_personal_best_positions, d_personal_best_fitnesses, d_states);
    cudaDeviceSynchronize();

    // Main loop
    for (int iter = 0; iter < MAX_ITERATIONS; ++iter) {
        updateParticles<<<(NUM_PARTICLES + 255) / 256, 256>>>(d_positions, d_velocities, d_personal_best_positions, d_personal_best_fitnesses);
        cudaDeviceSynchronize();
    }

    // Copy results back to host
    cudaMemcpy(h_personal_best_positions, d_personal_best_positions, NUM_PARTICLES * DIM * sizeof(float), cudaMemcpyDeviceToHost);
    cudaMemcpy(h_personal_best_fitnesses, d_personal_best_fitnesses, NUM_PARTICLES * sizeof(float), cudaMemcpyDeviceToHost);

    // Find global best on host
    float host_global_best_fitness = 1e30;
    int best_idx = 0;
    for (int i = 0; i < NUM_PARTICLES; ++i) {
        if (h_personal_best_fitnesses[i] < host_global_best_fitness) {
            host_global_best_fitness = h_personal_best_fitnesses[i];
            best_idx = i;
        }
    }

    // Output the best solution
    std::cout << "Global best position: (" << h_personal_best_positions[best_idx * DIM] << ", " << h_personal_best_positions[best_idx * DIM + 1] << ")" << std::endl;
    std::cout << "Global best fitness: " << host_global_best_fitness << std::endl;

    // Free device memory
    cudaFree(d_positions);
    cudaFree(d_velocities);
    cudaFree(d_personal_best_positions);
    cudaFree(d_personal_best_fitnesses);
    cudaFree(d_states);

    // Free host memory
    free(h_positions);
    free(h_velocities);
    free(h_personal_best_positions);
    free(h_personal_best_fitnesses);

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

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3853:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3853:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z15evaluateFitnessPf
	.type	_Z15evaluateFitnessPf, @function
_Z15evaluateFitnessPf:
.LFB3849:
	.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
.LFE3849:
	.size	_Z15evaluateFitnessPf, .-_Z15evaluateFitnessPf
	.globl	_Z65__device_stub__Z19initializeParticlesPfS_S_S_P17curandStateXORWOWPfS_S_S_P17curandStateXORWOW
	.type	_Z65__device_stub__Z19initializeParticlesPfS_S_S_P17curandStateXORWOWPfS_S_S_P17curandStateXORWOW, @function
_Z65__device_stub__Z19initializeParticlesPfS_S_S_P17curandStateXORWOWPfS_S_S_P17curandStateXORWOW:
.LFB3875:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movq	%r8, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L4
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z19initializeParticlesPfS_S_S_P17curandStateXORWOW(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L4:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L6
	call	__stack_chk_fail@PLT
.L6:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3875:
	.size	_Z65__device_stub__Z19initializeParticlesPfS_S_S_P17curandStateXORWOWPfS_S_S_P17curandStateXORWOW, .-_Z65__device_stub__Z19initializeParticlesPfS_S_S_P17curandStateXORWOWPfS_S_S_P17curandStateXORWOW
	.globl	_Z19initializeParticlesPfS_S_S_P17curandStateXORWOW
	.type	_Z19initializeParticlesPfS_S_S_P17curandStateXORWOW, @function
_Z19initializeParticlesPfS_S_S_P17curandStateXORWOW:
.LFB3876:
	.cfi_startproc
	endbr64
	jmp	_Z65__device_stub__Z19initializeParticlesPfS_S_S_P17curandStateXORWOWPfS_S_S_P17curandStateXORWOW
	.cfi_endproc
.LFE3876:
	.size	_Z19initializeParticlesPfS_S_S_P17curandStateXORWOW, .-_Z19initializeParticlesPfS_S_S_P17curandStateXORWOW
	.globl	_Z41__device_stub__Z15updateParticlesPfS_S_S_PfS_S_S_
	.type	_Z41__device_stub__Z15updateParticlesPfS_S_S_PfS_S_S_, @function
_Z41__device_stub__Z15updateParticlesPfS_S_S_PfS_S_S_:
.LFB3877:
	.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
	movq	%rcx, (%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)
	movq	%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	.L10
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z15updateParticlesPfS_S_S_(%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
.L10:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L12
	call	__stack_chk_fail@PLT
.L12:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3877:
	.size	_Z41__device_stub__Z15updateParticlesPfS_S_S_PfS_S_S_, .-_Z41__device_stub__Z15updateParticlesPfS_S_S_PfS_S_S_
	.globl	_Z15updateParticlesPfS_S_S_
	.type	_Z15updateParticlesPfS_S_S_, @function
_Z15updateParticlesPfS_S_S_:
.LFB3878:
	.cfi_startproc
	endbr64
	jmp	_Z41__device_stub__Z15updateParticlesPfS_S_S_PfS_S_S_
	.cfi_endproc
.LFE3878:
	.size	_Z15updateParticlesPfS_S_S_, .-_Z15updateParticlesPfS_S_S_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"Global best position: ("
.LC2:
	.string	", "
.LC3:
	.string	")"
.LC4:
	.string	"Global best fitness: "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3850:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$1024, %edi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$104, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	call	malloc@PLT
	movl	$512, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	leaq	24(%rsp), %rdi
	movl	$1024, %esi
	movq	%rax, %r12
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movl	$1024, %esi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movl	$1024, %esi
	call	cudaMalloc@PLT
	leaq	48(%rsp), %rdi
	movl	$512, %esi
	call	cudaMalloc@PLT
	leaq	56(%rsp), %rdi
	movl	$6144, %esi
	call	cudaMalloc@PLT
	movl	$16777217, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$8, %rdx
	movl	$1, %ecx
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movq	%rdx, 76(%rsp)
	movl	$1, 84(%rsp)
	movq	%rdi, 64(%rsp)
	movl	$1, 72(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L16
	movq	56(%rsp), %r8
	movq	48(%rsp), %rcx
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z65__device_stub__Z19initializeParticlesPfS_S_S_P17curandStateXORWOWPfS_S_S_P17curandStateXORWOW
.L16:
	call	cudaDeviceSynchronize@PLT
	movl	$1000, %ebx
	movabsq	$4294967552, %r13
.L18:
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r13, %rdx
	movl	$1, %ecx
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movq	%r13, 76(%rsp)
	movl	$1, 84(%rsp)
	movq	%rdi, 64(%rsp)
	movl	$1, 72(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L17
	movq	48(%rsp), %rcx
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	call	_Z41__device_stub__Z15updateParticlesPfS_S_S_PfS_S_S_
.L17:
	call	cudaDeviceSynchronize@PLT
	decl	%ebx
	jne	.L18
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdi
	xorl	%ebx, %ebx
	movl	$1024, %edx
	call	cudaMemcpy@PLT
	movq	48(%rsp), %rsi
	movl	$2, %ecx
	movq	%r12, %rdi
	movl	$512, %edx
	call	cudaMemcpy@PLT
	movss	.LC0(%rip), %xmm1
	xorl	%eax, %eax
.L21:
	movss	(%r12,%rax,4), %xmm0
	comiss	%xmm0, %xmm1
	minss	%xmm1, %xmm0
	cmova	%eax, %ebx
	incq	%rax
	movaps	%xmm0, %xmm1
	cmpq	$128, %rax
	jne	.L21
	leaq	_ZSt4cout(%rip), %r13
	leaq	.LC1(%rip), %rsi
	movss	%xmm0, 12(%rsp)
	addl	%ebx, %ebx
	movq	%r13, %rdi
	movslq	%ebx, %rbx
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	0(%rbp,%rbx,4), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	4(%rbp,%rbx,4), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	leaq	.LC4(%rip), %rsi
	movq	%r13, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movss	12(%rsp), %xmm1
	movq	%rax, %rdi
	cvtss2sd	%xmm1, %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	addq	$104, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	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
.LFE3850:
	.size	main, .-main
	.section	.rodata.str1.1
.LC5:
	.string	"_Z15updateParticlesPfS_S_S_"
.LC6:
	.string	"_Z19initializeParticlesPfS_S_S_P17curandStateXORWOW"
.LC7:
	.string	"precalc_xorwow_matrix"
.LC8:
	.string	"precalc_xorwow_offset_matrix"
.LC9:
	.string	"mrg32k3aM1"
.LC10:
	.string	"mrg32k3aM2"
.LC11:
	.string	"mrg32k3aM1SubSeq"
.LC12:
	.string	"mrg32k3aM2SubSeq"
.LC13:
	.string	"mrg32k3aM1Seq"
.LC14:
	.string	"mrg32k3aM2Seq"
.LC15:
	.string	"__cr_lgamma_table"
.LC16:
	.string	"global_best_position"
.LC17:
	.string	"global_best_fitness"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3880:
	.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	.LC5(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z15updateParticlesPfS_S_S_(%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	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC6(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z19initializeParticlesPfS_S_S_P17curandStateXORWOW(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC7(%rip), %rdx
	movl	$102400, %r9d
	leaq	_ZL21precalc_xorwow_matrix(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC8(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$102400, %r9d
	leaq	_ZL28precalc_xorwow_offset_matrix(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC9(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL10mrg32k3aM1(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC10(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL10mrg32k3aM2(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC11(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2016, %r9d
	leaq	_ZL16mrg32k3aM1SubSeq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r11
	.cfi_def_cfa_offset 24
	popq	%rax
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC12(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2016, %r9d
	leaq	_ZL16mrg32k3aM2SubSeq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC13(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL13mrg32k3aM1Seq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC14(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL13mrg32k3aM2Seq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC15(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$72, %r9d
	leaq	_ZL17__cr_lgamma_table(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC16(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$8, %r9d
	leaq	_ZL20global_best_position(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r11
	.cfi_def_cfa_offset 24
	popq	%rax
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC17(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$4, %r9d
	leaq	_ZL19global_best_fitness(%rip), %rsi
	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
.LFE3880:
	.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
	.local	_ZL19global_best_fitness
	.comm	_ZL19global_best_fitness,4,4
	.local	_ZL20global_best_position
	.comm	_ZL20global_best_position,8,8
	.local	_ZL17__cr_lgamma_table
	.comm	_ZL17__cr_lgamma_table,72,32
	.local	_ZL13mrg32k3aM2Seq
	.comm	_ZL13mrg32k3aM2Seq,2304,32
	.local	_ZL13mrg32k3aM1Seq
	.comm	_ZL13mrg32k3aM1Seq,2304,32
	.local	_ZL16mrg32k3aM2SubSeq
	.comm	_ZL16mrg32k3aM2SubSeq,2016,32
	.local	_ZL16mrg32k3aM1SubSeq
	.comm	_ZL16mrg32k3aM1SubSeq,2016,32
	.local	_ZL10mrg32k3aM2
	.comm	_ZL10mrg32k3aM2,2304,32
	.local	_ZL10mrg32k3aM1
	.comm	_ZL10mrg32k3aM1,2304,32
	.local	_ZL28precalc_xorwow_offset_matrix
	.comm	_ZL28precalc_xorwow_offset_matrix,102400,32
	.local	_ZL21precalc_xorwow_matrix
	.comm	_ZL21precalc_xorwow_matrix,102400,32
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC0:
	.long	1900671690
	.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 <iostream>
#include <hip/hip_runtime.h>
#include <hiprand/hiprand_kernel.h>

#define NUM_PARTICLES 128
#define DIM 2
#define MAX_ITERATIONS 1000
#define LEARNING_RATE 0.5
#define SOCIAL_FACTOR 0.3
#define COGNITIVE_FACTOR 0.4

__device__ float global_best_position[DIM];
__device__ float global_best_fitness = 1e30;

__global__ void initializeParticles(float *positions, float *velocities, float *personal_best_positions, float *personal_best_fitnesses, hiprandState *states) {
    int idx = threadIdx.x + blockIdx.x * blockDim.x;
    if (idx < NUM_PARTICLES) {
        hiprandState localState = states[idx];
        for (int d = 0; d < DIM; ++d) {
            positions[idx * DIM + d] = hiprand_uniform(&localState) * 10.0f - 5.0f; // Random position between -5 and 5
            velocities[idx * DIM + d] = hiprand_uniform(&localState) * 2.0f - 1.0f; // Random velocity between -1 and 1
            personal_best_positions[idx * DIM + d] = positions[idx * DIM + d];
        }
        personal_best_fitnesses[idx] = 1e30;
        states[idx] = localState;
    }
}

__device__ float evaluateFitness(float *position) {
    // Sphere function: f(x, y) = x^2 + y^2
    return position[0] * position[0] + position[1] * position[1];
}

__global__ void updateParticles(float *positions, float *velocities, float *personal_best_positions, float *personal_best_fitnesses) {
    int idx = threadIdx.x + blockIdx.x * blockDim.x;
    if (idx < NUM_PARTICLES) {
        float position[DIM];
        float velocity[DIM];
        float fitness;

        // Load data
        for (int d = 0; d < DIM; ++d) {
            position[d] = positions[idx * DIM + d];
            velocity[d] = velocities[idx * DIM + d];
        }

        // Evaluate fitness
        fitness = evaluateFitness(position);

        // Update personal best
        if (fitness < personal_best_fitnesses[idx]) {
            for (int d = 0; d < DIM; ++d) {
                personal_best_positions[idx * DIM + d] = position[d];
            }
            personal_best_fitnesses[idx] = fitness;
        }

        // Update global best
        if (fitness < global_best_fitness) {
            atomicMin(reinterpret_cast<unsigned int*>(&global_best_fitness), __float_as_uint(fitness));
            for (int d = 0; d < DIM; ++d) {
                atomicExch(reinterpret_cast<unsigned int*>(&global_best_position[d]), __float_as_uint(position[d]));
            }
        }

        // Update velocity and position
        hiprandState localState;
        hiprand_init(idx, 0, 0, &localState);
        for (int d = 0; d < DIM; ++d) {
            float r1 = hiprand_uniform(&localState);
            float r2 = hiprand_uniform(&localState);
            velocity[d] = LEARNING_RATE * velocity[d] +
                          SOCIAL_FACTOR * r1 * (global_best_position[d] - position[d]) +
                          COGNITIVE_FACTOR * r2 * (personal_best_positions[idx * DIM + d] - position[d]);
            position[d] += velocity[d];
        }

        // Store updated data
        for (int d = 0; d < DIM; ++d) {
            positions[idx * DIM + d] = position[d];
            velocities[idx * DIM + d] = velocity[d];
        }
    }
}

int main() {
    float *h_positions, *h_velocities, *h_personal_best_positions, *h_personal_best_fitnesses;
    float *d_positions, *d_velocities, *d_personal_best_positions, *d_personal_best_fitnesses;
    hiprandState *d_states;

    // Allocate host memory
    h_positions = (float *)malloc(NUM_PARTICLES * DIM * sizeof(float));
    h_velocities = (float *)malloc(NUM_PARTICLES * DIM * sizeof(float));
    h_personal_best_positions = (float *)malloc(NUM_PARTICLES * DIM * sizeof(float));
    h_personal_best_fitnesses = (float *)malloc(NUM_PARTICLES * sizeof(float));

    // Allocate device memory
    hipMalloc(&d_positions, NUM_PARTICLES * DIM * sizeof(float));
    hipMalloc(&d_velocities, NUM_PARTICLES * DIM * sizeof(float));
    hipMalloc(&d_personal_best_positions, NUM_PARTICLES * DIM * sizeof(float));
    hipMalloc(&d_personal_best_fitnesses, NUM_PARTICLES * sizeof(float));
    hipMalloc(&d_states, NUM_PARTICLES * sizeof(hiprandState));

    // Initialize particles on device
    initializeParticles<<<(NUM_PARTICLES + 255) / 256, 256>>>(d_positions, d_velocities, d_personal_best_positions, d_personal_best_fitnesses, d_states);
    hipDeviceSynchronize();

    // Main loop
    for (int iter = 0; iter < MAX_ITERATIONS; ++iter) {
        updateParticles<<<(NUM_PARTICLES + 255) / 256, 256>>>(d_positions, d_velocities, d_personal_best_positions, d_personal_best_fitnesses);
        hipDeviceSynchronize();
    }

    // Copy results back to host
    hipMemcpy(h_personal_best_positions, d_personal_best_positions, NUM_PARTICLES * DIM * sizeof(float), hipMemcpyDeviceToHost);
    hipMemcpy(h_personal_best_fitnesses, d_personal_best_fitnesses, NUM_PARTICLES * sizeof(float), hipMemcpyDeviceToHost);

    // Find global best on host
    float host_global_best_fitness = 1e30;
    int best_idx = 0;
    for (int i = 0; i < NUM_PARTICLES; ++i) {
        if (h_personal_best_fitnesses[i] < host_global_best_fitness) {
            host_global_best_fitness = h_personal_best_fitnesses[i];
            best_idx = i;
        }
    }

    // Output the best solution
    std::cout << "Global best position: (" << h_personal_best_positions[best_idx * DIM] << ", " << h_personal_best_positions[best_idx * DIM + 1] << ")" << std::endl;
    std::cout << "Global best fitness: " << host_global_best_fitness << std::endl;

    // Free device memory
    hipFree(d_positions);
    hipFree(d_velocities);
    hipFree(d_personal_best_positions);
    hipFree(d_personal_best_fitnesses);
    hipFree(d_states);

    // Free host memory
    free(h_positions);
    free(h_velocities);
    free(h_personal_best_positions);
    free(h_personal_best_fitnesses);

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

                                        # End of file scope inline assembly
	.globl	_Z34__device_stub__initializeParticlesPfS_S_S_P12hiprandState # -- Begin function _Z34__device_stub__initializeParticlesPfS_S_S_P12hiprandState
	.type	_Z34__device_stub__initializeParticlesPfS_S_S_P12hiprandState,@function
_Z34__device_stub__initializeParticlesPfS_S_S_P12hiprandState: # @_Z34__device_stub__initializeParticlesPfS_S_S_P12hiprandState
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	24(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%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	$_Z19initializeParticlesPfS_S_S_P12hiprandState, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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	_Z34__device_stub__initializeParticlesPfS_S_S_P12hiprandState, .Lfunc_end0-_Z34__device_stub__initializeParticlesPfS_S_S_P12hiprandState
	.cfi_endproc
                                        # -- End function
	.globl	_Z30__device_stub__updateParticlesPfS_S_S_ # -- Begin function _Z30__device_stub__updateParticlesPfS_S_S_
	.type	_Z30__device_stub__updateParticlesPfS_S_S_,@function
_Z30__device_stub__updateParticlesPfS_S_S_: # @_Z30__device_stub__updateParticlesPfS_S_S_
	.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	16(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z15updateParticlesPfS_S_S_, %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_end1:
	.size	_Z30__device_stub__updateParticlesPfS_S_S_, .Lfunc_end1-_Z30__device_stub__updateParticlesPfS_S_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x7149f2ca                      # float 1.00000002E+30
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movabsq	$4294967297, %r15               # imm = 0x100000001
	movl	$1024, %edi                     # imm = 0x400
	callq	malloc
	movq	%rax, %rbx
	movl	$512, %edi                      # imm = 0x200
	callq	malloc
	movq	%rax, %r14
	leaq	24(%rsp), %rdi
	movl	$1024, %esi                     # imm = 0x400
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movl	$1024, %esi                     # imm = 0x400
	callq	hipMalloc
	leaq	8(%rsp), %rdi
	movl	$1024, %esi                     # imm = 0x400
	callq	hipMalloc
	movq	%rsp, %rdi
	movl	$512, %esi                      # imm = 0x200
	callq	hipMalloc
	leaq	40(%rsp), %rdi
	movl	$6144, %esi                     # imm = 0x1800
	callq	hipMalloc
	leaq	255(%r15), %r12
	movq	%r15, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_2
# %bb.1:
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	movq	(%rsp), %rcx
	movq	40(%rsp), %r8
	callq	_Z34__device_stub__initializeParticlesPfS_S_S_P12hiprandState
.LBB2_2:
	callq	hipDeviceSynchronize
	movl	$1000, %ebp                     # imm = 0x3E8
.LBB2_3:                                # =>This Inner Loop Header: Depth=1
	movq	%r15, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_5
# %bb.4:                                #   in Loop: Header=BB2_3 Depth=1
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	movq	(%rsp), %rcx
	callq	_Z30__device_stub__updateParticlesPfS_S_S_
.LBB2_5:                                #   in Loop: Header=BB2_3 Depth=1
	callq	hipDeviceSynchronize
	decl	%ebp
	jne	.LBB2_3
# %bb.6:
	movq	8(%rsp), %rsi
	movl	$1024, %edx                     # imm = 0x400
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	(%rsp), %rsi
	movl	$512, %edx                      # imm = 0x200
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movss	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	xorl	%eax, %eax
	xorl	%r12d, %r12d
.LBB2_7:                                # =>This Inner Loop Header: Depth=1
	movaps	%xmm1, %xmm0
	movss	(%r14,%rax,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm1, %xmm0
	cmoval	%eax, %r12d
	minss	%xmm0, %xmm1
	incq	%rax
	cmpq	$128, %rax
	jne	.LBB2_7
# %bb.8:
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$23, %edx
	movss	%xmm1, 36(%rsp)                 # 4-byte Spill
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	leal	(%r12,%r12), %eax
	cltq
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%rax,4), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movl	$.L.str.1, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	leal	1(,%r12,2), %eax
	cltq
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%rax,4), %xmm0
	movq	%r15, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movl	$.L.str.2, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r15), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$21, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorps	%xmm0, %xmm0
	cvtss2sd	36(%rsp), %xmm0                 # 4-byte Folded Reload
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r15
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%r15, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r15, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	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_end2:
	.size	main, .Lfunc_end2-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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z19initializeParticlesPfS_S_S_P12hiprandState, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z15updateParticlesPfS_S_S_, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$0, 8(%rsp)
	movl	$0, (%rsp)
	movl	$global_best_position, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movl	$8, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	callq	__hipRegisterVar
	movl	$0, 8(%rsp)
	movl	$0, (%rsp)
	movl	$global_best_fitness, %esi
	movl	$.L__unnamed_4, %edx
	movl	$.L__unnamed_4, %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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	global_best_position,@object    # @global_best_position
	.local	global_best_position
	.comm	global_best_position,8,4
	.type	global_best_fitness,@object     # @global_best_fitness
	.local	global_best_fitness
	.comm	global_best_fitness,4,4
	.type	_Z19initializeParticlesPfS_S_S_P12hiprandState,@object # @_Z19initializeParticlesPfS_S_S_P12hiprandState
	.section	.rodata,"a",@progbits
	.globl	_Z19initializeParticlesPfS_S_S_P12hiprandState
	.p2align	3, 0x0
_Z19initializeParticlesPfS_S_S_P12hiprandState:
	.quad	_Z34__device_stub__initializeParticlesPfS_S_S_P12hiprandState
	.size	_Z19initializeParticlesPfS_S_S_P12hiprandState, 8

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

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Global best position: ("
	.size	.L.str, 24

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

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

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Global best fitness: "
	.size	.L.str.3, 22

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z19initializeParticlesPfS_S_S_P12hiprandState"
	.size	.L__unnamed_1, 47

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z15updateParticlesPfS_S_S_"
	.size	.L__unnamed_2, 28

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"global_best_position"
	.size	.L__unnamed_3, 21

	.type	.L__unnamed_4,@object           # @3
.L__unnamed_4:
	.asciz	"global_best_fitness"
	.size	.L__unnamed_4, 20

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

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

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z34__device_stub__initializeParticlesPfS_S_S_P12hiprandState
	.addrsig_sym _Z30__device_stub__updateParticlesPfS_S_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym global_best_position
	.addrsig_sym global_best_fitness
	.addrsig_sym _Z19initializeParticlesPfS_S_S_P12hiprandState
	.addrsig_sym _Z15updateParticlesPfS_S_S_
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z19initializeParticlesPfS_S_S_P12hiprandState ; -- Begin function _Z19initializeParticlesPfS_S_S_P12hiprandState
	.globl	_Z19initializeParticlesPfS_S_S_P12hiprandState
	.p2align	8
	.type	_Z19initializeParticlesPfS_S_S_P12hiprandState,@function
_Z19initializeParticlesPfS_S_S_P12hiprandState: ; @_Z19initializeParticlesPfS_S_S_P12hiprandState
; %bb.0:
	s_load_b32 s4, s[2:3], 0x34
	v_and_b32_e32 v5, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[7:8], null, s15, s4, v[5:6]
	s_mov_b32 s4, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e32 0x80, v7
	s_cbranch_execz .LBB0_4
; %bb.1:
	s_load_b64 s[4:5], s[2:3], 0x20
	s_load_b64 s[0:1], s[0:1], 0x4
	v_bfe_u32 v8, v0, 10, 10
	v_bfe_u32 v0, v0, 20, 10
	v_lshlrev_b32_e32 v16, 1, v7
	s_waitcnt lgkmcnt(0)
	v_mad_i64_i32 v[9:10], null, v7, 48, s[4:5]
	s_lshr_b32 s0, s0, 16
	s_load_b256 s[4:11], s[2:3], 0x0
	s_mul_i32 s0, s0, s1
	v_mul_u32_u24_e32 v8, s1, v8
	v_mul_lo_u32 v5, s0, v5
	s_mov_b32 s2, 0
	s_clause 0x4
	global_load_b32 v15, v[9:10], off
	global_load_b128 v[17:20], v[9:10], off offset:4
	global_load_b32 v6, v[9:10], off offset:20
	global_load_b64 v[11:12], v[9:10], off offset:40
	global_load_b128 v[1:4], v[9:10], off offset:24
	v_add_co_u32 v13, vcc_lo, v9, 4
	v_add_co_ci_u32_e32 v14, vcc_lo, 0, v10, vcc_lo
	s_mov_b32 s0, -1
	v_add3_u32 v0, v5, v8, v0
	v_ashrrev_i32_e32 v8, 31, v7
	s_mov_b32 s1, 0x41200000
	s_delay_alu instid0(VALU_DEP_2)
	v_mul_lo_u32 v0, v0, 20
	s_waitcnt vmcnt(3)
	ds_store_2addr_b32 v0, v17, v18 offset1:1
	ds_store_2addr_b32 v0, v19, v20 offset0:2 offset1:3
	s_waitcnt vmcnt(2)
	ds_store_b32 v0, v6 offset:16
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	s_waitcnt vmcnt(0)
	v_lshrrev_b32_e32 v6, 2, v1
	v_mov_b32_e32 v5, v3
	v_mov_b32_e32 v3, v11
	v_lshrrev_b32_e32 v17, 2, v2
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_xor_b32_e32 v1, v6, v1
	v_lshlrev_b32_e32 v6, 4, v3
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_xor_b32_e32 v17, v17, v2
	v_lshlrev_b32_e32 v11, 1, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_xor_b32_e32 v11, v6, v11
	v_mov_b32_e32 v6, v4
	v_xor3_b32 v4, v11, v3, v1
	v_or_b32_e32 v1, s2, v16
	s_mov_b32 s2, 1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_add3_u32 v19, v15, v4, 0x587c5
	v_lshlrev_b32_e32 v11, 4, v4
	v_add_nc_u32_e32 v15, 0xb0f8a, v15
	v_cvt_f32_u32_e32 v19, v19
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_fmaak_f32 v21, 0x2f800000, v19, 0x2f800000 :: v_dual_lshlrev_b32 v2, 1, v17
	v_xor_b32_e32 v11, v2, v11
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmaak_f32 v21, s1, v21, 0xc0a00000
	v_xor3_b32 v11, v11, v17, v4
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[17:18], 2, v[1:2]
	v_add_nc_u32_e32 v2, v15, v11
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v1, vcc_lo, s4, v17
	v_cvt_f32_u32_e32 v20, v2
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e32 v2, vcc_lo, s5, v18, vcc_lo
	v_add_co_u32 v19, vcc_lo, s6, v17
	v_fmaak_f32 v22, 0x2f800000, v20, 0x2f800000
	v_add_co_ci_u32_e32 v20, vcc_lo, s7, v18, vcc_lo
	s_delay_alu instid0(VALU_DEP_2)
	v_fma_f32 v22, v22, 2.0, -1.0
	global_store_b32 v[1:2], v21, off
	global_store_b32 v[19:20], v22, off
	global_load_b32 v19, v[1:2], off
	v_cndmask_b32_e64 v1, 0, 1, s0
	v_add_co_u32 v17, s0, s8, v17
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v18, s0, s9, v18, s0
	v_cmp_ne_u32_e32 vcc_lo, 1, v1
	v_dual_mov_b32 v1, v5 :: v_dual_mov_b32 v2, v6
	s_mov_b32 s0, 0
	s_waitcnt vmcnt(0)
	global_store_b32 v[17:18], v19, off
	s_cbranch_vccz .LBB0_2
; %bb.3:
	ds_load_b32 v2, v0 offset:16
	ds_load_2addr_b32 v[18:19], v0 offset0:2 offset1:3
	ds_load_2addr_b32 v[16:17], v0 offset1:1
	v_lshlrev_b64 v[0:1], 2, v[7:8]
	v_dual_mov_b32 v20, 0x7149f2ca :: v_dual_mov_b32 v7, v3
	v_mov_b32_e32 v8, v4
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v0, vcc_lo, s10, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s11, v1, vcc_lo
	global_store_b32 v[0:1], v20, off
	s_clause 0x1
	global_store_b32 v[9:10], v15, off
	global_store_b128 v[9:10], v[5:8], off offset:24
	s_waitcnt lgkmcnt(2)
	global_store_b32 v[13:14], v2, off offset:16
	s_waitcnt lgkmcnt(0)
	s_clause 0x1
	global_store_b128 v[13:14], v[16:19], off
	global_store_b64 v[9:10], v[11:12], off offset:40
.LBB0_4:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z19initializeParticlesPfS_S_S_P12hiprandState
		.amdhsa_group_segment_fixed_size 20480
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 1
		.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 2
		.amdhsa_next_free_vgpr 23
		.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	_Z19initializeParticlesPfS_S_S_P12hiprandState, .Lfunc_end0-_Z19initializeParticlesPfS_S_S_P12hiprandState
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 712
; NumSgprs: 18
; NumVgprs: 23
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 20480 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 23
; 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: 2
	.text
	.protected	_Z15updateParticlesPfS_S_S_ ; -- Begin function _Z15updateParticlesPfS_S_S_
	.globl	_Z15updateParticlesPfS_S_S_
	.p2align	8
	.type	_Z15updateParticlesPfS_S_S_,@function
_Z15updateParticlesPfS_S_S_:            ; @_Z15updateParticlesPfS_S_S_
; %bb.0:
	s_load_b32 s2, s[0:1], 0x2c
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[5:6], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e32 0x80, v5
	s_cbranch_execz .LBB1_14
; %bb.1:                                ; %.preheader77
	s_load_b256 s[4:11], s[0:1], 0x0
	v_lshlrev_b32_e32 v3, 1, v5
	s_mov_b32 s1, 0
	s_mov_b32 s0, -1
                                        ; implicit-def: $vgpr0
                                        ; implicit-def: $vgpr8
                                        ; implicit-def: $vgpr1_vgpr2
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_or_b32_e32 v6, s1, v3
	s_cmp_eq_u32 s1, 0
	v_ashrrev_i32_e32 v7, 31, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[6:7], 2, v[6:7]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v9, vcc_lo, s4, v6
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v10, vcc_lo, s5, v7, vcc_lo
	v_add_co_u32 v6, vcc_lo, s6, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, s7, v7, vcc_lo
	global_load_b32 v4, v[9:10], off
	global_load_b32 v6, v[6:7], off
	v_cndmask_b32_e64 v7, 0, 1, s0
	s_cselect_b32 s0, -1, 0
	s_cmp_eq_u32 s1, 1
	s_cselect_b32 s1, -1, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u32_e32 vcc_lo, 1, v7
	s_and_b32 vcc_lo, exec_lo, vcc_lo
	s_waitcnt vmcnt(1)
	v_cndmask_b32_e64 v1, v1, v4, s1
	v_cndmask_b32_e64 v0, v0, v4, s0
	s_waitcnt vmcnt(0)
	v_cndmask_b32_e64 v2, v2, v6, s1
	v_cndmask_b32_e64 v8, v8, v6, s0
	s_mov_b32 s0, 0
	s_mov_b32 s1, 1
	s_cbranch_vccz .LBB1_2
; %bb.3:
	v_ashrrev_i32_e32 v6, 31, v5
	v_mul_f32_e32 v9, v1, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[6:7], 2, v[5:6]
	v_fmac_f32_e32 v9, v0, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v6, vcc_lo, s10, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, s11, v7, vcc_lo
	global_load_b32 v4, v[6:7], off
	s_waitcnt vmcnt(0)
	v_cmp_lt_f32_e32 vcc_lo, v9, v4
	v_ashrrev_i32_e32 v4, 31, v3
	s_and_saveexec_b32 s0, vcc_lo
	s_cbranch_execz .LBB1_5
; %bb.4:                                ; %.preheader76
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[10:11], 2, v[3:4]
	v_add_co_u32 v10, vcc_lo, s8, v10
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v11, vcc_lo, s9, v11, vcc_lo
	global_store_b64 v[10:11], v[0:1], off
	global_store_b32 v[6:7], v9, off
.LBB1_5:
	s_or_b32 exec_lo, exec_lo, s0
	v_mov_b32_e32 v6, 0
	s_getpc_b64 s[0:1]
	s_add_u32 s0, s0, global_best_fitness@rel32@lo+4
	s_addc_u32 s1, s1, global_best_fitness@rel32@hi+12
	global_load_b32 v6, v6, s[0:1]
	s_mov_b32 s0, exec_lo
	s_waitcnt vmcnt(0)
	v_cmpx_lt_f32_e32 v9, v6
	s_cbranch_execz .LBB1_11
; %bb.6:                                ; %.loopexit75.loopexit
	s_mov_b32 s2, exec_lo
	s_mov_b32 s1, -1
.LBB1_7:                                ; %ComputeLoop
                                        ; =>This Inner Loop Header: Depth=1
	s_ctz_i32_b32 s3, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_readlane_b32 s10, v9, s3
	s_lshl_b32 s3, 1, s3
	s_and_not1_b32 s2, s2, s3
	s_delay_alu instid0(VALU_DEP_1)
	s_min_u32 s1, s1, s10
	s_cmp_lg_u32 s2, 0
	s_cbranch_scc1 .LBB1_7
; %bb.8:                                ; %ComputeEnd
	v_mbcnt_lo_u32_b32 v6, exec_lo, 0
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_eq_u32_e32 0, v6
	s_xor_b32 s2, exec_lo, s2
	s_cbranch_execz .LBB1_10
; %bb.9:
	v_dual_mov_b32 v6, 0 :: v_dual_mov_b32 v7, s1
	s_getpc_b64 s[10:11]
	s_add_u32 s10, s10, global_best_fitness@rel32@lo+4
	s_addc_u32 s11, s11, global_best_fitness@rel32@hi+12
	global_atomic_min_u32 v6, v7, s[10:11]
.LBB1_10:
	s_or_b32 exec_lo, exec_lo, s2
	v_mov_b32_e32 v6, 0
	s_getpc_b64 s[2:3]
	s_add_u32 s2, s2, global_best_position@rel32@lo+4
	s_addc_u32 s3, s3, global_best_position@rel32@hi+12
	s_getpc_b64 s[10:11]
	s_add_u32 s10, s10, global_best_position@rel32@lo+8
	s_addc_u32 s11, s11, global_best_position@rel32@hi+16
	s_clause 0x1
	global_atomic_swap_b32 v6, v0, s[2:3]
	global_atomic_swap_b32 v6, v1, s[10:11]
.LBB1_11:                               ; %Flow
	s_or_b32 exec_lo, exec_lo, s0
	v_xor_b32_e32 v6, 0x2c7f967f, v5
	v_mov_b32_e32 v7, 0x8a5d614f
	v_cmp_lt_i32_e32 vcc_lo, -1, v5
	s_mov_b32 s13, 0
	s_mov_b32 s2, 0x33333333
	v_mul_lo_u32 v9, 0x493c4aa1, v6
	s_mov_b32 s10, 0x9999999a
	v_cndmask_b32_e32 v7, 0xfa091aa4, v7, vcc_lo
	s_mov_b32 s3, 0x3fd33333
	s_mov_b32 s11, 0x3fd99999
	s_mov_b32 s14, -1
	s_mov_b32 s12, s13
	v_add_nc_u32_e32 v5, 0x1f123bb5, v7
	v_xor_b32_e32 v6, 0x5491333, v7
	v_add_nc_u32_e32 v12, 0x75bcd15, v9
	v_xor_b32_e32 v11, 0x159a55e5, v9
	v_add_nc_u32_e32 v10, 0x583f19, v9
	v_add3_u32 v7, v7, v9, 0x6a788e
	v_mov_b32_e32 v9, 0
.LBB1_12:                               ; =>This Inner Loop Header: Depth=1
	s_cmp_eq_u32 s12, 1
	v_or_b32_e32 v13, s12, v3
	s_cselect_b32 vcc_lo, -1, 0
	s_getpc_b64 s[0:1]
	s_add_u32 s0, s0, global_best_position@rel32@lo+4
	s_addc_u32 s1, s1, global_best_position@rel32@hi+12
	s_lshl_b64 s[16:17], s[12:13], 2
	v_mov_b32_e32 v21, v5
	s_add_u32 s0, s16, s0
	s_addc_u32 s1, s17, s1
	v_ashrrev_i32_e32 v14, 31, v13
	global_load_b32 v15, v9, s[0:1]
	v_mov_b32_e32 v5, v10
	v_lshrrev_b32_e32 v17, 2, v11
	s_cmp_eq_u32 s12, 0
	v_lshlrev_b64 v[13:14], 2, v[13:14]
	v_dual_mov_b32 v22, v6 :: v_dual_cndmask_b32 v23, v0, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v13, s0, s8, v13
	v_add_co_ci_u32_e64 v14, s0, s9, v14, s0
	s_mov_b32 s0, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_mov_b32 s12, s0
	global_load_b32 v20, v[13:14], off
	v_lshrrev_b32_e32 v13, 2, v12
	s_cselect_b32 s0, -1, 0
	s_and_b32 s1, exec_lo, s14
	s_mov_b32 s14, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_xor_b32_e32 v10, v13, v12
	v_lshlrev_b32_e32 v12, 4, v5
	v_lshlrev_b32_e32 v13, 1, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v12, v13, v12
	v_xor3_b32 v6, v12, v10, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v10, v7, v6
	v_cvt_f32_u32_e32 v10, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmaak_f32 v10, 0x2f800000, v10, 0x2f800000
	v_cvt_f64_f32_e32 v[12:13], v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_mul_f64 v[12:13], v[12:13], s[2:3]
	s_waitcnt vmcnt(1)
	v_sub_f32_e32 v10, v15, v23
	v_cvt_f64_f32_e32 v[14:15], v10
	v_xor_b32_e32 v10, v17, v11
	v_lshlrev_b32_e32 v17, 4, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b32_e32 v11, 1, v10
	v_xor_b32_e32 v11, v11, v17
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor3_b32 v10, v11, v10, v6
	v_add3_u32 v11, v7, v10, 0x587c5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_f32_u32_e32 v11, v11
	v_dual_cndmask_b32 v16, v8, v2 :: v_dual_fmaak_f32 v11, 0x2f800000, v11, 0x2f800000
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cvt_f64_f32_e32 v[16:17], v16
	v_cvt_f64_f32_e32 v[18:19], v11
	v_mul_f64 v[11:12], v[12:13], v[14:15]
	s_waitcnt vmcnt(0)
	v_sub_f32_e32 v15, v20, v23
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f64 v[13:14], v[18:19], s[10:11]
	v_cvt_f64_f32_e32 v[18:19], v15
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[11:12], v[16:17], 0.5, v[11:12]
	v_fma_f64 v[11:12], v[13:14], v[18:19], v[11:12]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cvt_f32_f64_e32 v13, v[11:12]
	v_dual_mov_b32 v12, v21 :: v_dual_mov_b32 v11, v22
	v_dual_cndmask_b32 v2, v2, v13 :: v_dual_add_nc_u32 v7, 0xb0f8a, v7
	v_add_f32_e32 v14, v23, v13
	v_cndmask_b32_e64 v8, v8, v13, s0
	s_delay_alu instid0(VALU_DEP_2)
	v_cndmask_b32_e32 v1, v1, v14, vcc_lo
	v_cndmask_b32_e64 v0, v0, v14, s0
	s_mov_b32 vcc_lo, s1
	s_cbranch_vccnz .LBB1_12
; %bb.13:                               ; %.preheader
	v_lshlrev_b64 v[3:4], 2, v[3:4]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v5, vcc_lo, s4, v3
	v_add_co_ci_u32_e32 v6, vcc_lo, s5, v4, vcc_lo
	v_add_co_u32 v3, vcc_lo, s6, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s7, v4, vcc_lo
	global_store_b32 v[5:6], v0, off
	global_store_b32 v[3:4], v8, off
	global_store_b32 v[5:6], v1, off offset:4
	global_store_b32 v[3:4], v2, off offset:4
.LBB1_14:                               ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15updateParticlesPfS_S_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 24
		.amdhsa_next_free_sgpr 18
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z15updateParticlesPfS_S_S_, .Lfunc_end1-_Z15updateParticlesPfS_S_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1216
; NumSgprs: 20
; NumVgprs: 24
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 20
; NumVGPRsForWavesPerEU: 24
; 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	global_best_position    ; @global_best_position
	.type	global_best_position,@object
	.section	.bss,"aw",@nobits
	.globl	global_best_position
	.p2align	2, 0x0
global_best_position:
	.zero	8
	.size	global_best_position, 8

	.protected	global_best_fitness     ; @global_best_fitness
	.type	global_best_fitness,@object
	.data
	.globl	global_best_fitness
	.p2align	2, 0x0
global_best_fitness:
	.long	0x7149f2ca                      ; float 1.00000002E+30
	.size	global_best_fitness, 4

	.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 global_best_position
	.addrsig_sym global_best_fitness
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 20480
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z19initializeParticlesPfS_S_S_P12hiprandState
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z19initializeParticlesPfS_S_S_P12hiprandState.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     23
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z15updateParticlesPfS_S_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     20
    .sgpr_spill_count: 0
    .symbol:         _Z15updateParticlesPfS_S_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     24
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
