

// Host defines
#define NUM_THREADS 1024
#define NUM_GRID 1
#define MAX_SIM_NUM 50000
#define THRESHOLD 2

// Includes
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <limits.h>
using namespace std;
// GPU Kernels declarations
__global__ void CudaTest_kernel(int max_sim_num, int threshold, unsigned int* di_index, unsigned int* di_query, unsigned int* result, char* di_static_table, unsigned int* result_num, unsigned int frame_num_index, unsigned int frame_num_query);

void bulidSimTable(string hashcodePath, string queryPath, string resultPath, unsigned int frame_num_index, unsigned int frame_num_query, int threshold){
	clock_t cstart=clock();
	//initalize data size
//	unsigned int frame_num_index = 924287;//number of frames in lib
//	unsigned int frame_num_query =1068;//number of frames in query
	unsigned int static_table_num = 256;
	unsigned int mem_size_lib = frame_num_index * sizeof(unsigned int);//the memory size hvectors_in_lib needed
	unsigned int mem_size_query = frame_num_query * sizeof(unsigned int);//the memory size hvectors_query needed
	unsigned int result_size = frame_num_query * MAX_SIM_NUM * sizeof(unsigned int);//the memory size which will store the result
	unsigned int static_table_size = static_table_num * sizeof(char);


	// Host variables
	unsigned int* hi_index;//input data in cpu which contains all feature vectors of frames in lib
	unsigned int* hi_query;//input data in cpu which contains all feature vectors of query frames
	unsigned int* ho_result;//the result in host
	unsigned int* ho_result_cnt;
	char hi_static_table[256]=
	{
					0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
			        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
			        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
			        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
			        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
			        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
			        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
			        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
			        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
			        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
			        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
			        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
			        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
			        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
			        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
			        4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
	};


	// Device variables
	unsigned int* di_index;//input data in gpu which contains all feature vectors of frames
	unsigned int* di_query;//input data in cpu which contains all feature vectors of query frames
	unsigned int* do_result;//the result in device
	unsigned int* do_result_cnt;
	char* di_static_table;


	//allocate memory in host and device
	hi_index = (unsigned int*) malloc(mem_size_lib);//allocate the memory to hvectors_in_lib
	hi_query = (unsigned int*) malloc(mem_size_query);//allocate the memory to hvectors_query
	ho_result_cnt = (unsigned int*) malloc(mem_size_query);

	cudaMalloc((void**) &di_index, mem_size_lib);//allocate dvectors_in_lib to the device memory
	cudaMalloc((void**) &di_query, mem_size_query);//allocate dvectors_query to the device memory
	cudaMalloc((void**) &di_static_table, static_table_size);//allocate device_result to the device memory
	cudaMalloc((void**) &do_result_cnt, mem_size_query);

	cudaSetDevice(0);
	cudaSetDeviceFlags(cudaDeviceMapHost);
	cudaHostAlloc((void**)&(ho_result),result_size,cudaHostAllocMapped);
	cudaHostGetDevicePointer((void**)&(do_result),ho_result,0);


	//initalize host data
	unsigned int n;
	int cnt = 0;
	FILE *fp,*fp2;

	fp = fopen(hashcodePath.c_str(),"r");
	//cout<<hashcodePath.c_str()<<endl;
	while(!feof(fp) && cnt < frame_num_index){
		fscanf(fp, "%u", &n);
		hi_index[cnt] = n;
		cnt++;
	}
	//cout<<"count ="<<cnt<<endl;

	cnt = 0;
	fp = fopen(queryPath.c_str(),"r");
	//cout<<queryPath.c_str()<<endl;
	while(!feof(fp) && cnt < frame_num_query){
		fscanf(fp,"%u", &n);
		hi_query[cnt] = n;
		cnt++;
	}
	//cout<<"count = "<<cnt<<endl;


	memset(ho_result_cnt, 0, frame_num_query*4);


	//initalize device data
	 cudaMemcpy(di_index, hi_index, mem_size_lib, cudaMemcpyHostToDevice);//copy hvectors_in_lib in memory to dvectors_in_lib in gpu
	 cudaMemcpy(di_query, hi_query, mem_size_query, cudaMemcpyHostToDevice);//copy hvectors_query in memory to dvectors_query in gpu
	 cudaMemcpy(di_static_table,hi_static_table,static_table_size,cudaMemcpyHostToDevice);
	 cudaMemcpy(do_result_cnt, ho_result_cnt, mem_size_query, cudaMemcpyHostToDevice);


	//excute kernel in GPU
	//int threshold = THRESHOLD;
	int max_sim_num = MAX_SIM_NUM;
	dim3 grid((int)ceil((double)frame_num_index/1024), (int)ceil((double)frame_num_query/512), 1);


	CudaTest_kernel<<<grid, NUM_THREADS>>>(max_sim_num, threshold, di_index, di_query, do_result, di_static_table, do_result_cnt, frame_num_index, frame_num_query);

	cudaThreadSynchronize();
	//copy the result back to host memory
	cudaMemcpy(ho_result_cnt, do_result_cnt, mem_size_query, cudaMemcpyDeviceToHost);
	cudaMemcpy(ho_result, do_result, result_size, cudaMemcpyDeviceToHost);



	//deal with the result

//	printf("query:%u\n",hi_query[0]);
//	for(int i = 0; i < frame_num_query ; i ++)
//	{
//		//printf("result 0:%u\n",ho_result_cnt[i]);
//		for(int j = 0; j < ho_result_cnt[i]; j++)
//			cout<<ho_result[i*MAX_SIM_NUM+j]<<" ";
//		cout<<endl;
//	}
	fp2 = fopen(resultPath.c_str(),"w+");
	int max_length = 0;
	for(int i = 0 ; i < frame_num_query ; i++)
	{
		if(max_length < ho_result_cnt[i])
			max_length = ho_result_cnt[i];
		for(int j = 0; j < ho_result_cnt[i]; j++)
			fprintf(fp2,"%u ",ho_result[i*MAX_SIM_NUM+j]);
		fprintf(fp2,"\n");
	}
	cout<<"max matched count is: "<<max_length<<endl;
	cout << "size of long: " << sizeof(2l) << endl;
	clock_t cend=clock();
	printf("time:%f\n",(float)(cend-cstart)/CLOCKS_PER_SEC);

////	free up the host memory
//	free(ho_result_cnt);
//	free(hi_index);
//	free(hi_query);
//	free(ho_result);
//
//
////	free up the device memory
//	cudaFree(do_result_cnt);
//	cudaFree(di_index);//
//	cudaFree(di_query);
//	cudaFree(do_result);

}

void sortTable(unsigned int* ho_result_cnt, unsigned int* ho_result, unsigned int frame_num_query){

}

