#include <iostream>
#include <cuda_runtime.h>
#include <cufft.h>
#include <cuda.h>

// Define the size of the FFT
#define N 8192

// Error checking macro
#define CUDA_CHECK(call) \
    do { \
        cudaError_t err = call; \
        if (err != cudaSuccess) { \
            std::cerr << "CUDA error at " << __FILE__ << ":" << __LINE__ << " - " << cudaGetErrorString(err) << std::endl; \
            exit(EXIT_FAILURE); \
        } \
    } while (0)

#define CUFFT_CHECK(call) \
    do { \
        cufftResult err = call; \
        if (err != CUFFT_SUCCESS) { \
            std::cerr << "CUFFT error at " << __FILE__ << ":" << __LINE__ << std::endl; \
            exit(EXIT_FAILURE); \
        } \
    } while (0)

void performFFT(cufftComplex *h_data, cufftComplex *d_data, int numGPUs) {
    cufftHandle plan[numGPUs];
    cudaStream_t streams[numGPUs];
    size_t workSize[numGPUs];
    int sizePerGPU = N / numGPUs;

    // Create streams and plans
    for (int i = 0; i < numGPUs; ++i) {
        CUDA_CHECK(cudaSetDevice(i));
        CUDA_CHECK(cudaStreamCreate(&streams[i]));
        CUFFT_CHECK(cufftPlan1d(&plan[i], sizePerGPU, CUFFT_C2C, 1));
        CUFFT_CHECK(cufftMakePlan1d(plan[i], sizePerGPU, CUFFT_C2C, 1, &workSize[i]));
    }

    // Allocate device memory
    cufftComplex *d_dataPerGPU[numGPUs];
    for (int i = 0; i < numGPUs; ++i) {
        CUDA_CHECK(cudaSetDevice(i));
        CUDA_CHECK(cudaMalloc(&d_dataPerGPU[i], sizePerGPU * sizeof(cufftComplex)));
    }

    // Asynchronous data transfers and FFTs
    for (int i = 0; i < numGPUs; ++i) {
        CUDA_CHECK(cudaSetDevice(i));
        CUDA_CHECK(cudaMemcpyAsync(d_dataPerGPU[i], d_data + i * sizePerGPU, sizePerGPU * sizeof(cufftComplex), cudaMemcpyHostToDevice, streams[i]));
        CUFFT_CHECK(cufftExecC2C(plan[i], d_dataPerGPU[i], d_dataPerGPU[i], CUFFT_FORWARD));
        CUDA_CHECK(cudaMemcpyAsync(d_data + i * sizePerGPU, d_dataPerGPU[i], sizePerGPU * sizeof(cufftComplex), cudaMemcpyDeviceToHost, streams[i]));
    }

    // Synchronize streams
    for (int i = 0; i < numGPUs; ++i) {
        CUDA_CHECK(cudaSetDevice(i));
        CUDA_CHECK(cudaStreamSynchronize(streams[i]));
        CUDA_CHECK(cudaStreamDestroy(streams[i]));
        CUFFT_CHECK(cufftDestroy(plan[i]));
        CUDA_CHECK(cudaFree(d_dataPerGPU[i]));
    }
}

int main() {
    int numGPUs;
    CUDA_CHECK(cudaGetDeviceCount(&numGPUs));
    if (numGPUs < 1) {
        std::cerr << "No CUDA devices found." << std::endl;
        return EXIT_FAILURE;
    }

    // Allocate host memory
    cufftComplex *h_data = (cufftComplex *)malloc(N * sizeof(cufftComplex));
    if (!h_data) {
        std::cerr << "Failed to allocate host memory." << std::endl;
        return EXIT_FAILURE;
    }

    // Initialize data
    for (int i = 0; i < N; ++i) {
        h_data[i].x = static_cast<float>(i);
        h_data[i].y = 0.0f;
    }

    // Allocate device memory
    cufftComplex *d_data;
    CUDA_CHECK(cudaMalloc(&d_data, N * sizeof(cufftComplex)));

    // Perform FFT
    performFFT(h_data, d_data, numGPUs);

    // Verify results (simple print for demonstration)
    std::cout << "First 10 elements of the FFT result:" << std::endl;
    for (int i = 0; i < 10; ++i) {
        std::cout << h_data[i].x << " + " << h_data[i].y << "i" << std::endl;
    }

    // Free resources
    free(h_data);
    CUDA_CHECK(cudaFree(d_data));

    return EXIT_SUCCESS;
}
	.file	"tmpxft_00188bcd_00000000-6_cuda_code_014768.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3662:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3662:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.align 2
	.type	_ZNSolsEPFRSoS_E.isra.0, @function
