#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#ifndef D
	#define D 			10000
#endif

#ifndef N_FILES
	#define N_FILES 	21000
#endif

#define ARG_COUNT 			4
#define MAX_FILE_NAME 		100

#define GMEM_GRANULARITY	128
#define INV_DICT_WIDTH		((unsigned int)(ceil(N_FILES / (float)(sizeof(int)*8))))
#define INV_DICT_WIDTH_PAD	((INV_DICT_WIDTH/GMEM_GRANULARITY+1)*GMEM_GRANULARITY)
#define INV_DICT_SIZE		(D*INV_DICT_WIDTH_PAD)
#define BLOCK_SIZE 			64
#define N_BLOCKS			((unsigned int)(ceil(N_FILES/ (float)(sizeof(int)*8*BLOCK_SIZE))))
#define N_THREADS 			(BLOCK_SIZE*N_BLOCKS) 

unsigned int *inv_dictionary;
char files[N_FILES][MAX_FILE_NAME];
char query[D];
unsigned int query_ones[D];
unsigned int matches[N_FILES];

// inv_dict_width = width of inv dictionary in number of elements
// int_size = size of an integer in bytes
__global__ void queryKernel(unsigned int * __restrict__ inv_dictionary, unsigned int inv_dict_width, unsigned int inv_dict_width_pad, unsigned int * __restrict__ query_ones, unsigned int ones_cnt, unsigned int * matches, unsigned int int_size, unsigned int n_threads) {
	unsigned short curr_bit = 0;
	unsigned int match_pos;
	unsigned int match_cnt = 0;
	// unsigned int match_idx;

	__shared__ unsigned int match_idx_s[BLOCK_SIZE];

	unsigned int index = threadIdx.x + blockIdx.x * blockDim.x;

	if(index < inv_dict_width){ //inv_dict_width = 657
		match_idx_s[threadIdx.x] = 0xFFFFFFFF;
		for(int i = 0; i < ones_cnt; i++) {			
			match_idx_s[threadIdx.x] = match_idx_s[threadIdx.x] & *(inv_dictionary + query_ones[i]*inv_dict_width_pad + index);
		}

		match_cnt = 0;
		for(int j=1; j<=(int_size*8) && match_idx_s[threadIdx.x]>0; j++) {
			curr_bit = match_idx_s[threadIdx.x] & 1;
			match_idx_s[threadIdx.x] = match_idx_s[threadIdx.x] >> 1;
			if(curr_bit==1) {
				match_pos = (index + 1)*int_size*8 - j + 1; // starts indexing at 1 not 0
				matches[index*int_size*8+match_cnt] = match_pos;
				match_cnt++;
			}
		}
	}
}


__host__ void load_inv_dictionary(char file[]){

	unsigned int num_read;
	FILE *fp = NULL;
	fp = fopen(file, "r");

	if (fp == NULL){
		printf("Error while opening %s\n", file);
	}

	int i;
	for(int j = 0; j<D; j++) {
		for(i=0; i<INV_DICT_WIDTH-1; i++){
			// printf("%d:\t%d:\t", j, i);
			num_read = fscanf(fp, "%u ", inv_dictionary + j*INV_DICT_WIDTH_PAD + i);
			// printf("%u\n", *(inv_dictionary + j*INV_DICT_WIDTH_PAD + i));
			if (num_read != 1) 
				printf("ERROR!\t fscanf did not fill all arguments\n");
		}
		// printf("%d:\t%d:\t", j, i);
		num_read = fscanf(fp, "%u\n", inv_dictionary + j*INV_DICT_WIDTH_PAD + i);
		// printf("%u\n", *(inv_dictionary + j*INV_DICT_WIDTH_PAD + i));
		if (num_read != 1) 
			printf("ERROR!\t fscanf did not fill all arguments\n");
	}

	fclose(fp);
}

__host__ void load_query(char file[]){

	unsigned int num_read;
	FILE *fp = NULL;
	fp = fopen(file, "r");

	if (fp == NULL){
		printf("Error while opening %s\n", file);
	}

	for (int i=0; i<D; i++) {
		num_read = fscanf(fp, "%c", &query[i]);
		if (num_read != 1) 
			printf("ERROR!\t fscanf did not fill all arguments\n");
	}

	// printf("Loaded query: ");

	// for (int i=0; i<D; i++) {
	// 	printf("%c", query[i]);
	// }

	// printf("\n");

	fclose(fp);
}

__host__ void printMatches(){
	for (int i=0; i<N_FILES; i++) {
		printf("Match %d:\t%u\n", i, matches[i]);
	}
}

__host__ void load_files(char file[]) {
	FILE *fp = NULL;
	fp = fopen(file, "r");
	int num_read = 0;

	if (fp == NULL){
		printf("Error while opening %s\n", file);
	}

	for(int i = 0; i<N_FILES; i++) {
		num_read = fscanf(fp, "%s", files[i]);
		if (num_read != 1)
			printf("Error reading file: %s\n", file);
		// printf("%d: %s\n", i, files[i]);
	}
	fclose(fp);
}

unsigned int findQueryOnes(char* query){
	unsigned int ones_cnt = 0;
	for(unsigned int i=0; i<D; i++) {
		if(query[i] == '1')
		{
			query_ones[ones_cnt] = i;
			printf("One position:\t%d\n", i);
			ones_cnt++; 
		}
	}
	return ones_cnt;
}


__host__ void reportQuery(char* report_f){
	FILE *rep = fopen(report_f, "w+");

	for (int i=0; i < N_FILES; i++){
		if (matches[i] != 0)
		{
			fprintf(rep, "%s\n", files[matches[i]-1]);
		}
	}
	fclose(rep);
}


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

	// Command-line arguments:
	// D, itemmem input file, dictionary input file, query
	if(argc != (ARG_COUNT+1)){
		printf("Requires arguments: <files file> <dictionary input file> <query input file> <output directory>\n");
		return 1;
	}	

	char dict_file[MAX_FILE_NAME];  
	char files_file[MAX_FILE_NAME];  
	char query_file[MAX_FILE_NAME];
	char output_dir[MAX_FILE_NAME];
	char report_file[MAX_FILE_NAME];

	sprintf(files_file, "%s", argv[1]);
	sprintf(dict_file, "%s", argv[2]);
	sprintf(query_file, "%s", argv[3]);
	sprintf(output_dir, "%s", argv[4]);

	printf("INV_DICT_SIZE:\t%u\nINV_DICT_WIDTH:\t%u\nINV_DICT_WIDTH_PAD:\t%u\nN_BLOCKS:\t%u\nBLOCK_SIZE:\t%d\n", INV_DICT_SIZE, INV_DICT_WIDTH, INV_DICT_WIDTH_PAD, N_BLOCKS, BLOCK_SIZE);

	sprintf(report_file, "%s/cu_query_report.txt", output_dir);

	unsigned int *d_inv_dict, *d_matches;
	unsigned int *d_query_ones;
	unsigned int ones_cnt;

	inv_dictionary = (unsigned int *)malloc(INV_DICT_SIZE*sizeof(unsigned int));

	load_inv_dictionary(dict_file);
	load_query(query_file);
	ones_cnt = findQueryOnes(query);


