#include <iostream>
#include <cstdlib>
#include <cassert>
#include <zlib.h>
#include <png.h>

#define MASK_N 2
#define MASK_X 5
#define MASK_Y 5
#define SCALE 8

__device__ int mask[MASK_N][MASK_X][MASK_Y] = { 
    {{ -1, -4, -6, -4, -1},
     { -2, -8,-12, -8, -2},
     {  0,  0,  0,  0,  0}, 
     {  2,  8, 12,  8,  2}, 
     {  1,  4,  6,  4,  1}},
    {{ -1, -2,  0,  2,  1}, 
     { -4, -8,  0,  8,  4}, 
     { -6,-12,  0, 12,  6}, 
     { -4, -8,  0,  8,  4}, 
     { -1, -2,  0,  2,  1}} 
};

int read_png(const char* filename, unsigned char** image, unsigned* height, 
             unsigned* width, unsigned* channels) {

    unsigned char sig[8];
    FILE* infile;
    infile = fopen(filename, "rb");

    fread(sig, 1, 8, infile);
    if (!png_check_sig(sig, 8))
        return 1;   /* bad signature */

    png_structp png_ptr;
    png_infop info_ptr;

    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (!png_ptr)
        return 4;   /* out of memory */
  
    info_ptr = png_create_info_struct(png_ptr);
    if (!info_ptr) {
        png_destroy_read_struct(&png_ptr, NULL, NULL);
        return 4;   /* out of memory */
    }

    png_init_io(png_ptr, infile);
    png_set_sig_bytes(png_ptr, 8);
    png_read_info(png_ptr, info_ptr);
    int bit_depth, color_type;
    png_get_IHDR(png_ptr, info_ptr, width, height, &bit_depth, &color_type, NULL, NULL, NULL);

    png_uint_32  i, rowbytes;
    png_bytep  row_pointers[*height];
    png_read_update_info(png_ptr, info_ptr);
    rowbytes = png_get_rowbytes(png_ptr, info_ptr);
    *channels = (int) png_get_channels(png_ptr, info_ptr);

    if ((*image = (unsigned char *) malloc(rowbytes * *height)) == NULL) {
        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
        return 3;
    }

    for (i = 0;  i < *height;  ++i)
        row_pointers[i] = *image + i * rowbytes;
    png_read_image(png_ptr, row_pointers);
    png_read_end(png_ptr, NULL);
    return 0;
}

