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

#define NUM_BUCKETS 32
#define MAX_KICKS 512
#define THREADS_PER_BLOCK 256
#define BLOCKS_PER_GPU 64

__constant__ int d_hash_constants[2];

__device__ unsigned int hash(unsigned int key, int constant) {
    unsigned int hash_value = key * constant;
    return hash_value % NUM_BUCKETS;
}

__device__ void insert(unsigned int key, unsigned int *bucket1, unsigned int *bucket2, unsigned int *temp_bucket) {
    unsigned int h1 = hash(key, d_hash_constants[0]);
    unsigned int h2 = hash(key, d_hash_constants[1]);

    if (atomicCAS(&bucket1[h1], 0, key) == 0) return;
    if (atomicCAS(&bucket2[h2], 0, key) == 0) return;

    unsigned int current_key = key;
    for (int i = 0; i < MAX_KICKS; ++i) {
        unsigned int h = (i % 2 == 0) ? h1 : h2;
        unsigned int *bucket = (i % 2 == 0) ? bucket1 : bucket2;

        unsigned int old_key = atomicExch(&bucket[h], current_key);
        current_key = old_key;

        h1 = hash(current_key, d_hash_constants[0]);
        h2 = hash(current_key, d_hash_constants[1]);
    }
}

__global__ void cuckoo_insert(unsigned int *keys, unsigned int *bucket1, unsigned int *bucket2, unsigned int *temp_bucket, int num_keys) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx < num_keys) {
        insert(keys[idx], bucket1, bucket2, temp_bucket);
    }
}

