#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>

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

#define ASCIIMIN 32
#define ASCIIMAX 126

#define CHARS_PER_THREADS 256
#define THREADS_PER_BLOCK 256

void __global__ kernel(int nLines, char* dev_chars, int nChars, int* dev_counts, int nCounts) {
	const unsigned int tidb = threadIdx.x;
	const unsigned int ti = blockIdx.x*blockDim.x + tidb;

	__shared__ int shared_counts[ASCIIMAX - ASCIIMIN + 1];

	if (tidb == 0) {
		for (int i = 0; i < ASCIIMAX - ASCIIMIN - 1; ++i) {
			shared_counts[i] = 0;
		}
	}

	__syncthreads();

	if (ti < nLines) {
		for (int i = 0; i < CHARS_PER_THREADS; ++i) {
			int ascii = (int)dev_chars[CHARS_PER_THREADS * ti + i];
			atomicAdd(&shared_counts[ascii - ASCIIMIN], 1);
		}
	}

	__syncthreads();

	if (tidb == 0) {
		for (int i = 0; i < nCounts; ++i) {
			atomicAdd(&dev_counts[i], shared_counts[i]);
		}
	}
}

int isValid(char* c){
	int asciicode = (int)*c;
	int valid = (asciicode <= 126);
	valid = valid && (asciicode >= 32);
	return valid;
}

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

	clock_t t1, t2;
	printf("Initialisation...\n");
	t1 = clock();

	//Declarations
	FILE* inputFile =  NULL;
	FILE* outputFile =  NULL;
	char* inputFileName = NULL;
	char* outputFileName = NULL;

	int nChars = 0;
	char* chars;
	int nCounts = ASCIIMAX - ASCIIMIN + 1;
	int* counts;

	char* dev_chars;
	int* dev_counts;

	int opt;

	//Get comand line options
	while ((opt = getopt (argc, argv, "i:o:")) != -1) {
		switch(opt) {
			case 'i':
				inputFileName = optarg;
				break;
			case 'o':
				outputFileName = optarg;
				break;
		}
	}

	//Count number of chars in inputFile
	inputFile = fopen(inputFileName,"r");
	if (!inputFile) return 1;
	nChars = 0;
	for (char c = getc(inputFile); c != EOF; c = getc(inputFile)){
		if(isValid(&c)) ++nChars;
	}
	fclose(inputFile);

	//Allocate memory
	counts = (int*) malloc(nCounts * sizeof(int));
	chars = (char*) malloc(nChars * sizeof(char));
	if(chars == NULL) {
		printf("Input file too large!\n");
		return 1;
	}
	printf("%d chars processed\n", nChars);
	cudaMalloc( (void**)&dev_chars, nChars * sizeof(char));
	cudaMalloc( (void**)&dev_counts, nCounts * sizeof(int));

	//Filling chars array
	inputFile = fopen(inputFileName,"r");
	if (!inputFile) return 1;
	int i = 0;
	for (char c = getc(inputFile); c != EOF; c = getc(inputFile)){
		if(isValid(&c)){
			if (c>=65 && c<=90) chars[i] = (char)(c + 32);
			else chars[i] = c;
			++i;
		}
	}
	fclose(inputFile);

	t1 = clock() - t1;
	printf("Process...\n");
	t2 = clock();

	//Initialize counter array
	for (int i = 0; i < nCounts; ++i){
		counts[i] = 0;
	}

	cudaMemcpy(dev_chars, chars, nChars * sizeof(char), cudaMemcpyHostToDevice);
	cudaMemcpy(dev_counts, counts, nCounts * sizeof(int), cudaMemcpyHostToDevice);

	//Count chars
	for (int i = 0; i < nChars; ++i){
		int ascii = (int)chars[i];
		++counts[ascii - ASCIIMIN];
	}

	int nLines = (nChars + CHARS_PER_THREADS - 1) / CHARS_PER_THREADS;

	kernel<<<(nLines + THREADS_PER_BLOCK - 1 ) / THREADS_PER_BLOCK, THREADS_PER_BLOCK>>>(nLines, dev_chars, nChars, dev_counts, nCounts);

	cudaMemcpy(counts, dev_counts, nCounts * sizeof(int), cudaMemcpyDeviceToHost);

	t2 = clock() - t2;

	//Write in outputFile
	outputFile = fopen(outputFileName, "w+");
	if (!outputFile) return 1;
	for (int i = 0; i < 127 - ASCIIMIN; ++i){
		if (i + ASCIIMIN < 65 || i + ASCIIMIN > 90) {
			fprintf(outputFile, "%c:%d\n", (char)(i + ASCIIMIN), (int)counts[i]);
		}
	}
	fclose(outputFile);

	//Return memory
	cudaFree(dev_chars);
	cudaFree(dev_counts);
	free(chars);
	free(counts);

	printf("Timings:\nInitialisation: %f\nProcess:        %f\n", (float)1000 * t1/CLOCKS_PER_SEC, (float)1000 * t2/CLOCKS_PER_SEC);


	return 0;

}


	.file	"tmpxft_0030a66d_00000000-6_template.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2044:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2044:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z7isValidPc
	.type	_Z7isValidPc, @function