#ifdef PROFILING
	for (int i = 0; i < 100; ++i)
	{
#endif	

		// const int num_streams = 8;
		// cudaStream_t streams[num_streams];

		cudaMalloc((void **)&d_inv_dict, INV_DICT_SIZE*sizeof(unsigned int));
		cudaMalloc((void **)&d_query_ones, ones_cnt*sizeof(unsigned int));
		cudaMalloc((void **)&d_matches, N_FILES*sizeof(unsigned int));
		cudaMemset(d_matches, 0, N_FILES*sizeof(unsigned int));

		// printf("Allocated arrays...\n");

		cudaMemcpy(d_inv_dict, inv_dictionary, INV_DICT_SIZE*sizeof(unsigned int), cudaMemcpyHostToDevice);
		cudaError_t err = cudaMemcpy(d_query_ones, query_ones, ones_cnt*sizeof(unsigned int), cudaMemcpyHostToDevice);

		printf("Err: %d\n", err);
		// printf("Query...\n");

		// for(int i=0; i < num_streams; i++) {
		// 	cudaStreamCreate(&streams[i]);
		// }

		// for(int i=0; i < num_streams; i++) {
		queryKernel<<<N_BLOCKS, BLOCK_SIZE>>>((unsigned int *)d_inv_dict, INV_DICT_WIDTH, INV_DICT_WIDTH_PAD, d_query_ones, ones_cnt, d_matches, sizeof(int), N_THREADS);
		cudaMemcpy(matches, d_matches, N_FILES*sizeof(unsigned int), cudaMemcpyDeviceToHost);
		// }
		// printMatches();

		load_files(files_file);
		reportQuery(report_file);

		cudaFree(d_inv_dict);
		cudaFree(d_query_ones);
		cudaFree(d_matches);
		
#ifdef PROFILING
	}
#endif
	free(inv_dictionary);

	printf("Ended! :)\n");

	return 0;
}
	.file	"tmpxft_002647c9_00000000-6_cu-backup.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2045:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2045:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"r"
.LC1:
	.string	"Error while opening %s\n"
.LC2:
	.string	"%u "
.LC3:
	.string	"ERROR!\t fscanf did not fill all arguments\n"
.LC4:
	.string	"%u\n"
	.text
	.globl	_Z19load_inv_dictionaryPc
	.type	_Z19load_inv_dictionaryPc, @function
_Z19load_inv_dictionaryPc:
.LFB2036:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC0(%rip), %rsi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L3
	movq	%rbp, %rdx
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L3:
	xorl	%r12d, %r12d
	leaq	.LC2(%rip), %r14
.L4:
	leaq	0(,%r12,4), %r13
	xorl	%ebp, %ebp
.L6:
	xorl	%eax, %eax
	leaq	0(%r13,%rbp,4), %rdx
	movq	%r14, %rsi
	movq	%rbx, %rdi
	addq	inv_dictionary(%rip), %rdx
	call	__isoc23_fscanf@PLT
	decl	%eax
	je	.L5
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L5:
	incq	%rbp
	cmpq	$656, %rbp
	jne	.L6
	movq	inv_dictionary(%rip), %rax
	leaq	.LC4(%rip), %rsi
	movq	%rbx, %rdi
	leaq	2624(%rax,%r13), %rdx
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	decl	%eax
	je	.L7
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L7:
	addq	$768, %r12
	cmpq	$7680000, %r12
	jne	.L4
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	fclose@PLT
	.cfi_endproc
.LFE2036:
	.size	_Z19load_inv_dictionaryPc, .-_Z19load_inv_dictionaryPc
	.section	.rodata.str1.1
.LC5:
	.string	"%c"
	.text
	.globl	_Z10load_queryPc
	.type	_Z10load_queryPc, @function
_Z10load_queryPc:
.LFB2037:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%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
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	pushq	%rdx
	.cfi_def_cfa_offset 48
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L19
	movq	%rbp, %rdx
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L19:
	leaq	query(%rip), %rbp
	leaq	.LC5(%rip), %r13
	leaq	10000(%rbp), %r12
.L21:
	xorl	%eax, %eax
	movq	%rbp, %rdx
	movq	%r13, %rsi
	movq	%rbx, %rdi
	call	__isoc23_fscanf@PLT
	decl	%eax
	je	.L20
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L20:
	incq	%rbp
	cmpq	%r12, %rbp
	jne	.L21
	popq	%rax
	.cfi_def_cfa_offset 40
	movq	%rbx, %rdi
	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
	jmp	fclose@PLT
	.cfi_endproc
.LFE2037:
	.size	_Z10load_queryPc, .-_Z10load_queryPc
	.section	.rodata.str1.1
.LC6:
	.string	"Match %d:\t%u\n"
	.text
	.globl	_Z12printMatchesv
	.type	_Z12printMatchesv, @function
