#include <stdlib.h>
#include <stdio.h>
#include <jpeglib.h>
#include <jerror.h>
#include "image.cuh"

// load and save functions from https://www.tspi.at/2020/03/20/libjpegexample.html
struct imgRawImage* loadJpegImageFile(char* lpFilename) {
	struct jpeg_decompress_struct info;
	struct jpeg_error_mgr err;

	struct imgRawImage* lpNewImage;

	unsigned long int imgWidth, imgHeight;
	int numComponents;

	unsigned long int dwBufferBytes;
	unsigned char* lpData;

	unsigned char* lpRowBuffer[1];

	FILE* fHandle;

	fHandle = fopen(lpFilename, "rb");
	if(fHandle == NULL) {
		#ifdef DEBUG
			fprintf(stderr, "%s:%u: Failed to read file %s\n", __FILE__, __LINE__, lpFilename);
		#endif
		return NULL; /* ToDo */
	}

	info.err = jpeg_std_error(&err);
	jpeg_create_decompress(&info);

	jpeg_stdio_src(&info, fHandle);
	jpeg_read_header(&info, TRUE);

	jpeg_start_decompress(&info);
	imgWidth = info.output_width;
	imgHeight = info.output_height;
	numComponents = info.num_components;

	#ifdef DEBUG
		fprintf(
			stderr,
			"%s:%u: Reading JPEG with dimensions %lu x %lu and %u components\n",
			__FILE__, __LINE__,
			imgWidth, imgHeight, numComponents
		);
	#endif

	dwBufferBytes = imgWidth * imgHeight * 3; /* We only read RGB, not A */
	lpData = (unsigned char*)malloc(sizeof(unsigned char)*dwBufferBytes);

	lpNewImage = (struct imgRawImage*)malloc(sizeof(struct imgRawImage));
	lpNewImage->numComponents = numComponents;
	lpNewImage->width = imgWidth;
	lpNewImage->height = imgHeight;
	lpNewImage->lpData = lpData;

	/* Read scanline by scanline */
	while(info.output_scanline < info.output_height) {
		lpRowBuffer[0] = (unsigned char *)(&lpData[3*info.output_width*info.output_scanline]);
		jpeg_read_scanlines(&info, lpRowBuffer, 1);
	}

	jpeg_finish_decompress(&info);
	jpeg_destroy_decompress(&info);
	fclose(fHandle);

	return lpNewImage;
}

int storeJpegImageFile(struct imgRawImage* lpImage, char* lpFilename) {
	struct jpeg_compress_struct info;
	struct jpeg_error_mgr err;

	unsigned char* lpRowBuffer[1];

	FILE* fHandle;

	fHandle = fopen(lpFilename, "wb");
	if(fHandle == NULL) {
			fprintf(stderr, "%s:%u Failed to open output file %s\n", __FILE__, __LINE__, lpFilename);
		return 1;
	}

	info.err = jpeg_std_error(&err);
	jpeg_create_compress(&info);

	jpeg_stdio_dest(&info, fHandle);

	info.image_width = lpImage->width;
	info.image_height = lpImage->height;
	info.input_components = 3;
	info.in_color_space = JCS_RGB;

	jpeg_set_defaults(&info);
	jpeg_set_quality(&info, 100, TRUE);

	jpeg_start_compress(&info, TRUE);

	/* Write every scanline ... */
	while(info.next_scanline < info.image_height) {
		lpRowBuffer[0] = &(lpImage->lpData[info.next_scanline * (lpImage->width * 3)]);
		jpeg_write_scanlines(&info, lpRowBuffer, 1);
	}

	jpeg_finish_compress(&info);
	fclose(fHandle);

	jpeg_destroy_compress(&info);
	return 0;
}


	.file	"tmpxft_00237f31_00000000-6_image.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"rb"
	.text
	.globl	_Z17loadJpegImageFilePc
	.type	_Z17loadJpegImageFilePc, @function
