#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <getopt.h>
#include <string.h>
#include <math.h>

#define MAX_MANDELBROT_ITERATIONS (80)
#define DEFAULT_OUTPUT "mandelbrot.bmp"
#define THREADS_PER_BLOCK (1024/2)

unsigned int imageWidth = 1920;
unsigned int imageHeight = 1080;
unsigned int rowPadding;

const struct option options[] = {
        {"help", 0, NULL, 1},
        {"xleft", 1, NULL, 2},
        {"xright", 1, NULL, 3},
        {"ylower", 1, NULL, 4},
        {"yupper", 1, NULL, 5},
        {"width", 1, NULL, 6},
        {"height", 1, NULL, 7},
        {"output", 1, NULL, 8},
        {0, 0, 0, 0}
};
    
const char helpMessage[] = "Usage: %s [args]\n\
Mandelbrot-BMP generates a BMP image of a specified location in the Mandelbrot set.\n\n\
Possible arguments:\n\
    --help\n\
    --xleft [value]    Set the leftmost x value to render    (double)\n\
    --xright [value]   Set the rightmost x value to render   (double)\n\
    --ylower [value]   Set the lowest y value to render      (double)\n\
    --yupper [value]   Set the highest y value to render     (double)\n\
    --width [value]    Set the width of the output image     (int)\n\
    --height [value]   Set the height of the output image    (int)\n\
    --output [value]   Set the location of the output image  (string)\n\n\
If only 3 boundary values are specified, the other can be inferred from the image aspect ratio.\n";

struct __attribute__((__packed__)) BITMAPFILEHEADER {
  uint16_t bfType;
  uint32_t bfSize;
  uint16_t bfReserved1;
  uint16_t bfReserved2;
  uint32_t bfOffBits;
};

struct __attribute__((__packed__)) BITMAPINFOHEADER {
  uint32_t biSize;
  uint32_t biWidth;
  uint32_t biHeight;
  uint16_t biPlanes;
  uint16_t biBitCount;
  uint32_t biCompression;
  uint32_t biSizeImage;
  uint32_t biXPelsPerMeter;
  uint32_t biYPelsPerMeter;
  uint32_t biClrUsed;
  uint32_t biClrImportant;
};

__device__ int inMandelbrotSet(double x, double y)
{
    double real = x;
    double imaginary = y;

    for (int i = 0; i < MAX_MANDELBROT_ITERATIONS; i++) {
        double real2 = real * real;
        double imaginary2 = imaginary * imaginary;
        imaginary = real * imaginary * 2 + y;
        real = real2 - imaginary2 + x;
        if (real2 + imaginary2 > 4)
            return i;
    }
    return MAX_MANDELBROT_ITERATIONS;
}

__global__ void renderPixel(unsigned char* bufStart, int width, int height, double xStart, double xRange, double yStart, double yRange, int padding, int iters)
{
    for(int i = (blockIdx.x * blockDim.x + threadIdx.x) * iters; i < (blockIdx.x * blockDim.x + threadIdx.x) * iters + iters; i++) {
        if(i >= (width * height))
            return;
        unsigned int x = i % width;
        unsigned int y = i / width;
        
        unsigned char gradientR = (unsigned char)((float)x / ((float)(width - 1) / 127.5) + (float)y / ((float)(height - 1) / 127.5));
        unsigned char gradientG = (unsigned char)((float)(width - x - 1) / ((float)(width - 1) / 127.5) + (float)(height - y - 1) / ((float)(height - 1) / 127.5));
        unsigned char gradientB = (unsigned char)((float)x / ((float)(width - 1) / 127.5) + (float)(height - y - 1) / ((float)(height - 1) / 127.5));

        unsigned int mandel = inMandelbrotSet(((double)x / (double)width) * xRange + xStart,
           ((double)y / (double)height) * yRange + yStart);

        unsigned int baseIndex = y * padding + y * width * 3 + x * 3;
        if (mandel > 4) {
            float factor = (float)(MAX_MANDELBROT_ITERATIONS - (mandel - 5)) / MAX_MANDELBROT_ITERATIONS;
            bufStart[baseIndex] = factor * gradientB;
            bufStart[baseIndex + 1] = factor * gradientG;
            bufStart[baseIndex + 2] = factor * gradientR;
        } else {
            bufStart[baseIndex] = gradientB;
            bufStart[baseIndex + 1] = gradientG;
            bufStart[baseIndex + 2] = gradientR;
        }
    }
}

void setDefaultCorners(double corners[])
{
    printf("Warning: Falling back to default Mandelbrot corners.\n");
    corners[0] = -2.4;
    corners[1] = 1.4;
    corners[2] = -0.5 * (corners[1] - corners[0]) * ((double)imageHeight / (double)imageWidth);
    corners[3] = -1 * corners[2];
}

/*
* corners should be left x, right x, lower y, upper y
* returns 1 if the program should proceed
* REMEMBER TO FREE *fileName!
*/
int getArgs(int argc, char** argv, double corners[4], char** fileName)
{
    for(int i = 0; i < 4; i++)
        corners[i] = NAN;
    *fileName = NULL;
    
    int res;
    int tmpImageHeight;
    int tmpImageWidth;
    while((res = getopt_long_only(argc, argv, "", options, NULL)) != -1) {
        switch(res) {
            case '?':
                printf("Run '%s --help' for more information\n", argv[0]);
                break;
            case 1:
                printf(helpMessage, argv[0]);
                return 0;
                break;
            case 2:
                corners[0] = strtod(optarg, NULL);
                break;
            case 3:
                corners[1] = strtod(optarg, NULL);
                break;
            case 4:
                corners[2] = strtod(optarg, NULL);
                break;
            case 5:
                corners[3] = strtod(optarg, NULL);
                break;
            case 6:
                tmpImageWidth = atoi(optarg);
                if(tmpImageWidth > 0 && tmpImageWidth < 20000)
                    imageWidth = tmpImageWidth;
                else
                    printf("Warning: Image width is not between 0 and 20000 pixels! Falling back to default.\n");
                break;
            case 7:
                tmpImageHeight = atoi(optarg);
                if(tmpImageHeight > 0 && tmpImageHeight < 20000)
                    imageHeight = tmpImageHeight;
                else
                    printf("Warning: Image height is not between 0 and 20000 pixels! Falling back to default.\n");
                break;
            case 8:
                if(*fileName != NULL)
                    free(*fileName);
                *fileName = strdup(optarg);
                break;
        }
    }
    
    if(!isnan(corners[0]) && !isnan(corners[1]) && (isnan(corners[2]) != isnan(corners[3]))) {
         double otherRange = (corners[1] - corners[0]) * ((double)imageHeight / (double)imageWidth);
         if(!isnan(corners[2]))
            corners[3] = corners[2] + otherRange;
         else if(!isnan(corners[3]))
            corners[2] = corners[3] - otherRange;
    } else if(!isnan(corners[2]) && !isnan(corners[3]) && (isnan(corners[0]) != isnan(corners[1]))) {
        double otherRange = (corners[3] - corners[2]) * ((double)imageWidth / (double)imageHeight);
         if(!isnan(corners[0]))
            corners[1] = corners[0] + otherRange;
         else if(!isnan(corners[1]))
            corners[0] = corners[1] - otherRange;
    } else if(!(!isnan(corners[0]) && !isnan(corners[1]) && !isnan(corners[2]) && !isnan(corners[3]))) {
        setDefaultCorners(corners);
    }
    
    if(*fileName == NULL)
        *fileName = strdup(DEFAULT_OUTPUT);
    
    return 1;
}

void gpuAssert(cudaError_t retVal)
{
    if(retVal != cudaSuccess) {
        printf("CUDA assertion failed: %s\n", cudaGetErrorString(retVal));
        exit(EXIT_FAILURE);
    }
}

int main(int argc, char** argv)
{
    char* fileName;
    double corners[4];
    if(!getArgs(argc, argv, corners, &fileName))
        return 0;
    rowPadding = (4 - (imageWidth % 4)) % 4;
    
    unsigned int dataSize = imageWidth * 3 * imageHeight + rowPadding * imageHeight;
    struct BITMAPFILEHEADER bmpHeader = {0x4D42, 54 + dataSize, 0, 0, 54}; /* data obtained from MSDN and Wikipedia */
    struct BITMAPINFOHEADER bmpInfo = { sizeof(struct BITMAPINFOHEADER), imageWidth, imageHeight, 1, 24, 0, dataSize, 2835, 2835, 0, 0 };

    FILE* bmpOut = fopen(fileName, "wb");
    if(bmpOut == NULL) {
        perror("Error opening file");
        return -1;
    }

    fwrite(&bmpHeader, 1, sizeof(struct BITMAPFILEHEADER), bmpOut);
    fwrite(&bmpInfo, 1, sizeof(struct BITMAPINFOHEADER), bmpOut);

    unsigned char* gpuImg;
    gpuAssert(cudaMalloc(&gpuImg, dataSize));
    renderPixel<<<(imageWidth * imageHeight) / THREADS_PER_BLOCK + 1, THREADS_PER_BLOCK>>>(gpuImg, imageWidth, imageHeight, corners[0], corners[1] - corners[0], corners[2], corners[3] - corners[2], rowPadding, 2);

    unsigned char* img = (unsigned char*) malloc(dataSize);
    gpuAssert(cudaMemcpy(img, gpuImg, dataSize, cudaMemcpyDeviceToHost));
    fwrite(img, 1, dataSize, bmpOut);
    gpuAssert(cudaFree(gpuImg));
    free(img);
    free(fileName);
    fclose(bmpOut);
    return EXIT_SUCCESS;
}

	.file	"tmpxft_003393f0_00000000-6_mandel.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z15inMandelbrotSetdd
	.type	_Z15inMandelbrotSetdd, @function
