#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <time.h>

/* Generates a mandelbrot set image
 *
 * The elements of bounds is the real min/max and imaginary min/max in that order
 * iterations is the number of iterations of z^2+c on each pixel
 * The percision is the real and imaginary step size in that order
 */
__global__ 
void mandelbrot(unsigned char* image, 
    const double left, 
    const double right, 
    const double down, 
    const double up, 
    const int iterations, 
    const double real_precision, 
    const double im_precision)
{
    // Representation of the image is in row-major order. Thus, the (re,im) pixel is image[re+im*re_size]
    
    int x = threadIdx.x + blockIdx.x * blockDim.x; // real part
    int y = threadIdx.y + blockIdx.y * blockDim.y; // imaginary part

    const int re_size = (int)((right-left)/real_precision);
    const int im_size = (int)((up-down)/im_precision);

    if (x < re_size && y < im_size) // check that it is in bounds
    {
        // c=r+it is the original number
        double r = left + real_precision*x;
        double t = down + im_precision*y;

        // start from z=0 and declare temporary variables
        double zr = 0.0, zt = 0.0, _zr, _zt;

        for (int iteration = 1; iteration < iterations; ++iteration)
        {
            // perform an iteration of z^2+c
            _zr = zr*zr - zt*zt + r;
            _zt = zr*zt*2 + t;
            zr = _zr;
            zt = _zt;
            // check for |z|>2 (or |z|^2>4)
            if (zr*zr+zt*zt > 4.0)
            {
                // convert to image using a log distribution.
                int q = (int)((sqrtf(iteration)*512)/sqrtf(iterations));
                int s = 3*(x+y*re_size); // s:red, s+1:green, s+2:blue
                if (q < 256)
                {
                    image[s+2] = 255-q;
                    image[s] = q;
                }
                else
                {
                    image[s] = 511-q;
                    image[s+1] = q-256;
                }                
                return;
            }
        }
        // If it never reaches |z|>2, the point is then in the mandobrot set given the limitations of the program.
        // Therefore, the point is represented in the image as black
    }
}

int check(double r, double t, int iterations)
{
    double zr = 0.0, zt = 0.0, _zr, _zt;
    for (int iteration = 0; iteration < iterations-1; ++iteration)
    {
        // perform an iteration of z^2+c
        _zr = zr*zr - zt*zt + r;
        _zt = zr*zt*2 + t;
        zr = _zr;
        zt = _zt;

        // check for |z|>2 (or |z|^2>4)
        if (zr*zr+zt*zt > 4.0)
        {
            // convert to image. here, a linear gamma curve is used
            return iteration;
        }
    }
    return iterations-1;
}