//////////////////////
// Program main
//////////////////////
int main(int argc, char** argv) {
	if(argc == 7)
	{
		string hashcodePath = argv[1];
		string queryPath = argv[2];
		string resultPath = argv[3];
		int frame_num_index = atoi(argv[4]);
		int frame_num_query = atoi(argv[5]);
		int threshold = atoi(argv[6]);
//		unsigned int frame_num_index = 1000001;
//		unsigned int frame_num_query =493;
//		int threshold = 2;
//		string hashcodePath = "/root/hashcode.txt";
//		string queryPath = "/root/query.txt";
//		string resultPath = "/root/result.txt";
		//cout<<hashcodePath<<endl<<queryPath<<endl<<frame_num_index<<endl<<frame_num_query<<endl<<threshold<<endl;
		bulidSimTable(hashcodePath, queryPath, resultPath, frame_num_index, frame_num_query, threshold);
	}
	return 0;
}


	.file	"tmpxft_00332c9a_00000000-6_cuda_match.32.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3640:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3640:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"r"
.LC2:
	.string	"%u"
.LC5:
	.string	"w+"
.LC6:
	.string	"%u "
.LC7:
	.string	"\n"
.LC8:
	.string	"max matched count is: "
.LC9:
	.string	"size of long: "
.LC11:
	.string	"time:%f\n"
	.section	.rodata
.LC0:
	.string	""
	.ascii	"\001\001\002\001\002\002\003\001\002\002\003\002\003\003\004"
	.ascii	"\001\002\002\003\002\003\003\004\002\003\003\004\003\004\004"
	.ascii	"\005\001\002\002\003\002\003\003\004\002\003\003\004\003\004"
	.ascii	"\004\005\002\003\003\004\003\004\004\005\003\004\004\005\004"
	.ascii	"\005\005\006\001\002\002\003\002\003\003\004\002\003\003\004"
	.ascii	"\003\004\004\005\002\003\003\004\003\004\004\005\003\004\004"
	.ascii	"\005\004\005\005\006\002\003\003\004\003\004\004\005\003\004"
	.ascii	"\004\005\004\005\005\006\003\004\004\005\004\005\005\006\004"
	.ascii	"\005\005\006\005\006\006\007\001\002\002\003\002\003\003\004"
	.ascii	"\002\003\003\004\003\004\004\005\002\003\003\004\003\004\004"
	.ascii	"\005\003\004\004\005\004\005\005\006\002\003\003\004\003\004"
	.ascii	"\004\005\003\004\004\005\004\005\005\006\003\004\004\005\004"
	.ascii	"\005\005\006\004\005\005\006\005\006\006\007\002\003\003\004"
	.ascii	"\003\004\004\005\003\004\004\005\004\005\005\006\003\004\004"
	.ascii	"\005\004\005\005\006\004\005\005\006\005\006\006\007\003\004"
	.ascii	"\004\005\004\005\005\006\004\005\005\006\005\006\006\007\004"
	.ascii	"\005\005\006\005\006\006\007\005\006\006\007\006\007\007\b"
	.text
	.globl	_Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji
	.type	_Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji, @function
_Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji:
.LFB3635:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	%ecx, %r15d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%r15, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%r8d, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$440, %rsp
	.cfi_def_cfa_offset 496
	movl	%r9d, 76(%rsp)
	movq	%rdx, 64(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 424(%rsp)
	xorl	%eax, %eax
	call	clock@PLT
	leaq	168(%rsp), %rdi
	movl	$64, %ecx
	leaq	.LC0(%rip), %rsi
	rep movsl
	movq	%rax, 56(%rsp)
	leal	0(,%r15,4), %eax
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movq	%rax, 32(%rsp)
	leal	0(,%rbp,4), %eax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movq	%rax, 40(%rsp)
	call	malloc@PLT
	movq	16(%rsp), %rsi
	leaq	104(%rsp), %rdi
	movq	%rax, %rbx
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	112(%rsp), %rdi
	call	cudaMalloc@PLT
	leaq	136(%rsp), %rdi
	movl	$256, %esi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	128(%rsp), %rdi
	call	cudaMalloc@PLT
	xorl	%edi, %edi
	call	cudaSetDevice@PLT
	movl	$8, %edi
	call	cudaSetDeviceFlags@PLT
	imull	$200000, %ebp, %eax
	leaq	96(%rsp), %rdi
	movl	$2, %edx
	movq	%rax, %rsi
	movq	%rax, 24(%rsp)
	call	cudaHostAlloc@PLT
	movq	96(%rsp), %rsi
	leaq	120(%rsp), %rdi
	xorl	%edx, %edx
	call	cudaHostGetDevicePointer@PLT
	movq	0(%r13), %rdi
	leaq	.LC1(%rip), %rsi
	xorl	%r13d, %r13d
	call	fopen@PLT
	movq	%rax, 48(%rsp)
.L4:
	movq	48(%rsp), %rdi
	call	feof@PLT
	testl	%eax, %eax
	jne	.L3
	cmpq	%r15, %r13
	je	.L3
	movq	48(%rsp), %rdi
	leaq	92(%rsp), %rdx
	leaq	.LC2(%rip), %rsi
	call	__isoc23_fscanf@PLT
	movl	92(%rsp), %eax
	movq	32(%rsp), %rcx
	movl	%eax, (%rcx,%r13,4)
	incq	%r13
	jmp	.L4
.L3:
	movq	(%r14), %rdi
	xorl	%r13d, %r13d
	movl	%ebp, %r14d
	leaq	.LC1(%rip), %rsi
	leaq	.LC2(%rip), %r15
	call	fopen@PLT
	movq	%rax, 48(%rsp)
.L13:
	movq	48(%rsp), %rdi
	call	feof@PLT
	testl	%eax, %eax
	jne	.L5
	cmpq	%r14, %r13
	jne	.L6
.L5:
	movq	8(%rsp), %rcx
	xorl	%esi, %esi
	movq	%rbx, %rdi
	movq	%rcx, %rdx
	call	__memset_chk@PLT
	movq	16(%rsp), %rdx
	movq	32(%rsp), %rsi
	movl	$1, %ecx
	movq	104(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movq	40(%rsp), %rsi
	movl	$1, %ecx
	movq	112(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	$1, %ecx
	movl	$256, %edx
	movq	136(%rsp), %rdi
	leaq	168(%rsp), %rsi
	call	cudaMemcpy@PLT
	movq	8(%rsp), %rdx
	movl	$1, %ecx
	movq	%rbx, %rsi
	movq	128(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	%ebp, %eax
	cvtsi2sdq	%rax, %xmm0
	mulsd	.LC3(%rip), %xmm0
	call	ceil@PLT
	movl	%r12d, %eax
	movq	%xmm0, %r13
	cvtsi2sdq	%rax, %xmm0
	mulsd	.LC4(%rip), %xmm0
	call	ceil@PLT
	movq	%r13, %xmm1
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	cvttsd2sil	%xmm0, %eax
	movl	$4194305, %edx
	movl	$1, %ecx
	movl	$1, %esi
	movl	$1, 152(%rsp)
	salq	$10, %rdx
	movq	%rdx, 156(%rsp)
	movl	$1, 164(%rsp)
	movl	%eax, 144(%rsp)
	cvttsd2sil	%xmm1, %eax
	movl	%eax, 148(%rsp)
	movq	144(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L11
	pushq	%rax
	.cfi_def_cfa_offset 504
	movl	$50000, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 512
	pushq	%r12
	.cfi_def_cfa_offset 520
	pushq	152(%rsp)
	.cfi_def_cfa_offset 528
	movq	168(%rsp), %r9
	movq	152(%rsp), %r8
	movq	144(%rsp), %rcx
	movq	136(%rsp), %rdx
	movl	108(%rsp), %esi
	call	_Z15CudaTest_kerneliiPjS_S_PcS_jj@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 496
	jmp	.L11
.L6:
	movq	48(%rsp), %rdi
	leaq	92(%rsp), %rdx
	movq	%r15, %rsi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movl	92(%rsp), %eax
	movq	40(%rsp), %rcx
	movl	%eax, (%rcx,%r13,4)
	incq	%r13
	jmp	.L13
.L11:
	call	cudaThreadSynchronize@PLT
	movq	8(%rsp), %rdx
	movq	%rbx, %rdi
	xorl	%r12d, %r12d
	movq	128(%rsp), %rsi
	movl	$2, %ecx
	xorl	%ebp, %ebp
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdx
	movq	120(%rsp), %rsi
	movl	$2, %ecx
	movq	96(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	64(%rsp), %rax
	leaq	.LC5(%rip), %rsi
	movq	(%rax), %rdi
	call	fopen@PLT
	movq	%rax, 8(%rsp)
.L14:
	cmpq	%r14, %r12
	je	.L23
	movl	(%rbx,%r12,4), %eax
	cmpl	%eax, %ebp
	cmovb	%eax, %ebp
	imull	$50000, %r12d, %r15d
	xorl	%r13d, %r13d
	movslq	%r15d, %r15
	salq	$2, %r15
.L16:
	cmpl	(%rbx,%r12,4), %r13d
	jnb	.L24
	movq	96(%rsp), %rax
	movq	8(%rsp), %rdi
	movl	$2, %esi
	incl	%r13d
	leaq	.LC6(%rip), %rdx
	movl	(%rax,%r15), %ecx
	xorl	%eax, %eax
	addq	$4, %r15
	call	__fprintf_chk@PLT
	jmp	.L16
.L24:
	movq	8(%rsp), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	incq	%r12
	leaq	.LC7(%rip), %rdx
	call	__fprintf_chk@PLT
	jmp	.L14
.L23:
	leaq	_ZSt4cout(%rip), %rbx
	leaq	.LC8(%rip), %rsi
	movq	%rbx, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	movq	%rbx, %rdi
	leaq	.LC9(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$8, %esi
	movq	%rax, %rdi
	call	_ZNSo9_M_insertImEERSoT_@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	call	clock@PLT
	movq	56(%rsp), %rbx
	movl	$2, %edi
	leaq	.LC11(%rip), %rsi
	subq	%rbx, %rax
	cvtsi2ssq	%rax, %xmm0
	movb	$1, %al
	divss	.LC10(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	424(%rsp), %rax
	subq	%fs:40, %rax
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	addq	$440, %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
.LFE3635:
	.size	_Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji, .-_Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji
	.globl	_Z9sortTablePjS_j
	.type	_Z9sortTablePjS_j, @function
_Z9sortTablePjS_j:
.LFB3636:
	.cfi_startproc
	endbr64
	ret
	.cfi_endproc
.LFE3636:
	.size	_Z9sortTablePjS_j, .-_Z9sortTablePjS_j
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3663:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3663:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.rodata._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_.str1.1,"aMS",@progbits,1
.LC13:
	.string	"basic_string: construction from null is not valid"
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC5IS3_EEPKcRKS3_,comdat
	.align 2
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, @function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_:
.LFB3968:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	16(%rdi), %rax
	movq	%rax, (%rdi)
	testq	%rsi, %rsi
	jne	.L29
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L34
	leaq	.LC13(%rip), %rdi
	call	_ZSt19__throw_logic_errorPKc@PLT
.L29:
	movq	%rdi, %rbx
	movq	%rsi, %rdi
	movq	%rsi, %rbp
	call	strlen@PLT
	movq	%rax, (%rsp)
	leaq	0(%rbp,%rax), %r12
	cmpq	$15, %rax
	jbe	.L31
	movq	%rsp, %rsi
	xorl	%edx, %edx
	movq	%rbx, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm@PLT
	movq	%rax, (%rbx)
	movq	(%rsp), %rax
	movq	%rax, 16(%rbx)
.L31:
	movq	(%rbx), %rdi
	movq	%r12, %rdx
	movq	%rbp, %rsi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE13_S_copy_charsEPcPKcS7_@PLT
	movq	(%rsp), %rax
	movq	(%rbx), %rdx
	movq	%rax, 8(%rbx)
	movb	$0, (%rdx,%rax)
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L32
.L34:
	call	__stack_chk_fail@PLT
.L32:
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3968:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, .-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
	.set	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB3637:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3637
	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	$248, %rsp
	.cfi_def_cfa_offset 304
	movq	%fs:40, %rax
	movq	%rax, 232(%rsp)
	xorl	%eax, %eax
	cmpl	$7, %edi
	jne	.L36
	leaq	40(%rsp), %rax
	movq	%rsi, %rbx
	leaq	39(%rsp), %rbp
	movq	8(%rsi), %rsi
	movq	%rax, %rdi
	movq	%rbp, %rdx
	movq	%rax, 8(%rsp)
.LEHB0:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
.LEHE0:
	leaq	72(%rsp), %rax
	movq	16(%rbx), %rsi
	movq	%rbp, %rdx
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
.LEHB1:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
.LEHE1:
	leaq	104(%rsp), %rax
	movq	24(%rbx), %rsi
	movq	%rbp, %rdx
	movq	%rax, %rdi
	movq	%rax, 24(%rsp)
.LEHB2:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
.LEHE2:
	movq	32(%rbx), %rdi
	call	atoi@PLT
	movq	40(%rbx), %rdi
	movl	%eax, %r13d
	call	atoi@PLT
	movq	48(%rbx), %rdi
	leaq	200(%rsp), %rbx
	movl	%eax, %r14d
	call	atoi@PLT
	movq	24(%rsp), %rsi
	movq	%rbx, %rdi
	movl	%eax, %r15d
.LEHB3:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1ERKS4_@PLT
.LEHE3:
	leaq	168(%rsp), %rbp
	movq	16(%rsp), %rsi
	movq	%rbp, %rdi
.LEHB4:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1ERKS4_@PLT
.LEHE4:
	leaq	136(%rsp), %r12
	movq	8(%rsp), %rsi
	movq	%r12, %rdi
.LEHB5:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1ERKS4_@PLT
.LEHE5:
	movl	%r15d, %r9d
	movl	%r14d, %r8d
	movl	%r13d, %ecx
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	movq	%r12, %rdi
.LEHB6:
	call	_Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji
.LEHE6:
	movq	%r12, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	%rbp, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	%rbx, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	24(%rsp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	16(%rsp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	8(%rsp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
.L36:
	movq	232(%rsp), %rax
	subq	%fs:40, %rax
	je	.L44
	jmp	.L51
.L50:
	endbr64
	movq	%rax, %r13
.L37:
	movq	%r12, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L38
.L49:
	endbr64
	movq	%rax, %r13
.L38:
	movq	%rbp, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L39
.L48:
	endbr64
	movq	%rax, %r13
.L39:
	movq	%rbx, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L40
.L47:
	endbr64
	movq	%rax, %r13
.L40:
	movq	24(%rsp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L41
.L46:
	endbr64
	movq	%rax, %r13
.L41:
	movq	16(%rsp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	jmp	.L42
.L45:
	endbr64
	movq	%rax, %r13
.L42:
	movq	8(%rsp), %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	232(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L51
	movq	%r13, %rdi
.LEHB7:
	call	_Unwind_Resume@PLT
.LEHE7:
.L51:
	call	__stack_chk_fail@PLT
.L44:
	addq	$248, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.LFE3637:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA3637:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3637-.LLSDACSB3637
.LLSDACSB3637:
	.uleb128 .LEHB0-.LFB3637
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB3637
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L45-.LFB3637
	.uleb128 0
	.uleb128 .LEHB2-.LFB3637
	.uleb128 .LEHE2-.LEHB2
	.uleb128 .L46-.LFB3637
	.uleb128 0
	.uleb128 .LEHB3-.LFB3637
	.uleb128 .LEHE3-.LEHB3
	.uleb128 .L47-.LFB3637
	.uleb128 0
	.uleb128 .LEHB4-.LFB3637
	.uleb128 .LEHE4-.LEHB4
	.uleb128 .L48-.LFB3637
	.uleb128 0
	.uleb128 .LEHB5-.LFB3637
	.uleb128 .LEHE5-.LEHB5
	.uleb128 .L49-.LFB3637
	.uleb128 0
	.uleb128 .LEHB6-.LFB3637
	.uleb128 .LEHE6-.LEHB6
	.uleb128 .L50-.LFB3637
	.uleb128 0
	.uleb128 .LEHB7-.LFB3637
	.uleb128 .LEHE7-.LEHB7
	.uleb128 0
	.uleb128 0
.LLSDACSE3637:
	.section	.text.startup
	.size	main, .-main
	.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.cst8,"aM",@progbits,8
	.align 8
.LC3:
	.long	0
	.long	1063256064
	.align 8
.LC4:
	.long	0
	.long	1062207488
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC10:
	.long	1232348160
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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:



// Host defines
#define NUM_THREADS 1024
#define NUM_GRID 1
#define MAX_SIM_NUM 50000
#define THRESHOLD 2

// Includes

#include <hip/hip_runtime.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <limits.h>
using namespace std;
// GPU Kernels declarations
__global__ void CudaTest_kernel(int max_sim_num, int threshold, unsigned int* di_index, unsigned int* di_query, unsigned int* result, char* di_static_table, unsigned int* result_num, unsigned int frame_num_index, unsigned int frame_num_query);

void bulidSimTable(string hashcodePath, string queryPath, string resultPath, unsigned int frame_num_index, unsigned int frame_num_query, int threshold){
	clock_t cstart=clock();
	//initalize data size
//	unsigned int frame_num_index = 924287;//number of frames in lib
//	unsigned int frame_num_query =1068;//number of frames in query
	unsigned int static_table_num = 256;
	unsigned int mem_size_lib = frame_num_index * sizeof(unsigned int);//the memory size hvectors_in_lib needed
	unsigned int mem_size_query = frame_num_query * sizeof(unsigned int);//the memory size hvectors_query needed
	unsigned int result_size = frame_num_query * MAX_SIM_NUM * sizeof(unsigned int);//the memory size which will store the result
	unsigned int static_table_size = static_table_num * sizeof(char);


	// Host variables
	unsigned int* hi_index;//input data in cpu which contains all feature vectors of frames in lib
	unsigned int* hi_query;//input data in cpu which contains all feature vectors of query frames
	unsigned int* ho_result;//the result in host
	unsigned int* ho_result_cnt;
	char hi_static_table[256]=
	{
					0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
			        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
			        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
			        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
			        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
			        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
			        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
			        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
			        1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
			        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
			        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
			        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
			        2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
			        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
			        3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
			        4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
	};


	// Device variables
	unsigned int* di_index;//input data in gpu which contains all feature vectors of frames
	unsigned int* di_query;//input data in cpu which contains all feature vectors of query frames
	unsigned int* do_result;//the result in device
	unsigned int* do_result_cnt;
	char* di_static_table;


	//allocate memory in host and device
	hi_index = (unsigned int*) malloc(mem_size_lib);//allocate the memory to hvectors_in_lib
	hi_query = (unsigned int*) malloc(mem_size_query);//allocate the memory to hvectors_query
	ho_result_cnt = (unsigned int*) malloc(mem_size_query);

	hipMalloc((void**) &di_index, mem_size_lib);//allocate dvectors_in_lib to the device memory
	hipMalloc((void**) &di_query, mem_size_query);//allocate dvectors_query to the device memory
	hipMalloc((void**) &di_static_table, static_table_size);//allocate device_result to the device memory
	hipMalloc((void**) &do_result_cnt, mem_size_query);

	hipSetDevice(0);
	hipSetDeviceFlags(hipDeviceMapHost);
	hipHostAlloc((void**)&(ho_result),result_size,hipHostMallocMapped);
	hipHostGetDevicePointer((void**)&(do_result),ho_result,0);


	//initalize host data
	unsigned int n;
	int cnt = 0;
	FILE *fp,*fp2;

	fp = fopen(hashcodePath.c_str(),"r");
	//cout<<hashcodePath.c_str()<<endl;
	while(!feof(fp) && cnt < frame_num_index){
		fscanf(fp, "%u", &n);
		hi_index[cnt] = n;
		cnt++;
	}
	//cout<<"count ="<<cnt<<endl;

	cnt = 0;
	fp = fopen(queryPath.c_str(),"r");
	//cout<<queryPath.c_str()<<endl;
	while(!feof(fp) && cnt < frame_num_query){
		fscanf(fp,"%u", &n);
		hi_query[cnt] = n;
		cnt++;
	}
	//cout<<"count = "<<cnt<<endl;


	memset(ho_result_cnt, 0, frame_num_query*4);


	//initalize device data
	 hipMemcpy(di_index, hi_index, mem_size_lib, hipMemcpyHostToDevice);//copy hvectors_in_lib in memory to dvectors_in_lib in gpu
	 hipMemcpy(di_query, hi_query, mem_size_query, hipMemcpyHostToDevice);//copy hvectors_query in memory to dvectors_query in gpu
	 hipMemcpy(di_static_table,hi_static_table,static_table_size,hipMemcpyHostToDevice);
	 hipMemcpy(do_result_cnt, ho_result_cnt, mem_size_query, hipMemcpyHostToDevice);


	//excute kernel in GPU
	//int threshold = THRESHOLD;
	int max_sim_num = MAX_SIM_NUM;
	dim3 grid((int)ceil((double)frame_num_index/1024), (int)ceil((double)frame_num_query/512), 1);


	CudaTest_kernel<<<grid, NUM_THREADS>>>(max_sim_num, threshold, di_index, di_query, do_result, di_static_table, do_result_cnt, frame_num_index, frame_num_query);

	hipDeviceSynchronize();
	//copy the result back to host memory
	hipMemcpy(ho_result_cnt, do_result_cnt, mem_size_query, hipMemcpyDeviceToHost);
	hipMemcpy(ho_result, do_result, result_size, hipMemcpyDeviceToHost);



	//deal with the result

//	printf("query:%u\n",hi_query[0]);
//	for(int i = 0; i < frame_num_query ; i ++)
//	{
//		//printf("result 0:%u\n",ho_result_cnt[i]);
//		for(int j = 0; j < ho_result_cnt[i]; j++)
//			cout<<ho_result[i*MAX_SIM_NUM+j]<<" ";
//		cout<<endl;
//	}
	fp2 = fopen(resultPath.c_str(),"w+");
	int max_length = 0;
	for(int i = 0 ; i < frame_num_query ; i++)
	{
		if(max_length < ho_result_cnt[i])
			max_length = ho_result_cnt[i];
		for(int j = 0; j < ho_result_cnt[i]; j++)
			fprintf(fp2,"%u ",ho_result[i*MAX_SIM_NUM+j]);
		fprintf(fp2,"\n");
	}
	cout<<"max matched count is: "<<max_length<<endl;
	cout << "size of long: " << sizeof(2l) << endl;
	clock_t cend=clock();
	printf("time:%f\n",(float)(cend-cstart)/CLOCKS_PER_SEC);

////	free up the host memory
//	free(ho_result_cnt);
//	free(hi_index);
//	free(hi_query);
//	free(ho_result);
//
//
////	free up the device memory
//	cudaFree(do_result_cnt);
//	cudaFree(di_index);//
//	cudaFree(di_query);
//	cudaFree(do_result);

}

void sortTable(unsigned int* ho_result_cnt, unsigned int* ho_result, unsigned int frame_num_query){

}

//////////////////////
// Program main
//////////////////////
int main(int argc, char** argv) {
	if(argc == 7)
	{
		string hashcodePath = argv[1];
		string queryPath = argv[2];
		string resultPath = argv[3];
		int frame_num_index = atoi(argv[4]);
		int frame_num_query = atoi(argv[5]);
		int threshold = atoi(argv[6]);
//		unsigned int frame_num_index = 1000001;
//		unsigned int frame_num_query =493;
//		int threshold = 2;
//		string hashcodePath = "/root/hashcode.txt";
//		string queryPath = "/root/query.txt";
//		string resultPath = "/root/result.txt";
		//cout<<hashcodePath<<endl<<queryPath<<endl<<frame_num_index<<endl<<frame_num_query<<endl<<threshold<<endl;
		bulidSimTable(hashcodePath, queryPath, resultPath, frame_num_index, frame_num_query, threshold);
	}
	return 0;
}


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

                                        # End of file scope inline assembly
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji
.LCPI0_0:
	.quad	0x3f50000000000000              # double 9.765625E-4
.LCPI0_1:
	.quad	0x3f60000000000000              # double 0.001953125
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI0_2:
	.long	0x49742400                      # float 1.0E+6
	.text
	.globl	_Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji
	.type	_Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji,@function
_Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji: # @_Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji
	.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	$408, %rsp                      # imm = 0x198
	.cfi_def_cfa_offset 464
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%r9d, 60(%rsp)                  # 4-byte Spill
	movl	%r8d, %ebx
	movl	%ecx, %ebp
	movq	%rdx, 128(%rsp)                 # 8-byte Spill
	movq	%rsi, 16(%rsp)                  # 8-byte Spill
	movq	%rdi, 24(%rsp)                  # 8-byte Spill
	callq	clock
	movq	%rax, 136(%rsp)                 # 8-byte Spill
	leal	(,%rbp,4), %r13d
	leal	(,%rbx,4), %r12d
	movq	%rbx, 32(%rsp)                  # 8-byte Spill
	imull	$200000, %ebx, %ebx             # imm = 0x30D40
	leaq	144(%rsp), %rdi
	movl	$.L__const._Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji.hi_static_table, %esi
	movl	$256, %edx                      # imm = 0x100
	callq	memcpy@PLT
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, 40(%rsp)                  # 8-byte Spill
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r14
	leaq	88(%rsp), %rdi
	movq	%r13, 104(%rsp)                 # 8-byte Spill
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	80(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	64(%rsp), %rdi
	movl	$256, %esi                      # imm = 0x100
	callq	hipMalloc
	leaq	48(%rsp), %rdi
	movq	%r12, 112(%rsp)                 # 8-byte Spill
	movq	%r12, %rsi
	callq	hipMalloc
	xorl	%edi, %edi
	callq	hipSetDevice
	movl	$8, %edi
	callq	hipSetDeviceFlags
	leaq	96(%rsp), %r12
	movq	%r12, %rdi
	movq	%rbx, 120(%rsp)                 # 8-byte Spill
	movq	%rbx, %rsi
	movl	$2, %edx
	callq	hipHostAlloc
	movq	(%r12), %rsi
	leaq	72(%rsp), %rdi
	xorl	%edx, %edx
	callq	hipHostGetDevicePointer
	movq	24(%rsp), %rax                  # 8-byte Reload
	movq	(%rax), %rdi
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %r13
	movq	%rax, %rdi
	callq	feof
	movq	%rbp, 24(%rsp)                  # 8-byte Spill
	movl	%ebp, %ebx
	testl	%eax, %eax
	jne	.LBB0_5
# %bb.1:
	cmpl	$0, 24(%rsp)                    # 4-byte Folded Reload
	je	.LBB0_5
# %bb.2:                                # %.lr.ph.preheader
	movl	$1, %ebp
	leaq	12(%rsp), %r12
.LBB0_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.1, %esi
	movq	%r13, %rdi
	movq	%r12, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	12(%rsp), %eax
	movl	%eax, -4(%r15,%rbp,4)
	movq	%r13, %rdi
	callq	feof
	testl	%eax, %eax
	jne	.LBB0_5
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB0_3 Depth=1
	leaq	1(%rbp), %rax
	cmpq	%rbx, %rbp
	movq	%rax, %rbp
	jb	.LBB0_3
.LBB0_5:                                # %._crit_edge
	movq	16(%rsp), %rax                  # 8-byte Reload
	movq	(%rax), %rdi
	movl	$.L.str, %esi
	callq	fopen
	movq	%rax, %r13
	movq	%rax, %rdi
	callq	feof
	movl	32(%rsp), %ecx                  # 4-byte Reload
	movq	%rcx, 16(%rsp)                  # 8-byte Spill
	testl	%eax, %eax
	jne	.LBB0_10
# %bb.6:                                # %._crit_edge
	cmpl	$0, 32(%rsp)                    # 4-byte Folded Reload
	je	.LBB0_10
# %bb.7:                                # %.lr.ph79.preheader
	movl	$1, %ebp
	leaq	12(%rsp), %r12
.LBB0_8:                                # %.lr.ph79
                                        # =>This Inner Loop Header: Depth=1
	movl	$.L.str.1, %esi
	movq	%r13, %rdi
	movq	%r12, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	12(%rsp), %eax
	movq	40(%rsp), %rcx                  # 8-byte Reload
	movl	%eax, -4(%rcx,%rbp,4)
	movq	%r13, %rdi
	callq	feof
	testl	%eax, %eax
	jne	.LBB0_10
# %bb.9:                                # %.lr.ph79
                                        #   in Loop: Header=BB0_8 Depth=1
	leaq	1(%rbp), %rax
	cmpq	16(%rsp), %rbp                  # 8-byte Folded Reload
	movq	%rax, %rbp
	jb	.LBB0_8
.LBB0_10:                               # %._crit_edge80
	xorl	%r13d, %r13d
	movq	%r14, %rdi
	xorl	%esi, %esi
	movq	112(%rsp), %r12                 # 8-byte Reload
	movq	%r12, %rdx
	callq	memset@PLT
	movq	88(%rsp), %rdi
	movq	%r15, %rsi
	movq	104(%rsp), %rdx                 # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	movq	80(%rsp), %rdi
	movq	40(%rsp), %rsi                  # 8-byte Reload
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	64(%rsp), %rdi
	leaq	144(%rsp), %rsi
	movl	$256, %edx                      # imm = 0x100
	movl	$1, %ecx
	callq	hipMemcpy
	movq	48(%rsp), %rdi
	movq	%r14, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	cvtsi2sd	%rbx, %xmm0
	mulsd	.LCPI0_0(%rip), %xmm0
	callq	ceil@PLT
	cvttsd2si	%xmm0, %ebx
	xorps	%xmm0, %xmm0
	cvtsi2sdq	16(%rsp), %xmm0         # 8-byte Folded Reload
	mulsd	.LCPI0_1(%rip), %xmm0
	callq	ceil@PLT
	cvttsd2si	%xmm0, %edi
	shlq	$32, %rdi
	orq	%rbx, %rdi
	movabsq	$4294968320, %rdx               # imm = 0x100000400
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB0_12
# %bb.11:
	movq	88(%rsp), %rdx
	movq	80(%rsp), %rcx
	movq	72(%rsp), %r8
	movq	64(%rsp), %r9
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movl	$50000, %edi                    # imm = 0xC350
	movl	68(%rsp), %esi                  # 4-byte Reload
	pushq	40(%rsp)                        # 8-byte Folded Reload
	.cfi_adjust_cfa_offset 8
	pushq	40(%rsp)                        # 8-byte Folded Reload
	.cfi_adjust_cfa_offset 8
	pushq	72(%rsp)
	.cfi_adjust_cfa_offset 8
	callq	_Z30__device_stub__CudaTest_kerneliiPjS_S_PcS_jj
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
.LBB0_12:
	callq	hipDeviceSynchronize
	movq	48(%rsp), %rsi
	movq	%r14, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	96(%rsp), %rdi
	movq	72(%rsp), %rsi
	movq	120(%rsp), %rdx                 # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	movq	128(%rsp), %rax                 # 8-byte Reload
	movq	(%rax), %rdi
	movl	$.L.str.2, %esi
	callq	fopen
	cmpl	$0, 32(%rsp)                    # 4-byte Folded Reload
	je	.LBB0_18
# %bb.13:                               # %.lr.ph88.preheader
	movq	%rax, %rbx
	xorl	%r15d, %r15d
	xorl	%r12d, %r12d
	xorl	%r13d, %r13d
.LBB0_14:                               # %.lr.ph88
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_16 Depth 2
	movl	(%r14,%r12,4), %eax
	cmpl	%eax, %r13d
	cmovbel	%eax, %r13d
	movq	%r13, 40(%rsp)                  # 8-byte Spill
	testl	%eax, %eax
	je	.LBB0_17
# %bb.15:                               # %.lr.ph83
                                        #   in Loop: Header=BB0_14 Depth=1
	movl	%r15d, %ebp
	andl	$268435455, %ebp                # imm = 0xFFFFFFF
	shlq	$6, %rbp
	xorl	%r13d, %r13d
.LBB0_16:                               #   Parent Loop BB0_14 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	96(%rsp), %rax
	addq	%rbp, %rax
	movl	(%rax,%r13,4), %edx
	movl	$.L.str.3, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r13
	movl	(%r14,%r12,4), %eax
	cmpq	%rax, %r13
	jb	.LBB0_16
.LBB0_17:                               # %._crit_edge84
                                        #   in Loop: Header=BB0_14 Depth=1
	movl	$10, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	incq	%r12
	addl	$3125, %r15d                    # imm = 0xC35
	cmpq	16(%rsp), %r12                  # 8-byte Folded Reload
	movq	40(%rsp), %r13                  # 8-byte Reload
	jne	.LBB0_14
.LBB0_18:                               # %._crit_edge89
	movl	$_ZSt4cout, %edi
	movl	$.L.str.5, %esi
	movl	$22, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	%r13d, %esi
	callq	_ZNSolsEi
	movq	%rax, %rbx
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	movl	$_ZSt4cout, %edi
	movl	$.L.str.6, %esi
	movl	$14, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$8, %esi
	callq	_ZNSo9_M_insertImEERSoT_
	movq	%rax, %rbx
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
	callq	clock
	subq	136(%rsp), %rax                 # 8-byte Folded Reload
	cvtsi2ss	%rax, %xmm0
	divss	.LCPI0_2(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.7, %edi
	movb	$1, %al
	callq	printf
	addq	$408, %rsp                      # imm = 0x198
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji, .Lfunc_end0-_Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji
	.cfi_endproc
                                        # -- End function
	.globl	_Z9sortTablePjS_j               # -- Begin function _Z9sortTablePjS_j
	.type	_Z9sortTablePjS_j,@function
_Z9sortTablePjS_j:                      # @_Z9sortTablePjS_j
	.cfi_startproc
# %bb.0:
	retq
.Lfunc_end1:
	.size	_Z9sortTablePjS_j, .Lfunc_end1-_Z9sortTablePjS_j
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %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	$200, %rsp
	.cfi_def_cfa_offset 256
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$7, %edi
	jne	.LBB2_19
# %bb.1:
	movq	%rsi, %r14
	movq	8(%rsi), %rsi
	leaq	168(%rsp), %rdi
	leaq	40(%rsp), %rdx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	movq	16(%r14), %rsi
.Ltmp0:
	leaq	40(%rsp), %rdi
	leaq	8(%rsp), %rdx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
.Ltmp1:
# %bb.2:
	movq	24(%r14), %rsi
.Ltmp3:
	leaq	8(%rsp), %rdi
	leaq	7(%rsp), %rdx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
.Ltmp4:
# %bb.3:
	movq	32(%r14), %rdi
	callq	atoi
	movl	%eax, %ebx
	movq	40(%r14), %rdi
	callq	atoi
	movl	%eax, %ebp
	movq	48(%r14), %rdi
	callq	atoi
	movl	%eax, %r14d
	leaq	152(%rsp), %r15
	movq	%r15, -16(%r15)
	movq	168(%rsp), %rsi
	movq	176(%rsp), %rdx
	addq	%rsi, %rdx
.Ltmp6:
	leaq	136(%rsp), %rdi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag
.Ltmp7:
# %bb.4:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2ERKS4_.exit
	leaq	120(%rsp), %r12
	movq	%r12, -16(%r12)
	movq	40(%rsp), %rsi
	movq	48(%rsp), %rdx
	addq	%rsi, %rdx
.Ltmp9:
	leaq	104(%rsp), %rdi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag
.Ltmp10:
# %bb.5:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2ERKS4_.exit23
	leaq	88(%rsp), %r13
	movq	%r13, -16(%r13)
	movq	8(%rsp), %rsi
	movq	16(%rsp), %rdx
	addq	%rsi, %rdx
.Ltmp12:
	leaq	72(%rsp), %rdi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag
.Ltmp13:
# %bb.6:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2ERKS4_.exit24
.Ltmp15:
	leaq	136(%rsp), %rdi
	leaq	104(%rsp), %rsi
	leaq	72(%rsp), %rdx
	movl	%ebx, %ecx
	movl	%ebp, %r8d
	movl	%r14d, %r9d
	callq	_Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji
.Ltmp16:
# %bb.7:
	movq	72(%rsp), %rdi
	cmpq	%r13, %rdi
	je	.LBB2_9
# %bb.8:                                # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i
	callq	_ZdlPv
.LBB2_9:                                # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit
	movq	104(%rsp), %rdi
	cmpq	%r12, %rdi
	je	.LBB2_11
# %bb.10:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i25
	callq	_ZdlPv
.LBB2_11:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit27
	movq	136(%rsp), %rdi
	cmpq	%r15, %rdi
	je	.LBB2_13
# %bb.12:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i28
	callq	_ZdlPv
.LBB2_13:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit30
	leaq	24(%rsp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB2_15
# %bb.14:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i31
	callq	_ZdlPv
.LBB2_15:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit33
	leaq	56(%rsp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB2_17
# %bb.16:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i34
	callq	_ZdlPv
.LBB2_17:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit36
	leaq	184(%rsp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB2_19
# %bb.18:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i37
	callq	_ZdlPv
.LBB2_19:
	xorl	%eax, %eax
	addq	$200, %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
.LBB2_25:
	.cfi_def_cfa_offset 256
.Ltmp17:
	movq	%rax, %rbx
	movq	72(%rsp), %rdi
	cmpq	%r13, %rdi
	je	.LBB2_27
# %bb.26:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i40
	callq	_ZdlPv
	jmp	.LBB2_27
.LBB2_24:
.Ltmp14:
	movq	%rax, %rbx
.LBB2_27:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit42
	movq	104(%rsp), %rdi
	cmpq	%r12, %rdi
	je	.LBB2_29
# %bb.28:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i43
	callq	_ZdlPv
	jmp	.LBB2_29
.LBB2_23:
.Ltmp11:
	movq	%rax, %rbx
.LBB2_29:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit45
	movq	136(%rsp), %rdi
	cmpq	%r15, %rdi
	je	.LBB2_31
# %bb.30:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i46
	callq	_ZdlPv
	jmp	.LBB2_31
.LBB2_22:
.Ltmp8:
	movq	%rax, %rbx
.LBB2_31:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit48
	leaq	24(%rsp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB2_33
# %bb.32:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i49
	callq	_ZdlPv
	jmp	.LBB2_33
.LBB2_21:
.Ltmp5:
	movq	%rax, %rbx
.LBB2_33:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit51
	leaq	56(%rsp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB2_35
# %bb.34:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i52
	callq	_ZdlPv
	jmp	.LBB2_35
.LBB2_20:
.Ltmp2:
	movq	%rax, %rbx
.LBB2_35:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit54
	leaq	184(%rsp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB2_37
# %bb.36:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i55
	callq	_ZdlPv
.LBB2_37:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit57
	movq	%rbx, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end2:
	.size	main, .Lfunc_end2-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table2:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp2-.Lfunc_begin0           #     jumps to .Ltmp2
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp3-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp4-.Ltmp3                  #   Call between .Ltmp3 and .Ltmp4
	.uleb128 .Ltmp5-.Lfunc_begin0           #     jumps to .Ltmp5
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp6-.Lfunc_begin0           # >> Call Site 4 <<
	.uleb128 .Ltmp7-.Ltmp6                  #   Call between .Ltmp6 and .Ltmp7
	.uleb128 .Ltmp8-.Lfunc_begin0           #     jumps to .Ltmp8
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp9-.Lfunc_begin0           # >> Call Site 5 <<
	.uleb128 .Ltmp10-.Ltmp9                 #   Call between .Ltmp9 and .Ltmp10
	.uleb128 .Ltmp11-.Lfunc_begin0          #     jumps to .Ltmp11
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp12-.Lfunc_begin0          # >> Call Site 6 <<
	.uleb128 .Ltmp13-.Ltmp12                #   Call between .Ltmp12 and .Ltmp13
	.uleb128 .Ltmp14-.Lfunc_begin0          #     jumps to .Ltmp14
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp15-.Lfunc_begin0          # >> Call Site 7 <<
	.uleb128 .Ltmp16-.Ltmp15                #   Call between .Ltmp15 and .Ltmp16
	.uleb128 .Ltmp17-.Lfunc_begin0          #     jumps to .Ltmp17
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp16-.Lfunc_begin0          # >> Call Site 8 <<
	.uleb128 .Lfunc_end2-.Ltmp16            #   Call between .Ltmp16 and .Lfunc_end2
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,comdat
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_ # -- Begin function _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.p2align	1, 0x90
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,@function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_: # @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.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
	leaq	16(%rdi), %rax
	movq	%rax, (%rdi)
	testq	%rsi, %rsi
	je	.LBB3_1
# %bb.2:
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movq	%rsi, %rdi
	callq	strlen
	leaq	(%rax,%rbx), %rdx
	movq	%r14, %rdi
	movq	%rbx, %rsi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag # TAILCALL
.LBB3_1:
	.cfi_def_cfa_offset 32
	movl	$.L.str.8, %edi
	callq	_ZSt19__throw_logic_errorPKc
.Lfunc_end3:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, .Lfunc_end3-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,comdat
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag # -- Begin function _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.p2align	1, 0x90
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,@function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag: # @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %r14
	movq	%rsi, %r15
	movq	%rdi, %rbx
	subq	%rsi, %r14
	movq	%r14, (%rsp)
	cmpq	$15, %r14
	jbe	.LBB4_1
# %bb.2:
	movq	%rsp, %r12
	movq	%rbx, %rdi
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm
	movq	%rax, (%rbx)
	movq	(%r12), %rcx
	movq	%rcx, 16(%rbx)
	jmp	.LBB4_3
.LBB4_1:                                # %._crit_edge
	movq	(%rbx), %rax
.LBB4_3:
	testq	%r14, %r14
	je	.LBB4_7
# %bb.4:
	cmpq	$1, %r14
	jne	.LBB4_6
# %bb.5:
	movb	(%r15), %cl
	movb	%cl, (%rax)
	jmp	.LBB4_7
.LBB4_6:
	movq	%rax, %rdi
	movq	%r15, %rsi
	movq	%r14, %rdx
	callq	memcpy@PLT
.LBB4_7:                                # %_ZZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tagEN6_GuardD2Ev.exit
	movq	(%rsp), %rax
	movq	%rax, 8(%rbx)
	movq	(%rbx), %rcx
	movb	$0, (%rcx,%rax)
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag, .Lfunc_end4-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag,comdat
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag # -- Begin function _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag
	.p2align	1, 0x90
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag,@function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag: # @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdx, %r14
	movq	%rsi, %r15
	movq	%rdi, %rbx
	subq	%rsi, %r14
	movq	%r14, (%rsp)
	cmpq	$15, %r14
	jbe	.LBB5_1
# %bb.2:
	movq	%rsp, %r12
	movq	%rbx, %rdi
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm
	movq	%rax, (%rbx)
	movq	(%r12), %rcx
	movq	%rcx, 16(%rbx)
	jmp	.LBB5_3
.LBB5_1:                                # %._crit_edge
	movq	(%rbx), %rax
.LBB5_3:
	testq	%r14, %r14
	je	.LBB5_7
# %bb.4:
	cmpq	$1, %r14
	jne	.LBB5_6
# %bb.5:
	movb	(%r15), %cl
	movb	%cl, (%rax)
	jmp	.LBB5_7
.LBB5_6:
	movq	%rax, %rdi
	movq	%r15, %rsi
	movq	%r14, %rdx
	callq	memcpy@PLT
.LBB5_7:                                # %_ZZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tagEN6_GuardD2Ev.exit
	movq	(%rsp), %rax
	movq	%rax, 8(%rbx)
	movq	(%rbx), %rcx
	movb	$0, (%rcx,%rax)
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag, .Lfunc_end5-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag
	.cfi_endproc
                                        # -- End function
	.type	.L__const._Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji.hi_static_table,@object # @__const._Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji.hi_static_table
	.section	.rodata,"a",@progbits
	.p2align	4, 0x0
.L__const._Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji.hi_static_table:
	.ascii	"\000\001\001\002\001\002\002\003\001\002\002\003\002\003\003\004\001\002\002\003\002\003\003\004\002\003\003\004\003\004\004\005\001\002\002\003\002\003\003\004\002\003\003\004\003\004\004\005\002\003\003\004\003\004\004\005\003\004\004\005\004\005\005\006\001\002\002\003\002\003\003\004\002\003\003\004\003\004\004\005\002\003\003\004\003\004\004\005\003\004\004\005\004\005\005\006\002\003\003\004\003\004\004\005\003\004\004\005\004\005\005\006\003\004\004\005\004\005\005\006\004\005\005\006\005\006\006\007\001\002\002\003\002\003\003\004\002\003\003\004\003\004\004\005\002\003\003\004\003\004\004\005\003\004\004\005\004\005\005\006\002\003\003\004\003\004\004\005\003\004\004\005\004\005\005\006\003\004\004\005\004\005\005\006\004\005\005\006\005\006\006\007\002\003\003\004\003\004\004\005\003\004\004\005\004\005\005\006\003\004\004\005\004\005\005\006\004\005\005\006\005\006\006\007\003\004\004\005\004\005\005\006\004\005\005\006\005\006\006\007\004\005\005\006\005\006\006\007\005\006\006\007\006\007\007\b"
	.size	.L__const._Z13bulidSimTableNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES4_S4_jji.hi_static_table, 256

	.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	"%u"
	.size	.L.str.1, 3

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

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"max matched count is: "
	.size	.L.str.5, 23

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"size of long: "
	.size	.L.str.6, 15

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"time:%f\n"
	.size	.L.str.7, 9

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"basic_string: construction from null is not valid"
	.size	.L.str.8, 50

	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _ZSt4cout
	.addrsig_sym __hip_cuid_

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

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

	.end_amdgpu_metadata