_Z15inMandelbrotSetdd:
.LFB2027:
	.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
.LFE2027:
	.size	_Z15inMandelbrotSetdd, .-_Z15inMandelbrotSetdd
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Warning: Falling back to default Mandelbrot corners.\n"
	.text
	.globl	_Z17setDefaultCornersPd
	.type	_Z17setDefaultCornersPd, @function
_Z17setDefaultCornersPd:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	.LC0(%rip), %rsi
	movq	%rdi, %rbx
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	.LC1(%rip), %rax
	movq	%rax, (%rbx)
	movq	.LC2(%rip), %rax
	movq	%rax, 8(%rbx)
	movl	imageHeight(%rip), %eax
	cvtsi2sdq	%rax, %xmm0
	movl	imageWidth(%rip), %eax
	cvtsi2sdq	%rax, %xmm1
	divsd	%xmm1, %xmm0
	mulsd	.LC3(%rip), %xmm0
	movsd	%xmm0, 16(%rbx)
	xorps	.LC4(%rip), %xmm0
	movsd	%xmm0, 24(%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z17setDefaultCornersPd, .-_Z17setDefaultCornersPd
	.section	.rodata.str1.1
.LC6:
	.string	"Run '%s --help' for more information\n"
.LC7:
	.string	"Warning: Image width is not between 0 and 20000 pixels! Falling back to default.\n"
.LC8:
	.string	"Warning: Image height is not between 0 and 20000 pixels! Falling back to default.\n"
.LC9:
	.string	""
.LC10:
	.string	"mandelbrot.bmp"
	.text
	.globl	_Z7getArgsiPPcPdS0_
	.type	_Z7getArgsiPPcPdS0_, @function
_Z7getArgsiPPcPdS0_:
.LFB2029:
	.cfi_startproc
	endbr64
	movsd	.LC5(%rip), %xmm0
	xorl	%eax, %eax
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	_ZL7options(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movl	%edi, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rcx, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movq	%rdx, %rbx
	movsd	%xmm0, (%rdx)
	movsd	%xmm0, 8(%rdx)
	movsd	%xmm0, 16(%rdx)
	movsd	%xmm0, 24(%rdx)
	movq	%rax, (%rcx)
.L51:
	xorl	%r8d, %r8d
	movq	%r14, %rcx
	leaq	.LC9(%rip), %rdx
	movq	%r12, %rsi
	movl	%r13d, %edi
	call	getopt_long_only@PLT
	cmpl	$-1, %eax
	je	.L58
	cmpl	$8, %eax
	jg	.L12
	testl	%eax, %eax
	jle	.L51
	subl	$2, %eax
	cmpl	$6, %eax
	ja	.L14
	leaq	.L16(%rip), %rdx
	movslq	(%rdx,%rax,4), %rax
	addq	%rdx, %rax
	notrack jmp	*%rax
	.section	.rodata
	.align 4
	.align 4
.L16:
	.long	.L22-.L16
	.long	.L21-.L16
	.long	.L20-.L16
	.long	.L19-.L16
	.long	.L18-.L16
	.long	.L17-.L16
	.long	.L15-.L16
	.text
.L12:
	cmpl	$63, %eax
	jne	.L51
	movq	(%r12), %rdx
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L51
.L14:
	movq	(%r12), %rdx
	leaq	_ZL11helpMessage(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	jmp	.L10
.L22:
	movq	optarg(%rip), %rdi
	xorl	%esi, %esi
	call	strtod@PLT
	movsd	%xmm0, (%rbx)
	jmp	.L51
.L21:
	movq	optarg(%rip), %rdi
	xorl	%esi, %esi
	call	strtod@PLT
	movsd	%xmm0, 8(%rbx)
	jmp	.L51
.L20:
	movq	optarg(%rip), %rdi
	xorl	%esi, %esi
	call	strtod@PLT
	movsd	%xmm0, 16(%rbx)
	jmp	.L51
.L19:
	movq	optarg(%rip), %rdi
	xorl	%esi, %esi
	call	strtod@PLT
	movsd	%xmm0, 24(%rbx)
	jmp	.L51
.L18:
	movq	optarg(%rip), %rdi
	call	atoi@PLT
	leal	-1(%rax), %edx
	cmpl	$19998, %edx
	ja	.L25
	movl	%eax, imageWidth(%rip)
	jmp	.L51
.L25:
	leaq	.LC7(%rip), %rsi
	jmp	.L56
.L17:
	movq	optarg(%rip), %rdi
	call	atoi@PLT
	leal	-1(%rax), %edx
	cmpl	$19998, %edx
	ja	.L26
	movl	%eax, imageHeight(%rip)
	jmp	.L51
.L26:
	leaq	.LC8(%rip), %rsi
.L56:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L51
.L15:
	movq	0(%rbp), %rdi
	testq	%rdi, %rdi
	je	.L27
	call	free@PLT
.L27:
	movq	optarg(%rip), %rdi
	call	strdup@PLT
	movq	%rax, 0(%rbp)
	jmp	.L51
.L58:
	movsd	(%rbx), %xmm0
	movsd	16(%rbx), %xmm1
	ucomisd	%xmm0, %xmm0
	jp	.L29
	movsd	8(%rbx), %xmm4
	ucomisd	%xmm4, %xmm4
	jp	.L29
	ucomisd	%xmm1, %xmm1
	movsd	24(%rbx), %xmm3
	setp	%dl
	ucomisd	%xmm3, %xmm3
	setp	%al
	cmpb	%al, %dl
	je	.L29
	movl	imageHeight(%rip), %eax
	subsd	%xmm0, %xmm4
	ucomisd	%xmm1, %xmm1
	cvtsi2sdq	%rax, %xmm2
	movl	imageWidth(%rip), %eax
	cvtsi2sdq	%rax, %xmm5
	divsd	%xmm5, %xmm2
	mulsd	%xmm4, %xmm2
	movaps	%xmm2, %xmm0
	jp	.L59
	addsd	%xmm1, %xmm0
	movsd	%xmm0, 24(%rbx)
	jmp	.L38
.L29:
	ucomisd	%xmm1, %xmm1
	jnp	.L36
	jmp	.L37
.L59:
	ucomisd	%xmm3, %xmm3
	jp	.L38
	subsd	%xmm2, %xmm3
	movsd	%xmm3, 16(%rbx)
	jmp	.L38
.L36:
	movsd	24(%rbx), %xmm2
	ucomisd	%xmm2, %xmm2
	jp	.L39
	ucomisd	%xmm0, %xmm0
	movsd	8(%rbx), %xmm3
	setp	%dl
	ucomisd	%xmm3, %xmm3
	setp	%al
	cmpb	%al, %dl
	jne	.L40
.L39:
	ucomisd	%xmm0, %xmm0
	jnp	.L54
	jmp	.L37
.L40:
	movl	imageWidth(%rip), %eax
	subsd	%xmm1, %xmm2
	ucomisd	%xmm0, %xmm0
	cvtsi2sdq	%rax, %xmm4
	movl	imageHeight(%rip), %eax
	cvtsi2sdq	%rax, %xmm5
	divsd	%xmm5, %xmm4
	mulsd	%xmm2, %xmm4
	jp	.L46
	addsd	%xmm4, %xmm0
	movsd	%xmm0, 8(%rbx)
	jmp	.L38
.L46:
	ucomisd	%xmm3, %xmm3
	jp	.L38
	subsd	%xmm4, %xmm3
	movsd	%xmm3, (%rbx)
	jmp	.L38
.L54:
	ucomisd	8(%rbx), %xmm1
	jp	.L37
	ucomisd	%xmm2, %xmm2
	jnp	.L38
.L37:
	movq	%rbx, %rdi
	call	_Z17setDefaultCornersPd
.L38:
	cmpq	$0, 0(%rbp)
	je	.L47
.L48:
	movl	$1, %eax
	jmp	.L10
.L47:
	leaq	.LC10(%rip), %rdi
	call	strdup@PLT
	movq	%rax, 0(%rbp)
	jmp	.L48
.L10:
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z7getArgsiPPcPdS0_, .-_Z7getArgsiPPcPdS0_
	.section	.rodata.str1.1
.LC11:
	.string	"CUDA assertion failed: %s\n"
	.text
	.globl	_Z9gpuAssert9cudaError
	.type	_Z9gpuAssert9cudaError, @function
_Z9gpuAssert9cudaError:
.LFB2030:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L60
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	cudaGetErrorString@PLT
	movl	$2, %edi
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L60:
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z9gpuAssert9cudaError, .-_Z9gpuAssert9cudaError
	.globl	_Z39__device_stub__Z11renderPixelPhiiddddiiPhiiddddii
	.type	_Z39__device_stub__Z11renderPixelPhiiddddiiPhiiddddii, @function
_Z39__device_stub__Z11renderPixelPhiiddddiiPhiiddddii:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$216, %rsp
	.cfi_def_cfa_offset 224
	movq	%rdi, 56(%rsp)
	leaq	80(%rsp), %rdi
	movl	%esi, 52(%rsp)
	leaq	92(%rsp), %rsi
	movl	%edx, 48(%rsp)
	leaq	64(%rsp), %rdx
	movl	%ecx, 12(%rsp)
	leaq	72(%rsp), %rcx
	movl	%r8d, 8(%rsp)
	movsd	%xmm0, 40(%rsp)
	movsd	%xmm1, 32(%rsp)
	movsd	%xmm2, 24(%rsp)
	movsd	%xmm3, 16(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 200(%rsp)
	xorl	%eax, %eax
	leaq	56(%rsp), %rax
	movl	$1, 88(%rsp)
	movq	%rax, 128(%rsp)
	leaq	52(%rsp), %rax
	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	16(%rsp), %rax
	movq	%rax, 176(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 184(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 192(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 80(%rsp)
	movq	%rax, 92(%rsp)
	movl	$1, 100(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L65
	pushq	72(%rsp)
	.cfi_def_cfa_offset 232
	leaq	_Z11renderPixelPhiiddddii(%rip), %rdi
	pushq	72(%rsp)
	.cfi_def_cfa_offset 240
	movq	108(%rsp), %rcx
	movl	116(%rsp), %r8d
	movq	96(%rsp), %rsi
	movl	104(%rsp), %edx
	leaq	144(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 232
	popq	%rdx
	.cfi_def_cfa_offset 224
.L65:
	movq	200(%rsp), %rax
	subq	%fs:40, %rax
	je	.L67
	call	__stack_chk_fail@PLT
.L67:
	addq	$216, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z39__device_stub__Z11renderPixelPhiiddddiiPhiiddddii, .-_Z39__device_stub__Z11renderPixelPhiiddddiiPhiiddddii
	.globl	_Z11renderPixelPhiiddddii
	.type	_Z11renderPixelPhiiddddii, @function
_Z11renderPixelPhiiddddii:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z11renderPixelPhiiddddiiPhiiddddii
	.cfi_endproc
.LFE2057:
	.size	_Z11renderPixelPhiiddddii, .-_Z11renderPixelPhiiddddii
	.section	.rodata.str1.1
.LC12:
	.string	"wb"
.LC13:
	.string	"Error opening file"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2031:
	.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	$152, %rsp
	.cfi_def_cfa_offset 192
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rcx
	leaq	104(%rsp), %rdx
	call	_Z7getArgsiPPcPdS0_
	testl	%eax, %eax
	je	.L71
	movl	imageWidth(%rip), %edx
	movl	imageHeight(%rip), %ecx
	leaq	.LC12(%rip), %rsi
	movw	$19778, 50(%rsp)
	movq	8(%rsp), %r12
	movl	$40, 64(%rsp)
	movl	%edx, %eax
	leal	(%rdx,%rdx,2), %ebx
	movq	$1572865, 76(%rsp)
	negl	%eax
	movq	%r12, %rdi
	movl	%edx, 68(%rsp)
	andl	$3, %eax
	movl	%ecx, 72(%rsp)
	addl	%eax, %ebx
	movl	%eax, rowPadding(%rip)
	movl	$27, %eax
	movq	$2835, 92(%rsp)
	imull	%ecx, %ebx
	salq	$33, %rax
	movq	%rax, 56(%rsp)
	leal	54(%rbx), %eax
	movl	%eax, 52(%rsp)
	movl	$2835, %eax
	salq	$32, %rax
	movq	%rax, 84(%rsp)
	xorl	%eax, %eax
	movl	%eax, 100(%rsp)
	movl	%ebx, 84(%rsp)
	call	fopen@PLT
	movq	%rax, %rbp
	testq	%rax, %rax
	jne	.L72
	leaq	.LC13(%rip), %rdi
	call	perror@PLT
	orl	$-1, %eax
	jmp	.L70
.L72:
	leaq	50(%rsp), %rdi
	movq	%rax, %rcx
	movl	$14, %edx
	movl	$1, %esi
	call	fwrite@PLT
	movq	%rbp, %rcx
	movl	$40, %edx
	leaq	64(%rsp), %rdi
	movl	$1, %esi
	call	fwrite@PLT
	movq	%rbx, %rsi
	leaq	16(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaError
	movl	$8388609, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	imageWidth(%rip), %eax
	salq	$9, %rdx
	movl	$1, %ecx
	imull	imageHeight(%rip), %eax
	shrl	$9, %eax
	incl	%eax
	movl	%eax, 24(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 28(%rsp)
	movq	24(%rsp), %rdi
	movl	32(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L74
	movsd	120(%rsp), %xmm2
	movsd	104(%rsp), %xmm0
	movl	$2, %r8d
	movsd	128(%rsp), %xmm3
	movsd	112(%rsp), %xmm1
	movl	rowPadding(%rip), %ecx
	movl	imageHeight(%rip), %edx
	subsd	%xmm2, %xmm3
	subsd	%xmm0, %xmm1
	movl	imageWidth(%rip), %esi
	movq	16(%rsp), %rdi
	call	_Z39__device_stub__Z11renderPixelPhiiddddiiPhiiddddii
.L74:
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdx
	movq	%rax, %rdi
	movq	%rax, %r13
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaError
	movq	%rbp, %rcx
	movq	%rbx, %rdx
	movl	$1, %esi
	movq	%r13, %rdi
	call	fwrite@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movl	%eax, %edi
	call	_Z9gpuAssert9cudaError
	movq	%r13, %rdi
	call	free@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	fclose@PLT
.L71:
	xorl	%eax, %eax
.L70:
	movq	136(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L75
	call	__stack_chk_fail@PLT
.L75:
	addq	$152, %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
.LFE2031:
	.size	main, .-main
	.section	.rodata.str1.1
.LC14:
	.string	"_Z11renderPixelPhiiddddii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2059:
	.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	.LC14(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z11renderPixelPhiiddddii(%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
.LFE2059:
	.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
	.align 32
	.type	_ZL11helpMessage, @object
	.size	_ZL11helpMessage, 715
_ZL11helpMessage:
	.ascii	"Usage: %s [args]\nMandelbrot-BMP generates a BMP image of a "
	.ascii	"specified location in the Mandelbrot set.\n\nPossible argume"
	.ascii	"nts:\n    --help\n    --xleft [value]    Set the leftmost x "
	.ascii	"value to render    (double)\n    --xright [value]   Set the "
	.ascii	"rightmost x value to render   (double)\n    --ylower [value]"
	.ascii	"   Set the lowest y value to render      (double)\n    --yup"
	.ascii	"per [value]   Set the highest y value to render     (double)"
	.ascii	"\n    --width [value]    Set the width of the o"
	.string	"utput image     (int)\n    --height [value]   Set the height of the output image    (int)\n    --output [value]   Set the location of the output image  (string)\n\nIf only 3 boundary values are specified, the other can be inferred from the image aspect ratio.\n"
	.section	.rodata.str1.1
.LC15:
	.string	"help"
.LC16:
	.string	"xleft"
.LC17:
	.string	"xright"
.LC18:
	.string	"ylower"
.LC19:
	.string	"yupper"
.LC20:
	.string	"width"
.LC21:
	.string	"height"
.LC22:
	.string	"output"
	.section	.data.rel.ro.local,"aw"
	.align 32
	.type	_ZL7options, @object
	.size	_ZL7options, 288
_ZL7options:
	.quad	.LC15
	.long	0
	.zero	4
	.quad	0
	.long	1
	.zero	4
	.quad	.LC16
	.long	1
	.zero	4
	.quad	0
	.long	2
	.zero	4
	.quad	.LC17
	.long	1
	.zero	4
	.quad	0
	.long	3
	.zero	4
	.quad	.LC18
	.long	1
	.zero	4
	.quad	0
	.long	4
	.zero	4
	.quad	.LC19
	.long	1
	.zero	4
	.quad	0
	.long	5
	.zero	4
	.quad	.LC20
	.long	1
	.zero	4
	.quad	0
	.long	6
	.zero	4
	.quad	.LC21
	.long	1
	.zero	4
	.quad	0
	.long	7
	.zero	4
	.quad	.LC22
	.long	1
	.zero	4
	.quad	0
	.long	8
	.zero	4
	.quad	0
	.long	0
	.zero	4
	.quad	0
	.long	0
	.zero	4
	.globl	rowPadding
	.bss
	.align 4
	.type	rowPadding, @object
	.size	rowPadding, 4
rowPadding:
	.zero	4
	.globl	imageHeight
	.data
	.align 4
	.type	imageHeight, @object
	.size	imageHeight, 4
imageHeight:
	.long	1080
	.globl	imageWidth
	.align 4
	.type	imageWidth, @object
	.size	imageWidth, 4
imageWidth:
	.long	1920
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC1:
	.long	858993459
	.long	-1073532109
	.align 8
.LC2:
	.long	1717986918
	.long	1073112678
	.align 8
.LC3:
	.long	1717986918
	.long	-1073846682
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC4:
	.long	0
	.long	-2147483648
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC5:
	.long	0
	.long	2146959360
	.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 <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <getopt.h>
#include <string.h>
#include <math.h>

#define MAX_MANDELBROT_ITERATIONS (80)
#define DEFAULT_OUTPUT "mandelbrot.bmp"
#define THREADS_PER_BLOCK (1024/2)

unsigned int imageWidth = 1920;
unsigned int imageHeight = 1080;
unsigned int rowPadding;

const struct option options[] = {
        {"help", 0, NULL, 1},
        {"xleft", 1, NULL, 2},
        {"xright", 1, NULL, 3},
        {"ylower", 1, NULL, 4},
        {"yupper", 1, NULL, 5},
        {"width", 1, NULL, 6},
        {"height", 1, NULL, 7},
        {"output", 1, NULL, 8},
        {0, 0, 0, 0}
};
    
const char helpMessage[] = "Usage: %s [args]\n\
Mandelbrot-BMP generates a BMP image of a specified location in the Mandelbrot set.\n\n\
Possible arguments:\n\
    --help\n\
    --xleft [value]    Set the leftmost x value to render    (double)\n\
    --xright [value]   Set the rightmost x value to render   (double)\n\
    --ylower [value]   Set the lowest y value to render      (double)\n\
    --yupper [value]   Set the highest y value to render     (double)\n\
    --width [value]    Set the width of the output image     (int)\n\
    --height [value]   Set the height of the output image    (int)\n\
    --output [value]   Set the location of the output image  (string)\n\n\
If only 3 boundary values are specified, the other can be inferred from the image aspect ratio.\n";

struct __attribute__((__packed__)) BITMAPFILEHEADER {
  uint16_t bfType;
  uint32_t bfSize;
  uint16_t bfReserved1;
  uint16_t bfReserved2;
  uint32_t bfOffBits;
};

struct __attribute__((__packed__)) BITMAPINFOHEADER {
  uint32_t biSize;
  uint32_t biWidth;
  uint32_t biHeight;
  uint16_t biPlanes;
  uint16_t biBitCount;
  uint32_t biCompression;
  uint32_t biSizeImage;
  uint32_t biXPelsPerMeter;
  uint32_t biYPelsPerMeter;
  uint32_t biClrUsed;
  uint32_t biClrImportant;
};

__device__ int inMandelbrotSet(double x, double y)
{
    double real = x;
    double imaginary = y;

    for (int i = 0; i < MAX_MANDELBROT_ITERATIONS; i++) {
        double real2 = real * real;
        double imaginary2 = imaginary * imaginary;
        imaginary = real * imaginary * 2 + y;
        real = real2 - imaginary2 + x;
        if (real2 + imaginary2 > 4)
            return i;
    }
    return MAX_MANDELBROT_ITERATIONS;
}

__global__ void renderPixel(unsigned char* bufStart, int width, int height, double xStart, double xRange, double yStart, double yRange, int padding, int iters)
{
    for(int i = (blockIdx.x * blockDim.x + threadIdx.x) * iters; i < (blockIdx.x * blockDim.x + threadIdx.x) * iters + iters; i++) {
        if(i >= (width * height))
            return;
        unsigned int x = i % width;
        unsigned int y = i / width;
        
        unsigned char gradientR = (unsigned char)((float)x / ((float)(width - 1) / 127.5) + (float)y / ((float)(height - 1) / 127.5));
        unsigned char gradientG = (unsigned char)((float)(width - x - 1) / ((float)(width - 1) / 127.5) + (float)(height - y - 1) / ((float)(height - 1) / 127.5));
        unsigned char gradientB = (unsigned char)((float)x / ((float)(width - 1) / 127.5) + (float)(height - y - 1) / ((float)(height - 1) / 127.5));

        unsigned int mandel = inMandelbrotSet(((double)x / (double)width) * xRange + xStart,
           ((double)y / (double)height) * yRange + yStart);

        unsigned int baseIndex = y * padding + y * width * 3 + x * 3;
        if (mandel > 4) {
            float factor = (float)(MAX_MANDELBROT_ITERATIONS - (mandel - 5)) / MAX_MANDELBROT_ITERATIONS;
            bufStart[baseIndex] = factor * gradientB;
            bufStart[baseIndex + 1] = factor * gradientG;
            bufStart[baseIndex + 2] = factor * gradientR;
        } else {
            bufStart[baseIndex] = gradientB;
            bufStart[baseIndex + 1] = gradientG;
            bufStart[baseIndex + 2] = gradientR;
        }
    }
}

void setDefaultCorners(double corners[])
{
    printf("Warning: Falling back to default Mandelbrot corners.\n");
    corners[0] = -2.4;
    corners[1] = 1.4;
    corners[2] = -0.5 * (corners[1] - corners[0]) * ((double)imageHeight / (double)imageWidth);
    corners[3] = -1 * corners[2];
}

/*
* corners should be left x, right x, lower y, upper y
* returns 1 if the program should proceed
* REMEMBER TO FREE *fileName!
*/
int getArgs(int argc, char** argv, double corners[4], char** fileName)
{
    for(int i = 0; i < 4; i++)
        corners[i] = NAN;
    *fileName = NULL;
    
    int res;
    int tmpImageHeight;
    int tmpImageWidth;
    while((res = getopt_long_only(argc, argv, "", options, NULL)) != -1) {
        switch(res) {
            case '?':
                printf("Run '%s --help' for more information\n", argv[0]);
                break;
            case 1:
                printf(helpMessage, argv[0]);
                return 0;
                break;
            case 2:
                corners[0] = strtod(optarg, NULL);
                break;
            case 3:
                corners[1] = strtod(optarg, NULL);
                break;
            case 4:
                corners[2] = strtod(optarg, NULL);
                break;
            case 5:
                corners[3] = strtod(optarg, NULL);
                break;
            case 6:
                tmpImageWidth = atoi(optarg);
                if(tmpImageWidth > 0 && tmpImageWidth < 20000)
                    imageWidth = tmpImageWidth;
                else
                    printf("Warning: Image width is not between 0 and 20000 pixels! Falling back to default.\n");
                break;
            case 7:
                tmpImageHeight = atoi(optarg);
                if(tmpImageHeight > 0 && tmpImageHeight < 20000)
                    imageHeight = tmpImageHeight;
                else
                    printf("Warning: Image height is not between 0 and 20000 pixels! Falling back to default.\n");
                break;
            case 8:
                if(*fileName != NULL)
                    free(*fileName);
                *fileName = strdup(optarg);
                break;
        }
    }
    
    if(!isnan(corners[0]) && !isnan(corners[1]) && (isnan(corners[2]) != isnan(corners[3]))) {
         double otherRange = (corners[1] - corners[0]) * ((double)imageHeight / (double)imageWidth);
         if(!isnan(corners[2]))
            corners[3] = corners[2] + otherRange;
         else if(!isnan(corners[3]))
            corners[2] = corners[3] - otherRange;
    } else if(!isnan(corners[2]) && !isnan(corners[3]) && (isnan(corners[0]) != isnan(corners[1]))) {
        double otherRange = (corners[3] - corners[2]) * ((double)imageWidth / (double)imageHeight);
         if(!isnan(corners[0]))
            corners[1] = corners[0] + otherRange;
         else if(!isnan(corners[1]))
            corners[0] = corners[1] - otherRange;
    } else if(!(!isnan(corners[0]) && !isnan(corners[1]) && !isnan(corners[2]) && !isnan(corners[3]))) {
        setDefaultCorners(corners);
    }
    
    if(*fileName == NULL)
        *fileName = strdup(DEFAULT_OUTPUT);
    
    return 1;
}

void gpuAssert(hipError_t retVal)
{
    if(retVal != hipSuccess) {
        printf("CUDA assertion failed: %s\n", hipGetErrorString(retVal));
        exit(EXIT_FAILURE);
    }
}

int main(int argc, char** argv)
{
    char* fileName;
    double corners[4];
    if(!getArgs(argc, argv, corners, &fileName))
        return 0;
    rowPadding = (4 - (imageWidth % 4)) % 4;
    
    unsigned int dataSize = imageWidth * 3 * imageHeight + rowPadding * imageHeight;
    struct BITMAPFILEHEADER bmpHeader = {0x4D42, 54 + dataSize, 0, 0, 54}; /* data obtained from MSDN and Wikipedia */
    struct BITMAPINFOHEADER bmpInfo = { sizeof(struct BITMAPINFOHEADER), imageWidth, imageHeight, 1, 24, 0, dataSize, 2835, 2835, 0, 0 };

    FILE* bmpOut = fopen(fileName, "wb");
    if(bmpOut == NULL) {
        perror("Error opening file");
        return -1;
    }

    fwrite(&bmpHeader, 1, sizeof(struct BITMAPFILEHEADER), bmpOut);
    fwrite(&bmpInfo, 1, sizeof(struct BITMAPINFOHEADER), bmpOut);

    unsigned char* gpuImg;
    gpuAssert(hipMalloc(&gpuImg, dataSize));
    renderPixel<<<(imageWidth * imageHeight) / THREADS_PER_BLOCK + 1, THREADS_PER_BLOCK>>>(gpuImg, imageWidth, imageHeight, corners[0], corners[1] - corners[0], corners[2], corners[3] - corners[2], rowPadding, 2);

    unsigned char* img = (unsigned char*) malloc(dataSize);
    gpuAssert(hipMemcpy(img, gpuImg, dataSize, hipMemcpyDeviceToHost));
    fwrite(img, 1, dataSize, bmpOut);
    gpuAssert(hipFree(gpuImg));
    free(img);
    free(fileName);
    fclose(bmpOut);
    return EXIT_SUCCESS;
}

	.text
	.file	"mandel.hip"
	.globl	_Z26__device_stub__renderPixelPhiiddddii # -- Begin function _Z26__device_stub__renderPixelPhiiddddii
	.type	_Z26__device_stub__renderPixelPhiiddddii,@function
_Z26__device_stub__renderPixelPhiiddddii: # @_Z26__device_stub__renderPixelPhiiddddii
	.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	$192, %rsp
	.cfi_def_cfa_offset 240
	.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	20(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	16(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	64(%rsp), %rdx
	movsd	%xmm0, (%rdx)
	leaq	56(%rsp), %r9
	movsd	%xmm1, (%r9)
	leaq	48(%rsp), %r10
	movsd	%xmm2, (%r10)
	leaq	40(%rsp), %r11
	movsd	%xmm3, (%r11)
	leaq	12(%rsp), %r14
	movl	%ecx, (%r14)
	leaq	8(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	112(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%r9, 32(%rbx)
	movq	%r10, 40(%rbx)
	movq	%r11, 48(%rbx)
	movq	%r14, 56(%rbx)
	movq	%rcx, 64(%rbx)
	leaq	96(%rsp), %r14
	leaq	80(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%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	$_Z11renderPixelPhiiddddii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$208, %rsp
	.cfi_adjust_cfa_offset -208
	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	_Z26__device_stub__renderPixelPhiiddddii, .Lfunc_end0-_Z26__device_stub__renderPixelPhiiddddii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z17setDefaultCornersPd
.LCPI1_0:
	.quad	0xbffe666666666666              # double -1.8999999999999999
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI1_1:
	.quad	0x8000000000000000              # double -0
	.quad	0x8000000000000000              # double -0
	.text
	.globl	_Z17setDefaultCornersPd
	.type	_Z17setDefaultCornersPd,@function
_Z17setDefaultCornersPd:                # @_Z17setDefaultCornersPd
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movl	$.Lstr, %edi
	callq	puts@PLT
	movabsq	$-4610785298501913805, %rax     # imm = 0xC003333333333333
	movq	%rax, (%rbx)
	movabsq	$4608983858650965606, %rax      # imm = 0x3FF6666666666666
	movq	%rax, 8(%rbx)
	movl	imageHeight(%rip), %eax
	cvtsi2sd	%rax, %xmm0
	movl	imageWidth(%rip), %eax
	cvtsi2sd	%rax, %xmm1
	divsd	%xmm1, %xmm0
	mulsd	.LCPI1_0(%rip), %xmm0
	movsd	%xmm0, 16(%rbx)
	xorpd	.LCPI1_1(%rip), %xmm0
	movlpd	%xmm0, 24(%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z17setDefaultCornersPd, .Lfunc_end1-_Z17setDefaultCornersPd
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z7getArgsiPPcPdS0_
.LCPI2_0:
	.quad	0xbffe666666666666              # double -1.8999999999999999
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI2_1:
	.quad	0x8000000000000000              # double -0
	.quad	0x8000000000000000              # double -0
	.text
	.globl	_Z7getArgsiPPcPdS0_
	.type	_Z7getArgsiPPcPdS0_,@function
_Z7getArgsiPPcPdS0_:                    # @_Z7getArgsiPPcPdS0_
	.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	%rcx, %rbx
	movq	%rdx, %r14
	movq	%rsi, %r15
	movl	%edi, %ebp
	xorl	%eax, %eax
	movabsq	$9221120237041090560, %rcx      # imm = 0x7FF8000000000000
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
	movq	%rcx, (%r14,%rax,8)
	incq	%rax
	cmpq	$4, %rax
	jne	.LBB2_1
# %bb.2:
	movq	$0, (%rbx)
.LBB2_3:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str.1, %edx
	movl	$_ZL7options, %ecx
	movl	%ebp, %edi
	movq	%r15, %rsi
	xorl	%r8d, %r8d
	callq	getopt_long_only
                                        # kill: def $eax killed $eax def $rax
	leal	1(%rax), %ecx
	cmpl	$9, %ecx
	ja	.LBB2_4
# %bb.42:                               #   in Loop: Header=BB2_3 Depth=1
	jmpq	*.LJTI2_0(,%rcx,8)
.LBB2_7:                                #   in Loop: Header=BB2_3 Depth=1
	movq	optarg(%rip), %rdi
	xorl	%esi, %esi
	callq	strtod
	movsd	%xmm0, (%r14)
	jmp	.LBB2_3
.LBB2_4:                                #   in Loop: Header=BB2_3 Depth=1
	cmpl	$63, %eax
	jne	.LBB2_3
# %bb.5:                                #   in Loop: Header=BB2_3 Depth=1
	movq	(%r15), %rsi
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB2_3
.LBB2_17:                               #   in Loop: Header=BB2_3 Depth=1
	movq	(%rbx), %rdi
	testq	%rdi, %rdi
	je	.LBB2_19
# %bb.18:                               #   in Loop: Header=BB2_3 Depth=1
	callq	free
.LBB2_19:                               #   in Loop: Header=BB2_3 Depth=1
	movq	optarg(%rip), %rdi
	callq	strdup
	movq	%rax, (%rbx)
	jmp	.LBB2_3
.LBB2_11:                               #   in Loop: Header=BB2_3 Depth=1
	movq	optarg(%rip), %rdi
	callq	atoi
                                        # kill: def $eax killed $eax def $rax
	leal	-1(%rax), %ecx
	cmpl	$19998, %ecx                    # imm = 0x4E1E
	ja	.LBB2_13
# %bb.12:                               #   in Loop: Header=BB2_3 Depth=1
	movl	%eax, imageWidth(%rip)
	jmp	.LBB2_3
.LBB2_9:                                #   in Loop: Header=BB2_3 Depth=1
	movq	optarg(%rip), %rdi
	xorl	%esi, %esi
	callq	strtod
	movsd	%xmm0, 16(%r14)
	jmp	.LBB2_3
.LBB2_8:                                #   in Loop: Header=BB2_3 Depth=1
	movq	optarg(%rip), %rdi
	xorl	%esi, %esi
	callq	strtod
	movsd	%xmm0, 8(%r14)
	jmp	.LBB2_3
.LBB2_14:                               #   in Loop: Header=BB2_3 Depth=1
	movq	optarg(%rip), %rdi
	callq	atoi
                                        # kill: def $eax killed $eax def $rax
	leal	-1(%rax), %ecx
	cmpl	$19998, %ecx                    # imm = 0x4E1E
	ja	.LBB2_16
# %bb.15:                               #   in Loop: Header=BB2_3 Depth=1
	movl	%eax, imageHeight(%rip)
	jmp	.LBB2_3
.LBB2_10:                               #   in Loop: Header=BB2_3 Depth=1
	movq	optarg(%rip), %rdi
	xorl	%esi, %esi
	callq	strtod
	movsd	%xmm0, 24(%r14)
	jmp	.LBB2_3
.LBB2_13:                               #   in Loop: Header=BB2_3 Depth=1
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	jmp	.LBB2_3
.LBB2_16:                               #   in Loop: Header=BB2_3 Depth=1
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	jmp	.LBB2_3
.LBB2_20:
	movsd	(%r14), %xmm0                   # xmm0 = mem[0],zero
	ucomisd	%xmm0, %xmm0
	jp	.LBB2_21
# %bb.27:
	movsd	8(%r14), %xmm3                  # xmm3 = mem[0],zero
	movsd	16(%r14), %xmm1                 # xmm1 = mem[0],zero
	ucomisd	%xmm3, %xmm3
	jp	.LBB2_22
# %bb.28:
	ucomisd	%xmm1, %xmm1
	setp	%al
	movsd	24(%r14), %xmm2                 # xmm2 = mem[0],zero
	ucomisd	%xmm2, %xmm2
	setp	%cl
	cmpb	%cl, %al
	je	.LBB2_22
# %bb.29:
	ucomisd	%xmm1, %xmm1
	subsd	%xmm0, %xmm3
	movl	imageHeight(%rip), %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	movl	imageWidth(%rip), %eax
	cvtsi2sd	%rax, %xmm4
	divsd	%xmm4, %xmm0
	mulsd	%xmm3, %xmm0
	jp	.LBB2_31
# %bb.30:
	addsd	%xmm0, %xmm1
	movsd	%xmm1, 24(%r14)
	jmp	.LBB2_39
.LBB2_6:
	movq	(%r15), %rsi
	xorl	%ebp, %ebp
	movl	$_ZL11helpMessage, %edi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB2_41
.LBB2_21:                               # %._crit_edge
	movsd	16(%r14), %xmm1                 # xmm1 = mem[0],zero
.LBB2_22:
	ucomisd	%xmm1, %xmm1
	jp	.LBB2_35
# %bb.23:
	movsd	24(%r14), %xmm3                 # xmm3 = mem[0],zero
	ucomisd	%xmm3, %xmm3
	jp	.LBB2_35
# %bb.24:
	ucomisd	%xmm0, %xmm0
	setp	%al
	movsd	8(%r14), %xmm2                  # xmm2 = mem[0],zero
	ucomisd	%xmm2, %xmm2
	setp	%cl
	cmpb	%cl, %al
	je	.LBB2_35
# %bb.25:
	ucomisd	%xmm0, %xmm0
	subsd	%xmm1, %xmm3
	movl	imageWidth(%rip), %eax
	xorps	%xmm1, %xmm1
	cvtsi2sd	%rax, %xmm1
	movl	imageHeight(%rip), %eax
	cvtsi2sd	%rax, %xmm4
	divsd	%xmm4, %xmm1
	mulsd	%xmm3, %xmm1
	jp	.LBB2_33
# %bb.26:
	addsd	%xmm1, %xmm0
	movsd	%xmm0, 8(%r14)
	jmp	.LBB2_39
.LBB2_35:
	ucomisd	%xmm0, %xmm0
	jp	.LBB2_38
# %bb.36:
	ucomisd	8(%r14), %xmm1
	jp	.LBB2_38
# %bb.37:
	movsd	24(%r14), %xmm0                 # xmm0 = mem[0],zero
	ucomisd	%xmm0, %xmm0
	jp	.LBB2_38
.LBB2_39:
	movl	$1, %ebp
	cmpq	$0, (%rbx)
	jne	.LBB2_41
# %bb.40:
	movl	$.L.str.5, %edi
	callq	strdup
	movq	%rax, (%rbx)
.LBB2_41:
	movl	%ebp, %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
.LBB2_38:
	.cfi_def_cfa_offset 48
	movl	$.Lstr, %edi
	callq	puts@PLT
	movabsq	$-4610785298501913805, %rax     # imm = 0xC003333333333333
	movq	%rax, (%r14)
	movabsq	$4608983858650965606, %rax      # imm = 0x3FF6666666666666
	movq	%rax, 8(%r14)
	movl	imageHeight(%rip), %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	movl	imageWidth(%rip), %eax
	xorps	%xmm1, %xmm1
	cvtsi2sd	%rax, %xmm1
	divsd	%xmm1, %xmm0
	mulsd	.LCPI2_0(%rip), %xmm0
	movsd	%xmm0, 16(%r14)
	xorpd	.LCPI2_1(%rip), %xmm0
	movlpd	%xmm0, 24(%r14)
	jmp	.LBB2_39
.LBB2_31:
	ucomisd	%xmm2, %xmm2
	jp	.LBB2_39
# %bb.32:
	subsd	%xmm0, %xmm2
	movsd	%xmm2, 16(%r14)
	jmp	.LBB2_39
.LBB2_33:
	ucomisd	%xmm2, %xmm2
	jp	.LBB2_39
# %bb.34:
	subsd	%xmm1, %xmm2
	movsd	%xmm2, (%r14)
	jmp	.LBB2_39
.Lfunc_end2:
	.size	_Z7getArgsiPPcPdS0_, .Lfunc_end2-_Z7getArgsiPPcPdS0_
	.cfi_endproc
	.section	.rodata,"a",@progbits
	.p2align	3, 0x0
.LJTI2_0:
	.quad	.LBB2_20
	.quad	.LBB2_3
	.quad	.LBB2_6
	.quad	.LBB2_7
	.quad	.LBB2_8
	.quad	.LBB2_9
	.quad	.LBB2_10
	.quad	.LBB2_11
	.quad	.LBB2_14
	.quad	.LBB2_17
                                        # -- End function
	.text
	.globl	_Z9gpuAssert10hipError_t        # -- Begin function _Z9gpuAssert10hipError_t
	.type	_Z9gpuAssert10hipError_t,@function
_Z9gpuAssert10hipError_t:               # @_Z9gpuAssert10hipError_t
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jne	.LBB3_2
# %bb.1:
	retq
.LBB3_2:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	hipGetErrorString
	movl	$.L.str.6, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	_Z9gpuAssert10hipError_t, .Lfunc_end3-_Z9gpuAssert10hipError_t
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI4_0:
	.long	2835                            # 0xb13
	.long	2835                            # 0xb13
	.long	0                               # 0x0
	.long	0                               # 0x0
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	80(%rsp), %rdx
	leaq	32(%rsp), %rcx
	callq	_Z7getArgsiPPcPdS0_
	testl	%eax, %eax
	je	.LBB4_1
# %bb.2:
	movl	imageWidth(%rip), %eax
	leal	(%rax,%rax,2), %r15d
	movl	$40, 40(%rsp)
	movl	%eax, 44(%rsp)
                                        # kill: def $eax killed $eax killed $rax
	negl	%eax
	andl	$3, %eax
	movl	%eax, rowPadding(%rip)
	movl	imageHeight(%rip), %ecx
	addl	%eax, %r15d
	imull	%ecx, %r15d
	movw	$19778, 18(%rsp)                # imm = 0x4D42
	leal	54(%r15), %eax
	movl	%eax, 20(%rsp)
	movabsq	$231928233984, %rax             # imm = 0x3600000000
	movq	%rax, 24(%rsp)
	movl	%ecx, 48(%rsp)
	movq	$1572865, 52(%rsp)              # imm = 0x180001
	movl	%r15d, 60(%rsp)
	movapd	.LCPI4_0(%rip), %xmm0           # xmm0 = [2835,2835,0,0]
	movupd	%xmm0, 64(%rsp)
	movq	32(%rsp), %rbx
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB4_3
# %bb.4:
	movq	%rax, %r14
	leaq	18(%rsp), %rdi
	movl	$1, %esi
	movl	$14, %edx
	movq	%rax, %rcx
	callq	fwrite
	leaq	40(%rsp), %rdi
	movl	$1, %esi
	movl	$40, %edx
	movq	%r14, %rcx
	callq	fwrite
	movl	%r15d, %r12d
	leaq	8(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	movl	%eax, %edi
	callq	_Z9gpuAssert10hipError_t
	movl	imageHeight(%rip), %eax
	imull	imageWidth(%rip), %eax
	shrl	$9, %eax
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	leaq	(%rdx,%rax), %rdi
	incq	%rdi
	orq	$512, %rdx                      # imm = 0x200
	xorl	%r15d, %r15d
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_6
# %bb.5:
	movq	8(%rsp), %rdi
	movl	imageWidth(%rip), %esi
	movl	imageHeight(%rip), %edx
	movsd	80(%rsp), %xmm0                 # xmm0 = mem[0],zero
	movsd	88(%rsp), %xmm1                 # xmm1 = mem[0],zero
	subsd	%xmm0, %xmm1
	movsd	96(%rsp), %xmm2                 # xmm2 = mem[0],zero
	movsd	104(%rsp), %xmm3                # xmm3 = mem[0],zero
	subsd	%xmm2, %xmm3
	movl	rowPadding(%rip), %ecx
	movl	$2, %r8d
	callq	_Z26__device_stub__renderPixelPhiiddddii
.LBB4_6:
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r13
	movq	8(%rsp), %rsi
	movq	%rax, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	%eax, %edi
	callq	_Z9gpuAssert10hipError_t
	movl	$1, %esi
	movq	%r13, %rdi
	movq	%r12, %rdx
	movq	%r14, %rcx
	callq	fwrite
	movq	8(%rsp), %rdi
	callq	hipFree
	movl	%eax, %edi
	callq	_Z9gpuAssert10hipError_t
	movq	%r13, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	fclose
	jmp	.LBB4_7
.LBB4_1:
	xorl	%r15d, %r15d
.LBB4_7:
	movl	%r15d, %eax
	addq	$112, %rsp
	.cfi_def_cfa_offset 48
	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
.LBB4_3:
	.cfi_def_cfa_offset 160
	movl	$.L.str.8, %edi
	callq	perror
	movl	$-1, %r15d
	jmp	.LBB4_7
.Lfunc_end4:
	.size	main, .Lfunc_end4-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	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z11renderPixelPhiiddddii, %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_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	imageWidth,@object              # @imageWidth
	.data
	.globl	imageWidth
	.p2align	2, 0x0
imageWidth:
	.long	1920                            # 0x780
	.size	imageWidth, 4

	.type	imageHeight,@object             # @imageHeight
	.globl	imageHeight
	.p2align	2, 0x0
imageHeight:
	.long	1080                            # 0x438
	.size	imageHeight, 4

	.type	rowPadding,@object              # @rowPadding
	.bss
	.globl	rowPadding
	.p2align	2, 0x0
rowPadding:
	.long	0                               # 0x0
	.size	rowPadding, 4

	.type	_Z11renderPixelPhiiddddii,@object # @_Z11renderPixelPhiiddddii
	.section	.rodata,"a",@progbits
	.globl	_Z11renderPixelPhiiddddii
	.p2align	3, 0x0
_Z11renderPixelPhiiddddii:
	.quad	_Z26__device_stub__renderPixelPhiiddddii
	.size	_Z11renderPixelPhiiddddii, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.zero	1
	.size	.L.str.1, 1

	.type	_ZL7options,@object             # @_ZL7options
	.section	.rodata,"a",@progbits
	.p2align	4, 0x0
_ZL7options:
	.quad	.L.str.9
	.long	0                               # 0x0
	.zero	4
	.quad	0
	.long	1                               # 0x1
	.zero	4
	.quad	.L.str.10
	.long	1                               # 0x1
	.zero	4
	.quad	0
	.long	2                               # 0x2
	.zero	4
	.quad	.L.str.11
	.long	1                               # 0x1
	.zero	4
	.quad	0
	.long	3                               # 0x3
	.zero	4
	.quad	.L.str.12
	.long	1                               # 0x1
	.zero	4
	.quad	0
	.long	4                               # 0x4
	.zero	4
	.quad	.L.str.13
	.long	1                               # 0x1
	.zero	4
	.quad	0
	.long	5                               # 0x5
	.zero	4
	.quad	.L.str.14
	.long	1                               # 0x1
	.zero	4
	.quad	0
	.long	6                               # 0x6
	.zero	4
	.quad	.L.str.15
	.long	1                               # 0x1
	.zero	4
	.quad	0
	.long	7                               # 0x7
	.zero	4
	.quad	.L.str.16
	.long	1                               # 0x1
	.zero	4
	.quad	0
	.long	8                               # 0x8
	.zero	4
	.zero	32
	.size	_ZL7options, 288

	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"Run '%s --help' for more information\n"
	.size	.L.str.2, 38

	.type	_ZL11helpMessage,@object        # @_ZL11helpMessage
	.section	.rodata,"a",@progbits
	.p2align	4, 0x0
_ZL11helpMessage:
	.asciz	"Usage: %s [args]\nMandelbrot-BMP generates a BMP image of a specified location in the Mandelbrot set.\n\nPossible arguments:\n    --help\n    --xleft [value]    Set the leftmost x value to render    (double)\n    --xright [value]   Set the rightmost x value to render   (double)\n    --ylower [value]   Set the lowest y value to render      (double)\n    --yupper [value]   Set the highest y value to render     (double)\n    --width [value]    Set the width of the output image     (int)\n    --height [value]   Set the height of the output image    (int)\n    --output [value]   Set the location of the output image  (string)\n\nIf only 3 boundary values are specified, the other can be inferred from the image aspect ratio.\n"
	.size	_ZL11helpMessage, 715

	.type	.L.str.5,@object                # @.str.5
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.5:
	.asciz	"mandelbrot.bmp"
	.size	.L.str.5, 15

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"CUDA assertion failed: %s\n"
	.size	.L.str.6, 27

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Error opening file"
	.size	.L.str.8, 19

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

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"xleft"
	.size	.L.str.10, 6

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"xright"
	.size	.L.str.11, 7

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"ylower"
	.size	.L.str.12, 7

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"yupper"
	.size	.L.str.13, 7

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"width"
	.size	.L.str.14, 6

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"height"
	.size	.L.str.15, 7

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"output"
	.size	.L.str.16, 7

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z11renderPixelPhiiddddii"
	.size	.L__unnamed_1, 26

	.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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Warning: Falling back to default Mandelbrot corners."
	.size	.Lstr, 53

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Warning: Image height is not between 0 and 20000 pixels! Falling back to default."
	.size	.Lstr.1, 82

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Warning: Image width is not between 0 and 20000 pixels! Falling back to default."
	.size	.Lstr.2, 81

	.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 _Z26__device_stub__renderPixelPhiiddddii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z11renderPixelPhiiddddii
	.addrsig_sym _ZL7options
	.addrsig_sym _ZL11helpMessage
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z11renderPixelPhiiddddii ; -- Begin function _Z11renderPixelPhiiddddii
	.globl	_Z11renderPixelPhiiddddii
	.p2align	8
	.type	_Z11renderPixelPhiiddddii,@function
_Z11renderPixelPhiiddddii:              ; @_Z11renderPixelPhiiddddii
; %bb.0:
	s_clause 0x2
	s_load_b32 s2, s[0:1], 0x44
	s_load_b64 s[16:17], s[0:1], 0x30
	s_load_b64 s[12:13], s[0:1], 0x8
	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_mul_i32 s3, s13, s12
	v_mul_lo_u32 v18, v1, s17
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v19, s17, v18
	v_cmp_gt_i32_e64 s2, s3, v18
	v_cmp_lt_u32_e32 vcc_lo, v18, v19
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s2, vcc_lo, s2
	s_and_saveexec_b32 s4, s2
	s_cbranch_execz .LBB0_11
; %bb.1:                                ; %.lr.ph
	s_add_i32 s2, s12, -1
	s_ashr_i32 s17, s12, 31
	v_cvt_f32_i32_e32 v0, s2
	s_add_i32 s2, s13, -1
	s_load_b64 s[14:15], s[0:1], 0x0
	v_cvt_f32_i32_e32 v1, s2
	s_load_b256 s[4:11], s[0:1], 0x10
	v_cvt_f64_f32_e32 v[2:3], v0
	s_mul_i32 s0, s12, 3
	s_mov_b32 s19, 0
	v_cvt_f64_f32_e32 v[4:5], v1
	s_add_i32 s16, s0, s16
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_div_scale_f64 v[0:1], null, 0x405fe000, 0x405fe000, v[2:3]
	v_div_scale_f64 v[16:17], vcc_lo, v[2:3], 0x405fe000, v[2:3]
	v_div_scale_f64 v[6:7], null, 0x405fe000, 0x405fe000, v[4:5]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[8:9], v[0:1]
	v_rcp_f64_e32 v[10:11], v[6:7]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[12:13], -v[0:1], v[8:9], 1.0
	v_fma_f64 v[14:15], -v[6:7], v[10:11], 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[8:9], v[8:9], v[12:13], v[8:9]
	v_fma_f64 v[10:11], v[10:11], v[14:15], v[10:11]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[12:13], -v[0:1], v[8:9], 1.0
	v_fma_f64 v[14:15], -v[6:7], v[10:11], 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_fma_f64 v[8:9], v[8:9], v[12:13], v[8:9]
	v_div_scale_f64 v[12:13], s2, v[4:5], 0x405fe000, v[4:5]
	v_fma_f64 v[10:11], v[10:11], v[14:15], v[10:11]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f64 v[14:15], v[16:17], v[8:9]
	v_mul_f64 v[20:21], v[12:13], v[10:11]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[0:1], -v[0:1], v[14:15], v[16:17]
	v_fma_f64 v[6:7], -v[6:7], v[20:21], v[12:13]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_div_fmas_f64 v[8:9], v[0:1], v[8:9], v[14:15]
	s_mov_b32 vcc_lo, s2
	s_add_i32 s2, s12, s17
	v_cvt_f64_i32_e32 v[0:1], s12
	v_div_fmas_f64 v[6:7], v[6:7], v[10:11], v[20:21]
	s_xor_b32 s18, s2, s17
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cvt_f32_u32_e32 v10, s18
	s_sub_i32 s2, 0, s18
	v_rcp_iflag_f32_e32 v10, v10
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_4) | instid1(VALU_DEP_3)
	v_div_fixup_f64 v[2:3], v[8:9], 0x405fe000, v[2:3]
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v8, 0x4f7ffffe, v10
	v_div_fixup_f64 v[4:5], v[6:7], 0x405fe000, v[4:5]
	v_cvt_f64_i32_e32 v[6:7], s13
	v_cvt_u32_f32_e32 v8, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v9, s2, v8
	v_mul_hi_u32 v9, v8, v9
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v20, v8, v9
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_3 Depth 2
	v_ashrrev_i32_e32 v8, 31, v18
	s_mov_b32 s1, 0
                                        ; implicit-def: $sgpr2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v9, v18, v8
	v_xor_b32_e32 v9, v9, v8
	v_xor_b32_e32 v8, s17, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v10, v9, v20
	v_mul_lo_u32 v11, v10, s18
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v9, v9, v11
	v_add_nc_u32_e32 v11, 1, v10
	v_subrev_nc_u32_e32 v12, s18, v9
	v_cmp_le_u32_e32 vcc_lo, s18, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_cndmask_b32 v10, v10, v11 :: v_dual_cndmask_b32 v9, v9, v12
	v_add_nc_u32_e32 v11, 1, v10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_le_u32_e32 vcc_lo, s18, v9
	v_cndmask_b32_e32 v9, v10, v11, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v9, v9, v8
	v_sub_nc_u32_e32 v21, v9, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v8, v21, s12
	v_cvt_f64_u32_e32 v[10:11], v21
	v_sub_nc_u32_e32 v22, v18, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cvt_f64_u32_e32 v[8:9], v22
	v_div_scale_f64 v[14:15], null, v[6:7], v[6:7], v[10:11]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_div_scale_f64 v[12:13], null, v[0:1], v[0:1], v[8:9]
	v_div_scale_f64 v[29:30], vcc_lo, v[8:9], v[0:1], v[8:9]
	v_rcp_f64_e32 v[23:24], v[14:15]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_2)
	v_rcp_f64_e32 v[16:17], v[12:13]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[27:28], -v[14:15], v[23:24], 1.0
	v_fma_f64 v[25:26], -v[12:13], v[16:17], 1.0
	v_fma_f64 v[23:24], v[23:24], v[27:28], v[23:24]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[16:17], v[16:17], v[25:26], v[16:17]
	v_fma_f64 v[27:28], -v[14:15], v[23:24], 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[25:26], -v[12:13], v[16:17], 1.0
	v_fma_f64 v[23:24], v[23:24], v[27:28], v[23:24]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_fma_f64 v[16:17], v[16:17], v[25:26], v[16:17]
	v_div_scale_f64 v[25:26], s0, v[10:11], v[6:7], v[10:11]
	v_mul_f64 v[27:28], v[29:30], v[16:17]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f64 v[31:32], v[25:26], v[23:24]
	v_fma_f64 v[12:13], -v[12:13], v[27:28], v[29:30]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[14:15], -v[14:15], v[31:32], v[25:26]
	v_div_fmas_f64 v[12:13], v[12:13], v[16:17], v[27:28]
	s_mov_b32 vcc_lo, s0
	s_mov_b32 s0, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fmas_f64 v[14:15], v[14:15], v[23:24], v[31:32]
	v_div_fixup_f64 v[8:9], v[12:13], v[0:1], v[8:9]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_fixup_f64 v[10:11], v[14:15], v[6:7], v[10:11]
	s_waitcnt lgkmcnt(0)
	v_fma_f64 v[8:9], v[8:9], s[6:7], s[4:5]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[10:11], v[10:11], s[10:11], s[8:9]
	v_dual_mov_b32 v15, v9 :: v_dual_mov_b32 v14, v8
	s_delay_alu instid0(VALU_DEP_2)
	v_dual_mov_b32 v13, v11 :: v_dual_mov_b32 v12, v10
.LBB0_3:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mul_f64 v[16:17], v[12:13], v[12:13]
	s_or_b32 s2, s2, exec_lo
	v_fma_f64 v[23:24], v[14:15], v[14:15], v[16:17]
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_nlt_f64_e32 vcc_lo, 4.0, v[23:24]
	v_mov_b32_e32 v23, s1
	s_and_saveexec_b32 s20, vcc_lo
	s_cbranch_execz .LBB0_5
; %bb.4:                                ;   in Loop: Header=BB0_3 Depth=2
	v_mul_f64 v[23:24], v[14:15], v[14:15]
	v_mul_f64 v[12:13], v[14:15], v[12:13]
	s_add_i32 s1, s1, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_3) | instid1(SALU_CYCLE_1)
	s_cmpk_eq_i32 s1, 0x50
	s_cselect_b32 s21, -1, 0
	s_and_not1_b32 s2, s2, exec_lo
	s_and_b32 s21, s21, exec_lo
	s_or_b32 s2, s2, s21
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_f64 v[16:17], v[23:24], -v[16:17]
	v_fma_f64 v[12:13], v[12:13], 2.0, v[10:11]
	v_mov_b32_e32 v23, 0x50
	s_delay_alu instid0(VALU_DEP_3)
	v_add_f64 v[14:15], v[8:9], v[16:17]
.LBB0_5:                                ; %Flow96
                                        ;   in Loop: Header=BB0_3 Depth=2
	s_or_b32 exec_lo, exec_lo, s20
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s20, exec_lo, s2
	s_or_b32 s0, s20, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s0
	s_cbranch_execnz .LBB0_3
; %bb.6:                                ; %_Z15inMandelbrotSetdd.exit
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	v_xad_u32 v10, v22, -1, s12
	v_cvt_f32_u32_e32 v8, v22
	v_xad_u32 v12, v21, -1, s13
	v_cvt_f32_u32_e32 v11, v21
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cvt_f32_u32_e32 v13, v10
	v_cvt_f64_f32_e32 v[8:9], v8
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cvt_f32_u32_e32 v14, v12
	v_cvt_f64_f32_e32 v[10:11], v11
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cvt_f64_f32_e32 v[12:13], v13
	v_cvt_f64_f32_e32 v[14:15], v14
	v_div_scale_f64 v[16:17], null, v[2:3], v[2:3], v[8:9]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_div_scale_f64 v[24:25], null, v[4:5], v[4:5], v[10:11]
	v_div_scale_f64 v[26:27], null, v[2:3], v[2:3], v[12:13]
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_2) | instid1(VALU_DEP_4)
	v_div_scale_f64 v[28:29], null, v[4:5], v[4:5], v[14:15]
	v_div_scale_f64 v[46:47], vcc_lo, v[8:9], v[2:3], v[8:9]
	v_rcp_f64_e32 v[30:31], v[16:17]
	v_rcp_f64_e32 v[32:33], v[24:25]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_rcp_f64_e32 v[34:35], v[26:27]
	v_rcp_f64_e32 v[36:37], v[28:29]
	v_fma_f64 v[38:39], -v[16:17], v[30:31], 1.0
	s_delay_alu instid0(TRANS32_DEP_3)
	v_fma_f64 v[40:41], -v[24:25], v[32:33], 1.0
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[42:43], -v[26:27], v[34:35], 1.0
	v_fma_f64 v[44:45], -v[28:29], v[36:37], 1.0
	v_fma_f64 v[30:31], v[30:31], v[38:39], v[30:31]
	v_fma_f64 v[32:33], v[32:33], v[40:41], v[32:33]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_fma_f64 v[34:35], v[34:35], v[42:43], v[34:35]
	v_fma_f64 v[36:37], v[36:37], v[44:45], v[36:37]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_fma_f64 v[38:39], -v[16:17], v[30:31], 1.0
	v_fma_f64 v[40:41], -v[24:25], v[32:33], 1.0
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_fma_f64 v[42:43], -v[26:27], v[34:35], 1.0
	v_fma_f64 v[44:45], -v[28:29], v[36:37], 1.0
	s_delay_alu instid0(VALU_DEP_4)
	v_fma_f64 v[30:31], v[30:31], v[38:39], v[30:31]
	v_div_scale_f64 v[38:39], s0, v[10:11], v[4:5], v[10:11]
	v_fma_f64 v[32:33], v[32:33], v[40:41], v[32:33]
	v_div_scale_f64 v[40:41], s1, v[12:13], v[2:3], v[12:13]
	v_fma_f64 v[34:35], v[34:35], v[42:43], v[34:35]
	v_div_scale_f64 v[42:43], s2, v[14:15], v[4:5], v[14:15]
	v_fma_f64 v[36:37], v[36:37], v[44:45], v[36:37]
	v_mul_f64 v[44:45], v[46:47], v[30:31]
	v_mul_f64 v[48:49], v[38:39], v[32:33]
	v_mul_f64 v[50:51], v[40:41], v[34:35]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_mul_f64 v[52:53], v[42:43], v[36:37]
	v_fma_f64 v[16:17], -v[16:17], v[44:45], v[46:47]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_fma_f64 v[24:25], -v[24:25], v[48:49], v[38:39]
	v_fma_f64 v[26:27], -v[26:27], v[50:51], v[40:41]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_fma_f64 v[28:29], -v[28:29], v[52:53], v[42:43]
	v_div_fmas_f64 v[16:17], v[16:17], v[30:31], v[44:45]
	s_mov_b32 vcc_lo, s0
	s_mov_b32 s0, exec_lo
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_div_fmas_f64 v[24:25], v[24:25], v[32:33], v[48:49]
	s_mov_b32 vcc_lo, s1
	v_div_fmas_f64 v[26:27], v[26:27], v[34:35], v[50:51]
	s_mov_b32 vcc_lo, s2
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_div_fmas_f64 v[28:29], v[28:29], v[36:37], v[52:53]
	v_div_fixup_f64 v[8:9], v[16:17], v[2:3], v[8:9]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_div_fixup_f64 v[10:11], v[24:25], v[4:5], v[10:11]
	v_div_fixup_f64 v[12:13], v[26:27], v[2:3], v[12:13]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_div_fixup_f64 v[14:15], v[28:29], v[4:5], v[14:15]
	v_add_f64 v[10:11], v[8:9], v[10:11]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_add_f64 v[12:13], v[12:13], v[14:15]
	v_add_f64 v[8:9], v[8:9], v[14:15]
	v_cvt_i32_f64_e32 v10, v[10:11]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cvt_i32_f64_e32 v11, v[12:13]
	v_cvt_i32_f64_e32 v12, v[8:9]
	v_lshl_add_u32 v13, v22, 1, v22
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[8:9], null, s16, v21, v[13:14]
	v_add_nc_u32_e32 v9, 1, v8
	v_cmpx_gt_u32_e32 5, v23
	s_xor_b32 s0, exec_lo, s0
; %bb.7:                                ;   in Loop: Header=BB0_2 Depth=1
	s_clause 0x1
	global_store_b8 v8, v12, s[14:15]
	global_store_b8 v9, v11, s[14:15]
                                        ; implicit-def: $vgpr12
                                        ; implicit-def: $vgpr11
                                        ; implicit-def: $vgpr9
; %bb.8:                                ; %Flow
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_and_not1_saveexec_b32 s0, s0
	s_cbranch_execz .LBB0_10
; %bb.9:                                ;   in Loop: Header=BB0_2 Depth=1
	v_sub_nc_u32_e32 v13, 0x55, v23
	v_cvt_f32_ubyte0_e32 v12, v12
	v_cvt_f32_ubyte0_e32 v10, v10
	v_cvt_f32_ubyte0_e32 v11, v11
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_f32_u32_e32 v13, v13
	v_div_scale_f32 v14, null, 0x42a00000, 0x42a00000, v13
	v_div_scale_f32 v17, vcc_lo, v13, 0x42a00000, v13
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v15, v14
	s_waitcnt_depctr 0xfff
	v_fma_f32 v16, -v14, v15, 1.0
	v_fmac_f32_e32 v15, v16, v15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v16, v17, v15
	v_fma_f32 v21, -v14, v16, v17
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v16, v21, v15
	v_fma_f32 v14, -v14, v16, v17
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f32 v14, v14, v15, v16
	v_div_fixup_f32 v13, v14, 0x42a00000, v13
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_mul_f32_e32 v12, v13, v12
	v_mul_f32_e32 v10, v13, v10
	v_mul_f32_e32 v11, v13, v11
	v_cvt_i32_f32_e32 v12, v12
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cvt_i32_f32_e32 v10, v10
	v_cvt_i32_f32_e32 v11, v11
	s_clause 0x1
	global_store_b8 v8, v12, s[14:15]
	global_store_b8 v9, v11, s[14:15]
.LBB0_10:                               ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	v_add_nc_u32_e32 v18, 1, v18
	v_add_nc_u32_e32 v8, 2, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(SALU_CYCLE_1)
	v_cmp_ge_u32_e32 vcc_lo, v18, v19
	v_cmp_le_i32_e64 s0, s3, v18
	global_store_b8 v8, v10, s[14:15]
	s_or_b32 s0, vcc_lo, s0
	s_and_b32 s0, exec_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_or_b32 s19, s0, s19
	s_and_not1_b32 exec_lo, exec_lo, s19
	s_cbranch_execnz .LBB0_2
.LBB0_11:                               ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11renderPixelPhiiddddii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 312
		.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 54
		.amdhsa_next_free_sgpr 22
		.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	_Z11renderPixelPhiiddddii, .Lfunc_end0-_Z11renderPixelPhiiddddii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1856
; NumSgprs: 24
; NumVgprs: 54
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 6
; NumSGPRsForWavesPerEU: 24
; NumVGPRsForWavesPerEU: 54
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         12
        .size:           4
        .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:           8
        .value_kind:     by_value
      - .offset:         48
        .size:           4
        .value_kind:     by_value
      - .offset:         52
        .size:           4
        .value_kind:     by_value
      - .offset:         56
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         60
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         64
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         68
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         70
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         72
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         74
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         76
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         78
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         112
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         120
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 312
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z11renderPixelPhiiddddii
    .private_segment_fixed_size: 0
    .sgpr_count:     24
    .sgpr_spill_count: 0
    .symbol:         _Z11renderPixelPhiiddddii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     54
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