_ZNSolsEPFRSoS_E.isra.0:
.LFB4315:
	.cfi_startproc
	jmp	*%rsi
	.cfi_endproc
.LFE4315:
	.size	_ZNSolsEPFRSoS_E.isra.0, .-_ZNSolsEPFRSoS_E.isra.0
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"CUDA error at "
.LC1:
	.string	"/home/ubuntu/Datasets/cuda-codes-80k-from-llm-dedup/cuda_code_014768.cu"
.LC2:
	.string	":"
.LC3:
	.string	" - "
.LC4:
	.string	"CUFFT error at "
	.text
	.globl	_Z10performFFTP6float2S0_i
	.type	_Z10performFFTP6float2S0_i, @function
_Z10performFFTP6float2S0_i:
.LFB3658:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movslq	%edx, %rcx
	leaq	15(,%rcx,4), %rdx
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%rcx, %rbx
	subq	$72, %rsp
	movq	%rsi, -104(%rbp)
	movq	%rsp, %rsi
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	movq	%rdx, %rax
	andq	$-4096, %rdx
	andq	$-16, %rax
	subq	%rdx, %rsi
.L4:
	cmpq	%rsi, %rsp
	je	.L5
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L4
.L5:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L6
	orq	$0, -8(%rsp,%rax)
.L6:
	leaq	0(,%rcx,8), %rax
	movq	%rsp, %rcx
	movq	%rsp, %r15
	movq	%rax, -80(%rbp)
	addq	$15, %rax
	movq	%rax, %rsi
	movq	%rax, %rdx
	andq	$-4096, %rsi
	andq	$-16, %rdx
	subq	%rsi, %rcx
.L7:
	cmpq	%rcx, %rsp
	je	.L8
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L7
.L8:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	je	.L9
	orq	$0, -8(%rsp,%rdx)
.L9:
	movq	%rax, %rdx
	movq	%rsp, %rcx
	andq	$-4096, %rax
	movq	%rsp, %r12
	andq	$-16, %rdx
	subq	%rax, %rcx
.L10:
	cmpq	%rcx, %rsp
	je	.L11
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L10
.L11:
	movq	%rdx, %rax
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L12
	orq	$0, -8(%rsp,%rax)
.L12:
	movl	$8192, %eax
	movq	%rsp, -88(%rbp)
	movq	%r15, %r14
	xorl	%r13d, %r13d
	cltd
	movq	%r12, -96(%rbp)
	idivl	%ebx
	movl	%eax, -72(%rbp)