_Z17loadJpegImageFilePc:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC0(%rip), %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$872, %rsp
	.cfi_def_cfa_offset 928
	movq	%fs:40, %rax
	movq	%rax, 856(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.L2
	leaq	32(%rsp), %rdi
	call	jpeg_std_error@PLT
	movl	$656, %edx
	movl	$80, %esi
	movq	%rax, 200(%rsp)
	leaq	200(%rsp), %rax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	jpeg_CreateDecompress@PLT
	movq	8(%rsp), %rdi
	movq	%rbx, %rsi
	call	jpeg_stdio_src@PLT
	movq	8(%rsp), %rdi
	movl	$1, %esi
	call	jpeg_read_header@PLT
	movq	8(%rsp), %rdi
	call	jpeg_start_decompress@PLT
	movl	336(%rsp), %r15d
	movl	340(%rsp), %r13d
	movl	256(%rsp), %ebp
	movq	%r15, %rdi
	imulq	%r13, %rdi
	leaq	(%rdi,%rdi,2), %rdi
	call	malloc@PLT
	movl	$32, %edi
	movq	%rax, %r12
	call	malloc@PLT
	movl	%ebp, (%rax)
	movq	%rax, %r14
	movq	%r15, 8(%rax)
	movq	%r12, 24(%rax)
	movq	%r13, 16(%rax)
	leaq	24(%rsp), %r13
.L4:
	movl	368(%rsp), %eax
	cmpl	340(%rsp), %eax
	jnb	.L12
	imull	336(%rsp), %eax
	movq	8(%rsp), %rdi
	movl	$1, %edx
	movq	%r13, %rsi
	imull	$3, %eax, %eax
	addq	%r12, %rax
	movq	%rax, 24(%rsp)
	call	jpeg_read_scanlines@PLT
	jmp	.L4
.L12:
	movq	8(%rsp), %rdi
	call	jpeg_finish_decompress@PLT
	movq	8(%rsp), %rdi
	call	jpeg_destroy_decompress@PLT
	movq	%rbx, %rdi
	movq	%r14, %rbx
	call	fclose@PLT
.L2:
	movq	856(%rsp), %rax
	subq	%fs:40, %rax
	je	.L6
	call	__stack_chk_fail@PLT
.L6:
	addq	$872, %rsp
	.cfi_def_cfa_offset 56
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z17loadJpegImageFilePc, .-_Z17loadJpegImageFilePc
	.section	.rodata.str1.1
.LC1:
	.string	"wb"
.LC2:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/Cybren/EinfParaAPGAS_CUDA/main/CUDA/image.cu"
.LC3:
	.string	"%s:%u Failed to open output file %s\n"
	.text
	.globl	_Z18storeJpegImageFileP11imgRawImagePc
	.type	_Z18storeJpegImageFileP11imgRawImagePc, @function
_Z18storeJpegImageFileP11imgRawImagePc:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rsi, %r9
	leaq	.LC1(%rip), %rsi
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rdi, %rbp
	movq	%r9, %rdi
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$792, %rsp
	.cfi_def_cfa_offset 832
	movq	%fs:40, %rax
	movq	%rax, 776(%rsp)
	xorl	%eax, %eax
	movq	%r9, 8(%rsp)
	call	fopen@PLT
	movq	8(%rsp), %r9
	testq	%rax, %rax
	jne	.L14
	movq	stderr(%rip), %rdi
	movl	$84, %r8d
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rcx
	leaq	.LC3(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	$1, %eax
	jmp	.L13
.L14:
	leaq	192(%rsp), %rbx
	leaq	24(%rsp), %rdi
	movq	%rax, %r12
	call	jpeg_std_error@PLT
	movl	$584, %edx
	movl	$80, %esi
	movq	%rbx, %rdi
	movq	%rax, 192(%rsp)
	leaq	16(%rsp), %r13
	call	jpeg_CreateCompress@PLT
	movq	%r12, %rsi
	movq	%rbx, %rdi
	call	jpeg_stdio_dest@PLT
	movq	8(%rbp), %rax
	movq	%rbx, %rdi
	movl	%eax, 240(%rsp)
	movq	16(%rbp), %rax
	movl	%eax, 244(%rsp)
	movabsq	$8589934595, %rax
	movq	%rax, 248(%rsp)
	call	jpeg_set_defaults@PLT
	movl	$1, %edx
	movl	$100, %esi
	movq	%rbx, %rdi
	call	jpeg_set_quality@PLT
	movl	$1, %esi
	movq	%rbx, %rdi
	call	jpeg_start_compress@PLT
.L16:
	movl	532(%rsp), %eax
	cmpl	244(%rsp), %eax
	jnb	.L20
	imulq	8(%rbp), %rax
	movl	$1, %edx
	movq	%r13, %rsi
	movq	%rbx, %rdi
	leaq	(%rax,%rax,2), %rax
	addq	24(%rbp), %rax
	movq	%rax, 16(%rsp)
	call	jpeg_write_scanlines@PLT
	jmp	.L16
.L20:
	movq	%rbx, %rdi
	call	jpeg_finish_compress@PLT
	movq	%r12, %rdi
	call	fclose@PLT
	movq	%rbx, %rdi
	call	jpeg_destroy_compress@PLT
	xorl	%eax, %eax
.L13:
	movq	776(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	addq	$792, %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
.LFE2028:
	.size	_Z18storeJpegImageFileP11imgRawImagePc, .-_Z18storeJpegImageFileP11imgRawImagePc
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2054:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2054:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdlib.h>
#include <stdio.h>
#include <jpeglib.h>
#include <jerror.h>
#include "image.cuh"

// load and save functions from https://www.tspi.at/2020/03/20/libjpegexample.html
struct imgRawImage* loadJpegImageFile(char* lpFilename) {
	struct jpeg_decompress_struct info;
	struct jpeg_error_mgr err;

	struct imgRawImage* lpNewImage;

	unsigned long int imgWidth, imgHeight;
	int numComponents;

	unsigned long int dwBufferBytes;
	unsigned char* lpData;

	unsigned char* lpRowBuffer[1];

	FILE* fHandle;

	fHandle = fopen(lpFilename, "rb");
	if(fHandle == NULL) {
		#ifdef DEBUG
			fprintf(stderr, "%s:%u: Failed to read file %s\n", __FILE__, __LINE__, lpFilename);
		#endif
		return NULL; /* ToDo */
	}

	info.err = jpeg_std_error(&err);
	jpeg_create_decompress(&info);

	jpeg_stdio_src(&info, fHandle);
	jpeg_read_header(&info, TRUE);

	jpeg_start_decompress(&info);
	imgWidth = info.output_width;
	imgHeight = info.output_height;
	numComponents = info.num_components;

	#ifdef DEBUG
		fprintf(
			stderr,
			"%s:%u: Reading JPEG with dimensions %lu x %lu and %u components\n",
			__FILE__, __LINE__,
			imgWidth, imgHeight, numComponents
		);
	#endif

	dwBufferBytes = imgWidth * imgHeight * 3; /* We only read RGB, not A */
	lpData = (unsigned char*)malloc(sizeof(unsigned char)*dwBufferBytes);

	lpNewImage = (struct imgRawImage*)malloc(sizeof(struct imgRawImage));
	lpNewImage->numComponents = numComponents;
	lpNewImage->width = imgWidth;
	lpNewImage->height = imgHeight;
	lpNewImage->lpData = lpData;

	/* Read scanline by scanline */
	while(info.output_scanline < info.output_height) {
		lpRowBuffer[0] = (unsigned char *)(&lpData[3*info.output_width*info.output_scanline]);
		jpeg_read_scanlines(&info, lpRowBuffer, 1);
	}

	jpeg_finish_decompress(&info);
	jpeg_destroy_decompress(&info);
	fclose(fHandle);

	return lpNewImage;
}

int storeJpegImageFile(struct imgRawImage* lpImage, char* lpFilename) {
	struct jpeg_compress_struct info;
	struct jpeg_error_mgr err;

	unsigned char* lpRowBuffer[1];

	FILE* fHandle;

	fHandle = fopen(lpFilename, "wb");
	if(fHandle == NULL) {
			fprintf(stderr, "%s:%u Failed to open output file %s\n", __FILE__, __LINE__, lpFilename);
		return 1;
	}

	info.err = jpeg_std_error(&err);
	jpeg_create_compress(&info);

	jpeg_stdio_dest(&info, fHandle);

	info.image_width = lpImage->width;
	info.image_height = lpImage->height;
	info.input_components = 3;
	info.in_color_space = JCS_RGB;

	jpeg_set_defaults(&info);
	jpeg_set_quality(&info, 100, TRUE);

	jpeg_start_compress(&info, TRUE);

	/* Write every scanline ... */
	while(info.next_scanline < info.image_height) {
		lpRowBuffer[0] = &(lpImage->lpData[info.next_scanline * (lpImage->width * 3)]);
		jpeg_write_scanlines(&info, lpRowBuffer, 1);
	}

	jpeg_finish_compress(&info);
	fclose(fHandle);

	jpeg_destroy_compress(&info);
	return 0;
}


	.text
	.file	"image.hip"
	.globl	_Z17loadJpegImageFilePc         # -- Begin function _Z17loadJpegImageFilePc
	.type	_Z17loadJpegImageFilePc,@function
_Z17loadJpegImageFilePc:                # @_Z17loadJpegImageFilePc
	.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	$840, %rsp                      # imm = 0x348
	.cfi_def_cfa_offset 896
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$.L.str, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_1
# %bb.2:
	movq	%rax, %rbx
	leaq	672(%rsp), %rdi
	callq	jpeg_std_error
	leaq	16(%rsp), %r15
	movq	%rax, (%r15)
	movl	$656, %edx                      # imm = 0x290
	movq	%r15, %rdi
	movl	$80, %esi
	callq	jpeg_CreateDecompress
	movq	%r15, %rdi
	movq	%rbx, (%rsp)                    # 8-byte Spill
	movq	%rbx, %rsi
	callq	jpeg_stdio_src
	movq	%r15, %rdi
	movl	$1, %esi
	callq	jpeg_read_header
	movq	%r15, %rdi
	callq	jpeg_start_decompress
	movl	56(%r15), %ebp
	movl	136(%r15), %r13d
	movl	140(%r15), %ebx
	movq	%r13, %rax
	imulq	%rbx, %rax
	leaq	(%rax,%rax,2), %rdi
	callq	malloc
	movq	%rax, %r12
	movl	$32, %edi
	callq	malloc
	movq	%rax, %r14
	movl	%ebp, (%rax)
	movq	%r13, 8(%rax)
	movq	%rbx, 16(%rax)
	movq	%r12, 24(%rax)
	movl	168(%r15), %eax
	cmpl	%ebx, %eax
	jae	.LBB0_5
# %bb.3:                                # %.lr.ph.preheader
	leaq	16(%rsp), %r15
	leaq	8(%rsp), %r13
.LBB0_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	imull	152(%rsp), %eax
	leal	(%rax,%rax,2), %eax
	addq	%r12, %rax
	movq	%rax, 8(%rsp)
	movq	%r15, %rdi
	movq	%r13, %rsi
	movl	$1, %edx
	callq	jpeg_read_scanlines
	movl	184(%rsp), %eax
	cmpl	156(%rsp), %eax
	jb	.LBB0_4
.LBB0_5:                                # %._crit_edge
	leaq	16(%rsp), %r15
	movq	%r15, %rdi
	callq	jpeg_finish_decompress
	movq	%r15, %rdi
	callq	jpeg_destroy_decompress
	movq	(%rsp), %rdi                    # 8-byte Reload
	callq	fclose
	jmp	.LBB0_6
.LBB0_1:
	xorl	%r14d, %r14d
.LBB0_6:
	movq	%r14, %rax
	addq	$840, %rsp                      # imm = 0x348
	.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_end0:
	.size	_Z17loadJpegImageFilePc, .Lfunc_end0-_Z17loadJpegImageFilePc
	.cfi_endproc
                                        # -- End function
	.globl	_Z18storeJpegImageFileP11imgRawImagePc # -- Begin function _Z18storeJpegImageFileP11imgRawImagePc
	.type	_Z18storeJpegImageFileP11imgRawImagePc,@function
_Z18storeJpegImageFileP11imgRawImagePc: # @_Z18storeJpegImageFileP11imgRawImagePc
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	subq	$760, %rsp                      # imm = 0x2F8
	.cfi_def_cfa_offset 800
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %r15
	movq	%rdi, %rbx
	movl	$.L.str.1, %esi
	movq	%r15, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_1
# %bb.2:
	movq	%rax, %r14
	leaq	592(%rsp), %rdi
	callq	jpeg_std_error
	leaq	8(%rsp), %r15
	movq	%rax, (%r15)
	movl	$584, %edx                      # imm = 0x248
	movq	%r15, %rdi
	movl	$80, %esi
	callq	jpeg_CreateCompress
	movq	%r15, %rdi
	movq	%r14, %rsi
	callq	jpeg_stdio_dest
	movl	8(%rbx), %eax
	movl	%eax, 48(%r15)
	movl	16(%rbx), %eax
	movl	%eax, 52(%r15)
	movabsq	$8589934595, %rax               # imm = 0x200000003
	movq	%rax, 56(%r15)
	movq	%r15, %rdi
	callq	jpeg_set_defaults
	movq	%r15, %rdi
	movl	$100, %esi
	movl	$1, %edx
	callq	jpeg_set_quality
	movq	%r15, %rdi
	movl	$1, %esi
	callq	jpeg_start_compress
	movl	340(%r15), %eax
	cmpl	52(%r15), %eax
	jae	.LBB1_5
# %bb.3:                                # %.lr.ph
	leaq	8(%rsp), %r15
	movq	%rsp, %r12
.LBB1_4:                                # =>This Inner Loop Header: Depth=1
	movl	%eax, %eax
	imulq	8(%rbx), %rax
	leaq	(%rax,%rax,2), %rax
	addq	24(%rbx), %rax
	movq	%rax, (%rsp)
	movq	%r15, %rdi
	movq	%r12, %rsi
	movl	$1, %edx
	callq	jpeg_write_scanlines
	movl	348(%rsp), %eax
	cmpl	60(%rsp), %eax
	jb	.LBB1_4
.LBB1_5:                                # %._crit_edge
	leaq	8(%rsp), %rbx
	movq	%rbx, %rdi
	callq	jpeg_finish_compress
	movq	%r14, %rdi
	callq	fclose
	movq	%rbx, %rdi
	callq	jpeg_destroy_compress
	xorl	%eax, %eax
.LBB1_6:
	addq	$760, %rsp                      # imm = 0x2F8
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB1_1:
	.cfi_def_cfa_offset 800
	movq	stderr(%rip), %rdi
	movl	$.L.str.2, %esi
	movl	$.L.str.3, %edx
	movl	$86, %ecx
	movq	%r15, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %eax
	jmp	.LBB1_6
.Lfunc_end1:
	.size	_Z18storeJpegImageFileP11imgRawImagePc, .Lfunc_end1-_Z18storeJpegImageFileP11imgRawImagePc
	.cfi_endproc
                                        # -- End function
	.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	"wb"
	.size	.L.str.1, 3

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%s:%u Failed to open output file %s\n"
	.size	.L.str.2, 37

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/Cybren/EinfParaAPGAS_CUDA/main/CUDA/image.hip"
	.size	.L.str.3, 108

	.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 __hip_cuid_

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

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

	.end_amdgpu_metadata