_Z12printMatchesv:
.LFB2038:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	matches(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	xorl	%ebx, %ebx
	pushq	%rdx
	.cfi_def_cfa_offset 32
.L28:
	movl	0(%rbp,%rbx,4), %ecx
	movl	%ebx, %edx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	incq	%rbx
	call	__printf_chk@PLT
	cmpq	$21000, %rbx
	jne	.L28
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2038:
	.size	_Z12printMatchesv, .-_Z12printMatchesv
	.section	.rodata.str1.1
.LC7:
	.string	"%s"
.LC8:
	.string	"Error reading file: %s\n"
	.text
	.globl	_Z10load_filesPc
	.type	_Z10load_filesPc, @function
_Z10load_filesPc:
.LFB2039:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC0(%rip), %rsi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	call	fopen@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L32
	movq	%rbp, %rdx
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L32:
	leaq	files(%rip), %r12
	leaq	.LC7(%rip), %r14
	leaq	2100000(%r12), %r13
.L34:
	xorl	%eax, %eax
	movq	%r12, %rdx
	movq	%r14, %rsi
	movq	%rbx, %rdi
	call	__isoc23_fscanf@PLT
	decl	%eax
	je	.L33
	movq	%rbp, %rdx
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L33:
	addq	$100, %r12
	cmpq	%r13, %r12
	jne	.L34
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	fclose@PLT
	.cfi_endproc
.LFE2039:
	.size	_Z10load_filesPc, .-_Z10load_filesPc
	.section	.rodata.str1.1
.LC9:
	.string	"One position:\t%d\n"
	.text
	.globl	_Z13findQueryOnesPc
	.type	_Z13findQueryOnesPc, @function
_Z13findQueryOnesPc:
.LFB2040:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	query_ones(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 48
.L42:
	cmpb	$49, (%r12,%rbx)
	jne	.L41
	movl	%ebp, %eax
	movl	%ebx, %edx
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	movl	%ebx, 0(%r13,%rax,4)
	xorl	%eax, %eax
	incl	%ebp
	call	__printf_chk@PLT
.L41:
	incq	%rbx
	cmpq	$10000, %rbx
	jne	.L42
	popq	%rdx
	.cfi_def_cfa_offset 40
	movl	%ebp, %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
.LFE2040:
	.size	_Z13findQueryOnesPc, .-_Z13findQueryOnesPc
	.section	.rodata.str1.1
.LC10:
	.string	"w+"
.LC11:
	.string	"%s\n"
	.text
	.globl	_Z11reportQueryPc
	.type	_Z11reportQueryPc, @function
_Z11reportQueryPc:
.LFB2041:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC10(%rip), %rsi
	leaq	files(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	leaq	matches(%rip), %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	84000(%rbp), %r12
	pushq	%rdx
	.cfi_def_cfa_offset 48
	call	fopen@PLT
	movq	%rax, %rbx
.L47:
	movl	0(%rbp), %eax
	testl	%eax, %eax
	je	.L46
	leal	-1(%rax), %ecx
	leaq	.LC11(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%eax, %eax
	imulq	$100, %rcx, %rcx
	movl	$2, %esi
	addq	%r13, %rcx
	call	__fprintf_chk@PLT
.L46:
	addq	$4, %rbp
	cmpq	%r12, %rbp
	jne	.L47
	popq	%rax
	.cfi_def_cfa_offset 40
	movq	%rbx, %rdi
	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
	jmp	fclose@PLT
	.cfi_endproc
.LFE2041:
	.size	_Z11reportQueryPc, .-_Z11reportQueryPc
	.globl	_Z40__device_stub__Z11queryKernelPjjjS_jS_jjPjjjS_jS_jj
	.type	_Z40__device_stub__Z11queryKernelPjjjS_jS_jjPjjjS_jS_jj, @function
_Z40__device_stub__Z11queryKernelPjjjS_jS_jjPjjjS_jS_jj:
.LFB2067:
	.cfi_startproc
	endbr64
	subq	$200, %rsp
	.cfi_def_cfa_offset 208
	movl	%esi, 28(%rsp)
	leaq	84(%rsp), %rsi
	movl	%edx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movl	%r8d, 20(%rsp)
	movq	%r9, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 184(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rax, 120(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	48(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	208(%rsp), %rax
	movq	%rax, 168(%rsp)
	leaq	216(%rsp), %rax
	movq	%rcx, 48(%rsp)
	leaq	64(%rsp), %rcx
	movq	%rax, 176(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movl	$1, 80(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L53
	pushq	64(%rsp)
	.cfi_def_cfa_offset 216
	leaq	_Z11queryKernelPjjjS_jS_jj(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 224
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 216
	popq	%rdx
	.cfi_def_cfa_offset 208
.L53:
	movq	184(%rsp), %rax
	subq	%fs:40, %rax
	je	.L55
	call	__stack_chk_fail@PLT
.L55:
	addq	$200, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2067:
	.size	_Z40__device_stub__Z11queryKernelPjjjS_jS_jjPjjjS_jS_jj, .-_Z40__device_stub__Z11queryKernelPjjjS_jS_jjPjjjS_jS_jj
	.globl	_Z11queryKernelPjjjS_jS_jj
	.type	_Z11queryKernelPjjjS_jS_jj, @function
_Z11queryKernelPjjjS_jS_jj:
.LFB2068:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z11queryKernelPjjjS_jS_jjPjjjS_jS_jj
	.cfi_endproc
.LFE2068:
	.size	_Z11queryKernelPjjjS_jS_jj, .-_Z11queryKernelPjjjS_jS_jj
	.section	.rodata.str1.1
.LC12:
	.string	"Requires arguments: <files file> <dictionary input file> <query input file> <output directory>\n"
.LC13:
	.string	"INV_DICT_SIZE:\t%u\nINV_DICT_WIDTH:\t%u\nINV_DICT_WIDTH_PAD:\t%u\nN_BLOCKS:\t%u\nBLOCK_SIZE:\t%d\n"
.LC14:
	.string	"%s/cu_query_report.txt"
.LC15:
	.string	"Err: %d\n"
.LC16:
	.string	"Ended! :)\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2042:
	.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
	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	$568, %rsp
	.cfi_def_cfa_offset 624
	movq	%fs:40, %rax
	movq	%rax, 552(%rsp)
	xorl	%eax, %eax
	cmpl	$5, %edi
	je	.L59
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	$1, %eax
	jmp	.L58
.L59:
	leaq	.LC7(%rip), %r12
	movq	8(%rsi), %r8
	movq	%rsi, %rbx
	xorl	%eax, %eax
	leaq	152(%rsp), %r13
	movq	%r12, %rcx
	movl	$100, %edx
	movl	$2, %esi
	movq	%r13, %rdi
	leaq	52(%rsp), %r14
	leaq	252(%rsp), %rbp
	call	__sprintf_chk@PLT
	movq	16(%rbx), %r8
	movq	%r12, %rcx
	movq	%r14, %rdi
	movl	$100, %edx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__sprintf_chk@PLT
	movq	24(%rbx), %r8
	movq	%r12, %rcx
	movq	%rbp, %rdi
	movl	$100, %edx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__sprintf_chk@PLT
	movq	32(%rbx), %r8
	movq	%r12, %rcx
	xorl	%eax, %eax
	leaq	352(%rsp), %r15
	movl	$100, %edx
	movl	$2, %esi
	movq	%r15, %rdi
	call	__sprintf_chk@PLT
	movl	$11, %r9d
	xorl	%eax, %eax
	movl	$768, %r8d
	pushq	%rcx
	.cfi_def_cfa_offset 632
	movl	$7680000, %edx
	movl	$657, %ecx
	leaq	.LC13(%rip), %rsi
	pushq	$64
	.cfi_def_cfa_offset 640
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	%r15, %r8
	movl	$100, %edx
	xorl	%eax, %eax
	leaq	468(%rsp), %r12
	leaq	.LC14(%rip), %rcx
	movl	$2, %esi
	movq	%r12, %rdi
	call	__sprintf_chk@PLT
	movl	$30720000, %edi
	call	malloc@PLT
	popq	%rsi
	.cfi_def_cfa_offset 632
	popq	%rdi
	.cfi_def_cfa_offset 624
	movq	%r14, %rdi
	movq	%rax, inv_dictionary(%rip)
	call	_Z19load_inv_dictionaryPc
	movq	%rbp, %rdi
	call	_Z10load_queryPc
	leaq	query(%rip), %rdi
	call	_Z13findQueryOnesPc
	movq	%rsp, %rdi
	movl	$30720000, %esi
	movl	%eax, %ebp
	call	cudaMalloc@PLT
	movq	%rbp, %rbx
	salq	$2, %rbp
	leaq	16(%rsp), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	leaq	8(%rsp), %rdi
	movl	$84000, %esi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	movl	$84000, %edx
	call	cudaMemset@PLT
	movq	inv_dictionary(%rip), %rsi
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movl	$30720000, %edx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdi
	movq	%rbp, %rdx
	movl	$1, %ecx
	leaq	query_ones(%rip), %rsi
	call	cudaMemcpy@PLT
	leaq	.LC15(%rip), %rsi
	movl	$2, %edi
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$67108865, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$6, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	movabsq	$4294967307, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L61
	pushq	$704
	.cfi_def_cfa_offset 632
	movl	$768, %edx
	movl	%ebx, %r8d
	movl	$657, %esi
	pushq	$4
	.cfi_def_cfa_offset 640
	movq	24(%rsp), %r9
	movq	32(%rsp), %rcx
	movq	16(%rsp), %rdi
	call	_Z40__device_stub__Z11queryKernelPjjjS_jS_jjPjjjS_jS_jj
	popq	%rax
	.cfi_def_cfa_offset 632
	popq	%rdx
	.cfi_def_cfa_offset 624
.L61:
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movl	$84000, %edx
	leaq	matches(%rip), %rdi
	call	cudaMemcpy@PLT
	movq	%r13, %rdi
	call	_Z10load_filesPc
	movq	%r12, %rdi
	call	_Z11reportQueryPc
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	inv_dictionary(%rip), %rdi
	call	free@PLT
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
.L58:
	movq	552(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L62
	call	__stack_chk_fail@PLT
.L62:
	addq	$568, %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
.LFE2042:
	.size	main, .-main
	.section	.rodata.str1.1
.LC17:
	.string	"_Z11queryKernelPjjjS_jS_jj"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2070:
	.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	.LC17(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z11queryKernelPjjjS_jS_jj(%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
.LFE2070:
	.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
	.globl	matches
	.bss
	.align 32
	.type	matches, @object
	.size	matches, 84000
matches:
	.zero	84000
	.globl	query_ones
	.align 32
	.type	query_ones, @object
	.size	query_ones, 40000
query_ones:
	.zero	40000
	.globl	query
	.align 32
	.type	query, @object
	.size	query, 10000
query:
	.zero	10000
	.globl	files
	.align 32
	.type	files, @object
	.size	files, 2100000
files:
	.zero	2100000
	.globl	inv_dictionary
	.align 8
	.type	inv_dictionary, @object
	.size	inv_dictionary, 8
inv_dictionary:
	.zero	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 <pthread.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#ifndef D
	#define D 			10000
#endif

#ifndef N_FILES
	#define N_FILES 	21000
#endif

#define ARG_COUNT 			4
#define MAX_FILE_NAME 		100

#define GMEM_GRANULARITY	128
#define INV_DICT_WIDTH		((unsigned int)(ceil(N_FILES / (float)(sizeof(int)*8))))
#define INV_DICT_WIDTH_PAD	((INV_DICT_WIDTH/GMEM_GRANULARITY+1)*GMEM_GRANULARITY)
#define INV_DICT_SIZE		(D*INV_DICT_WIDTH_PAD)
#define BLOCK_SIZE 			64
#define N_BLOCKS			((unsigned int)(ceil(N_FILES/ (float)(sizeof(int)*8*BLOCK_SIZE))))
#define N_THREADS 			(BLOCK_SIZE*N_BLOCKS) 

unsigned int *inv_dictionary;
char files[N_FILES][MAX_FILE_NAME];
char query[D];
unsigned int query_ones[D];
unsigned int matches[N_FILES];

// inv_dict_width = width of inv dictionary in number of elements
// int_size = size of an integer in bytes
__global__ void queryKernel(unsigned int * __restrict__ inv_dictionary, unsigned int inv_dict_width, unsigned int inv_dict_width_pad, unsigned int * __restrict__ query_ones, unsigned int ones_cnt, unsigned int * matches, unsigned int int_size, unsigned int n_threads) {
	unsigned short curr_bit = 0;
	unsigned int match_pos;
	unsigned int match_cnt = 0;
	// unsigned int match_idx;

	__shared__ unsigned int match_idx_s[BLOCK_SIZE];

	unsigned int index = threadIdx.x + blockIdx.x * blockDim.x;

	if(index < inv_dict_width){ //inv_dict_width = 657
		match_idx_s[threadIdx.x] = 0xFFFFFFFF;
		for(int i = 0; i < ones_cnt; i++) {			
			match_idx_s[threadIdx.x] = match_idx_s[threadIdx.x] & *(inv_dictionary + query_ones[i]*inv_dict_width_pad + index);
		}

		match_cnt = 0;
		for(int j=1; j<=(int_size*8) && match_idx_s[threadIdx.x]>0; j++) {
			curr_bit = match_idx_s[threadIdx.x] & 1;
			match_idx_s[threadIdx.x] = match_idx_s[threadIdx.x] >> 1;
			if(curr_bit==1) {
				match_pos = (index + 1)*int_size*8 - j + 1; // starts indexing at 1 not 0
				matches[index*int_size*8+match_cnt] = match_pos;
				match_cnt++;
			}
		}
	}
}


__host__ void load_inv_dictionary(char file[]){

	unsigned int num_read;
	FILE *fp = NULL;
	fp = fopen(file, "r");

	if (fp == NULL){
		printf("Error while opening %s\n", file);
	}

	int i;
	for(int j = 0; j<D; j++) {
		for(i=0; i<INV_DICT_WIDTH-1; i++){
			// printf("%d:\t%d:\t", j, i);
			num_read = fscanf(fp, "%u ", inv_dictionary + j*INV_DICT_WIDTH_PAD + i);
			// printf("%u\n", *(inv_dictionary + j*INV_DICT_WIDTH_PAD + i));
			if (num_read != 1) 
				printf("ERROR!\t fscanf did not fill all arguments\n");
		}
		// printf("%d:\t%d:\t", j, i);
		num_read = fscanf(fp, "%u\n", inv_dictionary + j*INV_DICT_WIDTH_PAD + i);
		// printf("%u\n", *(inv_dictionary + j*INV_DICT_WIDTH_PAD + i));
		if (num_read != 1) 
			printf("ERROR!\t fscanf did not fill all arguments\n");
	}

	fclose(fp);
}

__host__ void load_query(char file[]){

	unsigned int num_read;
	FILE *fp = NULL;
	fp = fopen(file, "r");

	if (fp == NULL){
		printf("Error while opening %s\n", file);
	}

	for (int i=0; i<D; i++) {
		num_read = fscanf(fp, "%c", &query[i]);
		if (num_read != 1) 
			printf("ERROR!\t fscanf did not fill all arguments\n");
	}

	// printf("Loaded query: ");

	// for (int i=0; i<D; i++) {
	// 	printf("%c", query[i]);
	// }

	// printf("\n");

	fclose(fp);
}

__host__ void printMatches(){
	for (int i=0; i<N_FILES; i++) {
		printf("Match %d:\t%u\n", i, matches[i]);
	}
}

__host__ void load_files(char file[]) {
	FILE *fp = NULL;
	fp = fopen(file, "r");
	int num_read = 0;

	if (fp == NULL){
		printf("Error while opening %s\n", file);
	}

	for(int i = 0; i<N_FILES; i++) {
		num_read = fscanf(fp, "%s", files[i]);
		if (num_read != 1)
			printf("Error reading file: %s\n", file);
		// printf("%d: %s\n", i, files[i]);
	}
	fclose(fp);
}

unsigned int findQueryOnes(char* query){
	unsigned int ones_cnt = 0;
	for(unsigned int i=0; i<D; i++) {
		if(query[i] == '1')
		{
			query_ones[ones_cnt] = i;
			printf("One position:\t%d\n", i);
			ones_cnt++; 
		}
	}
	return ones_cnt;
}


__host__ void reportQuery(char* report_f){
	FILE *rep = fopen(report_f, "w+");

	for (int i=0; i < N_FILES; i++){
		if (matches[i] != 0)
		{
			fprintf(rep, "%s\n", files[matches[i]-1]);
		}
	}
	fclose(rep);
}


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

	// Command-line arguments:
	// D, itemmem input file, dictionary input file, query
	if(argc != (ARG_COUNT+1)){
		printf("Requires arguments: <files file> <dictionary input file> <query input file> <output directory>\n");
		return 1;
	}	

	char dict_file[MAX_FILE_NAME];  
	char files_file[MAX_FILE_NAME];  
	char query_file[MAX_FILE_NAME];
	char output_dir[MAX_FILE_NAME];
	char report_file[MAX_FILE_NAME];

	sprintf(files_file, "%s", argv[1]);
	sprintf(dict_file, "%s", argv[2]);
	sprintf(query_file, "%s", argv[3]);
	sprintf(output_dir, "%s", argv[4]);

	printf("INV_DICT_SIZE:\t%u\nINV_DICT_WIDTH:\t%u\nINV_DICT_WIDTH_PAD:\t%u\nN_BLOCKS:\t%u\nBLOCK_SIZE:\t%d\n", INV_DICT_SIZE, INV_DICT_WIDTH, INV_DICT_WIDTH_PAD, N_BLOCKS, BLOCK_SIZE);

	sprintf(report_file, "%s/cu_query_report.txt", output_dir);

	unsigned int *d_inv_dict, *d_matches;
	unsigned int *d_query_ones;
	unsigned int ones_cnt;

	inv_dictionary = (unsigned int *)malloc(INV_DICT_SIZE*sizeof(unsigned int));

	load_inv_dictionary(dict_file);
	load_query(query_file);
	ones_cnt = findQueryOnes(query);


#ifdef PROFILING
	for (int i = 0; i < 100; ++i)
	{
#endif	

		// const int num_streams = 8;
		// cudaStream_t streams[num_streams];

		hipMalloc((void **)&d_inv_dict, INV_DICT_SIZE*sizeof(unsigned int));
		hipMalloc((void **)&d_query_ones, ones_cnt*sizeof(unsigned int));
		hipMalloc((void **)&d_matches, N_FILES*sizeof(unsigned int));
		hipMemset(d_matches, 0, N_FILES*sizeof(unsigned int));

		// printf("Allocated arrays...\n");

		hipMemcpy(d_inv_dict, inv_dictionary, INV_DICT_SIZE*sizeof(unsigned int), hipMemcpyHostToDevice);
		hipError_t err = hipMemcpy(d_query_ones, query_ones, ones_cnt*sizeof(unsigned int), hipMemcpyHostToDevice);

		printf("Err: %d\n", err);
		// printf("Query...\n");

		// for(int i=0; i < num_streams; i++) {
		// 	cudaStreamCreate(&streams[i]);
		// }

		// for(int i=0; i < num_streams; i++) {
		queryKernel<<<N_BLOCKS, BLOCK_SIZE>>>((unsigned int *)d_inv_dict, INV_DICT_WIDTH, INV_DICT_WIDTH_PAD, d_query_ones, ones_cnt, d_matches, sizeof(int), N_THREADS);
		hipMemcpy(matches, d_matches, N_FILES*sizeof(unsigned int), hipMemcpyDeviceToHost);
		// }
		// printMatches();

		load_files(files_file);
		reportQuery(report_file);

		hipFree(d_inv_dict);
		hipFree(d_query_ones);
		hipFree(d_matches);
		
#ifdef PROFILING
	}
#endif
	free(inv_dictionary);

	printf("Ended! :)\n");

	return 0;
}
	.text
	.file	"cu-backup.hip"
	.globl	_Z26__device_stub__queryKernelPjjjS_jS_jj # -- Begin function _Z26__device_stub__queryKernelPjjjS_jS_jj
	.type	_Z26__device_stub__queryKernelPjjjS_jS_jj,@function
_Z26__device_stub__queryKernelPjjjS_jS_jj: # @_Z26__device_stub__queryKernelPjjjS_jS_jj
	.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	$160, %rsp
	.cfi_def_cfa_offset 208
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	20(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	16(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	48(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	12(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	40(%rsp), %r8
	movq	%r9, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	208(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	216(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z11queryKernelPjjjS_jS_jj, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$176, %rsp
	.cfi_adjust_cfa_offset -176
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z26__device_stub__queryKernelPjjjS_jS_jj, .Lfunc_end0-_Z26__device_stub__queryKernelPjjjS_jS_jj
	.cfi_endproc
                                        # -- End function
	.globl	_Z19load_inv_dictionaryPc       # -- Begin function _Z19load_inv_dictionaryPc
	.type	_Z19load_inv_dictionaryPc,@function
_Z19load_inv_dictionaryPc:              # @_Z19load_inv_dictionaryPc
	.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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %r14
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.LBB1_2
# %bb.1:
	movl	$.L.str.1, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB1_2:                                # %.preheader.preheader
	xorl	%r14d, %r14d
	xorl	%r15d, %r15d
.LBB1_3:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
	movq	%r15, %rax
	shlq	$8, %rax
	leaq	(%rax,%rax,2), %r12
	xorl	%r13d, %r13d
.LBB1_4:                                #   Parent Loop BB1_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	inv_dictionary(%rip), %rdx
	addq	%r14, %rdx
	addq	%r13, %rdx
	movl	$.L.str.2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$1, %eax
	je	.LBB1_6
# %bb.5:                                #   in Loop: Header=BB1_4 Depth=2
	movl	$.Lstr.2, %edi
	callq	puts@PLT
.LBB1_6:                                #   in Loop: Header=BB1_4 Depth=2
	addq	$4, %r13
	cmpq	$2624, %r13                     # imm = 0xA40
	jne	.LBB1_4
# %bb.7:                                #   in Loop: Header=BB1_3 Depth=1
	movq	inv_dictionary(%rip), %rax
	leaq	(%rax,%r12,4), %rdx
	addq	$2624, %rdx                     # imm = 0xA40
	movl	$.L.str.4, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$1, %eax
	je	.LBB1_9
# %bb.8:                                #   in Loop: Header=BB1_3 Depth=1
	movl	$.Lstr.2, %edi
	callq	puts@PLT
.LBB1_9:                                #   in Loop: Header=BB1_3 Depth=1
	incq	%r15
	addq	$3072, %r14                     # imm = 0xC00
	cmpq	$10000, %r15                    # imm = 0x2710
	jne	.LBB1_3
# %bb.10:
	movq	%rbx, %rdi
	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
	jmp	fclose                          # TAILCALL
.Lfunc_end1:
	.size	_Z19load_inv_dictionaryPc, .Lfunc_end1-_Z19load_inv_dictionaryPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z10load_queryPc                # -- Begin function _Z10load_queryPc
	.type	_Z10load_queryPc,@function
_Z10load_queryPc:                       # @_Z10load_queryPc
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %r14
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.LBB2_1
# %bb.6:
	movl	$.L.str.1, %edi
	movq	%r14, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB2_1:                                # %.preheader
	xorl	%r14d, %r14d
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
	leaq	query(%r14), %rdx
	movl	$.L.str.5, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$1, %eax
	je	.LBB2_4
# %bb.3:                                #   in Loop: Header=BB2_2 Depth=1
	movl	$.Lstr.2, %edi
	callq	puts@PLT
.LBB2_4:                                #   in Loop: Header=BB2_2 Depth=1
	incq	%r14
	cmpq	$10000, %r14                    # imm = 0x2710
	jne	.LBB2_2
# %bb.5:
	movq	%rbx, %rdi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	fclose                          # TAILCALL
.Lfunc_end2:
	.size	_Z10load_queryPc, .Lfunc_end2-_Z10load_queryPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z12printMatchesv               # -- Begin function _Z12printMatchesv
	.type	_Z12printMatchesv,@function
_Z12printMatchesv:                      # @_Z12printMatchesv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	xorl	%ebx, %ebx
.LBB3_1:                                # =>This Inner Loop Header: Depth=1
	movl	matches(,%rbx,4), %edx
	movl	$.L.str.6, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	incq	%rbx
	cmpq	$21000, %rbx                    # imm = 0x5208
	jne	.LBB3_1
# %bb.2:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z12printMatchesv, .Lfunc_end3-_Z12printMatchesv
	.cfi_endproc
                                        # -- End function
	.globl	_Z10load_filesPc                # -- Begin function _Z10load_filesPc
	.type	_Z10load_filesPc,@function
_Z10load_filesPc:                       # @_Z10load_filesPc
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %rbx
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %r14
	testq	%rax, %rax
	jne	.LBB4_1
# %bb.6:
	movl	$.L.str.1, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB4_1:                                # %.preheader
	xorl	%r15d, %r15d
.LBB4_2:                                # =>This Inner Loop Header: Depth=1
	leaq	files(%r15), %rdx
	movl	$.L.str.7, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$1, %eax
	je	.LBB4_4
# %bb.3:                                #   in Loop: Header=BB4_2 Depth=1
	movl	$.L.str.8, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB4_4:                                #   in Loop: Header=BB4_2 Depth=1
	addq	$100, %r15
	cmpq	$2100000, %r15                  # imm = 0x200B20
	jne	.LBB4_2
# %bb.5:
	movq	%r14, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	fclose                          # TAILCALL
.Lfunc_end4:
	.size	_Z10load_filesPc, .Lfunc_end4-_Z10load_filesPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z13findQueryOnesPc             # -- Begin function _Z13findQueryOnesPc
	.type	_Z13findQueryOnesPc,@function
_Z13findQueryOnesPc:                    # @_Z13findQueryOnesPc
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movq	%rdi, %rbx
	xorl	%r14d, %r14d
	xorl	%ebp, %ebp
.LBB5_1:                                # =>This Inner Loop Header: Depth=1
	cmpb	$49, (%rbx,%r14)
	jne	.LBB5_3
# %bb.2:                                #   in Loop: Header=BB5_1 Depth=1
	movl	%ebp, %eax
	movl	%r14d, query_ones(,%rax,4)
	movl	$.L.str.9, %edi
	movl	%r14d, %esi
	xorl	%eax, %eax
	callq	printf
	incl	%ebp
.LBB5_3:                                #   in Loop: Header=BB5_1 Depth=1
	incq	%r14
	cmpq	$10000, %r14                    # imm = 0x2710
	jne	.LBB5_1
# %bb.4:
	movl	%ebp, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z13findQueryOnesPc, .Lfunc_end5-_Z13findQueryOnesPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z11reportQueryPc               # -- Begin function _Z11reportQueryPc
	.type	_Z11reportQueryPc,@function
_Z11reportQueryPc:                      # @_Z11reportQueryPc
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	$.L.str.10, %esi
	callq	fopen
	movq	%rax, %rbx
	movq	$-84000, %r14                   # imm = 0xFFFEB7E0
.LBB6_1:                                # =>This Inner Loop Header: Depth=1
	movl	matches+84000(%r14), %eax
	testl	%eax, %eax
	je	.LBB6_3
# %bb.2:                                #   in Loop: Header=BB6_1 Depth=1
	decl	%eax
	imulq	$100, %rax, %rax
	leaq	files(%rax), %rdx
	movl	$.L.str.11, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
.LBB6_3:                                #   in Loop: Header=BB6_1 Depth=1
	addq	$4, %r14
	jne	.LBB6_1
# %bb.4:
	movq	%rbx, %rdi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	fclose                          # TAILCALL
.Lfunc_end6:
	.size	_Z11reportQueryPc, .Lfunc_end6-_Z11reportQueryPc
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$592, %rsp                      # imm = 0x250
	.cfi_def_cfa_offset 640
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	cmpl	$5, %edi
	jne	.LBB7_1
# %bb.2:
	movq	%rsi, %r15
	movq	8(%rsi), %rsi
	leaq	144(%rsp), %rdi
	callq	strcpy@PLT
	movq	16(%r15), %rsi
	leaq	480(%rsp), %rbx
	movq	%rbx, %rdi
	callq	strcpy@PLT
	movq	24(%r15), %rsi
	leaq	368(%rsp), %r14
	movq	%r14, %rdi
	callq	strcpy@PLT
	movq	32(%r15), %rsi
	leaq	256(%rsp), %r15
	movq	%r15, %rdi
	callq	strcpy@PLT
	movl	$.L.str.13, %edi
	movl	$7680000, %esi                  # imm = 0x753000
	movl	$657, %edx                      # imm = 0x291
	movl	$768, %ecx                      # imm = 0x300
	movl	$11, %r8d
	movl	$64, %r9d
	xorl	%eax, %eax
	callq	printf
	leaq	32(%rsp), %rdi
	movl	$.L.str.14, %esi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	sprintf
	movl	$30720000, %edi                 # imm = 0x1D4C000
	callq	malloc
	movq	%rax, inv_dictionary(%rip)
	movq	%rbx, %rdi
	callq	_Z19load_inv_dictionaryPc
	movq	%r14, %rdi
	callq	_Z10load_queryPc
	xorl	%r14d, %r14d
	xorl	%ebx, %ebx
.LBB7_3:                                # =>This Inner Loop Header: Depth=1
	cmpb	$49, query(%r14)
	jne	.LBB7_5
# %bb.4:                                #   in Loop: Header=BB7_3 Depth=1
	movl	%ebx, %eax
	movl	%r14d, query_ones(,%rax,4)
	movl	$.L.str.9, %edi
	movl	%r14d, %esi
	xorl	%eax, %eax
	callq	printf
	incl	%ebx
.LBB7_5:                                #   in Loop: Header=BB7_3 Depth=1
	incq	%r14
	cmpq	$10000, %r14                    # imm = 0x2710
	jne	.LBB7_3
# %bb.6:                                # %_Z13findQueryOnesPc.exit
	leaq	24(%rsp), %r12
	movl	$30720000, %esi                 # imm = 0x1D4C000
	movq	%r12, %rdi
	callq	hipMalloc
	movl	%ebx, %r15d
	shlq	$2, %r15
	leaq	16(%rsp), %r13
	movq	%r13, %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	leaq	8(%rsp), %r14
	movl	$84000, %esi                    # imm = 0x14820
	movq	%r14, %rdi
	callq	hipMalloc
	movq	(%r14), %rdi
	xorl	%r14d, %r14d
	movl	$84000, %edx                    # imm = 0x14820
	xorl	%esi, %esi
	callq	hipMemset
	movq	(%r12), %rdi
	movq	inv_dictionary(%rip), %rsi
	movl	$30720000, %edx                 # imm = 0x1D4C000
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%r13), %rdi
	movl	$query_ones, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$.L.str.15, %edi
	movl	%eax, %esi
	xorl	%eax, %eax
	callq	printf
	movabsq	$4294967307, %rdi               # imm = 0x10000000B
	leaq	53(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB7_8
# %bb.7:
	movq	24(%rsp), %rdi
	movq	16(%rsp), %rcx
	movq	8(%rsp), %r9
	movl	$657, %esi                      # imm = 0x291
	movl	$768, %edx                      # imm = 0x300
	movl	%ebx, %r8d
	pushq	$704                            # imm = 0x2C0
	.cfi_adjust_cfa_offset 8
	pushq	$4
	.cfi_adjust_cfa_offset 8
	callq	_Z26__device_stub__queryKernelPjjjS_jS_jj
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
.LBB7_8:
	movq	8(%rsp), %rsi
	movl	$matches, %edi
	movl	$84000, %edx                    # imm = 0x14820
	movl	$2, %ecx
	callq	hipMemcpy
	leaq	144(%rsp), %rdi
	callq	_Z10load_filesPc
	leaq	32(%rsp), %rdi
	callq	_Z11reportQueryPc
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	inv_dictionary(%rip), %rdi
	callq	free
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	jmp	.LBB7_9
.LBB7_1:
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	movl	$1, %r14d
.LBB7_9:
	movl	%r14d, %eax
	addq	$592, %rsp                      # imm = 0x250
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end7:
	.size	main, .Lfunc_end7-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	.LBB8_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB8_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z11queryKernelPjjjS_jS_jj, %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_end8:
	.size	__hip_module_ctor, .Lfunc_end8-__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	.LBB9_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
.LBB9_2:
	retq
.Lfunc_end9:
	.size	__hip_module_dtor, .Lfunc_end9-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	inv_dictionary,@object          # @inv_dictionary
	.bss
	.globl	inv_dictionary
	.p2align	3, 0x0
inv_dictionary:
	.quad	0
	.size	inv_dictionary, 8

	.type	files,@object                   # @files
	.globl	files
	.p2align	4, 0x0
files:
	.zero	2100000
	.size	files, 2100000

	.type	query,@object                   # @query
	.globl	query
	.p2align	4, 0x0
query:
	.zero	10000
	.size	query, 10000

	.type	query_ones,@object              # @query_ones
	.globl	query_ones
	.p2align	4, 0x0
query_ones:
	.zero	40000
	.size	query_ones, 40000

	.type	matches,@object                 # @matches
	.globl	matches
	.p2align	4, 0x0
matches:
	.zero	84000
	.size	matches, 84000

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

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

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Error while opening %s\n"
	.size	.L.str.1, 24

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%u "
	.size	.L.str.2, 4

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%u\n"
	.size	.L.str.4, 4

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%c"
	.size	.L.str.5, 3

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Match %d:\t%u\n"
	.size	.L.str.6, 14

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Error reading file: %s\n"
	.size	.L.str.8, 24

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"One position:\t%d\n"
	.size	.L.str.9, 18

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

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"%s\n"
	.size	.L.str.11, 4

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"INV_DICT_SIZE:\t%u\nINV_DICT_WIDTH:\t%u\nINV_DICT_WIDTH_PAD:\t%u\nN_BLOCKS:\t%u\nBLOCK_SIZE:\t%d\n"
	.size	.L.str.13, 89

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"%s/cu_query_report.txt"
	.size	.L.str.14, 23

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"Err: %d\n"
	.size	.L.str.15, 9

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z11queryKernelPjjjS_jS_jj"
	.size	.L__unnamed_1, 27

	.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.2,@object                 # @str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr.2:
	.asciz	"ERROR!\t fscanf did not fill all arguments"
	.size	.Lstr.2, 42

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Ended! :)"
	.size	.Lstr.3, 10

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"Requires arguments: <files file> <dictionary input file> <query input file> <output directory>"
	.size	.Lstr.4, 95

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z26__device_stub__queryKernelPjjjS_jS_jj
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym files
	.addrsig_sym query
	.addrsig_sym query_ones
	.addrsig_sym matches
	.addrsig_sym _Z11queryKernelPjjjS_jS_jj
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z11queryKernelPjjjS_jS_jj ; -- Begin function _Z11queryKernelPjjjS_jS_jj
	.globl	_Z11queryKernelPjjjS_jS_jj
	.p2align	8
	.type	_Z11queryKernelPjjjS_jS_jj,@function
_Z11queryKernelPjjjS_jS_jj:             ; @_Z11queryKernelPjjjS_jS_jj
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x3c
	s_load_b64 s[2:3], s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_cmp_gt_u32_e32 vcc_lo, s2, v1
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB0_12
; %bb.1:
	s_load_b32 s2, s[0:1], 0x18
	s_mov_b32 s5, 0
	s_waitcnt lgkmcnt(0)
	s_cmp_eq_u32 s2, 0
	s_cbranch_scc1 .LBB0_4
; %bb.2:                                ; %.lr.ph
	s_clause 0x1
	s_load_b64 s[8:9], s[0:1], 0x0
	s_load_b64 s[6:7], s[0:1], 0x10
	v_mov_b32_e32 v2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s8, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s9, v3, vcc_lo
	v_mov_b32_e32 v2, -1
.LBB0_3:                                ; =>This Inner Loop Header: Depth=1
	s_load_b32 s4, s[6:7], 0x0
	s_add_i32 s2, s2, -1
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s4, s4, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b64 s[8:9], s[4:5], 2
	s_add_u32 s6, s6, 4
	v_add_co_u32 v4, vcc_lo, v0, s8
	v_add_co_ci_u32_e32 v5, vcc_lo, s9, v3, vcc_lo
	s_addc_u32 s7, s7, 0
	s_cmp_eq_u32 s2, 0
	global_load_b32 v4, v[4:5], off
	s_waitcnt vmcnt(0)
	v_and_b32_e32 v2, v4, v2
	s_cbranch_scc0 .LBB0_3
	s_branch .LBB0_5
.LBB0_4:
	v_mov_b32_e32 v2, -1
.LBB0_5:                                ; %.preheader
	s_load_b32 s2, s[0:1], 0x28
	s_mov_b32 s3, 0
	s_waitcnt lgkmcnt(0)
	s_lshl_b32 s2, s2, 3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s2, 0
	s_cbranch_scc1 .LBB0_12
; %bb.6:                                ; %.lr.ph34
	s_load_b64 s[0:1], s[0:1], 0x20
	v_mul_lo_u32 v3, s2, v1
	v_mov_b32_e32 v1, 0
                                        ; implicit-def: $sgpr4
	s_delay_alu instid0(VALU_DEP_2)
	v_dual_mov_b32 v5, 0 :: v_dual_add_nc_u32 v4, s2, v3
.LBB0_7:                                ; =>This Inner Loop Header: Depth=1
	s_or_b32 s4, s4, exec_lo
	s_mov_b32 s5, exec_lo
	v_cmpx_ne_u32_e32 0, v2
	s_cbranch_execz .LBB0_11
; %bb.8:                                ;   in Loop: Header=BB0_7 Depth=1
	v_and_b32_e32 v0, 1, v2
	s_mov_b32 s6, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_eq_u32_e32 1, v0
	s_cbranch_execz .LBB0_10
; %bb.9:                                ;   in Loop: Header=BB0_7 Depth=1
	v_add_nc_u32_e32 v0, v5, v3
	v_add_nc_u32_e32 v5, 1, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[6:7], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v6, vcc_lo, s0, v6
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v7, vcc_lo, s1, v7, vcc_lo
	global_store_b32 v[6:7], v4, off
.LBB0_10:                               ;   in Loop: Header=BB0_7 Depth=1
	s_or_b32 exec_lo, exec_lo, s6
	s_add_i32 s2, s2, -1
	v_lshrrev_b32_e32 v2, 1, v2
	s_cmp_eq_u32 s2, 0
	v_add_nc_u32_e32 v4, -1, v4
	s_cselect_b32 s6, -1, 0
	s_and_not1_b32 s4, s4, exec_lo
	s_and_b32 s6, s6, exec_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 s4, s4, s6
.LBB0_11:                               ; %Flow
                                        ;   in Loop: Header=BB0_7 Depth=1
	s_or_b32 exec_lo, exec_lo, s5
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s5, exec_lo, s4
	s_or_b32 s3, s5, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s3
	s_cbranch_execnz .LBB0_7
.LBB0_12:                               ; %.critedge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11queryKernelPjjjS_jS_jj
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 304
		.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 8
		.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	_Z11queryKernelPjjjS_jS_jj, .Lfunc_end0-_Z11queryKernelPjjjS_jS_jj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 448
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 1
; 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:
      - .actual_access:  read_only
        .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         12
        .size:           4
        .value_kind:     by_value
      - .actual_access:  read_only
        .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .offset:         40
        .size:           4
        .value_kind:     by_value
      - .offset:         44
        .size:           4
        .value_kind:     by_value
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         52
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         56
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         60
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         62
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         64
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         66
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         68
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         70
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         104
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         112
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 304
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z11queryKernelPjjjS_jS_jj
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z11queryKernelPjjjS_jS_jj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