.L13:
	cmpl	%ebx, %r13d
	jge	.L59
	movl	%r13d, %edi
	call	cudaSetDevice@PLT
	testl	%eax, %eax
	je	.L14
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	movl	%eax, -72(%rbp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$36, %esi
	movq	%rax, %rdi
	jmp	.L55
.L14:
	movq	-96(%rbp), %rdi
	call	cudaStreamCreate@PLT
	testl	%eax, %eax
	je	.L15
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	movl	%eax, -72(%rbp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$37, %esi
	movq	%rax, %rdi
.L55:
	call	_ZNSolsEi@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	-72(%rbp), %edi
	movq	%rax, %rbx
	call	cudaGetErrorString@PLT
	movq	%rbx, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L56:
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	$1, %edi
	call	exit@PLT
.L15:
	movl	-72(%rbp), %esi
	movl	$1, %ecx
	movl	$41, %edx
	movq	%r14, %rdi
	call	cufftPlan1d@PLT
	testl	%eax, %eax
	je	.L16
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$38, %esi
	movq	%rax, %rdi
	jmp	.L57
.L16:
	movl	(%r14), %edi
	movq	-88(%rbp), %r8
	movl	$1, %ecx
	addq	$4, %r14
	movl	-72(%rbp), %esi
	movl	$41, %edx
	call	cufftMakePlan1d@PLT
	addq	$8, -88(%rbp)
	addq	$8, -96(%rbp)
	testl	%eax, %eax
	je	.L17
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$39, %esi
	movq	%rax, %rdi
	jmp	.L57
.L17:
	incl	%r13d
	jmp	.L13
.L59:
	movq	-80(%rbp), %rax
	movq	%rsp, %rcx
	addq	$15, %rax
	movq	%rax, %rdx
	andq	$-4096, %rax
	andq	$-16, %rdx
	subq	%rax, %rcx
.L19:
	cmpq	%rcx, %rsp
	je	.L20
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L19
.L20:
	movq	%rdx, %rax
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L21
	orq	$0, -8(%rsp,%rax)
.L21:
	movslq	-72(%rbp), %rax
	movq	%rsp, %r13
	xorl	%r14d, %r14d
	movq	%r13, -80(%rbp)
	salq	$3, %rax
	movq	%rax, -72(%rbp)
.L22:
	cmpl	%ebx, %r14d
	jge	.L60
	movl	%r14d, %edi
	call	cudaSetDevice@PLT
	testl	%eax, %eax
	je	.L23
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	movl	%eax, -72(%rbp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$45, %esi
	movq	%rax, %rdi
	jmp	.L55
.L23:
	movq	-72(%rbp), %rsi
	movq	-80(%rbp), %rdi
	call	cudaMalloc@PLT
	addq	$8, -80(%rbp)
	testl	%eax, %eax
	je	.L24
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	movl	%eax, -72(%rbp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$46, %esi
	movq	%rax, %rdi
	jmp	.L55
.L24:
	incl	%r14d
	jmp	.L22
.L60:
	movq	-104(%rbp), %rax
	xorl	%r14d, %r14d
	movq	%rax, -80(%rbp)
.L26:
	movl	%r14d, %edi
	cmpl	%r14d, %ebx
	jle	.L61
	call	cudaSetDevice@PLT
	testl	%eax, %eax
	je	.L27
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	movl	%eax, -72(%rbp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$51, %esi
	movq	%rax, %rdi
	jmp	.L55
.L27:
	movq	0(%r13,%r14,8), %rdi
	movq	(%r12,%r14,8), %r8
	movl	$1, %ecx
	movq	-72(%rbp), %rdx
	movq	-80(%rbp), %rsi
	call	cudaMemcpyAsync@PLT
	testl	%eax, %eax
	je	.L28
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	movl	%eax, -72(%rbp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$52, %esi
	movq	%rax, %rdi
	jmp	.L55
.L28:
	movq	0(%r13,%r14,8), %rsi
	movl	(%r15,%r14,4), %edi
	orl	$-1, %ecx
	movq	%rsi, %rdx
	call	cufftExecC2C@PLT
	testl	%eax, %eax
	je	.L29
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$53, %esi
	movq	%rax, %rdi
	jmp	.L57
.L29:
	movq	0(%r13,%r14,8), %rsi
	movq	(%r12,%r14,8), %r8
	movl	$2, %ecx
	incq	%r14
	movq	-72(%rbp), %rdx
	movq	-80(%rbp), %rdi
	call	cudaMemcpyAsync@PLT
	movq	-72(%rbp), %rcx
	addq	%rcx, -80(%rbp)
	testl	%eax, %eax
	je	.L26
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	movl	%eax, -72(%rbp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$54, %esi
	movq	%rax, %rdi
	jmp	.L55
.L61:
	xorl	%r14d, %r14d
	jmp	.L31
.L34:
	movl	(%r15,%r14,4), %edi
	call	cufftDestroy@PLT
	testl	%eax, %eax
	je	.L35
	leaq	.LC4(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$62, %esi
	movq	%rax, %rdi
.L57:
	call	_ZNSolsEi@PLT
	jmp	.L56
.L31:
	movl	%r14d, %edi
	cmpl	%r14d, %ebx
	jle	.L62
	call	cudaSetDevice@PLT
	testl	%eax, %eax
	je	.L32
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	movl	%eax, -72(%rbp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$59, %esi
	movq	%rax, %rdi
	jmp	.L55
.L32:
	movq	(%r12,%r14,8), %rdi
	call	cudaStreamSynchronize@PLT
	testl	%eax, %eax
	je	.L33
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	movl	%eax, -72(%rbp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$60, %esi
	movq	%rax, %rdi
	jmp	.L55
.L33:
	movq	(%r12,%r14,8), %rdi
	call	cudaStreamDestroy@PLT
	testl	%eax, %eax
	je	.L34
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	movl	%eax, -72(%rbp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$61, %esi
	movq	%rax, %rdi
	jmp	.L55
.L35:
	movq	0(%r13,%r14,8), %rdi
	incq	%r14
	call	cudaFree@PLT
	testl	%eax, %eax
	je	.L31
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	movl	%eax, -72(%rbp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$63, %esi
	movq	%rax, %rdi
	jmp	.L55
.L62:
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L37
	call	__stack_chk_fail@PLT
.L37:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3658:
	.size	_Z10performFFTP6float2S0_i, .-_Z10performFFTP6float2S0_i
	.section	.rodata.str1.1
.LC5:
	.string	"No CUDA devices found."
.LC6:
	.string	"Failed to allocate host memory."
.LC8:
	.string	"First 10 elements of the FFT result:"
.LC9:
	.string	" + "
.LC10:
	.string	"i"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3659:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	testl	%eax, %eax
	je	.L64
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	movl	%eax, %ebx
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$69, %esi
	movq	%rax, %rdi
	jmp	.L81
.L64:
	cmpl	$0, 12(%rsp)
	leaq	.LC5(%rip), %rsi
	jle	.L79
	movl	$65536, %edi
	call	malloc@PLT
	movq	%rax, %rbx
	xorl	%eax, %eax
	testq	%rbx, %rbx
	jne	.L67
	leaq	.LC6(%rip), %rsi
.L79:
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	$1, %eax
	jmp	.L63
.L67:
	cvtsi2ssl	%eax, %xmm0
	movl	$0x00000000, 4(%rbx,%rax,8)
	movss	%xmm0, (%rbx,%rax,8)
	incq	%rax
	cmpq	$8192, %rax
	jne	.L67
	leaq	16(%rsp), %rdi
	movl	$65536, %esi
	call	cudaMalloc@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.L69
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$90, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %edi
	movq	%rax, %rbx
	call	cudaGetErrorString@PLT
	movq	%rbx, %rdi
	movq	%rax, %rsi
.L80:
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	movl	$1, %edi
	call	exit@PLT
.L69:
	movl	12(%rsp), %edx
	movq	16(%rsp), %rsi
	movq	%rbx, %rdi
	xorl	%ebp, %ebp
	leaq	_ZSt4cout(%rip), %r12
	leaq	.LC9(%rip), %r13
	call	_Z10performFFTP6float2S0_i
	leaq	.LC8(%rip), %rsi
	movq	%r12, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
.L70:
	movq	%r12, %rdi
	cvtss2sd	(%rbx,%rbp), %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r13, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	cvtss2sd	4(%rbx,%rbp), %xmm0
	addq	$8, %rbp
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GOTPCREL(%rip), %rsi
	movq	%rax, %rdi
	call	_ZNSolsEPFRSoS_E.isra.0
	cmpq	$80, %rbp
	jne	.L70
	movq	%rbx, %rdi
	call	free@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %ebx
	xorl	%eax, %eax
	testl	%ebx, %ebx
	je	.L63
	leaq	.LC0(%rip), %rsi
	leaq	_ZSt4cerr(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC1(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC2(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$103, %esi
	movq	%rax, %rdi
.L81:
	call	_ZNSolsEi@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebx, %edi
	movq	%rax, %rbp
	call	cudaGetErrorString@PLT
	movq	%rbp, %rdi
	movq	%rax, %rsi
	jmp	.L80
.L63:
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L71
	call	__stack_chk_fail@PLT
.L71:
	addq	$40, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3659:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3685:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3685:
	.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
	.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 <hipfft/hipfft.h>


// Define the size of the FFT
#define N 8192

// Error checking macro
#define CUDA_CHECK(call) \
    do { \
        hipError_t err = call; \
        if (err != hipSuccess) { \
            std::cerr << "CUDA error at " << __FILE__ << ":" << __LINE__ << " - " << hipGetErrorString(err) << std::endl; \
            exit(EXIT_FAILURE); \
        } \
    } while (0)

#define CUFFT_CHECK(call) \
    do { \
        hipfftResult err = call; \
        if (err != HIPFFT_SUCCESS) { \
            std::cerr << "CUFFT error at " << __FILE__ << ":" << __LINE__ << std::endl; \
            exit(EXIT_FAILURE); \
        } \
    } while (0)

void performFFT(hipfftComplex *h_data, hipfftComplex *d_data, int numGPUs) {
    hipfftHandle plan[numGPUs];
    hipStream_t streams[numGPUs];
    size_t workSize[numGPUs];
    int sizePerGPU = N / numGPUs;

    // Create streams and plans
    for (int i = 0; i < numGPUs; ++i) {
        CUDA_CHECK(hipSetDevice(i));
        CUDA_CHECK(hipStreamCreate(&streams[i]));
        CUFFT_CHECK(hipfftPlan1d(&plan[i], sizePerGPU, HIPFFT_C2C, 1));
        CUFFT_CHECK(hipfftMakePlan1d(plan[i], sizePerGPU, HIPFFT_C2C, 1, &workSize[i]));
    }

    // Allocate device memory
    hipfftComplex *d_dataPerGPU[numGPUs];
    for (int i = 0; i < numGPUs; ++i) {
        CUDA_CHECK(hipSetDevice(i));
        CUDA_CHECK(hipMalloc(&d_dataPerGPU[i], sizePerGPU * sizeof(hipfftComplex)));
    }

    // Asynchronous data transfers and FFTs
    for (int i = 0; i < numGPUs; ++i) {
        CUDA_CHECK(hipSetDevice(i));
        CUDA_CHECK(hipMemcpyAsync(d_dataPerGPU[i], d_data + i * sizePerGPU, sizePerGPU * sizeof(hipfftComplex), hipMemcpyHostToDevice, streams[i]));
        CUFFT_CHECK(hipfftExecC2C(plan[i], d_dataPerGPU[i], d_dataPerGPU[i], HIPFFT_FORWARD));
        CUDA_CHECK(hipMemcpyAsync(d_data + i * sizePerGPU, d_dataPerGPU[i], sizePerGPU * sizeof(hipfftComplex), hipMemcpyDeviceToHost, streams[i]));
    }

    // Synchronize streams
    for (int i = 0; i < numGPUs; ++i) {
        CUDA_CHECK(hipSetDevice(i));
        CUDA_CHECK(hipStreamSynchronize(streams[i]));
        CUDA_CHECK(hipStreamDestroy(streams[i]));
        CUFFT_CHECK(hipfftDestroy(plan[i]));
        CUDA_CHECK(hipFree(d_dataPerGPU[i]));
    }
}

int main() {
    int numGPUs;
    CUDA_CHECK(hipGetDeviceCount(&numGPUs));
    if (numGPUs < 1) {
        std::cerr << "No CUDA devices found." << std::endl;
        return EXIT_FAILURE;
    }

    // Allocate host memory
    hipfftComplex *h_data = (hipfftComplex *)malloc(N * sizeof(hipfftComplex));
    if (!h_data) {
        std::cerr << "Failed to allocate host memory." << std::endl;
        return EXIT_FAILURE;
    }

    // Initialize data
    for (int i = 0; i < N; ++i) {
        h_data[i].x = static_cast<float>(i);
        h_data[i].y = 0.0f;
    }

    // Allocate device memory
    hipfftComplex *d_data;
    CUDA_CHECK(hipMalloc(&d_data, N * sizeof(hipfftComplex)));

    // Perform FFT
    performFFT(h_data, d_data, numGPUs);

    // Verify results (simple print for demonstration)
    std::cout << "First 10 elements of the FFT result:" << std::endl;
    for (int i = 0; i < 10; ++i) {
        std::cout << h_data[i].x << " + " << h_data[i].y << "i" << std::endl;
    }

    // Free resources
    free(h_data);
    CUDA_CHECK(hipFree(d_data));

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

                                        # End of file scope inline assembly
	.globl	_Z10performFFTP15HIP_vector_typeIfLj2EES1_i # -- Begin function _Z10performFFTP15HIP_vector_typeIfLj2EES1_i
	.type	_Z10performFFTP15HIP_vector_typeIfLj2EES1_i,@function
_Z10performFFTP15HIP_vector_typeIfLj2EES1_i: # @_Z10performFFTP15HIP_vector_typeIfLj2EES1_i
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$72, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movl	%edx, %r8d
	movq	%rsi, -88(%rbp)                 # 8-byte Spill
	movl	%edx, %eax
	movq	%rsp, %rcx
	movq	%rax, -56(%rbp)                 # 8-byte Spill
	leaq	15(,%rax,8), %rsi
	andq	$-16, %rsi
	subq	%rsi, %rcx
	movq	%rcx, -64(%rbp)                 # 8-byte Spill
	movq	%rcx, %rsp
	movq	%rsp, %rbx
	subq	%rsi, %rbx
	movq	%rbx, %rsp
	movq	%rsp, %r15
	subq	%rsi, %r15
	movq	%r15, %rsp
	xorl	%edi, %edi
	movl	$8192, %eax                     # imm = 0x2000
	xorl	%edx, %edx
	idivl	%r8d
                                        # kill: def $eax killed $eax def $rax
	movq	%rax, -80(%rbp)                 # 8-byte Spill
	movl	%r8d, -44(%rbp)                 # 4-byte Spill
	testl	%r8d, %r8d
	jle	.LBB0_48
# %bb.1:                                # %.lr.ph.preheader
	movq	%rsi, -104(%rbp)                # 8-byte Spill
	movq	-56(%rbp), %r12                 # 8-byte Reload
	movq	%rbx, -72(%rbp)                 # 8-byte Spill
	movq	-64(%rbp), %r14                 # 8-byte Reload
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%edi, -96(%rbp)                 # 4-byte Spill
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB0_3
# %bb.10:                               #   in Loop: Header=BB0_2 Depth=1
	movq	%r15, %r13
	movq	%rbx, %rdi
	callq	hipStreamCreate
	testl	%eax, %eax
	jne	.LBB0_11
# %bb.12:                               #   in Loop: Header=BB0_2 Depth=1
	movq	%r14, %rdi
	movq	-80(%rbp), %r15                 # 8-byte Reload
	movl	%r15d, %esi
	movl	$41, %edx
	movl	$1, %ecx
	callq	hipfftPlan1d
	testl	%eax, %eax
	jne	.LBB0_13
# %bb.16:                               #   in Loop: Header=BB0_2 Depth=1
	movq	(%r14), %rdi
	movl	%r15d, %esi
	movl	$41, %edx
	movl	$1, %ecx
	movq	%r13, %r15
	movq	%r13, %r8
	callq	hipfftMakePlan1d
	testl	%eax, %eax
	jne	.LBB0_17
# %bb.4:                                #   in Loop: Header=BB0_2 Depth=1
	movl	-96(%rbp), %edi                 # 4-byte Reload
	incl	%edi
	addq	$8, %r15
	addq	$8, %r14
	addq	$8, %rbx
	decq	%r12
	jne	.LBB0_2
# %bb.5:                                # %._crit_edge
	movq	%rsp, %r13
	subq	-104(%rbp), %r13                # 8-byte Folded Reload
	movq	%r13, %rsp
	cmpl	$0, -44(%rbp)                   # 4-byte Folded Reload
	jle	.LBB0_48
# %bb.6:                                # %.lr.ph137
	movq	-80(%rbp), %rax                 # 8-byte Reload
	leal	(,%rax,8), %r12d
	xorl	%r14d, %r14d
	movq	%r13, %r15
.LBB0_7:                                # =>This Inner Loop Header: Depth=1
	movl	%r14d, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB0_8
# %bb.23:                               #   in Loop: Header=BB0_7 Depth=1
	movq	%r15, %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB0_24
# %bb.18:                               #   in Loop: Header=BB0_7 Depth=1
	incq	%r14
	addq	$8, %r15
	cmpq	%r14, -56(%rbp)                 # 8-byte Folded Reload
	jne	.LBB0_7
# %bb.19:                               # %.preheader103
	cmpl	$0, -44(%rbp)                   # 4-byte Folded Reload
	jle	.LBB0_48
# %bb.20:                               # %.lr.ph139
	movl	-80(%rbp), %eax                 # 4-byte Reload
	shlq	$3, %rax
	movq	%rax, -96(%rbp)                 # 8-byte Spill
	xorl	%r15d, %r15d
.LBB0_21:                               # =>This Inner Loop Header: Depth=1
	movl	%r15d, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB0_22
# %bb.28:                               #   in Loop: Header=BB0_21 Depth=1
	movq	(%r13,%r15,8), %rdi
	movq	-72(%rbp), %rax                 # 8-byte Reload
	movq	(%rax,%r15,8), %r8
	movq	-88(%rbp), %rsi                 # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpyAsync
	testl	%eax, %eax
	jne	.LBB0_29
# %bb.30:                               #   in Loop: Header=BB0_21 Depth=1
	movq	-64(%rbp), %rax                 # 8-byte Reload
	movq	(%rax,%r15,8), %rdi
	movq	(%r13,%r15,8), %rdx
	movq	%rdx, %rsi
	movl	$-1, %ecx
	callq	hipfftExecC2C
	testl	%eax, %eax
	jne	.LBB0_31
# %bb.32:                               #   in Loop: Header=BB0_21 Depth=1
	movq	(%r13,%r15,8), %rsi
	movq	-72(%rbp), %rax                 # 8-byte Reload
	movq	(%rax,%r15,8), %r8
	movq	-88(%rbp), %r14                 # 8-byte Reload
	movq	%r14, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpyAsync
	testl	%eax, %eax
	jne	.LBB0_33
# %bb.25:                               #   in Loop: Header=BB0_21 Depth=1
	incq	%r15
	addq	-96(%rbp), %r14                 # 8-byte Folded Reload
	movq	%r14, -88(%rbp)                 # 8-byte Spill
	cmpq	%r15, -56(%rbp)                 # 8-byte Folded Reload
	jne	.LBB0_21
# %bb.26:                               # %.preheader
	cmpl	$0, -44(%rbp)                   # 4-byte Folded Reload
	movq	-72(%rbp), %r15                 # 8-byte Reload
	jle	.LBB0_48
# %bb.27:                               # %.lr.ph141.preheader
	xorl	%ebx, %ebx
.LBB0_35:                               # %.lr.ph141
                                        # =>This Inner Loop Header: Depth=1
	movl	%ebx, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	jne	.LBB0_36
# %bb.40:                               #   in Loop: Header=BB0_35 Depth=1
	movq	(%r15,%rbx,8), %rdi
	callq	hipStreamSynchronize
	testl	%eax, %eax
	jne	.LBB0_41
# %bb.42:                               #   in Loop: Header=BB0_35 Depth=1
	movq	(%r15,%rbx,8), %rdi
	callq	hipStreamDestroy
	testl	%eax, %eax
	jne	.LBB0_43
# %bb.44:                               #   in Loop: Header=BB0_35 Depth=1
	movq	-64(%rbp), %rax                 # 8-byte Reload
	movq	(%rax,%rbx,8), %rdi
	callq	hipfftDestroy
	testl	%eax, %eax
	jne	.LBB0_45
# %bb.46:                               #   in Loop: Header=BB0_35 Depth=1
	movq	(%r13,%rbx,8), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB0_47
# %bb.34:                               #   in Loop: Header=BB0_35 Depth=1
	incq	%rbx
	cmpq	%rbx, -56(%rbp)                 # 8-byte Folded Reload
	jne	.LBB0_35
.LBB0_48:                               # %._crit_edge142
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.LBB0_17:
	.cfi_def_cfa %rbp, 16
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.4, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$39, %esi
	jmp	.LBB0_14
.LBB0_13:
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.4, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$38, %esi
	jmp	.LBB0_14
.LBB0_11:
	movl	%eax, %r15d
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$37, %esi
	callq	_ZNSolsEi
	movl	$.L.str.3, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rbx
	movl	%r15d, %edi
	jmp	.LBB0_38
.LBB0_3:
	movl	%eax, %r13d
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$36, %esi
	callq	_ZNSolsEi
	movl	$.L.str.3, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rbx
	movl	%r13d, %edi
	jmp	.LBB0_38
.LBB0_24:
	movl	%eax, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$46, %esi
	jmp	.LBB0_9
.LBB0_8:
	movl	%eax, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$45, %esi
	jmp	.LBB0_9
.LBB0_33:
	movl	%eax, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$54, %esi
	jmp	.LBB0_9
.LBB0_31:
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.4, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$53, %esi
	jmp	.LBB0_14
.LBB0_29:
	movl	%eax, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$52, %esi
	jmp	.LBB0_9
.LBB0_22:
	movl	%eax, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$51, %esi
.LBB0_9:
	callq	_ZNSolsEi
	movl	$.L.str.3, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %r14
	movl	%ebx, %edi
	callq	hipGetErrorString
	movq	%r14, %rdi
	jmp	.LBB0_39
.LBB0_47:
	movl	%eax, %r14d
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$63, %esi
	jmp	.LBB0_37
.LBB0_45:
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.4, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$62, %esi
.LBB0_14:
	callq	_ZNSolsEi
	jmp	.LBB0_15
.LBB0_43:
	movl	%eax, %r14d
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$61, %esi
	jmp	.LBB0_37
.LBB0_41:
	movl	%eax, %r14d
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$60, %esi
	jmp	.LBB0_37
.LBB0_36:
	movl	%eax, %r14d
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$59, %esi
.LBB0_37:
	callq	_ZNSolsEi
	movl	$.L.str.3, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rbx
	movl	%r14d, %edi
.LBB0_38:
	callq	hipGetErrorString
	movq	%rbx, %rdi
.LBB0_39:
	movq	%rax, %rsi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
.LBB0_15:
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z10performFFTP15HIP_vector_typeIfLj2EES1_i, .Lfunc_end0-_Z10performFFTP15HIP_vector_typeIfLj2EES1_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	%rbx
	.cfi_def_cfa_offset 40
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	12(%rsp), %rdi
	callq	hipGetDeviceCount
	testl	%eax, %eax
	jne	.LBB1_1
# %bb.4:
	cmpl	$0, 12(%rsp)
	jle	.LBB1_5
# %bb.7:
	movl	$65536, %edi                    # imm = 0x10000
	callq	malloc
	testq	%rax, %rax
	je	.LBB1_18
# %bb.8:                                # %.preheader.preheader
	movq	%rax, %rbx
	xorl	%eax, %eax
.LBB1_9:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	movss	%xmm0, (%rbx,%rax,8)
	movl	$0, 4(%rbx,%rax,8)
	incq	%rax
	cmpq	$8192, %rax                     # imm = 0x2000
	jne	.LBB1_9
# %bb.10:
	leaq	16(%rsp), %rdi
	movl	$65536, %esi                    # imm = 0x10000
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_11
# %bb.12:
	movq	16(%rsp), %rsi
	movl	12(%rsp), %edx
	callq	_Z10performFFTP15HIP_vector_typeIfLj2EES1_i
	movl	$_ZSt4cout, %r14d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.7, %esi
	movl	$36, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	xorl	%r15d, %r15d
.LBB1_13:                               # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbx,%r15,8), %xmm0
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r14
	movl	$.L.str.8, %esi
	movl	$3, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorps	%xmm0, %xmm0
	cvtss2sd	4(%rbx,%r15,8), %xmm0
	movq	%r14, %rdi
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %r14
	movl	$.L.str.9, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r14), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%r14, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	incq	%r15
	cmpq	$10, %r15
	jne	.LBB1_13
# %bb.14:
	movq	%rbx, %rdi
	callq	free
	movq	16(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB1_15
# %bb.16:
	xorl	%eax, %eax
	jmp	.LBB1_17
.LBB1_5:
	movl	$_ZSt4cerr, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.5, %esi
	movl	$22, %edx
	jmp	.LBB1_6
.LBB1_18:
	movl	$_ZSt4cerr, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.6, %esi
	movl	$31, %edx
.LBB1_6:
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cerr, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$1, %eax
.LBB1_17:
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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
.LBB1_1:
	.cfi_def_cfa_offset 64
	movl	%eax, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$69, %esi
	jmp	.LBB1_2
.LBB1_11:
	movl	%eax, %ebp
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$90, %esi
	callq	_ZNSolsEi
	movl	$.L.str.3, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rbx
	movl	%ebp, %edi
	callq	hipGetErrorString
	movq	%rbx, %rdi
	jmp	.LBB1_3
.LBB1_15:
	movl	%eax, %ebx
	movl	$_ZSt4cerr, %edi
	movl	$.L.str, %esi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.1, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movl	$.L.str.2, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	movl	$103, %esi
.LBB1_2:
	callq	_ZNSolsEi
	movl	$.L.str.3, %esi
	movq	%rax, %rdi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %r14
	movl	%ebx, %edi
	callq	hipGetErrorString
	movq	%r14, %rdi
.LBB1_3:
	movq	%rax, %rsi
	callq	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
	movq	%rax, %rdi
	callq	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"CUDA error at "
	.size	.L.str, 15

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/hip-codes-80k-from-llm-dedup-disassemble-sm89/cuda_code_014768.hip"
	.size	.L.str.1, 89

	.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	" - "
	.size	.L.str.3, 4

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"CUFFT error at "
	.size	.L.str.4, 16

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"No CUDA devices found."
	.size	.L.str.5, 23

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Failed to allocate host memory."
	.size	.L.str.6, 32

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"First 10 elements of the FFT result:"
	.size	.L.str.7, 37

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	" + "
	.size	.L.str.8, 4

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

	.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 _ZSt4cerr
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