_Z7isValidPc:
.LFB2040:
	.cfi_startproc
	endbr64
	movb	(%rdi), %al
	subl	$32, %eax
	cmpb	$94, %al
	setbe	%al
	movzbl	%al, %eax
	ret
	.cfi_endproc
.LFE2040:
	.size	_Z7isValidPc, .-_Z7isValidPc
	.globl	_Z30__device_stub__Z6kerneliPciPiiiPciPii
	.type	_Z30__device_stub__Z6kerneliPciPiiiPciPii, @function
_Z30__device_stub__Z6kerneliPciPiiiPciPii:
.LFB2066:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movl	%edi, 28(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 24(%rsp)
	leaq	32(%rsp), %rdx
	movq	%rcx, 8(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, 4(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	28(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	24(%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	.L3
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z6kerneliPciPii(%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
.L3:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L5
	call	__stack_chk_fail@PLT
.L5:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2066:
	.size	_Z30__device_stub__Z6kerneliPciPiiiPciPii, .-_Z30__device_stub__Z6kerneliPciPiiiPciPii
	.globl	_Z6kerneliPciPii
	.type	_Z6kerneliPciPii, @function
_Z6kerneliPciPii:
.LFB2067:
	.cfi_startproc
	endbr64
	jmp	_Z30__device_stub__Z6kerneliPciPiiiPciPii
	.cfi_endproc
.LFE2067:
	.size	_Z6kerneliPciPii, .-_Z6kerneliPciPii
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Initialisation...\n"
.LC1:
	.string	"i:o:"
.LC2:
	.string	"r"
.LC3:
	.string	"Input file too large!\n"
.LC4:
	.string	"%d chars processed\n"
.LC5:
	.string	"Process...\n"
.LC6:
	.string	"w+"
.LC7:
	.string	"%c:%d\n"
.LC10:
	.string	"Timings:\nInitialisation: %f\nProcess:        %f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2041:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	.LC1(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	leaq	.LC0(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edi, %ebx
	movl	$2, %edi
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	call	clock@PLT
	movq	%rax, %r14
	xorl	%eax, %eax
	movq	%rax, 8(%rsp)
.L10:
	movq	%r12, %rdx
	movq	%rbp, %rsi
	movl	%ebx, %edi
	call	getopt@PLT
	cmpl	$-1, %eax
	je	.L47
	cmpl	$105, %eax
	je	.L11
	cmpl	$111, %eax
	jne	.L10
	movq	optarg(%rip), %rax
	movq	%rax, 8(%rsp)
	jmp	.L10
.L11:
	movq	optarg(%rip), %r13
	jmp	.L10
.L47:
	leaq	.LC2(%rip), %r15
	movq	%r13, %rdi
	movq	%r15, %rsi
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.L16
	movq	%rax, %rdi
	xorl	%r12d, %r12d
	leaq	60(%rsp), %rbp
	call	getc@PLT
.L17:
	movb	%al, 60(%rsp)
	incb	%al
	je	.L48
	movq	%rbp, %rdi
	call	_Z7isValidPc
	movq	%rbx, %rdi
	cmpl	$1, %eax
	sbbl	$-1, %r12d
	call	getc@PLT
	jmp	.L17
.L48:
	movq	%rbx, %rdi
	call	fclose@PLT
	movl	$380, %edi
	call	malloc@PLT
	movq	%rax, %rbx
	movslq	%r12d, %rax
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movq	%rax, %rbp
	testq	%rax, %rax
	jne	.L20
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L16:
	movl	$1, %eax
	jmp	.L9
.L20:
	movl	%r12d, %edx
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	32(%rsp), %rdi
	movslq	%r12d, %rsi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movl	$380, %esi
	call	cudaMalloc@PLT
	movq	%r13, %rdi
	movq	%r15, %rsi
	call	fopen@PLT
	movq	%rax, %r13
	testq	%rax, %rax
	je	.L16
	movq	%rax, %rdi
	xorl	%r15d, %r15d
	call	getc@PLT
	movl	%eax, %edx
	leaq	60(%rsp), %rax
	movq	%rax, 24(%rsp)
.L23:
	movb	%dl, 60(%rsp)
	cmpb	$-1, %dl
	je	.L49
	movq	24(%rsp), %rdi
	call	_Z7isValidPc
	testl	%eax, %eax
	je	.L24
	movslq	%r15d, %rax
	leal	-65(%rdx), %ecx
	addq	%rbp, %rax
	cmpb	$25, %cl
	ja	.L25
	addl	$32, %edx
.L25:
	movb	%dl, (%rax)
	incl	%r15d
.L24:
	movq	%r13, %rdi
	call	getc@PLT
	movl	%eax, %edx
	jmp	.L23
.L49:
	movq	%r13, %rdi
	call	fclose@PLT
	call	clock@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	subq	%r14, %rax
	movq	%rax, %r13
	xorl	%eax, %eax
	call	__printf_chk@PLT
	call	clock@PLT
	movl	$95, %ecx
	movq	%rbx, %rdi
	movq	%rbp, %rsi
	movq	%rax, %r14
	xorl	%eax, %eax
	movq	16(%rsp), %rdx
	rep stosl
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	40(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$380, %edx
	call	cudaMemcpy@PLT
	xorl	%eax, %eax
.L27:
	cmpl	%eax, %r12d
	jle	.L50
	movsbq	0(%rbp,%rax), %rdx
	incq	%rax
	incl	-128(%rbx,%rdx,4)
	jmp	.L27
.L50:
	movl	$256, %ecx
	movl	$16777217, %esi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	leal	255(%r12), %eax
	salq	$8, %rsi
	movl	$1, 68(%rsp)
	cltd
	movq	%rsi, 60(%rsp)
	idivl	%ecx
	movl	%eax, %r15d
	leal	255(%rax), %eax
	cltd
	idivl	%ecx
	movq	%rsi, %rdx
	movl	$1, %ecx
	movl	%eax, 48(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 52(%rsp)
	movq	48(%rsp), %rdi
	movl	56(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L29
	movq	40(%rsp), %rcx
	movq	32(%rsp), %rsi
	movl	%r12d, %edx
	movl	%r15d, %edi
	movl	$95, %r8d
	call	_Z30__device_stub__Z6kerneliPciPiiiPciPii
.L29:
	movq	40(%rsp), %rsi
	movl	$2, %ecx
	movl	$380, %edx
	movq	%rbx, %rdi
	call	cudaMemcpy@PLT
	call	clock@PLT
	movq	8(%rsp), %rdi
	leaq	.LC6(%rip), %rsi
	subq	%r14, %rax
	movq	%rax, %r12
	call	fopen@PLT
	movq	%rax, %r14
	testq	%rax, %rax
	je	.L16
	xorl	%edx, %edx
.L33:
	leal	-33(%rdx), %eax
	leaq	1(%rdx), %r15
	cmpl	$25, %eax
	ja	.L30
	movq	%r15, %rdx
	jmp	.L33
.L30:
	movl	(%rbx,%rdx,4), %r8d
	leal	32(%rdx), %ecx
	movl	$2, %esi
	movq	%r14, %rdi
	leaq	.LC7(%rip), %rdx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	%r15, %rdx
	cmpq	$95, %r15
	jne	.L33
	movq	%r14, %rdi
	call	fclose@PLT
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	cvtsi2ssq	%r12, %xmm1
	movb	$2, %al
	movss	.LC8(%rip), %xmm3
	cvtsi2ssq	%r13, %xmm0
	movss	.LC9(%rip), %xmm2
	movl	$2, %edi
	leaq	.LC10(%rip), %rsi
	mulss	%xmm3, %xmm1
	mulss	%xmm3, %xmm0
	divss	%xmm2, %xmm1
	divss	%xmm2, %xmm0
	cvtss2sd	%xmm1, %xmm1
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	xorl	%eax, %eax
.L9:
	movq	72(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L34
	call	__stack_chk_fail@PLT
.L34:
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	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
.LFE2041:
	.size	main, .-main
	.section	.rodata.str1.1
.LC11:
	.string	"_Z6kerneliPciPii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2069:
	.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	.LC11(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z6kerneliPciPii(%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
.LFE2069:
	.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.cst4,"aM",@progbits,4
	.align 4
.LC8:
	.long	1148846080
	.align 4
.LC9:
	.long	1232348160
	.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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>

#include <hip/hip_runtime.h>


#define ASCIIMIN 32
#define ASCIIMAX 126

#define CHARS_PER_THREADS 256
#define THREADS_PER_BLOCK 256

void __global__ kernel(int nLines, char* dev_chars, int nChars, int* dev_counts, int nCounts) {
	const unsigned int tidb = threadIdx.x;
	const unsigned int ti = blockIdx.x*blockDim.x + tidb;

	__shared__ int shared_counts[ASCIIMAX - ASCIIMIN + 1];

	if (tidb == 0) {
		for (int i = 0; i < ASCIIMAX - ASCIIMIN - 1; ++i) {
			shared_counts[i] = 0;
		}
	}

	__syncthreads();

	if (ti < nLines) {
		for (int i = 0; i < CHARS_PER_THREADS; ++i) {
			int ascii = (int)dev_chars[CHARS_PER_THREADS * ti + i];
			atomicAdd(&shared_counts[ascii - ASCIIMIN], 1);
		}
	}

	__syncthreads();

	if (tidb == 0) {
		for (int i = 0; i < nCounts; ++i) {
			atomicAdd(&dev_counts[i], shared_counts[i]);
		}
	}
}

int isValid(char* c){
	int asciicode = (int)*c;
	int valid = (asciicode <= 126);
	valid = valid && (asciicode >= 32);
	return valid;
}

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

	clock_t t1, t2;
	printf("Initialisation...\n");
	t1 = clock();

	//Declarations
	FILE* inputFile =  NULL;
	FILE* outputFile =  NULL;
	char* inputFileName = NULL;
	char* outputFileName = NULL;

	int nChars = 0;
	char* chars;
	int nCounts = ASCIIMAX - ASCIIMIN + 1;
	int* counts;

	char* dev_chars;
	int* dev_counts;

	int opt;

	//Get comand line options
	while ((opt = getopt (argc, argv, "i:o:")) != -1) {
		switch(opt) {
			case 'i':
				inputFileName = optarg;
				break;
			case 'o':
				outputFileName = optarg;
				break;
		}
	}

	//Count number of chars in inputFile
	inputFile = fopen(inputFileName,"r");
	if (!inputFile) return 1;
	nChars = 0;
	for (char c = getc(inputFile); c != EOF; c = getc(inputFile)){
		if(isValid(&c)) ++nChars;
	}
	fclose(inputFile);

	//Allocate memory
	counts = (int*) malloc(nCounts * sizeof(int));
	chars = (char*) malloc(nChars * sizeof(char));
	if(chars == NULL) {
		printf("Input file too large!\n");
		return 1;
	}
	printf("%d chars processed\n", nChars);
	hipMalloc( (void**)&dev_chars, nChars * sizeof(char));
	hipMalloc( (void**)&dev_counts, nCounts * sizeof(int));

	//Filling chars array
	inputFile = fopen(inputFileName,"r");
	if (!inputFile) return 1;
	int i = 0;
	for (char c = getc(inputFile); c != EOF; c = getc(inputFile)){
		if(isValid(&c)){
			if (c>=65 && c<=90) chars[i] = (char)(c + 32);
			else chars[i] = c;
			++i;
		}
	}
	fclose(inputFile);

	t1 = clock() - t1;
	printf("Process...\n");
	t2 = clock();

	//Initialize counter array
	for (int i = 0; i < nCounts; ++i){
		counts[i] = 0;
	}

	hipMemcpy(dev_chars, chars, nChars * sizeof(char), hipMemcpyHostToDevice);
	hipMemcpy(dev_counts, counts, nCounts * sizeof(int), hipMemcpyHostToDevice);

	//Count chars
	for (int i = 0; i < nChars; ++i){
		int ascii = (int)chars[i];
		++counts[ascii - ASCIIMIN];
	}

	int nLines = (nChars + CHARS_PER_THREADS - 1) / CHARS_PER_THREADS;

	kernel<<<(nLines + THREADS_PER_BLOCK - 1 ) / THREADS_PER_BLOCK, THREADS_PER_BLOCK>>>(nLines, dev_chars, nChars, dev_counts, nCounts);

	hipMemcpy(counts, dev_counts, nCounts * sizeof(int), hipMemcpyDeviceToHost);

	t2 = clock() - t2;

	//Write in outputFile
	outputFile = fopen(outputFileName, "w+");
	if (!outputFile) return 1;
	for (int i = 0; i < 127 - ASCIIMIN; ++i){
		if (i + ASCIIMIN < 65 || i + ASCIIMIN > 90) {
			fprintf(outputFile, "%c:%d\n", (char)(i + ASCIIMIN), (int)counts[i]);
		}
	}
	fclose(outputFile);

	//Return memory
	hipFree(dev_chars);
	hipFree(dev_counts);
	free(chars);
	free(counts);

	printf("Timings:\nInitialisation: %f\nProcess:        %f\n", (float)1000 * t1/CLOCKS_PER_SEC, (float)1000 * t2/CLOCKS_PER_SEC);


	return 0;

}


	.text
	.file	"template.hip"
	.globl	_Z21__device_stub__kerneliPciPii # -- Begin function _Z21__device_stub__kerneliPciPii
	.type	_Z21__device_stub__kerneliPciPii,@function
_Z21__device_stub__kerneliPciPii:       # @_Z21__device_stub__kerneliPciPii
	.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	12(%rsp), %rax
	movl	%edi, (%rax)
	leaq	40(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	8(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%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	$_Z6kerneliPciPii, %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_end0:
	.size	_Z21__device_stub__kerneliPciPii, .Lfunc_end0-_Z21__device_stub__kerneliPciPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z7isValidPc                    # -- Begin function _Z7isValidPc
	.type	_Z7isValidPc,@function
_Z7isValidPc:                           # @_Z7isValidPc
	.cfi_startproc
# %bb.0:
	movb	(%rdi), %cl
	addb	$-32, %cl
	xorl	%eax, %eax
	cmpb	$95, %cl
	setb	%al
	retq
.Lfunc_end1:
	.size	_Z7isValidPc, .Lfunc_end1-_Z7isValidPc
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI2_0:
	.long	0x447a0000                      # float 1000
.LCPI2_1:
	.long	0x49742400                      # float 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	%edi, %r15d
	movl	$.Lstr, %edi
	callq	puts@PLT
	callq	clock
	movq	%rax, %r12
	xorl	%r14d, %r14d
	xorl	%ebp, %ebp
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str.1, %edx
	movl	%r15d, %edi
	movq	%rbx, %rsi
	callq	getopt
	cmpl	$-1, %eax
	je	.LBB2_6
# %bb.2:                                #   in Loop: Header=BB2_1 Depth=1
	cmpl	$111, %eax
	je	.LBB2_5
# %bb.3:                                #   in Loop: Header=BB2_1 Depth=1
	cmpl	$105, %eax
	jne	.LBB2_1
# %bb.4:                                #   in Loop: Header=BB2_1 Depth=1
	movq	optarg(%rip), %rbp
	jmp	.LBB2_1
.LBB2_5:                                #   in Loop: Header=BB2_1 Depth=1
	movq	optarg(%rip), %r14
	jmp	.LBB2_1
.LBB2_6:
	movl	$.L.str.2, %esi
	movq	%rbp, %rdi
	callq	fopen
	movl	$1, %ebx
	testq	%rax, %rax
	je	.LBB2_29
# %bb.7:
	movq	%rax, %r15
	movq	%r12, 32(%rsp)                  # 8-byte Spill
	movq	%rax, %rdi
	callq	getc
	xorl	%r12d, %r12d
	cmpb	$-1, %al
	je	.LBB2_10
# %bb.8:                                # %.lr.ph.preheader
	xorl	%r12d, %r12d
.LBB2_9:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	addb	$-32, %al
	cmpb	$95, %al
	adcl	$0, %r12d
	movq	%r15, %rdi
	callq	getc
	cmpb	$-1, %al
	jne	.LBB2_9
.LBB2_10:                               # %._crit_edge
	movq	%r15, %rdi
	callq	fclose
	movl	$380, %edi                      # imm = 0x17C
	callq	malloc
	movq	%rax, %r15
	movl	%r12d, %r13d
	movq	%r13, %rdi
	callq	malloc
	testq	%rax, %rax
	je	.LBB2_11
# %bb.12:
	movq	%rax, %r12
	movl	$.L.str.4, %edi
	movl	%r13d, %esi
	xorl	%eax, %eax
	callq	printf
	leaq	8(%rsp), %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	%rsp, %rdi
	movl	$380, %esi                      # imm = 0x17C
	callq	hipMalloc
	movl	$.L.str.2, %esi
	movq	%rbp, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB2_29
# %bb.13:
	movq	%rax, %rbp
	movq	%rax, %rdi
	callq	getc
                                        # kill: def $eax killed $eax def $rax
	cmpb	$-1, %al
	je	.LBB2_18
# %bb.14:                               # %.lr.ph115.preheader
	xorl	%ebx, %ebx
.LBB2_15:                               # %.lr.ph115
                                        # =>This Inner Loop Header: Depth=1
	leal	-127(%rax), %ecx
	cmpb	$-95, %cl
	jb	.LBB2_17
# %bb.16:                               #   in Loop: Header=BB2_15 Depth=1
	leal	-65(%rax), %ecx
	movzbl	%al, %edx
	orb	$32, %al
	cmpb	$26, %cl
	movzbl	%al, %eax
	cmovael	%edx, %eax
	movslq	%ebx, %rbx
	movb	%al, (%r12,%rbx)
	incl	%ebx
.LBB2_17:                               #   in Loop: Header=BB2_15 Depth=1
	movq	%rbp, %rdi
	callq	getc
                                        # kill: def $eax killed $eax def $rax
	cmpb	$-1, %al
	jne	.LBB2_15
.LBB2_18:                               # %._crit_edge116
	movq	%rbp, %rdi
	callq	fclose
	callq	clock
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	callq	clock
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	$380, %edx                      # imm = 0x17C
	movq	%r15, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movq	8(%rsp), %rdi
	movq	%r12, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rsp), %rdi
	movl	$380, %edx                      # imm = 0x17C
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testq	%r13, %r13
	je	.LBB2_21
# %bb.19:                               # %.lr.ph120.preheader
	xorl	%eax, %eax
.LBB2_20:                               # %.lr.ph120
                                        # =>This Inner Loop Header: Depth=1
	movsbq	(%r12,%rax), %rcx
	incl	-128(%r15,%rcx,4)
	incq	%rax
	cmpq	%rax, %r13
	jne	.LBB2_20
.LBB2_21:                               # %._crit_edge121
	movl	$255, %edi
	leal	(%rdi,%r13), %ebp
	shrl	$8, %ebp
	addl	%ebp, %edi
	shrl	$8, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$256, %rdx                      # imm = 0x100
	movl	$1, %ebx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_23
# %bb.22:
	movq	8(%rsp), %rsi
	movq	(%rsp), %rcx
	movl	%ebp, %edi
	movl	%r13d, %edx
	movl	$95, %r8d
	callq	_Z21__device_stub__kerneliPciPii
.LBB2_23:
	movq	(%rsp), %rsi
	movl	$380, %edx                      # imm = 0x17C
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	callq	clock
	movq	%rax, %r13
	movl	$.L.str.6, %esi
	movq	%r14, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB2_29
# %bb.24:                               # %.preheader.preheader
	movq	%rax, %r14
	movq	24(%rsp), %rbp                  # 8-byte Reload
	subq	32(%rsp), %rbp                  # 8-byte Folded Reload
	subq	16(%rsp), %r13                  # 8-byte Folded Reload
	xorl	%ebx, %ebx
.LBB2_25:                               # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	leal	-59(%rbx), %eax
	cmpl	$-27, %eax
	ja	.LBB2_27
# %bb.26:                               #   in Loop: Header=BB2_25 Depth=1
	movl	(%r15,%rbx,4), %ecx
	leal	32(%rbx), %edx
	movl	$.L.str.7, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
.LBB2_27:                               #   in Loop: Header=BB2_25 Depth=1
	incq	%rbx
	cmpq	$95, %rbx
	jne	.LBB2_25
# %bb.28:
	movq	%r14, %rdi
	callq	fclose
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	(%rsp), %rdi
	callq	hipFree
	movq	%r12, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	cvtsi2ss	%rbp, %xmm0
	movss	.LCPI2_0(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	mulss	%xmm1, %xmm0
	movss	.LCPI2_1(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	divss	%xmm2, %xmm0
	cvtsi2ss	%r13, %xmm3
	cvtss2sd	%xmm0, %xmm0
	mulss	%xmm1, %xmm3
	divss	%xmm2, %xmm3
	xorps	%xmm1, %xmm1
	cvtss2sd	%xmm3, %xmm1
	movl	$.L.str.8, %edi
	movb	$2, %al
	callq	printf
	xorl	%ebx, %ebx
	jmp	.LBB2_29
.LBB2_11:
	movl	$.Lstr.2, %edi
	callq	puts@PLT
.LBB2_29:
	movl	%ebx, %eax
	addq	$40, %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_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6kerneliPciPii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB4_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z6kerneliPciPii,@object        # @_Z6kerneliPciPii
	.section	.rodata,"a",@progbits
	.globl	_Z6kerneliPciPii
	.p2align	3, 0x0
_Z6kerneliPciPii:
	.quad	_Z21__device_stub__kerneliPciPii
	.size	_Z6kerneliPciPii, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"i:o:"
	.size	.L.str.1, 5

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%d chars processed\n"
	.size	.L.str.4, 20

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"w+"
	.size	.L.str.6, 3

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%c:%d\n"
	.size	.L.str.7, 7

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Timings:\nInitialisation: %f\nProcess:        %f\n"
	.size	.L.str.8, 48

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6kerneliPciPii"
	.size	.L__unnamed_1, 17

	.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	"Initialisation..."
	.size	.Lstr, 18

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Process..."
	.size	.Lstr.1, 11

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Input file too large!"
	.size	.Lstr.2, 22

	.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 _Z21__device_stub__kerneliPciPii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z6kerneliPciPii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6kerneliPciPii        ; -- Begin function _Z6kerneliPciPii
	.globl	_Z6kerneliPciPii
	.p2align	8
	.type	_Z6kerneliPciPii,@function
_Z6kerneliPciPii:                       ; @_Z6kerneliPciPii
; %bb.0:
	v_cmp_eq_u32_e32 vcc_lo, 0, v0
	s_mov_b32 s3, 0
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB0_3
; %bb.1:                                ; %.preheader26.preheader
	v_mov_b32_e32 v1, 0
.LBB0_2:                                ; %.preheader26
                                        ; =>This Inner Loop Header: Depth=1
	v_mov_b32_e32 v2, s3
	s_add_i32 s3, s3, 4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmpk_lg_i32 s3, 0x174
	ds_store_b32 v2, v1
	s_cbranch_scc1 .LBB0_2
.LBB0_3:                                ; %Flow54
	s_or_b32 exec_lo, exec_lo, s2
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b32 s3, s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_b32 s2, 0xffff, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	v_cmp_gt_u32_e64 s2, s3, v1
	s_delay_alu instid0(VALU_DEP_1)
	s_and_saveexec_b32 s3, s2
	s_cbranch_execz .LBB0_6
; %bb.4:                                ; %.preheader24
	s_load_b64 s[4:5], s[0:1], 0x8
	v_lshlrev_b32_e32 v0, 8, v1
	v_mov_b32_e32 v2, 1
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v0, s2, s4, v0
	v_add_co_ci_u32_e64 v1, null, s5, 0, s2
	s_mov_b64 s[4:5], 0
.LBB0_5:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
	v_add_co_u32 v3, s2, v0, s4
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v4, s2, s5, v1, s2
	s_add_u32 s4, s4, 1
	s_addc_u32 s5, s5, 0
	s_cmpk_lg_i32 s4, 0x100
	global_load_i8 v3, v[3:4], off
	s_waitcnt vmcnt(0)
	v_lshl_add_u32 v3, v3, 2, 0xffffff80
	ds_add_u32 v3, v2
	s_cbranch_scc1 .LBB0_5
.LBB0_6:                                ; %Flow52
	s_or_b32 exec_lo, exec_lo, s3
	s_load_b32 s2, s[0:1], 0x20
	s_mov_b32 s3, 0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_cmp_gt_i32 s2, 0
	s_cselect_b32 s4, -1, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s4, vcc_lo, s4
	s_and_saveexec_b32 s5, s4
	s_cbranch_execz .LBB0_11
; %bb.7:                                ; %.lr.ph.preheader
	s_load_b64 s[0:1], s[0:1], 0x18
	v_mov_b32_e32 v0, 0
.LBB0_8:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s5, exec_lo
	s_mov_b32 s4, exec_lo
	v_mbcnt_lo_u32_b32 v1, s5, 0
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_eq_u32_e32 0, v1
	s_cbranch_execz .LBB0_10
; %bb.9:                                ;   in Loop: Header=BB0_8 Depth=1
	v_mov_b32_e32 v1, s3
	s_bcnt1_i32_b32 s5, s5
	ds_load_b32 v1, v1
	s_waitcnt lgkmcnt(0)
	v_mul_lo_u32 v1, v1, s5
	global_atomic_add_u32 v0, v1, s[0:1]
.LBB0_10:                               ;   in Loop: Header=BB0_8 Depth=1
	s_or_b32 exec_lo, exec_lo, s4
	s_add_i32 s2, s2, -1
	s_waitcnt lgkmcnt(0)
	s_add_u32 s0, s0, 4
	s_addc_u32 s1, s1, 0
	s_add_i32 s3, s3, 4
	s_cmp_lg_u32 s2, 0
	s_cbranch_scc1 .LBB0_8
.LBB0_11:                               ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6kerneliPciPii
		.amdhsa_group_segment_fixed_size 380
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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 5
		.amdhsa_next_free_sgpr 16
		.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	_Z6kerneliPciPii, .Lfunc_end0-_Z6kerneliPciPii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 420
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 380 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; 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:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 380
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6kerneliPciPii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z6kerneliPciPii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