int main() {
    int num_gpus;
    cudaGetDeviceCount(&num_gpus);
    if (num_gpus < 1) {
        std::cerr << "No GPUs found." << std::endl;
        return -1;
    }

    int num_keys = num_gpus * BLOCKS_PER_GPU * THREADS_PER_BLOCK;
    unsigned int *h_keys = new unsigned int[num_keys];
    unsigned int *h_bucket1 = new unsigned int[NUM_BUCKETS];
    unsigned int *h_bucket2 = new unsigned int[NUM_BUCKETS];
    unsigned int *h_temp_bucket = new unsigned int[NUM_BUCKETS];

    for (int i = 0; i < num_keys; ++i) {
        h_keys[i] = i; // Simple key generation
    }
    for (int i = 0; i < NUM_BUCKETS; ++i) {
        h_bucket1[i] = 0;
        h_bucket2[i] = 0;
        h_temp_bucket[i] = 0;
    }

    int hash_constants[2] = {17, 29}; // Simple hash constants
    cudaMemcpyToSymbol(d_hash_constants, hash_constants, sizeof(hash_constants));

    unsigned int *d_keys, *d_bucket1, *d_bucket2, *d_temp_bucket;
    cudaMalloc(&d_keys, num_keys * sizeof(unsigned int));
    cudaMalloc(&d_bucket1, NUM_BUCKETS * sizeof(unsigned int));
    cudaMalloc(&d_bucket2, NUM_BUCKETS * sizeof(unsigned int));
    cudaMalloc(&d_temp_bucket, NUM_BUCKETS * sizeof(unsigned int));

    cudaMemcpy(d_keys, h_keys, num_keys * sizeof(unsigned int), cudaMemcpyHostToDevice);
    cudaMemcpy(d_bucket1, h_bucket1, NUM_BUCKETS * sizeof(unsigned int), cudaMemcpyHostToDevice);
    cudaMemcpy(d_bucket2, h_bucket2, NUM_BUCKETS * sizeof(unsigned int), cudaMemcpyHostToDevice);
    cudaMemcpy(d_temp_bucket, h_temp_bucket, NUM_BUCKETS * sizeof(unsigned int), cudaMemcpyHostToDevice);

    dim3 threadsPerBlock(THREADS_PER_BLOCK);
    dim3 blocksPerGrid(BLOCKS_PER_GPU);

    for (int gpu = 0; gpu < num_gpus; ++gpu) {
        cudaSetDevice(gpu);
        cuckoo_insert<<<blocksPerGrid, threadsPerBlock>>>(d_keys + gpu * blocksPerGrid.x * threadsPerBlock.x,
                                                         d_bucket1,
                                                         d_bucket2,
                                                         d_temp_bucket,
                                                         blocksPerGrid.x * threadsPerBlock.x);
        cudaDeviceSynchronize();
        cudaError_t err = cudaGetLastError();
        if (err != cudaSuccess) {
            std::cerr << "CUDA error: " << cudaGetErrorString(err) << std::endl;
            return -1;
        }
    }

    cudaMemcpy(h_bucket1, d_bucket1, NUM_BUCKETS * sizeof(unsigned int), cudaMemcpyDeviceToHost);
    cudaMemcpy(h_bucket2, d_bucket2, NUM_BUCKETS * sizeof(unsigned int), cudaMemcpyDeviceToHost);

    std::cout << "Bucket 1 contents: ";
    for (int i = 0; i < NUM_BUCKETS; ++i) {
        std::cout << h_bucket1[i] << " ";
    }
    std::cout << std::endl;

    std::cout << "Bucket 2 contents: ";
    for (int i = 0; i < NUM_BUCKETS; ++i) {
        std::cout << h_bucket2[i] << " ";
    }
    std::cout << std::endl;

    delete[] h_keys;
    delete[] h_bucket1;
    delete[] h_bucket2;
    delete[] h_temp_bucket;

    cudaFree(d_keys);
    cudaFree(d_bucket1);
    cudaFree(d_bucket2);
    cudaFree(d_temp_bucket);

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

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3854:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3854:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z4hashji
	.type	_Z4hashji, @function
_Z4hashji:
.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	_Z4hashji, .-_Z4hashji
	.globl	_Z6insertjPjS_S_
	.type	_Z6insertjPjS_S_, @function
_Z6insertjPjS_S_:
.LFB3850:
	.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
.LFE3850:
	.size	_Z6insertjPjS_S_, .-_Z6insertjPjS_S_
	.globl	_Z40__device_stub__Z13cuckoo_insertPjS_S_S_iPjS_S_S_i
	.type	_Z40__device_stub__Z13cuckoo_insertPjS_S_S_iPjS_S_S_i, @function
_Z40__device_stub__Z13cuckoo_insertPjS_S_S_iPjS_S_S_i:
.LFB3876:
	.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
	movl	%r8d, 12(%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	12(%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	.L6
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z13cuckoo_insertPjS_S_S_i(%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
.L6:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L8
	call	__stack_chk_fail@PLT
.L8:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3876:
	.size	_Z40__device_stub__Z13cuckoo_insertPjS_S_S_iPjS_S_S_i, .-_Z40__device_stub__Z13cuckoo_insertPjS_S_S_iPjS_S_S_i
	.globl	_Z13cuckoo_insertPjS_S_S_i
	.type	_Z13cuckoo_insertPjS_S_S_i, @function
_Z13cuckoo_insertPjS_S_S_i:
.LFB3877:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z13cuckoo_insertPjS_S_S_iPjS_S_S_i
	.cfi_endproc
.LFE3877:
	.size	_Z13cuckoo_insertPjS_S_S_i, .-_Z13cuckoo_insertPjS_S_S_i
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"No GPUs found."
.LC1:
	.string	"CUDA error: "
.LC2:
	.string	"Bucket 1 contents: "
.LC3:
	.string	" "
.LC4:
	.string	"Bucket 2 contents: "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3851:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	movl	20(%rsp), %r15d
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	testl	%r15d, %r15d
	jle	.L28
	sall	$14, %r15d
	movslq	%r15d, %r13
	salq	$2, %r13
	movq	%r13, %rdi
	call	_Znam@PLT
	movl	$128, %edi
	movq	%rax, %r14
	call	_Znam@PLT
	movl	$128, %edi
	movq	%rax, %rbp
	call	_Znam@PLT
	movl	$128, %edi
	movq	%rax, %rbx
	call	_Znam@PLT
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
.L15:
	movl	%eax, (%r14,%rax,4)
	incq	%rax
	cmpl	%eax, %r15d
	jg	.L15
	xorl	%eax, %eax
	movl	$32, %ecx
	movq	%rbp, %rdi
	movl	$1, %r8d
	rep stosl
	movl	$32, %ecx
	movq	%rbx, %rdi
	movl	$8, %edx
	rep stosl
	movq	8(%rsp), %rdi
	movl	$32, %ecx
	leaq	80(%rsp), %rsi
	rep stosl
	leaq	_ZL16d_hash_constants(%rip), %rdi
	movabsq	$124554051601, %rax
	movq	%rax, 80(%rsp)
	call	cudaMemcpyToSymbol@PLT
	movq	%r13, %rsi
	leaq	24(%rsp), %rdi
	call	cudaMalloc@PLT
	leaq	32(%rsp), %rdi
	movl	$128, %esi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movl	$128, %esi
	call	cudaMalloc@PLT
	leaq	48(%rsp), %rdi
	movl	$128, %esi
	call	cudaMalloc@PLT
	movq	24(%rsp), %rdi
	movq	%r13, %rdx
	movq	%r14, %rsi
	movl	$1, %ecx
	xorl	%r13d, %r13d
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rsi
	movl	$128, %edx
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$128, %edx
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rsi
	movq	48(%rsp), %rdi
	movl	$1, %ecx
	movl	$128, %edx
	call	cudaMemcpy@PLT
	movabsq	$4294967297, %rax
	movq	%rax, 60(%rsp)
	movq	%rax, 72(%rsp)
	jmp	.L16
.L18:
	incl	%r13d
.L16:
	cmpl	%r13d, 20(%rsp)
	jle	.L29
	movl	%r13d, %edi
	call	cudaSetDevice@PLT
	movl	64(%rsp), %ecx
	movl	76(%rsp), %esi
	xorl	%r9d, %r9d
	movl	$64, 68(%rsp)
	movq	68(%rsp), %rdi
	xorl	%r8d, %r8d
	movl	$256, 56(%rsp)
	movq	56(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L17
	movq	24(%rsp), %rdx
	movl	%r13d, %eax
	movq	48(%rsp), %rcx
	movl	$16384, %r8d
	sall	$14, %eax
	movq	32(%rsp), %rsi
	leaq	(%rdx,%rax,4), %rdi
	movq	40(%rsp), %rdx
	call	_Z40__device_stub__Z13cuckoo_insertPjS_S_S_iPjS_S_S_i
.L17:
	call	cudaDeviceSynchronize@PLT
	call	cudaGetLastError@PLT
	movl	%eax, %r15d
	testl	%eax, %eax
	je	.L18
	leaq	.LC1(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r15d, %edi
	movq	%rax, %rbx
	call	cudaGetErrorString@PLT
	movq	%rbx, %rdi
	movq	%rax, %rsi
.L28:
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	orl	$-1, %eax
	jmp	.L12
.L29:
	movq	32(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdi
	xorl	%r12d, %r12d
	movl	$128, %edx
	leaq	_ZSt4cout(%rip), %r13
	leaq	.LC3(%rip), %r15
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdi
	movl	$128, %edx
	call	cudaMemcpy@PLT
	leaq	.LC2(%rip), %rsi
	movq	%r13, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L21:
	movl	0(%rbp,%r12,4), %esi
	movq	%r13, %rdi
	incq	%r12
	call	_ZNSo9_M_insertImEERSoT_@PLT
	movq	%r15, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cmpq	$32, %r12
	jne	.L21
	movq	%r13, %rdi
	xorl	%r12d, %r12d
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	leaq	.LC4(%rip), %rsi
	movq	%r13, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L22:
	movl	(%rbx,%r12,4), %esi
	movq	%r13, %rdi
	incq	%r12
	call	_ZNSo9_M_insertImEERSoT_@PLT
	movq	%r15, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cmpq	$32, %r12
	jne	.L22
	movq	%r13, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	%r14, %rdi
	call	_ZdaPv@PLT
	movq	%rbp, %rdi
	call	_ZdaPv@PLT
	movq	%rbx, %rdi
	call	_ZdaPv@PLT
	movq	8(%rsp), %rdi
	call	_ZdaPv@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
	xorl	%eax, %eax
.L12:
	movq	88(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L23
	call	__stack_chk_fail@PLT
.L23:
	addq	$104, %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
.LFE3851:
	.size	main, .-main
	.section	.rodata.str1.1
.LC5:
	.string	"_Z13cuckoo_insertPjS_S_S_i"
.LC6:
	.string	"precalc_xorwow_matrix"
.LC7:
	.string	"precalc_xorwow_offset_matrix"
.LC8:
	.string	"mrg32k3aM1"
.LC9:
	.string	"mrg32k3aM2"
.LC10:
	.string	"mrg32k3aM1SubSeq"
.LC11:
	.string	"mrg32k3aM2SubSeq"
.LC12:
	.string	"mrg32k3aM1Seq"
.LC13:
	.string	"mrg32k3aM2Seq"
.LC14:
	.string	"__cr_lgamma_table"
.LC15:
	.string	"d_hash_constants"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3879:
	.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	_Z13cuckoo_insertPjS_S_S_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC6(%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	.LC7(%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	.LC8(%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	.LC9(%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	.LC10(%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	.LC11(%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	.LC12(%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	.LC13(%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	.LC14(%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	$1
	.cfi_def_cfa_offset 32
	leaq	.LC15(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movl	$8, %r9d
	movq	%rdx, %rcx
	leaq	_ZL16d_hash_constants(%rip), %rsi
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%r11
	.cfi_def_cfa_offset 24
	popq	%rbx
	.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
.LFE3879:
	.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	_ZL16d_hash_constants
	.comm	_ZL16d_hash_constants,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
	.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_BUCKETS 32
#define MAX_KICKS 512
#define THREADS_PER_BLOCK 256
#define BLOCKS_PER_GPU 64

__constant__ int d_hash_constants[2];

__device__ unsigned int hash(unsigned int key, int constant) {
    unsigned int hash_value = key * constant;
    return hash_value % NUM_BUCKETS;
}

__device__ void insert(unsigned int key, unsigned int *bucket1, unsigned int *bucket2, unsigned int *temp_bucket) {
    unsigned int h1 = hash(key, d_hash_constants[0]);
    unsigned int h2 = hash(key, d_hash_constants[1]);

    if (atomicCAS(&bucket1[h1], 0, key) == 0) return;
    if (atomicCAS(&bucket2[h2], 0, key) == 0) return;

    unsigned int current_key = key;
    for (int i = 0; i < MAX_KICKS; ++i) {
        unsigned int h = (i % 2 == 0) ? h1 : h2;
        unsigned int *bucket = (i % 2 == 0) ? bucket1 : bucket2;

        unsigned int old_key = atomicExch(&bucket[h], current_key);
        current_key = old_key;

        h1 = hash(current_key, d_hash_constants[0]);
        h2 = hash(current_key, d_hash_constants[1]);
    }
}

__global__ void cuckoo_insert(unsigned int *keys, unsigned int *bucket1, unsigned int *bucket2, unsigned int *temp_bucket, int num_keys) {
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx < num_keys) {
        insert(keys[idx], bucket1, bucket2, temp_bucket);
    }
}

int main() {
    int num_gpus;
    hipGetDeviceCount(&num_gpus);
    if (num_gpus < 1) {
        std::cerr << "No GPUs found." << std::endl;
        return -1;
    }

    int num_keys = num_gpus * BLOCKS_PER_GPU * THREADS_PER_BLOCK;
    unsigned int *h_keys = new unsigned int[num_keys];
    unsigned int *h_bucket1 = new unsigned int[NUM_BUCKETS];
    unsigned int *h_bucket2 = new unsigned int[NUM_BUCKETS];
    unsigned int *h_temp_bucket = new unsigned int[NUM_BUCKETS];

    for (int i = 0; i < num_keys; ++i) {
        h_keys[i] = i; // Simple key generation
    }
    for (int i = 0; i < NUM_BUCKETS; ++i) {
        h_bucket1[i] = 0;
        h_bucket2[i] = 0;
        h_temp_bucket[i] = 0;
    }

    int hash_constants[2] = {17, 29}; // Simple hash constants
    hipMemcpyToSymbol(HIP_SYMBOL(d_hash_constants), hash_constants, sizeof(hash_constants));

    unsigned int *d_keys, *d_bucket1, *d_bucket2, *d_temp_bucket;
    hipMalloc(&d_keys, num_keys * sizeof(unsigned int));
    hipMalloc(&d_bucket1, NUM_BUCKETS * sizeof(unsigned int));
    hipMalloc(&d_bucket2, NUM_BUCKETS * sizeof(unsigned int));
    hipMalloc(&d_temp_bucket, NUM_BUCKETS * sizeof(unsigned int));

    hipMemcpy(d_keys, h_keys, num_keys * sizeof(unsigned int), hipMemcpyHostToDevice);
    hipMemcpy(d_bucket1, h_bucket1, NUM_BUCKETS * sizeof(unsigned int), hipMemcpyHostToDevice);
    hipMemcpy(d_bucket2, h_bucket2, NUM_BUCKETS * sizeof(unsigned int), hipMemcpyHostToDevice);
    hipMemcpy(d_temp_bucket, h_temp_bucket, NUM_BUCKETS * sizeof(unsigned int), hipMemcpyHostToDevice);

    dim3 threadsPerBlock(THREADS_PER_BLOCK);
    dim3 blocksPerGrid(BLOCKS_PER_GPU);

    for (int gpu = 0; gpu < num_gpus; ++gpu) {
        hipSetDevice(gpu);
        cuckoo_insert<<<blocksPerGrid, threadsPerBlock>>>(d_keys + gpu * blocksPerGrid.x * threadsPerBlock.x,
                                                         d_bucket1,
                                                         d_bucket2,
                                                         d_temp_bucket,
                                                         blocksPerGrid.x * threadsPerBlock.x);
        hipDeviceSynchronize();
        hipError_t err = hipGetLastError();
        if (err != hipSuccess) {
            std::cerr << "CUDA error: " << hipGetErrorString(err) << std::endl;
            return -1;
        }
    }

    hipMemcpy(h_bucket1, d_bucket1, NUM_BUCKETS * sizeof(unsigned int), hipMemcpyDeviceToHost);
    hipMemcpy(h_bucket2, d_bucket2, NUM_BUCKETS * sizeof(unsigned int), hipMemcpyDeviceToHost);

    std::cout << "Bucket 1 contents: ";
    for (int i = 0; i < NUM_BUCKETS; ++i) {
        std::cout << h_bucket1[i] << " ";
    }
    std::cout << std::endl;

    std::cout << "Bucket 2 contents: ";
    for (int i = 0; i < NUM_BUCKETS; ++i) {
        std::cout << h_bucket2[i] << " ";
    }
    std::cout << std::endl;

    delete[] h_keys;
    delete[] h_bucket1;
    delete[] h_bucket2;
    delete[] h_temp_bucket;

    hipFree(d_keys);
    hipFree(d_bucket1);
    hipFree(d_bucket2);
    hipFree(d_temp_bucket);

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

                                        # End of file scope inline assembly
	.globl	_Z28__device_stub__cuckoo_insertPjS_S_S_i # -- Begin function _Z28__device_stub__cuckoo_insertPjS_S_S_i
	.type	_Z28__device_stub__cuckoo_insertPjS_S_S_i,@function
_Z28__device_stub__cuckoo_insertPjS_S_S_i: # @_Z28__device_stub__cuckoo_insertPjS_S_S_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$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	12(%rsp), %rcx
	movl	%r8d, (%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	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	$_Z13cuckoo_insertPjS_S_S_i, %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	_Z28__device_stub__cuckoo_insertPjS_S_S_i, .Lfunc_end0-_Z28__device_stub__cuckoo_insertPjS_S_S_i
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	12(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	movl	(%rbx), %r14d
	testl	%r14d, %r14d
	jle	.LBB1_1
# %bb.4:                                # %.lr.ph.preheader
	shll	$14, %r14d
	leaq	(,%r14,4), %r13
	movq	%r13, %rdi
	callq	_Znam
	movq	%rax, %rbx
	movl	$128, %edi
	callq	_Znam
	movq	%rax, %r12
	movl	$128, %edi
	callq	_Znam
	movq	%rax, %r15
	movl	$128, %edi
	callq	_Znam
	movq	%rax, 40(%rsp)                  # 8-byte Spill
	cmpl	$2, %r14d
	movl	$1, %eax
	cmovgel	%r14d, %eax
	xorl	%ecx, %ecx
.LBB1_5:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%ecx, (%rbx,%rcx,4)
	incq	%rcx
	cmpq	%rcx, %rax
	jne	.LBB1_5
# %bb.2:                                # %.preheader
	xorps	%xmm0, %xmm0
	movups	%xmm0, 112(%r12)
	movups	%xmm0, 96(%r12)
	movups	%xmm0, 80(%r12)
	movups	%xmm0, 64(%r12)
	movups	%xmm0, 48(%r12)
	movups	%xmm0, 32(%r12)
	movups	%xmm0, 16(%r12)
	movups	%xmm0, (%r12)
	movups	%xmm0, 112(%r15)
	movups	%xmm0, 96(%r15)
	movups	%xmm0, 80(%r15)
	movups	%xmm0, 64(%r15)
	movups	%xmm0, 48(%r15)
	movups	%xmm0, 32(%r15)
	movups	%xmm0, 16(%r15)
	movups	%xmm0, (%r15)
	movq	40(%rsp), %rbp                  # 8-byte Reload
	movups	%xmm0, 112(%rbp)
	movups	%xmm0, 96(%rbp)
	movups	%xmm0, 80(%rbp)
	movups	%xmm0, 64(%rbp)
	movups	%xmm0, 48(%rbp)
	movups	%xmm0, 32(%rbp)
	movups	%xmm0, 16(%rbp)
	movups	%xmm0, (%rbp)
	movabsq	$124554051601, %rax             # imm = 0x1D00000011
	leaq	64(%rsp), %rsi
	movq	%rax, (%rsi)
	movl	$d_hash_constants, %edi
	movl	$8, %edx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	movq	%r12, %r14
	leaq	48(%rsp), %r12
	movq	%r12, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movl	$128, %esi
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movl	$128, %esi
	callq	hipMalloc
	leaq	32(%rsp), %rdi
	movl	$128, %esi
	callq	hipMalloc
	movq	(%r12), %rdi
	movq	%rbx, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	24(%rsp), %rax
	movq	(%rax), %rdi
	movl	$128, %edx
	movq	%r14, 56(%rsp)                  # 8-byte Spill
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	16(%rsp), %rax
	movq	(%rax), %rdi
	movl	$128, %edx
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	32(%rsp), %rax
	movq	(%rax), %rdi
	movl	$128, %edx
	movq	%rbp, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	cmpl	$0, 12(%rsp)
	jle	.LBB1_15
# %bb.3:                                # %.lr.ph73.preheader
	movabsq	$4294967360, %rax               # imm = 0x100000040
	xorl	%r14d, %r14d
	leaq	192(%rax), %rbp
	xorl	%r12d, %r12d
.LBB1_7:                                # %.lr.ph73
                                        # =>This Inner Loop Header: Depth=1
	movl	%r12d, %edi
	callq	hipSetDevice
	movabsq	$4294967360, %rdi               # imm = 0x100000040
	movl	$1, %esi
	movq	%rbp, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_9
# %bb.8:                                #   in Loop: Header=BB1_7 Depth=1
	movl	%r14d, %edi
	andl	$-16384, %edi                   # imm = 0xC000
	shlq	$2, %rdi
	addq	48(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	movq	32(%rsp), %rcx
	movl	$16384, %r8d                    # imm = 0x4000
	callq	_Z28__device_stub__cuckoo_insertPjS_S_S_i
.LBB1_9:                                #   in Loop: Header=BB1_7 Depth=1
	callq	hipDeviceSynchronize
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB1_10
# %bb.6:                                #   in Loop: Header=BB1_7 Depth=1
	incq	%r12
	movslq	12(%rsp), %rax
	addq	$16384, %r14                    # imm = 0x4000
	cmpq	%rax, %r12
	jl	.LBB1_7
.LBB1_15:                               # %._crit_edge
	movq	24(%rsp), %rsi
	movl	$128, %edx
	movq	56(%rsp), %r12                  # 8-byte Reload
	movq	%r12, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rsi
	movl	$128, %edx
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$19, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorl	%r14d, %r14d
.LBB1_16:                               # =>This Inner Loop Header: Depth=1
	movl	(%r12,%r14,4), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertImEERSoT_
	movl	$.L.str.3, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%r14
	cmpq	$32, %r14
	jne	.LBB1_16
# %bb.17:
	movq	_ZSt4cout(%rip), %rax
	movl	$_ZSt4cout, %ecx
	movq	-24(%rax), %rdi
	addq	%rcx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$19, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorl	%r14d, %r14d
.LBB1_18:                               # =>This Inner Loop Header: Depth=1
	movl	(%r15,%r14,4), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertImEERSoT_
	movl	$.L.str.3, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	incq	%r14
	cmpq	$32, %r14
	jne	.LBB1_18
# %bb.19:
	movq	_ZSt4cout(%rip), %rax
	movl	$_ZSt4cout, %ecx
	movq	-24(%rax), %rdi
	addq	%rcx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movq	%rbx, %rdi
	callq	_ZdaPv
	movq	%r12, %rdi
	callq	_ZdaPv
	movq	%r15, %rdi
	callq	_ZdaPv
	movq	40(%rsp), %rdi                  # 8-byte Reload
	callq	_ZdaPv
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	jmp	.LBB1_20
.LBB1_1:
	movl	$_ZSt4cerr, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	movl	$14, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	jmp	.LBB1_14
.LBB1_10:
	movl	%eax, %r13d
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.1, %esi
	movl	$12, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	%r13d, %edi
	callq	hipGetErrorString
	testq	%rax, %rax
	je	.LBB1_11
# %bb.12:
	movq	%rax, %rbx
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%rbx, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB1_13
.LBB1_11:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB1_13:                               # %.thread67
	movq	_ZSt4cerr(%rip), %rax
	movl	$_ZSt4cerr, %ecx
	movq	-24(%rax), %rdi
	addq	%rcx, %rdi
.LBB1_14:
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cerr, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$-1, %eax
.LBB1_20:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	main, .Lfunc_end1-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	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z13cuckoo_insertPjS_S_S_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$0, 8(%rsp)
	movl	$1, (%rsp)
	movl	$d_hash_constants, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movl	$8, %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_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	d_hash_constants,@object        # @d_hash_constants
	.local	d_hash_constants
	.comm	d_hash_constants,8,4
	.type	_Z13cuckoo_insertPjS_S_S_i,@object # @_Z13cuckoo_insertPjS_S_S_i
	.section	.rodata,"a",@progbits
	.globl	_Z13cuckoo_insertPjS_S_S_i
	.p2align	3, 0x0
_Z13cuckoo_insertPjS_S_S_i:
	.quad	_Z28__device_stub__cuckoo_insertPjS_S_S_i
	.size	_Z13cuckoo_insertPjS_S_S_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"No GPUs found."
	.size	.L.str, 15

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"CUDA error: "
	.size	.L.str.1, 13

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Bucket 1 contents: "
	.size	.L.str.2, 20

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Bucket 2 contents: "
	.size	.L.str.4, 20

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z13cuckoo_insertPjS_S_S_i"
	.size	.L__unnamed_1, 27

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"d_hash_constants"
	.size	.L__unnamed_2, 17

	.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 _Z28__device_stub__cuckoo_insertPjS_S_S_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym d_hash_constants
	.addrsig_sym _Z13cuckoo_insertPjS_S_S_i
	.addrsig_sym _ZSt4cerr
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z13cuckoo_insertPjS_S_S_i ; -- Begin function _Z13cuckoo_insertPjS_S_S_i
	.globl	_Z13cuckoo_insertPjS_S_S_i
	.p2align	8
	.type	_Z13cuckoo_insertPjS_S_S_i,@function
_Z13cuckoo_insertPjS_S_S_i:             ; @_Z13cuckoo_insertPjS_S_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b32 s3, s[0:1], 0x20
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB0_5
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_ashrrev_i32_e32 v2, 31, v1
	s_getpc_b64 s[2:3]
	s_add_u32 s2, s2, d_hash_constants@rel32@lo+4
	s_addc_u32 s3, s3, d_hash_constants@rel32@hi+12
	s_load_b64 s[2:3], s[2:3], 0x0
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	global_load_b32 v0, v[0:1], off
	s_waitcnt vmcnt(0)
	v_mul_lo_u32 v1, s2, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v3, 31, v1
	v_dual_mov_b32 v1, 0 :: v_dual_lshlrev_b32 v2, 2, v3
	global_atomic_cmpswap_b32 v2, v2, v[0:1], s[6:7] glc
	s_waitcnt vmcnt(0)
	v_cmp_ne_u32_e32 vcc_lo, 0, v2
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_5
; %bb.2:
	s_load_b64 s[0:1], s[0:1], 0x10
	v_mul_lo_u32 v2, s3, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v4, 31, v2
	v_lshlrev_b32_e32 v2, 2, v4
	s_waitcnt lgkmcnt(0)
	global_atomic_cmpswap_b32 v1, v2, v[0:1], s[0:1] glc
	s_waitcnt vmcnt(0)
	v_cmp_ne_u32_e32 vcc_lo, 0, v1
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_5
; %bb.3:                                ; %.preheader.i.preheader
	v_mov_b32_e32 v2, 0
	s_mov_b32 s4, 0
.LBB0_4:                                ; %.preheader.i
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	s_bitcmp0_b32 s4, 0
	s_cselect_b32 vcc_lo, -1, 0
	v_cndmask_b32_e32 v1, v4, v3, vcc_lo
	s_and_b32 s5, vcc_lo, exec_lo
	s_cselect_b32 s8, s6, s0
	s_cselect_b32 s5, s7, s1
	s_add_i32 s4, s4, 1
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	s_cmpk_lg_i32 s4, 0x200
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s8, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v4, vcc_lo
	global_atomic_swap_b32 v0, v[3:4], v0, off glc
	s_waitcnt vmcnt(0)
	v_mul_lo_u32 v1, v0, s2
	v_mul_lo_u32 v4, v0, s3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_and_b32_e32 v3, 31, v1
	v_and_b32_e32 v4, 31, v4
	s_cbranch_scc1 .LBB0_4
.LBB0_5:                                ; %_Z6insertjPjS_S_.exit
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z13cuckoo_insertPjS_S_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 5
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z13cuckoo_insertPjS_S_S_i, .Lfunc_end0-_Z13cuckoo_insertPjS_S_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 360
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.protected	d_hash_constants        ; @d_hash_constants
	.type	d_hash_constants,@object
	.section	.bss,"aw",@nobits
	.globl	d_hash_constants
	.p2align	2, 0x0
d_hash_constants:
	.zero	8
	.size	d_hash_constants, 8

	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym d_hash_constants
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         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: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z13cuckoo_insertPjS_S_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z13cuckoo_insertPjS_S_S_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