void write_png(const char* filename, png_bytep image, const unsigned height, const unsigned width, 
               const unsigned channels) {
    FILE* fp = fopen(filename, "wb");
    png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    png_infop info_ptr = png_create_info_struct(png_ptr);
    png_init_io(png_ptr, fp);
    png_set_IHDR(png_ptr, info_ptr, width, height, 8,
                 PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
                 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
    png_set_filter(png_ptr, 0, PNG_NO_FILTERS);
    png_write_info(png_ptr, info_ptr);
    png_set_compression_level(png_ptr, 1);

    png_bytep row_ptr[height];
    for (int i = 0; i < height; ++ i) {
        row_ptr[i] = image + i * width * channels * sizeof(unsigned char);
    }
    png_write_image(png_ptr, row_ptr);
    png_write_end(png_ptr, NULL);
    png_destroy_write_struct(&png_ptr, &info_ptr);
    fclose(fp);
}

__global__ void sobel (unsigned char* s, unsigned char* t, unsigned height, unsigned width, unsigned channels) {
    int  x, y, i, v, u;
    int  R, G, B;
    double val[MASK_N*3] = {0.0};
    int adjustX, adjustY, xBound, yBound;
    //y = threadIdx.x + blockIdx.x * blockDim.x;
    y = blockIdx.x;
//    for (y = 0; y < height; ++y) {
        for (x = threadIdx.x; x < width; x+=256) {
            for (i = 0; i < MASK_N; ++i) {
                adjustX = (MASK_X % 2) ? 1 : 0;
                adjustY = (MASK_Y % 2) ? 1 : 0;
                xBound = MASK_X /2;
                yBound = MASK_Y /2;

                val[i*3+2] = 0.0;
                val[i*3+1] = 0.0;
                val[i*3] = 0.0;

                for (v = -yBound; v < yBound + adjustY; ++v) {
                    for (u = -xBound; u < xBound + adjustX; ++u) {
                        if ((x + u) >= 0 && (x + u) < width && y + v >= 0 && y + v < height) {
                            R = s[channels * (width * (y+v) + (x+u)) + 2];
                            G = s[channels * (width * (y+v) + (x+u)) + 1];
                            B = s[channels * (width * (y+v) + (x+u)) + 0];
                            val[i*3+2] += R * mask[i][u + xBound][v + yBound];
                            val[i*3+1] += G * mask[i][u + xBound][v + yBound];
                            val[i*3+0] += B * mask[i][u + xBound][v + yBound];
                        }    
                    }
                }
            }

            double totalR = 0.0;
            double totalG = 0.0;
            double totalB = 0.0;
            for (i = 0; i < MASK_N; ++i) {
                totalR += val[i * 3 + 2] * val[i * 3 + 2];
                totalG += val[i * 3 + 1] * val[i * 3 + 1];
                totalB += val[i * 3 + 0] * val[i * 3 + 0];
            }

            totalR = sqrt(totalR) / SCALE;
            totalG = sqrt(totalG) / SCALE;
            totalB = sqrt(totalB) / SCALE;
            const unsigned char cR = (totalR > 255.0) ? 255 : totalR;
            const unsigned char cG = (totalG > 255.0) ? 255 : totalG;
            const unsigned char cB = (totalB > 255.0) ? 255 : totalB;
            t[channels * (width * y + x) + 2] = cR;
            t[channels * (width * y + x) + 1] = cG;
            t[channels * (width * y + x) + 0] = cB;
        }
//    }
}

int main(int argc, char** argv) {

    assert(argc == 3);
    unsigned height, width, channels;
    unsigned char* host_s = NULL;
    read_png(argv[1], &host_s, &height, &width, &channels);
    unsigned char* device_s;
    unsigned char* device_t;
    // malloc memory for GPU
    cudaMalloc(&device_s, height * width * channels);
    cudaMalloc(&device_t, height * width * channels);

    unsigned char* host_t = (unsigned char*) malloc(height * width * channels * sizeof(unsigned char));
    // use cudaMemcpy2D to accelerate
    //cudaMemcpy2D(device_t, channels, device_s, channels, height, width*sizeof(unsigned char), cudaMemcpyHostToDevice);
    cudaMemcpy(device_s, host_s, height * width * channels, cudaMemcpyHostToDevice);
    // by using multiple threads
    sobel<<<height, 256>>>(device_s, device_t, height, width, channels);
    cudaMemcpy(host_t, device_t, height * width * channels, cudaMemcpyDeviceToHost);
    write_png(argv[2], host_t, height, width, channels);

    return 0;
}

	.file	"tmpxft_00247505_00000000-6_sobel_cuda.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3653:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3653:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"rb"
.LC1:
	.string	"1.6.43"
	.text
	.globl	_Z8read_pngPKcPPhPjS3_S3_
	.type	_Z8read_pngPKcPPhPjS3_S3_, @function
_Z8read_pngPKcPPhPjS3_S3_:
.LFB3648:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	.cfi_offset 15, -24
	movq	%r8, %r15
	pushq	%r14
	.cfi_offset 14, -32
	movq	%rsi, %r14
	leaq	.LC0(%rip), %rsi
	pushq	%r13
	pushq	%r12
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	movq	%rdx, %r12
	pushq	%rbx
	.cfi_offset 3, -56
	leaq	-64(%rbp), %rbx
	subq	$72, %rsp
	movq	%rcx, -104(%rbp)
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	call	fopen@PLT
	movq	%rbx, %rdi
	movl	$8, %ecx
	movl	$1, %edx
	movq	%rax, %r8
	movl	$8, %esi
	movq	%rax, %r13
	call	__fread_chk@PLT
	movq	%rbx, %rdi
	movl	$8, %edx
	xorl	%esi, %esi
	call	png_sig_cmp@PLT
	movl	$1, %ebx
	testl	%eax, %eax
	jne	.L2
	leaq	.LC1(%rip), %rdi
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	xorl	%esi, %esi
	movl	%eax, %ebx
	call	png_create_read_struct@PLT
	movq	%rax, -80(%rbp)
	movq	%rax, %rdi
	testq	%rax, %rax
	je	.L4
	call	png_create_info_struct@PLT
	movq	%rax, -72(%rbp)
	testq	%rax, %rax
	jne	.L5
	leaq	-80(%rbp), %rdi
	xorl	%edx, %edx
	xorl	%esi, %esi
	call	png_destroy_read_struct@PLT
.L4:
	movl	$4, %ebx
	jmp	.L2
.L5:
	movq	-80(%rbp), %rdi
	movq	%r13, %rsi
	call	png_init_io@PLT
	movq	-80(%rbp), %rdi
	movl	$8, %esi
	call	png_set_sig_bytes@PLT
	movq	-72(%rbp), %rsi
	movq	-80(%rbp), %rdi
	call	png_read_info@PLT
	movq	%r12, %rcx
	leaq	-84(%rbp), %r9
	leaq	-88(%rbp), %r8
	pushq	%rax
	movq	-104(%rbp), %rdx
	movq	-72(%rbp), %rsi
	movq	-80(%rbp), %rdi
	pushq	$0
	pushq	$0
	pushq	$0
	call	png_get_IHDR@PLT
	movl	(%r12), %eax
	addq	$32, %rsp
	movq	%rsp, %rdx
	leaq	15(,%rax,8), %rax
	shrq	$4, %rax
	salq	$4, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	subq	%rcx, %rdx
.L6:
	cmpq	%rdx, %rsp
	je	.L7
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L6
.L7:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L8
	orq	$0, -8(%rsp,%rax)
.L8:
	movq	-72(%rbp), %rsi
	movq	-80(%rbp), %rdi
	movq	%rsp, -104(%rbp)
	call	png_read_update_info@PLT
	movq	-72(%rbp), %rsi
	movq	-80(%rbp), %rdi
	call	png_get_rowbytes@PLT
	movq	-72(%rbp), %rsi
	movq	-80(%rbp), %rdi
	movq	%rax, -112(%rbp)
	movl	%eax, %r13d
	call	png_get_channels@PLT
	movq	-112(%rbp), %rdx
	movzbl	%al, %eax
	movl	%eax, (%r15)
	movl	(%r12), %r12d
	movl	%edx, %edi
	imull	%r12d, %edi
	call	malloc@PLT
	xorl	%esi, %esi
	xorl	%edx, %edx
	movq	%rax, (%r14)
	testq	%rax, %rax
	jne	.L9
	leaq	-72(%rbp), %rsi
	leaq	-80(%rbp), %rdi
	movl	$3, %ebx
	call	png_destroy_read_struct@PLT
	jmp	.L2
.L9:
	cmpl	%r12d, %edx
	jnb	.L23
	movl	%esi, %edi
	movq	-104(%rbp), %rcx
	addl	%r13d, %esi
	addq	%rax, %rdi
	movq	%rdi, (%rcx,%rdx,8)
	incq	%rdx
	jmp	.L9
.L23:
	movq	-104(%rbp), %rsi
	movq	-80(%rbp), %rdi
	call	png_read_image@PLT
	movq	-80(%rbp), %rdi
	xorl	%esi, %esi
	call	png_read_end@PLT
.L2:
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	leaq	-40(%rbp), %rsp
	movl	%ebx, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3648:
	.size	_Z8read_pngPKcPPhPjS3_S3_, .-_Z8read_pngPKcPPhPjS3_S3_
	.section	.rodata.str1.1
.LC2:
	.string	"wb"
	.text
	.globl	_Z9write_pngPKcPhjjj
	.type	_Z9write_pngPKcPhjjj, @function
_Z9write_pngPKcPhjjj:
.LFB3649:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	.cfi_offset 15, -24
	movl	%r8d, %r15d
	pushq	%r14
	.cfi_offset 14, -32
	movq	%rsi, %r14
	leaq	.LC2(%rip), %rsi
	pushq	%r13
	pushq	%r12
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	movl	%edx, %r12d
	pushq	%rbx
	.cfi_offset 3, -56
	movl	%ecx, %ebx
	subq	$40, %rsp
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	call	fopen@PLT
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	xorl	%esi, %esi
	leaq	.LC1(%rip), %rdi
	movq	%rax, %r13
	call	png_create_write_struct@PLT
	movq	%rax, %rdi
	movq	%rax, -72(%rbp)
	call	png_create_info_struct@PLT
	movq	-72(%rbp), %rdi
	movq	%r13, %rsi
	movq	%rax, -64(%rbp)
	call	png_init_io@PLT
	movl	%r12d, %ecx
	movl	$2, %r9d
	movl	%ebx, %edx
	pushq	%rax
	movq	-64(%rbp), %rsi
	movl	$8, %r8d
	pushq	$0
	movq	-72(%rbp), %rdi
	pushq	$0
	pushq	$0
	call	png_set_IHDR@PLT
	movq	-72(%rbp), %rdi
	addq	$32, %rsp
	xorl	%edx, %edx
	xorl	%esi, %esi
	call	png_set_filter@PLT
	movq	-64(%rbp), %rsi
	movq	-72(%rbp), %rdi
	call	png_write_info@PLT
	movq	-72(%rbp), %rdi
	movl	$1, %esi
	call	png_set_compression_level@PLT
	movl	%r12d, %eax
	movq	%rsp, %rdx
	leaq	15(,%rax,8), %rax
	shrq	$4, %rax
	salq	$4, %rax
	movq	%rax, %rcx
	andq	$-4096, %rcx
	subq	%rcx, %rdx
.L25:
	cmpq	%rdx, %rsp
	je	.L26
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L25
.L26:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L27
	orq	$0, -8(%rsp,%rax)
.L27:
	imull	%r15d, %ebx
	movq	%rsp, %rsi
	xorl	%edx, %edx
	xorl	%eax, %eax
.L28:
	cmpl	%r12d, %eax
	jnb	.L35
	movl	%edx, %ecx
	addl	%ebx, %edx
	addq	%r14, %rcx
	movq	%rcx, (%rsi,%rax,8)
	incq	%rax
	jmp	.L28
.L35:
	movq	-72(%rbp), %rdi
	call	png_write_image@PLT
	movq	-72(%rbp), %rdi
	xorl	%esi, %esi
	call	png_write_end@PLT
	leaq	-72(%rbp), %rdi
	leaq	-64(%rbp), %rsi
	call	png_destroy_write_struct@PLT
	movq	%r13, %rdi
	call	fclose@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE3649:
	.size	_Z9write_pngPKcPhjjj, .-_Z9write_pngPKcPhjjj
	.globl	_Z29__device_stub__Z5sobelPhS_jjjPhS_jjj
	.type	_Z29__device_stub__Z5sobelPhS_jjjPhS_jjj, @function
_Z29__device_stub__Z5sobelPhS_jjjPhS_jjj:
.LFB3675:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, 4(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L36
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z5sobelPhS_jjj(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L36:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L38
	call	__stack_chk_fail@PLT
.L38:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3675:
	.size	_Z29__device_stub__Z5sobelPhS_jjjPhS_jjj, .-_Z29__device_stub__Z5sobelPhS_jjjPhS_jjj
	.globl	_Z5sobelPhS_jjj
	.type	_Z5sobelPhS_jjj, @function
_Z5sobelPhS_jjj:
.LFB3676:
	.cfi_startproc
	endbr64
	jmp	_Z29__device_stub__Z5sobelPhS_jjjPhS_jjj
	.cfi_endproc
.LFE3676:
	.size	_Z5sobelPhS_jjj, .-_Z5sobelPhS_jjj
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3650:
	.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
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$88, %rsp
	.cfi_def_cfa_offset 128
	movq	8(%r12), %rdi
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %r8
	leaq	16(%rsp), %rcx
	xorl	%eax, %eax
	leaq	12(%rsp), %rdx
	leaq	24(%rsp), %rsi
	movq	%rax, 24(%rsp)
	call	_Z8read_pngPKcPPhPjS3_S3_
	movl	12(%rsp), %esi
	imull	16(%rsp), %esi
	leaq	32(%rsp), %rdi
	movl	20(%rsp), %ebx
	imull	%ebx, %esi
	call	cudaMalloc@PLT
	movl	12(%rsp), %esi
	leaq	40(%rsp), %rdi
	imull	%ebx, %esi
	imull	16(%rsp), %esi
	call	cudaMalloc@PLT
	movl	12(%rsp), %r13d
	imull	%ebx, %r13d
	imull	16(%rsp), %r13d
	movq	%r13, %rdi
	call	malloc@PLT
	movq	24(%rsp), %rsi
	movq	32(%rsp), %rdi
	movq	%r13, %rdx
	movl	$1, %ecx
	movq	%rax, %rbp
	call	cudaMemcpy@PLT
	movl	12(%rsp), %eax
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$16777217, %edx
	movl	$1, %ecx
	movl	%eax, 48(%rsp)
	salq	$8, %rdx
	movabsq	$4294967297, %rax
	movq	%rax, 52(%rsp)
	movq	48(%rsp), %rdi
	movl	56(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L42
	movl	16(%rsp), %ecx
	movl	12(%rsp), %edx
	movl	%ebx, %r8d
	movq	40(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	_Z29__device_stub__Z5sobelPhS_jjjPhS_jjj
.L42:
	movl	12(%rsp), %edx
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdi
	imull	%ebx, %edx
	imull	16(%rsp), %edx
	call	cudaMemcpy@PLT
	movq	16(%r12), %rdi
	movl	%ebx, %r8d
	movq	%rbp, %rsi
	movl	16(%rsp), %ecx
	movl	12(%rsp), %edx
	call	_Z9write_pngPKcPhjjj
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L43
	call	__stack_chk_fail@PLT
.L43:
	addq	$88, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3650:
	.size	main, .-main
	.section	.rodata.str1.1
.LC3:
	.string	"_Z5sobelPhS_jjj"
.LC4:
	.string	"mask"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3678:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC3(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z5sobelPhS_jjj(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC4(%rip), %rdx
	movl	$200, %r9d
	leaq	_ZL4mask(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3678:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.local	_ZL4mask
	.comm	_ZL4mask,200,32
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <zlib.h>
#include <png.h>

#define MASK_N 2
#define MASK_X 5
#define MASK_Y 5
#define SCALE 8

__device__ int mask[MASK_N][MASK_X][MASK_Y] = { 
    {{ -1, -4, -6, -4, -1},
     { -2, -8,-12, -8, -2},
     {  0,  0,  0,  0,  0}, 
     {  2,  8, 12,  8,  2}, 
     {  1,  4,  6,  4,  1}},
    {{ -1, -2,  0,  2,  1}, 
     { -4, -8,  0,  8,  4}, 
     { -6,-12,  0, 12,  6}, 
     { -4, -8,  0,  8,  4}, 
     { -1, -2,  0,  2,  1}} 
};

int read_png(const char* filename, unsigned char** image, unsigned* height, 
             unsigned* width, unsigned* channels) {

    unsigned char sig[8];
    FILE* infile;
    infile = fopen(filename, "rb");

    fread(sig, 1, 8, infile);
    if (!png_check_sig(sig, 8))
        return 1;   /* bad signature */

    png_structp png_ptr;
    png_infop info_ptr;

    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    if (!png_ptr)
        return 4;   /* out of memory */
  
    info_ptr = png_create_info_struct(png_ptr);
    if (!info_ptr) {
        png_destroy_read_struct(&png_ptr, NULL, NULL);
        return 4;   /* out of memory */
    }

    png_init_io(png_ptr, infile);
    png_set_sig_bytes(png_ptr, 8);
    png_read_info(png_ptr, info_ptr);
    int bit_depth, color_type;
    png_get_IHDR(png_ptr, info_ptr, width, height, &bit_depth, &color_type, NULL, NULL, NULL);

    png_uint_32  i, rowbytes;
    png_bytep  row_pointers[*height];
    png_read_update_info(png_ptr, info_ptr);
    rowbytes = png_get_rowbytes(png_ptr, info_ptr);
    *channels = (int) png_get_channels(png_ptr, info_ptr);

    if ((*image = (unsigned char *) malloc(rowbytes * *height)) == NULL) {
        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
        return 3;
    }

    for (i = 0;  i < *height;  ++i)
        row_pointers[i] = *image + i * rowbytes;
    png_read_image(png_ptr, row_pointers);
    png_read_end(png_ptr, NULL);
    return 0;
}

void write_png(const char* filename, png_bytep image, const unsigned height, const unsigned width, 
               const unsigned channels) {
    FILE* fp = fopen(filename, "wb");
    png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
    png_infop info_ptr = png_create_info_struct(png_ptr);
    png_init_io(png_ptr, fp);
    png_set_IHDR(png_ptr, info_ptr, width, height, 8,
                 PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
                 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
    png_set_filter(png_ptr, 0, PNG_NO_FILTERS);
    png_write_info(png_ptr, info_ptr);
    png_set_compression_level(png_ptr, 1);

    png_bytep row_ptr[height];
    for (int i = 0; i < height; ++ i) {
        row_ptr[i] = image + i * width * channels * sizeof(unsigned char);
    }
    png_write_image(png_ptr, row_ptr);
    png_write_end(png_ptr, NULL);
    png_destroy_write_struct(&png_ptr, &info_ptr);
    fclose(fp);
}

__global__ void sobel (unsigned char* s, unsigned char* t, unsigned height, unsigned width, unsigned channels) {
    int  x, y, i, v, u;
    int  R, G, B;
    double val[MASK_N*3] = {0.0};
    int adjustX, adjustY, xBound, yBound;
    //y = threadIdx.x + blockIdx.x * blockDim.x;
    y = blockIdx.x;
//    for (y = 0; y < height; ++y) {
        for (x = threadIdx.x; x < width; x+=256) {
            for (i = 0; i < MASK_N; ++i) {
                adjustX = (MASK_X % 2) ? 1 : 0;
                adjustY = (MASK_Y % 2) ? 1 : 0;
                xBound = MASK_X /2;
                yBound = MASK_Y /2;

                val[i*3+2] = 0.0;
                val[i*3+1] = 0.0;
                val[i*3] = 0.0;

                for (v = -yBound; v < yBound + adjustY; ++v) {
                    for (u = -xBound; u < xBound + adjustX; ++u) {
                        if ((x + u) >= 0 && (x + u) < width && y + v >= 0 && y + v < height) {
                            R = s[channels * (width * (y+v) + (x+u)) + 2];
                            G = s[channels * (width * (y+v) + (x+u)) + 1];
                            B = s[channels * (width * (y+v) + (x+u)) + 0];
                            val[i*3+2] += R * mask[i][u + xBound][v + yBound];
                            val[i*3+1] += G * mask[i][u + xBound][v + yBound];
                            val[i*3+0] += B * mask[i][u + xBound][v + yBound];
                        }    
                    }
                }
            }

            double totalR = 0.0;
            double totalG = 0.0;
            double totalB = 0.0;
            for (i = 0; i < MASK_N; ++i) {
                totalR += val[i * 3 + 2] * val[i * 3 + 2];
                totalG += val[i * 3 + 1] * val[i * 3 + 1];
                totalB += val[i * 3 + 0] * val[i * 3 + 0];
            }

            totalR = sqrt(totalR) / SCALE;
            totalG = sqrt(totalG) / SCALE;
            totalB = sqrt(totalB) / SCALE;
            const unsigned char cR = (totalR > 255.0) ? 255 : totalR;
            const unsigned char cG = (totalG > 255.0) ? 255 : totalG;
            const unsigned char cB = (totalB > 255.0) ? 255 : totalB;
            t[channels * (width * y + x) + 2] = cR;
            t[channels * (width * y + x) + 1] = cG;
            t[channels * (width * y + x) + 0] = cB;
        }
//    }
}

int main(int argc, char** argv) {

    assert(argc == 3);
    unsigned height, width, channels;
    unsigned char* host_s = NULL;
    read_png(argv[1], &host_s, &height, &width, &channels);
    unsigned char* device_s;
    unsigned char* device_t;
    // malloc memory for GPU
    hipMalloc(&device_s, height * width * channels);
    hipMalloc(&device_t, height * width * channels);

    unsigned char* host_t = (unsigned char*) malloc(height * width * channels * sizeof(unsigned char));
    // use cudaMemcpy2D to accelerate
    //cudaMemcpy2D(device_t, channels, device_s, channels, height, width*sizeof(unsigned char), cudaMemcpyHostToDevice);
    hipMemcpy(device_s, host_s, height * width * channels, hipMemcpyHostToDevice);
    // by using multiple threads
    sobel<<<height, 256>>>(device_s, device_t, height, width, channels);
    hipMemcpy(host_t, device_t, height * width * channels, hipMemcpyDeviceToHost);
    write_png(argv[2], host_t, height, width, channels);

    return 0;
}

	.text
	.file	"sobel_cuda.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z8read_pngPKcPPhPjS3_S3_       # -- Begin function _Z8read_pngPKcPPhPjS3_S3_
	.type	_Z8read_pngPKcPPhPjS3_S3_,@function
_Z8read_pngPKcPPhPjS3_S3_:              # @_Z8read_pngPKcPPhPjS3_S3_
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$56, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movq	%r8, -72(%rbp)                  # 8-byte Spill
	movq	%rcx, %r13
	movq	%rdx, %r12
	movq	%rsi, %r15
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %rbx
	leaq	-96(%rbp), %r14
	movl	$1, %esi
	movl	$8, %edx
	movq	%r14, %rdi
	movq	%rax, %rcx
	callq	fread
	movl	$8, %edx
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	png_sig_cmp
	movl	$1, %r14d
	testl	%eax, %eax
	je	.LBB0_1
.LBB0_10:
	movl	%r14d, %eax
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.LBB0_1:
	.cfi_def_cfa %rbp, 16
	movq	%r15, -64(%rbp)                 # 8-byte Spill
	movq	%r13, -56(%rbp)                 # 8-byte Spill
	movl	$.L.str.1, %edi
	xorl	%esi, %esi
	xorl	%edx, %edx
	xorl	%ecx, %ecx
	callq	png_create_read_struct
	movq	%rax, -48(%rbp)
	movl	$4, %r14d
	testq	%rax, %rax
	je	.LBB0_10
# %bb.2:
	movq	%rax, %r15
	movq	%rax, %rdi
	callq	png_create_info_struct
	movq	%rax, -80(%rbp)
	testq	%rax, %rax
	je	.LBB0_3
# %bb.4:
	movq	%rax, %r13
	movq	%r15, %rdi
	movq	%rbx, %rsi
	callq	png_init_io
	movq	-48(%rbp), %rdi
	movl	$8, %esi
	callq	png_set_sig_bytes
	movq	-48(%rbp), %rdi
	movq	%r13, %rsi
	callq	png_read_info
	movq	-48(%rbp), %rdi
	subq	$32, %rsp
	xorps	%xmm0, %xmm0
	movups	%xmm0, (%rsp)
	movq	$0, 16(%rsp)
	leaq	-88(%rbp), %r8
	leaq	-84(%rbp), %r9
	movq	%r13, %rsi
	movq	-56(%rbp), %rdx                 # 8-byte Reload
	movq	%r12, %r14
	movq	%r12, %rcx
	callq	png_get_IHDR
	addq	$32, %rsp
	movq	%rsp, %r15
	movl	(%r12), %eax
	movq	%rsp, %r12
	leaq	15(,%rax,8), %rax
	andq	$-16, %rax
	subq	%rax, %r12
	movq	%r12, %rsp
	movq	-48(%rbp), %rdi
	movq	%r13, %rsi
	callq	png_read_update_info
	movq	-48(%rbp), %rdi
	movq	%r13, %rsi
	callq	png_get_rowbytes
	movq	%rax, %rbx
	movq	-48(%rbp), %rdi
	movq	%r13, %rsi
	callq	png_get_channels
	movzbl	%al, %eax
	movq	-72(%rbp), %rcx                 # 8-byte Reload
	movl	%eax, (%rcx)
	movl	(%r14), %r14d
	movl	%r14d, %edi
	imull	%ebx, %edi
	callq	malloc
	movq	-64(%rbp), %rcx                 # 8-byte Reload
	movq	%rax, (%rcx)
	testq	%rax, %rax
	je	.LBB0_11
# %bb.5:                                # %.preheader
	testq	%r14, %r14
	je	.LBB0_8
# %bb.6:                                # %.lr.ph.preheader
	xorl	%ecx, %ecx
	xorl	%edx, %edx
.LBB0_7:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%ecx, %esi
	addq	%rax, %rsi
	movq	%rsi, (%r12,%rdx,8)
	incq	%rdx
	addq	%rbx, %rcx
	cmpq	%rdx, %r14
	jne	.LBB0_7
.LBB0_8:                                # %._crit_edge
	movq	-48(%rbp), %rdi
	movq	%r12, %rsi
	callq	png_read_image
	movq	-48(%rbp), %rdi
	xorl	%r14d, %r14d
	xorl	%esi, %esi
	callq	png_read_end
	jmp	.LBB0_9
.LBB0_3:
	leaq	-48(%rbp), %rdi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	png_destroy_read_struct
	jmp	.LBB0_10
.LBB0_11:
	leaq	-48(%rbp), %rdi
	leaq	-80(%rbp), %rsi
	xorl	%edx, %edx
	callq	png_destroy_read_struct
	movl	$3, %r14d
.LBB0_9:
	movq	%r15, %rsp
	jmp	.LBB0_10
.Lfunc_end0:
	.size	_Z8read_pngPKcPPhPjS3_S3_, .Lfunc_end0-_Z8read_pngPKcPPhPjS3_S3_
	.cfi_endproc
                                        # -- End function
	.globl	_Z9write_pngPKcPhjjj            # -- Begin function _Z9write_pngPKcPhjjj
	.type	_Z9write_pngPKcPhjjj,@function
_Z9write_pngPKcPhjjj:                   # @_Z9write_pngPKcPhjjj
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$40, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movl	%r8d, %r14d
	movl	%ecx, -44(%rbp)                 # 4-byte Spill
	movl	%edx, -48(%rbp)                 # 4-byte Spill
	movq	%rsi, %r15
	movl	$.L.str.2, %esi
	callq	fopen
	movq	%rax, -56(%rbp)                 # 8-byte Spill
	xorl	%ebx, %ebx
	movl	$.L.str.1, %edi
	xorl	%esi, %esi
	xorl	%edx, %edx
	xorl	%ecx, %ecx
	callq	png_create_write_struct
	movq	%rax, %r12
	movq	%rax, -72(%rbp)
	movq	%rax, %rdi
	callq	png_create_info_struct
	movq	%rax, %r13
	movq	%rax, -64(%rbp)
	movq	%r12, %rdi
	movq	-56(%rbp), %rsi                 # 8-byte Reload
	callq	png_init_io
	subq	$8, %rsp
	movq	%r12, %rdi
	movq	%r13, %rsi
	movl	-44(%rbp), %edx                 # 4-byte Reload
	movl	-48(%rbp), %ecx                 # 4-byte Reload
	movl	$8, %r8d
	movl	$2, %r9d
	pushq	%rbx
	pushq	%rbx
	pushq	%rbx
	callq	png_set_IHDR
	addq	$32, %rsp
	movq	%r12, %rdi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	png_set_filter
	movq	%r12, %rdi
	movq	%r13, %rsi
	callq	png_write_info
	movq	%r12, %rdi
	movl	$1, %esi
	callq	png_set_compression_level
	movq	%rsp, %r13
	movl	-48(%rbp), %edx                 # 4-byte Reload
	movl	%edx, %eax
	movq	%rsp, %rsi
	leaq	15(,%rax,8), %rcx
	andq	$-16, %rcx
	subq	%rcx, %rsi
	movq	%rsi, %rsp
	testl	%edx, %edx
	je	.LBB1_3
# %bb.1:                                # %.lr.ph
	imull	-44(%rbp), %r14d                # 4-byte Folded Reload
	xorl	%ecx, %ecx
.LBB1_2:                                # =>This Inner Loop Header: Depth=1
	movl	%ebx, %edx
	addq	%r15, %rdx
	movq	%rdx, (%rsi,%rcx,8)
	incq	%rcx
	addl	%r14d, %ebx
	cmpq	%rcx, %rax
	jne	.LBB1_2
.LBB1_3:                                # %._crit_edge
	movq	%r12, %rdi
	callq	png_write_image
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	png_write_end
	leaq	-72(%rbp), %rdi
	leaq	-64(%rbp), %rsi
	callq	png_destroy_write_struct
	movq	-56(%rbp), %rdi                 # 8-byte Reload
	callq	fclose
	movq	%r13, %rsp
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.Lfunc_end1:
	.size	_Z9write_pngPKcPhjjj, .Lfunc_end1-_Z9write_pngPKcPhjjj
	.cfi_endproc
                                        # -- End function
	.globl	_Z20__device_stub__sobelPhS_jjj # -- Begin function _Z20__device_stub__sobelPhS_jjj
	.type	_Z20__device_stub__sobelPhS_jjj,@function
_Z20__device_stub__sobelPhS_jjj:        # @_Z20__device_stub__sobelPhS_jjj
	.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	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z5sobelPhS_jjj, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	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_end2:
	.size	_Z20__device_stub__sobelPhS_jjj, .Lfunc_end2-_Z20__device_stub__sobelPhS_jjj
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leaq	48(%rsp), %r12
	movq	$0, (%r12)
	movq	%rsi, 24(%rsp)                  # 8-byte Spill
	movq	8(%rsi), %rdi
	leaq	12(%rsp), %r15
	leaq	8(%rsp), %r14
	leaq	44(%rsp), %r13
	movq	%r12, %rsi
	movq	%r15, %rdx
	movq	%r14, %rcx
	movq	%r13, %r8
	callq	_Z8read_pngPKcPPhPjS3_S3_
	movl	(%r14), %esi
	imull	(%r15), %esi
	movl	(%r13), %ebp
	imull	%ebp, %esi
	leaq	32(%rsp), %r13
	movq	%r13, %rdi
	callq	hipMalloc
	movl	(%r15), %esi
	imull	%ebp, %esi
	imull	(%r14), %esi
	leaq	16(%rsp), %rdi
	callq	hipMalloc
	movl	(%r15), %ebx
	imull	%ebp, %ebx
	imull	(%r14), %ebx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	(%r13), %rdi
	movq	(%r12), %rsi
	movq	%rbx, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	(%r15), %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$256, %rdx                      # imm = 0x100
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_2
# %bb.1:
	movq	32(%rsp), %rdi
	movq	16(%rsp), %rsi
	movl	12(%rsp), %edx
	movl	8(%rsp), %ecx
	movl	%ebp, %r8d
	callq	_Z20__device_stub__sobelPhS_jjj
.LBB3_2:
	movq	16(%rsp), %rsi
	movl	12(%rsp), %edx
	imull	%ebp, %edx
	imull	8(%rsp), %edx
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	24(%rsp), %rax                  # 8-byte Reload
	movq	16(%rax), %rdi
	movl	12(%rsp), %edx
	movl	8(%rsp), %ecx
	movq	%r14, %rsi
	movl	%ebp, %r8d
	callq	_Z9write_pngPKcPhjjj
	xorl	%eax, %eax
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z5sobelPhS_jjj, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$0, 8(%rsp)
	movl	$0, (%rsp)
	movl	$mask, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movl	$200, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	callq	__hipRegisterVar
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	mask,@object                    # @mask
	.local	mask
	.comm	mask,200,16
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"rb"
	.size	.L.str, 3

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

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

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

	.type	.L__unnamed_1,@object           # @0
	.section	.rodata.str1.1,"aMS",@progbits,1
.L__unnamed_1:
	.asciz	"_Z5sobelPhS_jjj"
	.size	.L__unnamed_1, 16

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"mask"
	.size	.L__unnamed_2, 5

	.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 _Z20__device_stub__sobelPhS_jjj
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym mask
	.addrsig_sym _Z5sobelPhS_jjj
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z5sobelPhS_jjj         ; -- Begin function _Z5sobelPhS_jjj
	.globl	_Z5sobelPhS_jjj
	.p2align	8
	.type	_Z5sobelPhS_jjj,@function
_Z5sobelPhS_jjj:                        ; @_Z5sobelPhS_jjj
; %bb.0:
	s_load_b128 s[4:7], s[0:1], 0x10
	s_mov_b32 s2, exec_lo
	s_waitcnt lgkmcnt(0)
	v_cmpx_gt_u32_e64 s5, v0
	s_cbranch_execz .LBB0_13
; %bb.1:                                ; %.preheader125.lr.ph
	s_load_b128 s[8:11], s[0:1], 0x0
	s_add_i32 s2, s15, -2
	s_mov_b32 s16, 0
	s_mul_i32 s0, s5, s2
	s_mov_b32 s17, s16
	v_add3_u32 v1, v0, s0, -2
	s_mov_b32 s18, s16
	s_mov_b32 s19, s16
	s_mov_b32 s20, s16
	s_mov_b32 s21, s16
	v_mad_u64_u32 v[17:18], null, s6, v1, 1
	s_mov_b32 s22, s16
	s_mov_b32 s23, s16
	s_mov_b32 s24, s16
	s_mov_b32 s25, s16
	s_mov_b32 s26, s16
	s_mov_b32 s27, s16
	v_dual_mov_b32 v1, s16 :: v_dual_mov_b32 v2, s17
	v_dual_mov_b32 v3, s18 :: v_dual_mov_b32 v4, s19
	v_dual_mov_b32 v5, s20 :: v_dual_mov_b32 v6, s21
	v_dual_mov_b32 v7, s22 :: v_dual_mov_b32 v8, s23
	v_dual_mov_b32 v9, s24 :: v_dual_mov_b32 v10, s25
	v_dual_mov_b32 v11, s26 :: v_dual_mov_b32 v12, s27
	v_dual_mov_b32 v13, s28 :: v_dual_mov_b32 v14, s29
	v_dual_mov_b32 v15, s30 :: v_dual_mov_b32 v16, s31
	v_mov_b32_e32 v24, 0
	s_mul_i32 s7, s15, s5
	s_lshl_b32 s14, s6, 8
	s_mul_i32 s17, s6, s5
.LBB0_2:                                ; %.preheader125
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_3 Depth 2
                                        ;       Child Loop BB0_4 Depth 3
                                        ;         Child Loop BB0_5 Depth 4
                                        ;     Child Loop BB0_11 Depth 2
	s_mov_b32 s1, -1
	s_mov_b32 s0, 0
.LBB0_3:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB0_4 Depth 3
                                        ;         Child Loop BB0_5 Depth 4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_mul_i32 s12, s0, 3
	s_xor_b32 s1, s1, -1
	s_add_i32 s13, s12, 2
	s_add_i32 s20, s12, 1
	s_lshl_b32 s2, s13, 1
	s_mul_hi_u32 s19, s0, 0x64
	s_mov_b32 m0, s2
	s_lshl_b32 s2, s20, 1
	v_movreld_b32_e32 v1, 0
	v_movreld_b32_e32 v2, 0
	s_mov_b32 m0, s2
	s_lshl_b32 s18, s12, 1
	s_mulk_i32 s0, 0x64
	v_mov_b32_e32 v18, v17
	v_movreld_b32_e32 v1, 0
	s_getpc_b64 s[2:3]
	s_add_u32 s2, s2, mask@rel32@lo+4
	s_addc_u32 s3, s3, mask@rel32@hi+12
	v_movreld_b32_e32 v2, 0
	s_mov_b32 m0, s18
	s_add_u32 s2, s0, s2
	s_mov_b32 s18, -2
	s_addc_u32 s3, s19, s3
	s_lshl_b32 s19, s13, 1
	s_lshl_b32 s20, s20, 1
	s_lshl_b32 s21, s12, 1
	v_movreld_b32_e32 v1, 0
	v_movreld_b32_e32 v2, 0
.LBB0_4:                                ; %.preheader
                                        ;   Parent Loop BB0_2 Depth=1
                                        ;     Parent Loop BB0_3 Depth=2
                                        ; =>    This Loop Header: Depth=3
                                        ;         Child Loop BB0_5 Depth 4
	s_add_i32 s0, s18, s15
	v_mov_b32_e32 v19, v18
	s_cmp_lt_i32 s0, 0
	s_mov_b64 s[12:13], s[2:3]
	s_cselect_b32 s22, -1, 0
	s_cmp_ge_u32 s0, s4
	s_mov_b32 s23, -2
	s_cselect_b32 s0, -1, 0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 s22, s22, s0
.LBB0_5:                                ;   Parent Loop BB0_2 Depth=1
                                        ;     Parent Loop BB0_3 Depth=2
                                        ;       Parent Loop BB0_4 Depth=3
                                        ; =>      This Inner Loop Header: Depth=4
	v_add_nc_u32_e32 v20, s23, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cmp_gt_i32_e32 vcc_lo, 0, v20
	v_cmp_le_u32_e64 s0, s5, v20
	s_or_b32 s0, vcc_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_or_b32 s0, s0, s22
	s_xor_b32 s24, s0, -1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s0, s24
	s_cbranch_execz .LBB0_7
; %bb.6:                                ;   in Loop: Header=BB0_5 Depth=4
	v_add_nc_u32_e32 v20, 1, v19
	v_add_nc_u32_e32 v21, -1, v19
	s_mov_b32 m0, s19
	global_load_b32 v25, v24, s[12:13]
	s_waitcnt lgkmcnt(0)
	s_clause 0x1
	global_load_u8 v20, v20, s[8:9]
	global_load_u8 v26, v19, s[8:9]
	v_movrels_b32_e32 v23, v2
	global_load_u8 v27, v21, s[8:9]
	v_movrels_b32_e32 v22, v1
	s_waitcnt vmcnt(2)
	v_mul_lo_u32 v20, v25, v20
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_f64_i32_e32 v[20:21], v20
	v_add_f64 v[20:21], v[22:23], v[20:21]
	s_waitcnt vmcnt(1)
	v_mul_lo_u32 v22, v25, v26
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cvt_f64_i32_e32 v[22:23], v22
	v_movreld_b32_e32 v1, v20
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_movreld_b32_e32 v2, v21
	s_mov_b32 m0, s20
	v_movrels_b32_e32 v21, v2
	v_movrels_b32_e32 v20, v1
	v_add_f64 v[20:21], v[20:21], v[22:23]
	s_waitcnt vmcnt(0)
	v_mul_lo_u32 v22, v25, v27
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cvt_f64_i32_e32 v[22:23], v22
	v_movreld_b32_e32 v1, v20
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_movreld_b32_e32 v2, v21
	s_mov_b32 m0, s21
	v_movrels_b32_e32 v21, v2
	v_movrels_b32_e32 v20, v1
	v_add_f64 v[20:21], v[20:21], v[22:23]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_movreld_b32_e32 v1, v20
	v_movreld_b32_e32 v2, v21
.LBB0_7:                                ;   in Loop: Header=BB0_5 Depth=4
	s_or_b32 exec_lo, exec_lo, s0
	s_add_i32 s23, s23, 1
	v_add_nc_u32_e32 v19, s6, v19
	s_add_u32 s12, s12, 20
	s_addc_u32 s13, s13, 0
	s_cmp_lg_u32 s23, 3
	s_cbranch_scc1 .LBB0_5
; %bb.8:                                ;   in Loop: Header=BB0_4 Depth=3
	s_add_i32 s18, s18, 1
	v_add_nc_u32_e32 v18, s17, v18
	s_add_u32 s2, s2, 4
	s_addc_u32 s3, s3, 0
	s_cmp_lg_u32 s18, 3
	s_cbranch_scc1 .LBB0_4
; %bb.9:                                ;   in Loop: Header=BB0_3 Depth=2
	s_mov_b32 s0, 1
	s_and_not1_b32 vcc_lo, exec_lo, s1
	s_mov_b32 s1, 0
	s_cbranch_vccnz .LBB0_3
; %bb.10:                               ; %.preheader124.preheader
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_mov_b32_e32 v18, 0
	v_mov_b32_e32 v19, 0
	s_mov_b32 s0, -1
	s_delay_alu instid0(VALU_DEP_1)
	v_dual_mov_b32 v21, v19 :: v_dual_mov_b32 v20, v18
	v_dual_mov_b32 v23, v19 :: v_dual_mov_b32 v22, v18
.LBB0_11:                               ; %.preheader124
                                        ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_lshl_b32 s1, s1, 1
	s_and_b32 vcc_lo, exec_lo, s0
	s_add_i32 s2, s1, 5
	s_add_i32 s3, s1, 4
	s_mov_b32 m0, s2
	s_add_i32 s12, s1, 3
	v_movrels_b32_e32 v26, v1
	s_mov_b32 m0, s3
	s_add_i32 s13, s1, 2
	v_movrels_b32_e32 v25, v1
	s_mov_b32 m0, s12
	s_mov_b32 s0, 0
	v_movrels_b32_e32 v28, v1
	s_mov_b32 m0, s13
	v_fma_f64 v[22:23], v[25:26], v[25:26], v[22:23]
	v_movrels_b32_e32 v27, v1
	s_mov_b32 m0, s1
	s_mov_b32 s1, 3
	v_movrels_b32_e32 v30, v2
	v_movrels_b32_e32 v29, v1
	v_fma_f64 v[20:21], v[27:28], v[27:28], v[20:21]
	s_delay_alu instid0(VALU_DEP_2)
	v_fma_f64 v[18:19], v[29:30], v[29:30], v[18:19]
	s_cbranch_vccnz .LBB0_11
; %bb.12:                               ;   in Loop: Header=BB0_2 Depth=1
	v_cmp_gt_f64_e32 vcc_lo, 0x10000000, v[22:23]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cmp_gt_f64_e64 s0, 0x10000000, v[20:21]
	v_cmp_gt_f64_e64 s1, 0x10000000, v[18:19]
	v_add_nc_u32_e32 v17, s14, v17
	v_cndmask_b32_e64 v25, 0, 1, vcc_lo
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cndmask_b32_e64 v26, 0, 1, s0
	v_cndmask_b32_e64 v27, 0, 1, s1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b32_e32 v25, 8, v25
	v_lshlrev_b32_e32 v26, 8, v26
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ldexp_f64 v[22:23], v[22:23], v25
	v_ldexp_f64 v[20:21], v[20:21], v26
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_rsq_f64_e32 v[25:26], v[22:23]
	s_waitcnt_depctr 0xfff
	v_mul_f64 v[31:32], v[22:23], v[25:26]
	v_mul_f64 v[25:26], v[25:26], 0.5
	v_fma_f64 v[37:38], -v[25:26], v[31:32], 0.5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_fma_f64 v[31:32], v[31:32], v[37:38], v[31:32]
	v_fma_f64 v[25:26], v[25:26], v[37:38], v[25:26]
	v_fma_f64 v[37:38], -v[31:32], v[31:32], v[22:23]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[31:32], v[37:38], v[25:26], v[31:32]
	v_fma_f64 v[37:38], -v[31:32], v[31:32], v[22:23]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_4)
	v_fma_f64 v[25:26], v[37:38], v[25:26], v[31:32]
	v_cndmask_b32_e64 v31, 0, 0xffffff80, vcc_lo
	v_cmp_class_f64_e64 vcc_lo, v[22:23], 0x260
	v_cndmask_b32_e64 v32, 0, 0xffffff80, s0
	v_cmp_class_f64_e64 s0, v[20:21], 0x260
	v_ldexp_f64 v[25:26], v[25:26], v31
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_cndmask_b32 v22, v25, v22 :: v_dual_lshlrev_b32 v27, 8, v27
	v_ldexp_f64 v[18:19], v[18:19], v27
	v_rsq_f64_e32 v[27:28], v[20:21]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v23, v26, v23, vcc_lo
	v_rsq_f64_e32 v[29:30], v[18:19]
	s_waitcnt_depctr 0xfff
	v_mul_f64 v[33:34], v[20:21], v[27:28]
	v_mul_f64 v[27:28], v[27:28], 0.5
	v_mul_f64 v[35:36], v[18:19], v[29:30]
	v_mul_f64 v[29:30], v[29:30], 0.5
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[39:40], -v[27:28], v[33:34], 0.5
	v_fma_f64 v[41:42], -v[29:30], v[35:36], 0.5
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_fma_f64 v[33:34], v[33:34], v[39:40], v[33:34]
	v_fma_f64 v[27:28], v[27:28], v[39:40], v[27:28]
	v_fma_f64 v[35:36], v[35:36], v[41:42], v[35:36]
	v_fma_f64 v[29:30], v[29:30], v[41:42], v[29:30]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fma_f64 v[39:40], -v[33:34], v[33:34], v[20:21]
	v_fma_f64 v[41:42], -v[35:36], v[35:36], v[18:19]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[33:34], v[39:40], v[27:28], v[33:34]
	v_fma_f64 v[35:36], v[41:42], v[29:30], v[35:36]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[39:40], -v[33:34], v[33:34], v[20:21]
	v_fma_f64 v[41:42], -v[35:36], v[35:36], v[18:19]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_4)
	v_fma_f64 v[27:28], v[39:40], v[27:28], v[33:34]
	v_cndmask_b32_e64 v33, 0, 0xffffff80, s1
	v_cmp_class_f64_e64 s1, v[18:19], 0x260
	v_fma_f64 v[29:30], v[41:42], v[29:30], v[35:36]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ldexp_f64 v[27:28], v[27:28], v32
	v_ldexp_f64 v[29:30], v[29:30], v33
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v21, v28, v21, s0
	v_cndmask_b32_e64 v20, v27, v20, s0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_ldexp_f64 v[20:21], v[20:21], -3
	v_cndmask_b32_e64 v19, v30, v19, s1
	v_cndmask_b32_e64 v18, v29, v18, s1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_ldexp_f64 v[18:19], v[18:19], -3
	v_cmp_nlt_f64_e32 vcc_lo, 0x406fe000, v[20:21]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_cmp_nlt_f64_e64 s1, 0x406fe000, v[18:19]
	v_cndmask_b32_e32 v21, 0x406fe000, v21, vcc_lo
	v_cndmask_b32_e32 v20, 0, v20, vcc_lo
	v_cvt_i32_f64_e32 v20, v[20:21]
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v19, 0x406fe000, v19, s1
	v_cndmask_b32_e64 v18, 0, v18, s1
	v_cvt_i32_f64_e32 v18, v[18:19]
	v_add_nc_u32_e32 v19, s7, v0
	v_add_nc_u32_e32 v0, 0x100, v0
	v_ldexp_f64 v[22:23], v[22:23], -3
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_mul_lo_u32 v19, v19, s6
	v_cmp_le_u32_e32 vcc_lo, s5, v0
	s_or_b32 s16, vcc_lo, s16
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_nlt_f64_e64 s0, 0x406fe000, v[22:23]
	v_cndmask_b32_e64 v23, 0x406fe000, v23, s0
	v_cndmask_b32_e64 v22, 0, v22, s0
	s_delay_alu instid0(VALU_DEP_1)
	v_cvt_i32_f64_e32 v21, v[22:23]
	v_add_nc_u32_e32 v22, 1, v19
	v_add_nc_u32_e32 v23, 2, v19
	s_waitcnt lgkmcnt(0)
	s_clause 0x2
	global_store_b8 v22, v20, s[10:11]
	global_store_b8 v23, v21, s[10:11]
	global_store_b8 v19, v18, s[10:11]
	s_and_not1_b32 exec_lo, exec_lo, s16
	s_cbranch_execnz .LBB0_2
.LBB0_13:                               ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z5sobelPhS_jjj
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 28
		.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 43
		.amdhsa_next_free_sgpr 32
		.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	_Z5sobelPhS_jjj, .Lfunc_end0-_Z5sobelPhS_jjj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1600
; NumSgprs: 34
; NumVgprs: 43
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 4
; VGPRBlocks: 5
; NumSGPRsForWavesPerEU: 34
; NumVGPRsForWavesPerEU: 43
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.protected	mask                    ; @mask
	.type	mask,@object
	.data
	.globl	mask
	.p2align	4, 0x0
mask:
	.long	4294967295                      ; 0xffffffff
	.long	4294967292                      ; 0xfffffffc
	.long	4294967290                      ; 0xfffffffa
	.long	4294967292                      ; 0xfffffffc
	.long	4294967295                      ; 0xffffffff
	.long	4294967294                      ; 0xfffffffe
	.long	4294967288                      ; 0xfffffff8
	.long	4294967284                      ; 0xfffffff4
	.long	4294967288                      ; 0xfffffff8
	.long	4294967294                      ; 0xfffffffe
	.zero	20
	.long	2                               ; 0x2
	.long	8                               ; 0x8
	.long	12                              ; 0xc
	.long	8                               ; 0x8
	.long	2                               ; 0x2
	.long	1                               ; 0x1
	.long	4                               ; 0x4
	.long	6                               ; 0x6
	.long	4                               ; 0x4
	.long	1                               ; 0x1
	.long	4294967295                      ; 0xffffffff
	.long	4294967294                      ; 0xfffffffe
	.long	0                               ; 0x0
	.long	2                               ; 0x2
	.long	1                               ; 0x1
	.long	4294967292                      ; 0xfffffffc
	.long	4294967288                      ; 0xfffffff8
	.long	0                               ; 0x0
	.long	8                               ; 0x8
	.long	4                               ; 0x4
	.long	4294967290                      ; 0xfffffffa
	.long	4294967284                      ; 0xfffffff4
	.long	0                               ; 0x0
	.long	12                              ; 0xc
	.long	6                               ; 0x6
	.long	4294967292                      ; 0xfffffffc
	.long	4294967288                      ; 0xfffffff8
	.long	0                               ; 0x0
	.long	8                               ; 0x8
	.long	4                               ; 0x4
	.long	4294967295                      ; 0xffffffff
	.long	4294967294                      ; 0xfffffffe
	.long	0                               ; 0x0
	.long	2                               ; 0x2
	.long	1                               ; 0x1
	.size	mask, 200

	.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 mask
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 28
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z5sobelPhS_jjj
    .private_segment_fixed_size: 0
    .sgpr_count:     34
    .sgpr_spill_count: 0
    .symbol:         _Z5sobelPhS_jjj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     43
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