int main(int argc, char* argv[])
{
    // the default bounds for the mandelbrot set is usually -2<Re(z)<1 and -1<Im(z)<1
    double bounds[4] = {-0.235125-4e-5, -0.235125+12e-5, 0.827215-4e-5, 0.827215+7.5e-5};
    
    // given precision of 0.001, it will generate 3000x2000 image which is about 6 megapixel
    double precision[2] = {1e-8, 1e-8};
    
    // this just fits the 3 8-bit channels
    int iterations = 1 << 11;

    unsigned char *d_image, *h_image;
    int re_size, im_size;
    
    // compute the size of the image
    re_size = (int)((bounds[1]-bounds[0])/precision[0]);
    im_size = (int)((bounds[3]-bounds[2])/precision[1]);
    
    // allocate the GPU memory for the image
    if (cudaMalloc(&d_image, 3*re_size*im_size*sizeof(char)) != cudaSuccess) 
    {
        std::cout << "The device does not have enough memory. Program exited with error code -1." << std::endl;
        return -1;
    }

    // set the memory to 0
    if (cudaMemset(d_image, 0, 3*re_size*im_size*sizeof(char)) != cudaSuccess)
    {
        std::cout << "Failed to set memory to 0. Program exited with error code -2." << std::endl;
        return -2;
    }

    // create the grid and blocks to call the method. 32x32=1024 threads.
    dim3 grid((re_size+31)/32, (im_size+31)/32, 1);
    dim3 block(32,32,1);
    mandelbrot <<<grid, block>>> (d_image, bounds[0], bounds[1], bounds[2], bounds[3], iterations, precision[0], precision[1]);
    cudaDeviceSynchronize();

    h_image = (unsigned char*)calloc(3*re_size*im_size, sizeof(char));
    if (cudaMemcpy(h_image, d_image, 3*re_size*im_size*sizeof(char), cudaMemcpyDeviceToHost) != cudaSuccess)
    {
        std::cout << "Failed to copy the memory from device to host. Program exited with error code -9";
        return -9;
    }
    cudaFree(d_image);

    #ifdef DEBUG
    // check against CPU code
    srand(time(NULL));
    for (int i = 0; i < 20; ++i)
    {
        int x = rand() % re_size;
        int y = rand() % im_size;

        printf("z=%.2f+%.2fi GPU:%d CPU:%d\n", bounds[0]+(double)x*precision[0], bounds[2]+(double)y*precision[1], h_image[3*(x+y*re_size)], check(bounds[0]+(double)x*precision[0], bounds[2]+(double)y*precision[1], iterations));
    }
    #endif

    // write the image
    FILE *img;
    if (argc > 1)
        img = fopen(argv[1], "wb");
    else
        img = fopen("/mnt/ramdisk/image.ppm", "wb");
    fprintf(img, "P6\n%d %d\n%d\n", re_size, im_size, 255);
    fwrite(h_image, sizeof(char), 3*re_size*im_size, img);
    fclose(img);
    
    free(h_image);

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

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3770:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3770:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z5checkddi
	.type	_Z5checkddi, @function
_Z5checkddi:
.LFB3766:
	.cfi_startproc
	endbr64
	xorps	%xmm4, %xmm4
	movsd	.LC1(%rip), %xmm5
	xorl	%eax, %eax
	decl	%edi
	movaps	%xmm4, %xmm2
.L3:
	cmpl	%eax, %edi
	jle	.L7
	movaps	%xmm2, %xmm3
	movaps	%xmm4, %xmm6
	mulsd	%xmm2, %xmm3
	mulsd	%xmm4, %xmm2
	mulsd	%xmm4, %xmm6
	addsd	%xmm2, %xmm2
	subsd	%xmm6, %xmm3
	movaps	%xmm2, %xmm4
	addsd	%xmm0, %xmm3
	addsd	%xmm1, %xmm4
	movaps	%xmm3, %xmm2
	movaps	%xmm4, %xmm6
	mulsd	%xmm3, %xmm2
	mulsd	%xmm4, %xmm6
	addsd	%xmm6, %xmm2
	comisd	%xmm5, %xmm2
	ja	.L2
	incl	%eax
	movaps	%xmm3, %xmm2
	jmp	.L3
.L7:
	movl	%edi, %eax
.L2:
	ret
	.cfi_endproc
.LFE3766:
	.size	_Z5checkddi, .-_Z5checkddi
	.globl	_Z37__device_stub__Z10mandelbrotPhddddiddPhddddidd
	.type	_Z37__device_stub__Z10mandelbrotPhddddiddPhddddidd, @function
_Z37__device_stub__Z10mandelbrotPhddddiddPhddddidd:
.LFB3792:
	.cfi_startproc
	endbr64
	subq	$216, %rsp
	.cfi_def_cfa_offset 224
	movq	%rdi, 56(%rsp)
	leaq	80(%rsp), %rcx
	leaq	72(%rsp), %rdx
	movl	%esi, 20(%rsp)
	leaq	88(%rsp), %rdi
	leaq	100(%rsp), %rsi
	movsd	%xmm0, 48(%rsp)
	movsd	%xmm1, 40(%rsp)
	movsd	%xmm2, 32(%rsp)
	movsd	%xmm3, 24(%rsp)
	movsd	%xmm4, 8(%rsp)
	movsd	%xmm5, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 200(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rax
	movl	$1, 96(%rsp)
	movq	%rax, 136(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 184(%rsp)
	movq	%rsp, %rax
	movq	%rax, 192(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 88(%rsp)
	movq	%rax, 100(%rsp)
	movl	$1, 108(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	80(%rsp)
	.cfi_def_cfa_offset 232
	leaq	_Z10mandelbrotPhddddidd(%rip), %rdi
	pushq	80(%rsp)
	.cfi_def_cfa_offset 240
	movq	116(%rsp), %rcx
	movl	124(%rsp), %r8d
	movq	104(%rsp), %rsi
	movl	112(%rsp), %edx
	leaq	152(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 232
	popq	%rdx
	.cfi_def_cfa_offset 224
.L8:
	movq	200(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$216, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3792:
	.size	_Z37__device_stub__Z10mandelbrotPhddddiddPhddddidd, .-_Z37__device_stub__Z10mandelbrotPhddddiddPhddddidd
	.globl	_Z10mandelbrotPhddddidd
	.type	_Z10mandelbrotPhddddidd, @function
_Z10mandelbrotPhddddidd:
.LFB3793:
	.cfi_startproc
	endbr64
	jmp	_Z37__device_stub__Z10mandelbrotPhddddiddPhddddidd
	.cfi_endproc
.LFE3793:
	.size	_Z10mandelbrotPhddddidd, .-_Z10mandelbrotPhddddidd
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC2:
	.string	"The device does not have enough memory. Program exited with error code -1."
.LC3:
	.string	"Failed to set memory to 0. Program exited with error code -2."
.LC9:
	.string	"Failed to copy the memory from device to host. Program exited with error code -9"
.LC10:
	.string	"wb"
.LC11:
	.string	"/mnt/ramdisk/image.ppm"
.LC12:
	.string	"P6\n%d %d\n%d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3767:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%edi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rsi, %rbx
	movl	$552000000, %esi
	subq	$48, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	cudaMalloc@PLT
	testl	%eax, %eax
	je	.L14
	leaq	.LC2(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	orl	$-1, %eax
	jmp	.L13
.L14:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	movl	$552000000, %edx
	call	cudaMemset@PLT
	testl	%eax, %eax
	je	.L16
	leaq	.LC3(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movl	$-2, %eax
	jmp	.L13
.L16:
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movl	$1, %esi
	movabsq	$137438953504, %rdx
	movabsq	$1546188227060, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L17
	movsd	.LC4(%rip), %xmm5
	movsd	.LC5(%rip), %xmm3
	movl	$2048, %esi
	movsd	.LC6(%rip), %xmm2
	movsd	.LC7(%rip), %xmm1
	movsd	.LC8(%rip), %xmm0
	movq	8(%rsp), %rdi
	movaps	%xmm5, %xmm4
	call	_Z37__device_stub__Z10mandelbrotPhddddiddPhddddidd
.L17:
	call	cudaDeviceSynchronize@PLT
	movl	$1, %esi
	movl	$552000000, %edi
	call	calloc@PLT
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movl	$552000000, %edx
	movq	%rax, %rdi
	movq	%rax, %rbp
	call	cudaMemcpy@PLT
	testl	%eax, %eax
	je	.L18
	leaq	.LC9(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$-9, %eax
	jmp	.L13
.L18:
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	decl	%r12d
	leaq	.LC10(%rip), %rsi
	leaq	.LC11(%rip), %rdi
	jle	.L23
	movq	8(%rbx), %rdi
.L23:
	call	fopen@PLT
	movl	$255, %r9d
	movl	$11500, %r8d
	movl	$16000, %ecx
	movq	%rax, %rbx
	movq	%rax, %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC12(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	%rbx, %rcx
	movl	$552000000, %edx
	movq	%rbp, %rdi
	movl	$1, %esi
	call	fwrite@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	%rbp, %rdi
	call	free@PLT
	xorl	%eax, %eax
.L13:
	movq	40(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	addq	$48, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3767:
	.size	main, .-main
	.section	.rodata.str1.1
.LC13:
	.string	"_Z10mandelbrotPhddddidd"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3795:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC13(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z10mandelbrotPhddddidd(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3795:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC1:
	.long	0
	.long	1074790400
	.align 8
.LC4:
	.long	-500134854
	.long	1044740494
	.align 8
.LC5:
	.long	-523642412
	.long	1072331048
	.align 8
.LC6:
	.long	-1264438372
	.long	1072330807
	.align 8
.LC7:
	.long	-760037413
	.long	-1077013340
	.align 8
.LC8:
	.long	1374390
	.long	-1077011997
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <time.h>

/* Generates a mandelbrot set image
 *
 * The elements of bounds is the real min/max and imaginary min/max in that order
 * iterations is the number of iterations of z^2+c on each pixel
 * The percision is the real and imaginary step size in that order
 */
__global__ 
void mandelbrot(unsigned char* image, 
    const double left, 
    const double right, 
    const double down, 
    const double up, 
    const int iterations, 
    const double real_precision, 
    const double im_precision)
{
    // Representation of the image is in row-major order. Thus, the (re,im) pixel is image[re+im*re_size]
    
    int x = threadIdx.x + blockIdx.x * blockDim.x; // real part
    int y = threadIdx.y + blockIdx.y * blockDim.y; // imaginary part

    const int re_size = (int)((right-left)/real_precision);
    const int im_size = (int)((up-down)/im_precision);

    if (x < re_size && y < im_size) // check that it is in bounds
    {
        // c=r+it is the original number
        double r = left + real_precision*x;
        double t = down + im_precision*y;

        // start from z=0 and declare temporary variables
        double zr = 0.0, zt = 0.0, _zr, _zt;

        for (int iteration = 1; iteration < iterations; ++iteration)
        {
            // perform an iteration of z^2+c
            _zr = zr*zr - zt*zt + r;
            _zt = zr*zt*2 + t;
            zr = _zr;
            zt = _zt;
            // check for |z|>2 (or |z|^2>4)
            if (zr*zr+zt*zt > 4.0)
            {
                // convert to image using a log distribution.
                int q = (int)((sqrtf(iteration)*512)/sqrtf(iterations));
                int s = 3*(x+y*re_size); // s:red, s+1:green, s+2:blue
                if (q < 256)
                {
                    image[s+2] = 255-q;
                    image[s] = q;
                }
                else
                {
                    image[s] = 511-q;
                    image[s+1] = q-256;
                }                
                return;
            }
        }
        // If it never reaches |z|>2, the point is then in the mandobrot set given the limitations of the program.
        // Therefore, the point is represented in the image as black
    }
}

int check(double r, double t, int iterations)
{
    double zr = 0.0, zt = 0.0, _zr, _zt;
    for (int iteration = 0; iteration < iterations-1; ++iteration)
    {
        // perform an iteration of z^2+c
        _zr = zr*zr - zt*zt + r;
        _zt = zr*zt*2 + t;
        zr = _zr;
        zt = _zt;

        // check for |z|>2 (or |z|^2>4)
        if (zr*zr+zt*zt > 4.0)
        {
            // convert to image. here, a linear gamma curve is used
            return iteration;
        }
    }
    return iterations-1;
}

int main(int argc, char* argv[])
{
    // the default bounds for the mandelbrot set is usually -2<Re(z)<1 and -1<Im(z)<1
    double bounds[4] = {-0.235125-4e-5, -0.235125+12e-5, 0.827215-4e-5, 0.827215+7.5e-5};
    
    // given precision of 0.001, it will generate 3000x2000 image which is about 6 megapixel
    double precision[2] = {1e-8, 1e-8};
    
    // this just fits the 3 8-bit channels
    int iterations = 1 << 11;

    unsigned char *d_image, *h_image;
    int re_size, im_size;
    
    // compute the size of the image
    re_size = (int)((bounds[1]-bounds[0])/precision[0]);
    im_size = (int)((bounds[3]-bounds[2])/precision[1]);
    
    // allocate the GPU memory for the image
    if (hipMalloc(&d_image, 3*re_size*im_size*sizeof(char)) != hipSuccess) 
    {
        std::cout << "The device does not have enough memory. Program exited with error code -1." << std::endl;
        return -1;
    }

    // set the memory to 0
    if (hipMemset(d_image, 0, 3*re_size*im_size*sizeof(char)) != hipSuccess)
    {
        std::cout << "Failed to set memory to 0. Program exited with error code -2." << std::endl;
        return -2;
    }

    // create the grid and blocks to call the method. 32x32=1024 threads.
    dim3 grid((re_size+31)/32, (im_size+31)/32, 1);
    dim3 block(32,32,1);
    mandelbrot <<<grid, block>>> (d_image, bounds[0], bounds[1], bounds[2], bounds[3], iterations, precision[0], precision[1]);
    hipDeviceSynchronize();

    h_image = (unsigned char*)calloc(3*re_size*im_size, sizeof(char));
    if (hipMemcpy(h_image, d_image, 3*re_size*im_size*sizeof(char), hipMemcpyDeviceToHost) != hipSuccess)
    {
        std::cout << "Failed to copy the memory from device to host. Program exited with error code -9";
        return -9;
    }
    hipFree(d_image);

    #ifdef DEBUG
    // check against CPU code
    srand(time(NULL));
    for (int i = 0; i < 20; ++i)
    {
        int x = rand() % re_size;
        int y = rand() % im_size;

        printf("z=%.2f+%.2fi GPU:%d CPU:%d\n", bounds[0]+(double)x*precision[0], bounds[2]+(double)y*precision[1], h_image[3*(x+y*re_size)], check(bounds[0]+(double)x*precision[0], bounds[2]+(double)y*precision[1], iterations));
    }
    #endif

    // write the image
    FILE *img;
    if (argc > 1)
        img = fopen(argv[1], "wb");
    else
        img = fopen("/mnt/ramdisk/image.ppm", "wb");
    fprintf(img, "P6\n%d %d\n%d\n", re_size, im_size, 255);
    fwrite(h_image, sizeof(char), 3*re_size*im_size, img);
    fclose(img);
    
    free(h_image);

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

                                        # End of file scope inline assembly
	.globl	_Z25__device_stub__mandelbrotPhddddidd # -- Begin function _Z25__device_stub__mandelbrotPhddddidd
	.type	_Z25__device_stub__mandelbrotPhddddidd,@function
_Z25__device_stub__mandelbrotPhddddidd: # @_Z25__device_stub__mandelbrotPhddddidd
	.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	$176, %rsp
	.cfi_def_cfa_offset 224
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	72(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	64(%rsp), %rcx
	movsd	%xmm0, (%rcx)
	leaq	56(%rsp), %rdx
	movsd	%xmm1, (%rdx)
	leaq	48(%rsp), %rdi
	movsd	%xmm2, (%rdi)
	leaq	40(%rsp), %r8
	movsd	%xmm3, (%r8)
	leaq	4(%rsp), %r9
	movl	%esi, (%r9)
	leaq	32(%rsp), %rsi
	movsd	%xmm4, (%rsi)
	leaq	24(%rsp), %r10
	movsd	%xmm5, (%r10)
	leaq	112(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rdx, 16(%rbx)
	movq	%rdi, 24(%rbx)
	movq	%r8, 32(%rbx)
	movq	%r9, 40(%rbx)
	movq	%rsi, 48(%rbx)
	movq	%r10, 56(%rbx)
	leaq	96(%rsp), %r14
	leaq	80(%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	$_Z10mandelbrotPhddddidd, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$192, %rsp
	.cfi_adjust_cfa_offset -192
	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	_Z25__device_stub__mandelbrotPhddddidd, .Lfunc_end0-_Z25__device_stub__mandelbrotPhddddidd
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z5checkddi
.LCPI1_0:
	.quad	0x4010000000000000              # double 4
	.text
	.globl	_Z5checkddi
	.type	_Z5checkddi,@function
_Z5checkddi:                            # @_Z5checkddi
	.cfi_startproc
# %bb.0:
                                        # kill: def $edi killed $edi def $rdi
	leal	-1(%rdi), %eax
	xorl	%ecx, %ecx
	cmpl	$2, %edi
	jl	.LBB1_5
# %bb.1:                                # %.lr.ph.preheader
	xorpd	%xmm2, %xmm2
	xorl	%ecx, %ecx
	movsd	.LCPI1_0(%rip), %xmm3           # xmm3 = mem[0],zero
	xorpd	%xmm4, %xmm4
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movapd	%xmm2, %xmm5
	mulsd	%xmm2, %xmm2
	movapd	%xmm4, %xmm6
	mulsd	%xmm4, %xmm6
	subsd	%xmm6, %xmm2
	addsd	%xmm0, %xmm2
	mulsd	%xmm5, %xmm4
	addsd	%xmm4, %xmm4
	addsd	%xmm1, %xmm4
	movapd	%xmm2, %xmm5
	mulsd	%xmm2, %xmm5
	movapd	%xmm4, %xmm6
	mulsd	%xmm4, %xmm6
	addsd	%xmm5, %xmm6
	ucomisd	%xmm3, %xmm6
	ja	.LBB1_5
# %bb.3:                                #   in Loop: Header=BB1_2 Depth=1
	incl	%ecx
	cmpl	%ecx, %eax
	jne	.LBB1_2
# %bb.4:
	movl	%eax, %ecx
.LBB1_5:                                # %._crit_edge
	cmpl	%eax, %ecx
	cmovll	%ecx, %eax
	retq
.Lfunc_end1:
	.size	_Z5checkddi, .Lfunc_end1-_Z5checkddi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI2_0:
	.quad	0xbfce19e30014f8b6              # double -0.23516500000000001
.LCPI2_1:
	.quad	0xbfce14a4d2b2bfdb              # double -0.23500499999999999
.LCPI2_2:
	.quad	0x3fea7837b4a2339c              # double 0.82717499999999999
.LCPI2_3:
	.quad	0x3fea7928e0c9d9d4              # double 0.82729000000000008
.LCPI2_4:
	.quad	0x3e45798ee2308c3a              # double 1.0E-8
	.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	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	%edi, %ebp
	movq	%rsp, %rdi
	movl	$552000000, %esi                # imm = 0x20E6DA00
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB2_2
# %bb.1:
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$74, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$-1, %ebx
	jmp	.LBB2_12
.LBB2_2:
	movq	(%rsp), %rdi
	movl	$552000000, %edx                # imm = 0x20E6DA00
	xorl	%esi, %esi
	callq	hipMemset
	testl	%eax, %eax
	je	.LBB2_4
# %bb.3:
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$61, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$-2, %ebx
	jmp	.LBB2_12
.LBB2_4:
	movabsq	$1546188227060, %rdi            # imm = 0x168000001F4
	movabsq	$137438953504, %rdx             # imm = 0x2000000020
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_6
# %bb.5:
	movq	(%rsp), %rdi
	movsd	.LCPI2_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movsd	.LCPI2_1(%rip), %xmm1           # xmm1 = mem[0],zero
	movsd	.LCPI2_2(%rip), %xmm2           # xmm2 = mem[0],zero
	movsd	.LCPI2_3(%rip), %xmm3           # xmm3 = mem[0],zero
	movsd	.LCPI2_4(%rip), %xmm4           # xmm4 = mem[0],zero
	movl	$2048, %esi                     # imm = 0x800
	movaps	%xmm4, %xmm5
	callq	_Z25__device_stub__mandelbrotPhddddidd
.LBB2_6:
	callq	hipDeviceSynchronize
	movl	$552000000, %edi                # imm = 0x20E6DA00
	movl	$1, %esi
	callq	calloc
	movq	%rax, %r14
	movq	(%rsp), %rsi
	movl	$552000000, %edx                # imm = 0x20E6DA00
	movq	%rax, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB2_8
# %bb.7:
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$80, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$-9, %ebx
	jmp	.LBB2_12
.LBB2_8:
	movq	(%rsp), %rdi
	callq	hipFree
	cmpl	$2, %ebp
	jl	.LBB2_10
# %bb.9:
	movq	8(%rbx), %rdi
	jmp	.LBB2_11
.LBB2_10:
	movl	$.L.str.4, %edi
.LBB2_11:
	movl	$.L.str.3, %esi
	callq	fopen
	movq	%rax, %r15
	xorl	%ebx, %ebx
	movl	$.L.str.5, %esi
	movq	%rax, %rdi
	movl	$16000, %edx                    # imm = 0x3E80
	movl	$11500, %ecx                    # imm = 0x2CEC
	movl	$255, %r8d
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %esi
	movl	$552000000, %edx                # imm = 0x20E6DA00
	movq	%r14, %rdi
	movq	%r15, %rcx
	callq	fwrite
	movq	%r15, %rdi
	callq	fclose
	movq	%r14, %rdi
	callq	free
.LBB2_12:
	movl	%ebx, %eax
	addq	$8, %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
.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:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10mandelbrotPhddddidd, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_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	_Z10mandelbrotPhddddidd,@object # @_Z10mandelbrotPhddddidd
	.section	.rodata,"a",@progbits
	.globl	_Z10mandelbrotPhddddidd
	.p2align	3, 0x0
_Z10mandelbrotPhddddidd:
	.quad	_Z25__device_stub__mandelbrotPhddddidd
	.size	_Z10mandelbrotPhddddidd, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"The device does not have enough memory. Program exited with error code -1."
	.size	.L.str, 75

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Failed to set memory to 0. Program exited with error code -2."
	.size	.L.str.1, 62

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Failed to copy the memory from device to host. Program exited with error code -9"
	.size	.L.str.2, 81

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"/mnt/ramdisk/image.ppm"
	.size	.L.str.4, 23

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"P6\n%d %d\n%d\n"
	.size	.L.str.5, 13

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z10mandelbrotPhddddidd"
	.size	.L__unnamed_1, 24

	.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 _Z25__device_stub__mandelbrotPhddddidd
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z10mandelbrotPhddddidd
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z10mandelbrotPhddddidd ; -- Begin function _Z10mandelbrotPhddddidd
	.globl	_Z10mandelbrotPhddddidd
	.p2align	8
	.type	_Z10mandelbrotPhddddidd,@function
_Z10mandelbrotPhddddidd:                ; @_Z10mandelbrotPhddddidd
; %bb.0:
	s_clause 0x2
	s_load_b256 s[4:11], s[0:1], 0x0
	s_load_b128 s[16:19], s[0:1], 0x30
	s_load_b32 s2, s[0:1], 0x4c
	s_waitcnt lgkmcnt(0)
	v_add_f64 v[1:2], s[8:9], -s[6:7]
	s_and_b32 s3, s2, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_scale_f64 v[3:4], null, s[16:17], s[16:17], v[1:2]
	v_rcp_f64_e32 v[5:6], v[3:4]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[7:8], -v[3:4], v[5:6], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[5:6], v[5:6], v[7:8], v[5:6]
	v_fma_f64 v[7:8], -v[3:4], v[5:6], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fma_f64 v[5:6], v[5:6], v[7:8], v[5:6]
	v_div_scale_f64 v[7:8], vcc_lo, v[1:2], s[16:17], v[1:2]
	v_mul_f64 v[9:10], v[7:8], v[5:6]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[3:4], -v[3:4], v[9:10], v[7:8]
	v_div_fmas_f64 v[3:4], v[3:4], v[5:6], v[9:10]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_fixup_f64 v[1:2], v[3:4], s[16:17], v[1:2]
	v_and_b32_e32 v3, 0x3ff, v0
	v_cvt_i32_f64_e32 v11, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s14, s3, v[3:4]
	s_mov_b32 s3, exec_lo
	v_cmpx_lt_i32_e64 v1, v11
	s_cbranch_execz .LBB0_13
; %bb.1:
	s_load_b64 s[8:9], s[0:1], 0x20
	v_bfe_u32 v0, v0, 10, 10
	s_lshr_b32 s2, s2, 16
	s_waitcnt lgkmcnt(0)
	v_add_f64 v[2:3], s[8:9], -s[10:11]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_scale_f64 v[4:5], null, s[18:19], s[18:19], v[2:3]
	v_rcp_f64_e32 v[6:7], v[4:5]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	v_div_scale_f64 v[8:9], vcc_lo, v[2:3], s[18:19], v[2:3]
	v_mul_f64 v[12:13], v[8:9], v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[4:5], -v[4:5], v[12:13], v[8:9]
	v_div_fmas_f64 v[4:5], v[4:5], v[6:7], v[12:13]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fixup_f64 v[2:3], v[4:5], s[18:19], v[2:3]
	v_cvt_i32_f64_e32 v4, v[2:3]
	v_mad_u64_u32 v[2:3], null, s15, s2, v[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_lt_i32_e32 vcc_lo, v2, v4
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_13
; %bb.2:
	s_load_b32 s0, s[0:1], 0x28
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s0, 2
	s_cbranch_scc1 .LBB0_13
; %bb.3:                                ; %.lr.ph.preheader
	v_cvt_f64_i32_e32 v[3:4], v1
	v_cvt_f64_i32_e32 v[5:6], v2
	v_mov_b32_e32 v9, 0
	v_mov_b32_e32 v10, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mov_b32_e32 v7, v9
	s_mov_b32 s1, 0
                                        ; implicit-def: $sgpr3
                                        ; implicit-def: $sgpr2
	v_mov_b32_e32 v8, v10
	v_fma_f64 v[3:4], v[3:4], s[16:17], s[6:7]
	v_fma_f64 v[5:6], v[5:6], s[18:19], s[10:11]
	s_mov_b32 s7, 1
                                        ; implicit-def: $sgpr6
.LBB0_4:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_mul_f64 v[12:13], v[7:8], v[7:8]
	v_mul_f64 v[7:8], v[7:8], v[9:10]
	s_or_b32 s2, s2, exec_lo
	s_or_b32 s3, s3, exec_lo
	s_mov_b32 s9, exec_lo
                                        ; implicit-def: $sgpr8
	v_fma_f64 v[9:10], v[9:10], v[9:10], -v[12:13]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[7:8], v[7:8], 2.0, v[5:6]
	v_add_f64 v[9:10], v[3:4], v[9:10]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[12:13], v[7:8], v[7:8]
	v_fma_f64 v[12:13], v[9:10], v[9:10], v[12:13]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_nlt_f64_e32 4.0, v[12:13]
; %bb.5:                                ;   in Loop: Header=BB0_4 Depth=1
	s_add_i32 s8, s7, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s0, s8
	s_cselect_b32 s10, -1, 0
	s_and_not1_b32 s3, s3, exec_lo
	s_and_b32 s10, s10, exec_lo
	s_and_not1_b32 s2, s2, exec_lo
	s_or_b32 s3, s3, s10
; %bb.6:                                ; %Flow99
                                        ;   in Loop: Header=BB0_4 Depth=1
	s_or_b32 exec_lo, exec_lo, s9
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_4) | instid1(SALU_CYCLE_1)
	s_and_b32 s9, exec_lo, s3
	v_mov_b32_e32 v0, s7
	s_or_b32 s1, s9, s1
	s_and_not1_b32 s6, s6, exec_lo
	s_and_b32 s7, s2, exec_lo
	s_or_b32 s6, s6, s7
	s_mov_b32 s7, s8
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB0_4
; %bb.7:                                ; %loop.exit.guard
	s_or_b32 exec_lo, exec_lo, s1
	s_and_saveexec_b32 s1, s6
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s1, exec_lo, s1
	s_cbranch_execz .LBB0_13
; %bb.8:
	v_cvt_f32_i32_e32 v0, v0
	v_cvt_f32_i32_e32 v3, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_dual_mul_f32 v4, 0x4f800000, v0 :: v_dual_mul_f32 v5, 0x4f800000, v3
	v_cmp_gt_f32_e64 s0, 0xf800000, v3
	v_cmp_gt_f32_e32 vcc_lo, 0xf800000, v0
	v_cndmask_b32_e64 v3, v3, v5, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_sqrt_f32_e32 v5, v3
	s_waitcnt_depctr 0xfff
	v_dual_cndmask_b32 v0, v0, v4 :: v_dual_add_nc_u32 v7, -1, v5
	v_sqrt_f32_e32 v4, v0
	v_add_nc_u32_e32 v10, 1, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_fma_f32 v12, -v7, v5, v3
	s_waitcnt_depctr 0xfff
	v_add_nc_u32_e32 v6, -1, v4
	v_add_nc_u32_e32 v8, 1, v4
	v_fma_f32 v9, -v6, v4, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v13, -v8, v4, v0
	v_cmp_ge_f32_e64 s1, 0, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v4, v4, v6, s1
	v_cmp_ge_f32_e64 s1, 0, v12
	v_fma_f32 v6, -v10, v5, v3
	v_cndmask_b32_e64 v5, v5, v7, s1
	v_cmp_lt_f32_e64 s1, 0, v13
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v4, v4, v8, s1
	v_cmp_lt_f32_e64 s1, 0, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v6, 0x37800000, v4
	v_cndmask_b32_e64 v5, v5, v10, s1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_dual_cndmask_b32 v4, v4, v6 :: v_dual_mul_f32 v7, 0x37800000, v5
	v_cmp_class_f32_e64 vcc_lo, v0, 0x260
	v_cndmask_b32_e64 v5, v5, v7, s0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v0, v4, v0, vcc_lo
	v_cmp_class_f32_e64 vcc_lo, v3, 0x260
	v_dual_mul_f32 v0, 0x44000000, v0 :: v_dual_cndmask_b32 v5, v5, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_scale_f32 v3, null, v5, v5, v0
	v_div_scale_f32 v7, vcc_lo, v0, v5, v0
	v_rcp_f32_e32 v4, v3
	s_waitcnt_depctr 0xfff
	v_fma_f32 v6, -v3, v4, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v4, v6, v4
	v_mul_f32_e32 v6, v7, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v8, -v3, v6, v7
	v_fmac_f32_e32 v6, v8, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v3, -v3, v6, v7
	v_div_fmas_f32 v6, v3, v4, v6
	v_mad_u64_u32 v[3:4], null, v2, v11, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fixup_f32 v0, v6, v5, v0
	v_lshl_add_u32 v1, v3, 1, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cvt_i32_f32_e32 v2, v0
	v_ashrrev_i32_e32 v4, 31, v1
	v_add_co_u32 v0, s0, s4, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_xor_b32_e32 v3, -1, v2
	v_add_co_ci_u32_e64 v1, s0, s5, v4, s0
	s_mov_b32 s0, exec_lo
	v_cmpx_lt_i32_e32 0xff, v2
	s_xor_b32 s0, exec_lo, s0
	s_cbranch_execz .LBB0_10
; %bb.9:
	global_store_b8 v[0:1], v3, off
	v_add_co_u32 v0, vcc_lo, v0, 1
	v_add_co_ci_u32_e32 v1, vcc_lo, 0, v1, vcc_lo
                                        ; implicit-def: $vgpr3
.LBB0_10:                               ; %Flow
	s_and_not1_saveexec_b32 s0, s0
	s_cbranch_execz .LBB0_12
; %bb.11:
	global_store_b8 v[0:1], v3, off offset:2
.LBB0_12:                               ; %.critedge.sink.split
	s_or_b32 exec_lo, exec_lo, s0
	global_store_b8 v[0:1], v2, off
.LBB0_13:                               ; %.critedge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10mandelbrotPhddddidd
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 320
		.amdhsa_user_sgpr_count 14
		.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 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 14
		.amdhsa_next_free_sgpr 20
		.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	_Z10mandelbrotPhddddidd, .Lfunc_end0-_Z10mandelbrotPhddddidd
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1132
; NumSgprs: 22
; NumVgprs: 14
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 22
; NumVGPRsForWavesPerEU: 14
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           8
        .value_kind:     by_value
      - .offset:         16
        .size:           8
        .value_kind:     by_value
      - .offset:         24
        .size:           8
        .value_kind:     by_value
      - .offset:         32
        .size:           8
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     by_value
      - .offset:         48
        .size:           8
        .value_kind:     by_value
      - .offset:         56
        .size:           8
        .value_kind:     by_value
      - .offset:         64
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         68
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         72
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         76
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         78
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         80
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         82
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         84
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         86
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         112
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         120
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         128
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 320
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10mandelbrotPhddddidd
    .private_segment_fixed_size: 0
    .sgpr_count:     22
    .sgpr_spill_count: 0
    .symbol:         _Z10mandelbrotPhddddidd.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     14
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
