#include <cuda.h>
#include <stdio.h>
#include <string.h>

#define ITERS 32768

char* concat(const char *s1, const char *s2)
{
    char *result = (char*)malloc(strlen(s1) + strlen(s2) + 1); // +1 for the null-terminator
    // in real code you would check for errors in malloc here
    strcpy(result, s1);
    strcat(result, s2);
    return result;
}

#define CUDA_SAFE_CALL( call) {                                    \
    cudaError err = call;                                                    \
    if( cudaSuccess != err) {                                                \
        fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n",        \
                __FILE__, __LINE__, cudaGetErrorString( err) );              \
        exit(EXIT_FAILURE);                                                  \
    } }

void initializeEvents(cudaEvent_t *start, cudaEvent_t *stop){
	CUDA_SAFE_CALL( cudaEventCreate(start) );
	CUDA_SAFE_CALL( cudaEventCreate(stop) );
	CUDA_SAFE_CALL( cudaEventRecord(*start, 0) );
}

float finalizeEvents(cudaEvent_t start, cudaEvent_t stop){
	CUDA_SAFE_CALL( cudaGetLastError() );
	CUDA_SAFE_CALL( cudaEventRecord(stop, 0) );
	CUDA_SAFE_CALL( cudaEventSynchronize(stop) );
	float kernel_time;
	CUDA_SAFE_CALL( cudaEventElapsedTime(&kernel_time, start, stop) );
	CUDA_SAFE_CALL( cudaEventDestroy(start) );
	CUDA_SAFE_CALL( cudaEventDestroy(stop) );
	return kernel_time;
}

template<typename T>
void run(char * name, T scal, int type_size, int threads){
	char * file_name = concat(name, ".cubin");

	int *output;
	cudaMalloc((void**)&output, sizeof(int)*32);
	cudaMemset(output, 0, 32*sizeof(int));

	CUmodule module;
	CUfunction kernel;

	cuModuleLoad(&module, file_name);
	cuModuleGetFunction(&kernel, module, "kern");

	int blk_size = 32;
	int total_blks = 1;//size/blk_size;	
	int sh_mem_size = blk_size*sizeof(float)*type_size;
	void * args[2] = {&scal, &output};

	//cudaEvent_t start, stop;
	//initializeEvents(&start, &stop);
	cuLaunchKernel(kernel, total_blks, 1, 1,
			blk_size, 1, 1,
			sh_mem_size, 0, args, 0);
	//float krn_time_shmem_32b = finalizeEvents(start, stop);

	int *output_h = (int*)malloc(sizeof(int)*32);	

	cudaMemcpy(output_h, output, sizeof(int)*32, cudaMemcpyDeviceToHost);	

	/*for(int i=0; i<32; i++){
		printf("%d ", output_h[i]);
	}printf("\n");*/

	printf("%s took %d clocks \n", name, output_h[0]);
	double clocks_instr = (float)output_h[0]/(128.0*128.0); // wokload of a thread
	printf("Each instruction takes %.2f clocks.\n", clocks_instr);
	printf("Throughput %.2f bytes/cycle.\n\n", ((double)threads*128*128*type_size*4)/output_h[0]); // Size of information stores divided by the number of threads of the latest thread

	cudaFree(output);
	free(output_h);
}

int main(){
	float scal = 4;
	run("sts32", scal, 1, 32);
	printf("\n");
	float2 scal2;
	scal2.x = 4; scal2.y = 4;
	run("sts64", scal2, 2, 32);
	printf("\n");
	float4 scal4;
	scal4.x = 4; scal4.y = 4;
	scal4.z = 4; scal4.w = 4;
	// No thread-divergence
	run("sts128_0", scal4, 4, 32);

	printf("\n");
	// Only half of the threads store data
	run("sts128", scal4, 4, 16);

	/* run2_aux("sts64_2bank_conflict");
	printf("\n");
	run2_aux("sts64_broadcast");
	printf("\n");
	run2_aux("sts64_opt3");
	printf("\n"); */

	return 0;
}

	.file	"tmpxft_0037a278_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z6concatPKcS0_
	.type	_Z6concatPKcS0_, @function
_Z6concatPKcS0_:
.LFB2027:
	.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
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rsi, %rbx
	call	strlen@PLT
	movq	%rbx, %rdi
	movq	%rax, %r12
	call	strlen@PLT
	leaq	1(%r12,%rax), %r12
	movq	%r12, %rdi
	call	malloc@PLT
	movq	%r12, %rdx
	movq	%rbp, %rsi
	movq	%rax, %rdi
	call	__strcpy_chk@PLT
	movq	%r12, %rdx
	movq	%rbx, %rsi
	movq	%rax, %rdi
	call	__strcat_chk@PLT
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z6concatPKcS0_, .-_Z6concatPKcS0_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/YanqingWu/openCNN/main/bench/smem/STS/main.cu"
.LC1:
	.string	"Cuda error in file '%s' in line %i : %s.\n"
	.text
	.globl	_Z16initializeEventsPP10CUevent_stS1_
	.type	_Z16initializeEventsPP10CUevent_stS1_, @function
_Z16initializeEventsPP10CUevent_stS1_:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	pushq	%rdx
	.cfi_def_cfa_offset 32
	call	cudaEventCreate@PLT
	testl	%eax, %eax
	je	.L5
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$25, %r8d
	movq	%rax, %r9
	jmp	.L9
.L5:
	movq	%rbp, %rdi
	call	cudaEventCreate@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L6
	call	cudaGetErrorString@PLT
	movl	$26, %r8d
	movq	%rax, %r9
.L9:
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rcx
	leaq	.LC1(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L6:
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L4
	call	cudaGetErrorString@PLT
	movl	$27, %r8d
	movq	%rax, %r9
	jmp	.L9
.L4:
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z16initializeEventsPP10CUevent_stS1_, .-_Z16initializeEventsPP10CUevent_stS1_
	.globl	_Z14finalizeEventsP10CUevent_stS0_
	.type	_Z14finalizeEventsP10CUevent_stS0_, @function
_Z14finalizeEventsP10CUevent_stS0_:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rsi, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	cudaGetLastError@PLT
	testl	%eax, %eax
	je	.L12
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movl	$31, %r8d
	movq	%rax, %r9
	jmp	.L20
.L12:
	movq	%rbx, %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L13
	call	cudaGetErrorString@PLT
	movl	$32, %r8d
	movq	%rax, %r9
.L20:
	movq	stderr(%rip), %rdi
	leaq	.LC0(%rip), %rcx
	leaq	.LC1(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L13:
	movq	%rbx, %rdi
	call	cudaEventSynchronize@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L14
	call	cudaGetErrorString@PLT
	movl	$33, %r8d
	movq	%rax, %r9
	jmp	.L20
.L14:
	leaq	4(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	call	cudaEventElapsedTime@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L15
	call	cudaGetErrorString@PLT
	movl	$35, %r8d
	movq	%rax, %r9
	jmp	.L20
.L15:
	movq	%rbp, %rdi
	call	cudaEventDestroy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L16
	call	cudaGetErrorString@PLT
	movl	$36, %r8d
	movq	%rax, %r9
	jmp	.L20
.L16:
	movq	%rbx, %rdi
	call	cudaEventDestroy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L17
	call	cudaGetErrorString@PLT
	movl	$37, %r8d
	movq	%rax, %r9
	jmp	.L20
.L17:
	movss	4(%rsp), %xmm0
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L18
	call	__stack_chk_fail@PLT
.L18:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z14finalizeEventsP10CUevent_stS0_, .-_Z14finalizeEventsP10CUevent_stS0_
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2057:
	.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
.LFE2057:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.rodata._Z3runIfEvPcT_ii.str1.1,"aMS",@progbits,1
.LC2:
	.string	".cubin"
.LC3:
	.string	"kern"
.LC4:
	.string	"%s took %d clocks \n"
.LC6:
	.string	"Each instruction takes %.2f clocks.\n"
.LC9:
	.string	"Throughput %.2f bytes/cycle.\n\n"
	.section	.text._Z3runIfEvPcT_ii,"axG",@progbits,_Z3runIfEvPcT_ii,comdat
	.weak	_Z3runIfEvPcT_ii
	.type	_Z3runIfEvPcT_ii, @function
_Z3runIfEvPcT_ii:
.LFB2103:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movl	%edx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	%esi, %ebp
	leaq	.LC2(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	movss	%xmm0, 12(%rsp)
	leaq	16(%rsp), %r14
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	_Z6concatPKcS0_
	movl	$128, %esi
	movq	%r14, %rdi
	movq	%rax, %rbx
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movl	$128, %edx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	call	cuModuleLoad@PLT
	movq	24(%rsp), %rsi
	leaq	32(%rsp), %rdi
	leaq	.LC3(%rip), %rdx
	call	cuModuleGetFunction@PLT
	leaq	12(%rsp), %rax
	movq	%r14, 48(%rsp)
	movl	$1, %r9d
	movq	%rax, 40(%rsp)
	movl	$32, %r8d
	movl	$1, %ecx
	movl	$1, %edx
	pushq	%rax
	.cfi_def_cfa_offset 120
	movl	$1, %esi
	pushq	$0
	.cfi_def_cfa_offset 128
	leaq	56(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 136
	movl	%ebp, %eax
	sall	$7, %eax
	pushq	$0
	.cfi_def_cfa_offset 144
	pushq	%rax
	.cfi_def_cfa_offset 152
	pushq	$1
	.cfi_def_cfa_offset 160
	movq	80(%rsp), %rdi
	call	cuLaunchKernel@PLT
	addq	$48, %rsp
	.cfi_def_cfa_offset 112
	movl	$128, %edi
	call	malloc@PLT
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movl	$128, %edx
	movq	%rax, %rbx
	movq	%rax, %rdi
	call	cudaMemcpy@PLT
	movl	(%rbx), %ecx
	movq	%r12, %rdx
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	cvtsi2ssl	(%rbx), %xmm0
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC6(%rip), %rsi
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LC5(%rip), %xmm0
	call	__printf_chk@PLT
	cvtsi2sdl	%r13d, %xmm0
	movl	$2, %edi
	movb	$1, %al
	movsd	.LC7(%rip), %xmm1
	leaq	.LC9(%rip), %rsi
	mulsd	%xmm1, %xmm0
	mulsd	%xmm1, %xmm0
	cvtsi2sdl	%ebp, %xmm1
	mulsd	%xmm1, %xmm0
	cvtsi2sdl	(%rbx), %xmm1
	mulsd	.LC8(%rip), %xmm0
	divsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L24
	call	__stack_chk_fail@PLT
.L24:
	addq	$64, %rsp
	.cfi_def_cfa_offset 48
	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
	ret
	.cfi_endproc
.LFE2103:
	.size	_Z3runIfEvPcT_ii, .-_Z3runIfEvPcT_ii
	.section	.text._Z3runI6float2EvPcT_ii,"axG",@progbits,_Z3runI6float2EvPcT_ii,comdat
	.weak	_Z3runI6float2EvPcT_ii
	.type	_Z3runI6float2EvPcT_ii, @function
_Z3runI6float2EvPcT_ii:
.LFB2104:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movl	%edx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	%esi, %ebp
	leaq	.LC2(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	movq	%xmm0, 8(%rsp)
	leaq	16(%rsp), %r14
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	_Z6concatPKcS0_
	movl	$128, %esi
	movq	%r14, %rdi
	movq	%rax, %rbx
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movl	$128, %edx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	call	cuModuleLoad@PLT
	movq	24(%rsp), %rsi
	leaq	32(%rsp), %rdi
	leaq	.LC3(%rip), %rdx
	call	cuModuleGetFunction@PLT
	leaq	8(%rsp), %rax
	movq	%r14, 48(%rsp)
	movl	$1, %r9d
	movq	%rax, 40(%rsp)
	movl	$32, %r8d
	movl	$1, %ecx
	movl	$1, %edx
	pushq	%rax
	.cfi_def_cfa_offset 120
	movl	$1, %esi
	pushq	$0
	.cfi_def_cfa_offset 128
	leaq	56(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 136
	movl	%ebp, %eax
	sall	$7, %eax
	pushq	$0
	.cfi_def_cfa_offset 144
	pushq	%rax
	.cfi_def_cfa_offset 152
	pushq	$1
	.cfi_def_cfa_offset 160
	movq	80(%rsp), %rdi
	call	cuLaunchKernel@PLT
	addq	$48, %rsp
	.cfi_def_cfa_offset 112
	movl	$128, %edi
	call	malloc@PLT
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movl	$128, %edx
	movq	%rax, %rbx
	movq	%rax, %rdi
	call	cudaMemcpy@PLT
	movl	(%rbx), %ecx
	movq	%r12, %rdx
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	cvtsi2ssl	(%rbx), %xmm0
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC6(%rip), %rsi
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LC5(%rip), %xmm0
	call	__printf_chk@PLT
	cvtsi2sdl	%r13d, %xmm0
	movl	$2, %edi
	movb	$1, %al
	movsd	.LC7(%rip), %xmm1
	leaq	.LC9(%rip), %rsi
	mulsd	%xmm1, %xmm0
	mulsd	%xmm1, %xmm0
	cvtsi2sdl	%ebp, %xmm1
	mulsd	%xmm1, %xmm0
	cvtsi2sdl	(%rbx), %xmm1
	mulsd	.LC8(%rip), %xmm0
	divsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$64, %rsp
	.cfi_def_cfa_offset 48
	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
	ret
	.cfi_endproc
.LFE2104:
	.size	_Z3runI6float2EvPcT_ii, .-_Z3runI6float2EvPcT_ii
	.section	.text._Z3runI6float4EvPcT_ii,"axG",@progbits,_Z3runI6float4EvPcT_ii,comdat
	.weak	_Z3runI6float4EvPcT_ii
	.type	_Z3runI6float4EvPcT_ii, @function
_Z3runI6float4EvPcT_ii:
.LFB2105:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movl	%edx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movl	%esi, %ebp
	leaq	.LC2(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	movq	%xmm1, 8(%rsp)
	leaq	16(%rsp), %r14
	movq	%xmm0, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	_Z6concatPKcS0_
	movl	$128, %esi
	movq	%r14, %rdi
	movq	%rax, %rbx
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movl	$128, %edx
	xorl	%esi, %esi
	call	cudaMemset@PLT
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	call	cuModuleLoad@PLT
	movq	24(%rsp), %rsi
	leaq	32(%rsp), %rdi
	leaq	.LC3(%rip), %rdx
	call	cuModuleGetFunction@PLT
	movq	%rsp, %rax
	movq	%r14, 48(%rsp)
	movl	$1, %r9d
	movq	%rax, 40(%rsp)
	movl	$32, %r8d
	movl	$1, %ecx
	movl	$1, %edx
	pushq	%rax
	.cfi_def_cfa_offset 120
	movl	$1, %esi
	pushq	$0
	.cfi_def_cfa_offset 128
	leaq	56(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 136
	movl	%ebp, %eax
	sall	$7, %eax
	pushq	$0
	.cfi_def_cfa_offset 144
	pushq	%rax
	.cfi_def_cfa_offset 152
	pushq	$1
	.cfi_def_cfa_offset 160
	movq	80(%rsp), %rdi
	call	cuLaunchKernel@PLT
	addq	$48, %rsp
	.cfi_def_cfa_offset 112
	movl	$128, %edi
	call	malloc@PLT
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movl	$128, %edx
	movq	%rax, %rbx
	movq	%rax, %rdi
	call	cudaMemcpy@PLT
	movl	(%rbx), %ecx
	movq	%r12, %rdx
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	cvtsi2ssl	(%rbx), %xmm0
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC6(%rip), %rsi
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LC5(%rip), %xmm0
	call	__printf_chk@PLT
	cvtsi2sdl	%r13d, %xmm0
	movl	$2, %edi
	movb	$1, %al
	movsd	.LC7(%rip), %xmm1
	leaq	.LC9(%rip), %rsi
	mulsd	%xmm1, %xmm0
	mulsd	%xmm1, %xmm0
	cvtsi2sdl	%ebp, %xmm1
	mulsd	%xmm1, %xmm0
	cvtsi2sdl	(%rbx), %xmm1
	mulsd	.LC8(%rip), %xmm0
	divsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$64, %rsp
	.cfi_def_cfa_offset 48
	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
	ret
	.cfi_endproc
.LFE2105:
	.size	_Z3runI6float4EvPcT_ii, .-_Z3runI6float4EvPcT_ii
	.section	.rodata.str1.1
.LC10:
	.string	"sts32"
.LC12:
	.string	"\n"
.LC13:
	.string	"sts64"
.LC14:
	.string	"sts128_0"
.LC15:
	.string	"sts128"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC12(%rip), %rbp
	movl	$32, %edx
	movl	$1, %esi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	leaq	.LC10(%rip), %rdi
	movabsq	$4647714816528482304, %rbx
	pushq	%rax
	.cfi_def_cfa_offset 32
	movss	.LC11(%rip), %xmm0
	call	_Z3runIfEvPcT_ii
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %xmm0
	movl	$32, %edx
	movl	$2, %esi
	leaq	.LC13(%rip), %rdi
	call	_Z3runI6float2EvPcT_ii
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rbx, %xmm0
	movq	%rbx, %xmm1
	movl	$32, %edx
	movl	$4, %esi
	leaq	.LC14(%rip), %rdi
	call	_Z3runI6float4EvPcT_ii
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$16, %edx
	movq	%rbx, %xmm0
	movq	%rbx, %xmm1
	movl	$4, %esi
	leaq	.LC15(%rip), %rdi
	call	_Z3runI6float4EvPcT_ii
	popq	%rdx
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.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
.LC5:
	.long	0
	.long	1058013184
	.align 8
.LC7:
	.long	0
	.long	1080033280
	.align 8
.LC8:
	.long	0
	.long	1074790400
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC11:
	.long	1082130432
	.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 <stdio.h>
#include <string.h>

#define ITERS 32768

char* concat(const char *s1, const char *s2)
{
    char *result = (char*)malloc(strlen(s1) + strlen(s2) + 1); // +1 for the null-terminator
    // in real code you would check for errors in malloc here
    strcpy(result, s1);
    strcat(result, s2);
    return result;
}

#define CUDA_SAFE_CALL( call) {                                    \
    hipError_t err = call;                                                    \
    if( hipSuccess != err) {                                                \
        fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n",        \
                __FILE__, __LINE__, hipGetErrorString( err) );              \
        exit(EXIT_FAILURE);                                                  \
    } }

void initializeEvents(hipEvent_t *start, hipEvent_t *stop){
	CUDA_SAFE_CALL( hipEventCreate(start) );
	CUDA_SAFE_CALL( hipEventCreate(stop) );
	CUDA_SAFE_CALL( hipEventRecord(*start, 0) );
}

float finalizeEvents(hipEvent_t start, hipEvent_t stop){
	CUDA_SAFE_CALL( hipGetLastError() );
	CUDA_SAFE_CALL( hipEventRecord(stop, 0) );
	CUDA_SAFE_CALL( hipEventSynchronize(stop) );
	float kernel_time;
	CUDA_SAFE_CALL( hipEventElapsedTime(&kernel_time, start, stop) );
	CUDA_SAFE_CALL( hipEventDestroy(start) );
	CUDA_SAFE_CALL( hipEventDestroy(stop) );
	return kernel_time;
}

template<typename T>
void run(char * name, T scal, int type_size, int threads){
	char * file_name = concat(name, ".cubin");

	int *output;
	hipMalloc((void**)&output, sizeof(int)*32);
	hipMemset(output, 0, 32*sizeof(int));

	hipModule_t module;
	hipFunction_t kernel;

	hipModuleLoad(&module, file_name);
	hipModuleGetFunction(&kernel, module, "kern");

	int blk_size = 32;
	int total_blks = 1;//size/blk_size;	
	int sh_mem_size = blk_size*sizeof(float)*type_size;
	void * args[2] = {&scal, &output};

	//cudaEvent_t start, stop;
	//initializeEvents(&start, &stop);
	hipModuleLaunchKernel(kernel, total_blks, 1, 1,
			blk_size, 1, 1,
			sh_mem_size, 0, args, 0);
	//float krn_time_shmem_32b = finalizeEvents(start, stop);

	int *output_h = (int*)malloc(sizeof(int)*32);	

	hipMemcpy(output_h, output, sizeof(int)*32, hipMemcpyDeviceToHost);	

	/*for(int i=0; i<32; i++){
		printf("%d ", output_h[i]);
	}printf("\n");*/

	printf("%s took %d clocks \n", name, output_h[0]);
	double clocks_instr = (float)output_h[0]/(128.0*128.0); // wokload of a thread
	printf("Each instruction takes %.2f clocks.\n", clocks_instr);
	printf("Throughput %.2f bytes/cycle.\n\n", ((double)threads*128*128*type_size*4)/output_h[0]); // Size of information stores divided by the number of threads of the latest thread

	hipFree(output);
	free(output_h);
}

int main(){
	float scal = 4;
	run("sts32", scal, 1, 32);
	printf("\n");
	float2 scal2;
	scal2.x = 4; scal2.y = 4;
	run("sts64", scal2, 2, 32);
	printf("\n");
	float4 scal4;
	scal4.x = 4; scal4.y = 4;
	scal4.z = 4; scal4.w = 4;
	// No thread-divergence
	run("sts128_0", scal4, 4, 32);

	printf("\n");
	// Only half of the threads store data
	run("sts128", scal4, 4, 16);

	/* run2_aux("sts64_2bank_conflict");
	printf("\n");
	run2_aux("sts64_broadcast");
	printf("\n");
	run2_aux("sts64_opt3");
	printf("\n"); */

	return 0;
}

	.text
	.file	"main.hip"
	.globl	_Z6concatPKcS0_                 # -- Begin function _Z6concatPKcS0_
	.type	_Z6concatPKcS0_,@function
_Z6concatPKcS0_:                        # @_Z6concatPKcS0_
	.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	%rsi, %rbx
	movq	%rdi, %r14
	callq	strlen
	movq	%rax, %r15
	movq	%rbx, %rdi
	callq	strlen
	leaq	(%r15,%rax), %rdi
	incq	%rdi
	callq	malloc
	movq	%rax, %r15
	movq	%rax, %rdi
	movq	%r14, %rsi
	callq	strcpy
	movq	%r15, %rdi
	movq	%rbx, %rsi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	strcat                          # TAILCALL
.Lfunc_end0:
	.size	_Z6concatPKcS0_, .Lfunc_end0-_Z6concatPKcS0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z16initializeEventsPP11ihipEvent_tS1_ # -- Begin function _Z16initializeEventsPP11ihipEvent_tS1_
	.type	_Z16initializeEventsPP11ihipEvent_tS1_,@function
_Z16initializeEventsPP11ihipEvent_tS1_: # @_Z16initializeEventsPP11ihipEvent_tS1_
	.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	%rsi, %r14
	movq	%rdi, %rbx
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB1_1
# %bb.3:
	movq	%r14, %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB1_4
# %bb.5:
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB1_6
# %bb.7:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB1_1:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$25, %ecx
	jmp	.LBB1_2
.LBB1_4:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$26, %ecx
	jmp	.LBB1_2
.LBB1_6:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$27, %ecx
.LBB1_2:
	movq	%rax, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z16initializeEventsPP11ihipEvent_tS1_, .Lfunc_end1-_Z16initializeEventsPP11ihipEvent_tS1_
	.cfi_endproc
                                        # -- End function
	.globl	_Z14finalizeEventsP11ihipEvent_tS0_ # -- Begin function _Z14finalizeEventsP11ihipEvent_tS0_
	.type	_Z14finalizeEventsP11ihipEvent_tS0_,@function
_Z14finalizeEventsP11ihipEvent_tS0_:    # @_Z14finalizeEventsP11ihipEvent_tS0_
	.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	%rsi, %rbx
	movq	%rdi, %r14
	callq	hipGetLastError
	testl	%eax, %eax
	jne	.LBB2_1
# %bb.3:
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB2_4
# %bb.5:
	movq	%rbx, %rdi
	callq	hipEventSynchronize
	testl	%eax, %eax
	jne	.LBB2_6
# %bb.7:
	leaq	4(%rsp), %rdi
	movq	%r14, %rsi
	movq	%rbx, %rdx
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB2_8
# %bb.9:
	movq	%r14, %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB2_10
# %bb.11:
	movq	%rbx, %rdi
	callq	hipEventDestroy
	testl	%eax, %eax
	jne	.LBB2_12
# %bb.13:
	movss	4(%rsp), %xmm0                  # xmm0 = mem[0],zero,zero,zero
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB2_1:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$31, %ecx
	jmp	.LBB2_2
.LBB2_4:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$32, %ecx
	jmp	.LBB2_2
.LBB2_6:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$33, %ecx
	jmp	.LBB2_2
.LBB2_8:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$35, %ecx
	jmp	.LBB2_2
.LBB2_10:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$36, %ecx
	jmp	.LBB2_2
.LBB2_12:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str, %esi
	movl	$.L.str.1, %edx
	movq	%rbx, %rdi
	movl	$37, %ecx
.LBB2_2:
	movq	%rax, %r8
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	callq	exit
.Lfunc_end2:
	.size	_Z14finalizeEventsP11ihipEvent_tS0_, .Lfunc_end2-_Z14finalizeEventsP11ihipEvent_tS0_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI3_0:
	.long	0x40800000                      # float 4
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$48, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -16
	movss	.LCPI3_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movl	$.L.str.2, %edi
	movl	$1, %esi
	movl	$32, %edx
	callq	_Z3runIfEvPcT_ii
	movl	$10, %edi
	callq	putchar@PLT
	movabsq	$4647714816528482304, %rbx      # imm = 0x4080000040800000
	movq	%rbx, 40(%rsp)
	movsd	40(%rsp), %xmm0                 # xmm0 = mem[0],zero
	movl	$.L.str.4, %edi
	movl	$2, %esi
	movl	$32, %edx
	callq	_Z3runI15HIP_vector_typeIfLj2EEEvPcT_ii
	movl	$10, %edi
	callq	putchar@PLT
	movq	%rbx, (%rsp)
	movq	%rbx, 32(%rsp)
	movsd	(%rsp), %xmm0                   # xmm0 = mem[0],zero
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	movsd	32(%rsp), %xmm1                 # xmm1 = mem[0],zero
	movsd	%xmm1, 16(%rsp)                 # 8-byte Spill
	movl	$.L.str.5, %edi
	movl	$4, %esi
	movl	$32, %edx
	callq	_Z3runI15HIP_vector_typeIfLj4EEEvPcT_ii
	movl	$10, %edi
	callq	putchar@PLT
	movl	$.L.str.6, %edi
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movsd	16(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	movl	$4, %esi
	movl	$16, %edx
	callq	_Z3runI15HIP_vector_typeIfLj4EEEvPcT_ii
	xorl	%eax, %eax
	addq	$48, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z3runIfEvPcT_ii
.LCPI4_0:
	.quad	0x3f10000000000000              # double 6.103515625E-5
.LCPI4_1:
	.quad	0x4060000000000000              # double 128
.LCPI4_2:
	.quad	0x4010000000000000              # double 4
	.section	.text._Z3runIfEvPcT_ii,"axG",@progbits,_Z3runIfEvPcT_ii,comdat
	.weak	_Z3runIfEvPcT_ii
	.type	_Z3runIfEvPcT_ii,@function
_Z3runIfEvPcT_ii:                       # @_Z3runIfEvPcT_ii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, (%rsp)                    # 4-byte Spill
	movl	%esi, %ebp
	movq	%rdi, %r15
	leaq	4(%rsp), %rax
	movss	%xmm0, (%rax)
	movl	$.L.str.7, %esi
	callq	_Z6concatPKcS0_
	movq	%rax, %r12
	leaq	24(%rsp), %rbx
	movl	$128, %esi
	movq	%rbx, %rdi
	callq	hipMalloc
	movq	(%rbx), %rdi
	xorl	%r14d, %r14d
	movl	$128, %edx
	xorl	%esi, %esi
	callq	hipMemset
	leaq	16(%rsp), %r13
	movq	%r13, %rdi
	movq	%r12, %rsi
	callq	hipModuleLoad
	movq	(%r13), %rsi
	leaq	8(%rsp), %r12
	movl	$.L.str.8, %edx
	movq	%r12, %rdi
	callq	hipModuleGetFunction
	movl	%ebp, %eax
	shll	$7, %eax
	leaq	32(%rsp), %r10
	leaq	4(%rsp), %rcx
	movq	%rcx, (%r10)
	movq	%rbx, 8(%r10)
	movq	(%r12), %rdi
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movl	$1, %esi
	movl	$1, %edx
	movl	$1, %ecx
	movl	$32, %r8d
	movl	$1, %r9d
	pushq	%r14
	.cfi_adjust_cfa_offset 8
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	pushq	%r14
	.cfi_adjust_cfa_offset 8
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	hipModuleLaunchKernel
	addq	$48, %rsp
	.cfi_adjust_cfa_offset -48
	movl	$128, %edi
	callq	malloc
	movq	%rax, %r12
	movq	(%rbx), %rsi
	movl	$128, %edx
	movq	%rax, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	(%r12), %edx
	movl	$.L.str.9, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	cvtsi2ssl	(%r12), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LCPI4_0(%rip), %xmm0
	movl	$.L.str.10, %edi
	movb	$1, %al
	callq	printf
	cvtsi2sdl	(%rsp), %xmm1           # 4-byte Folded Reload
	movsd	.LCPI4_1(%rip), %xmm2           # xmm2 = mem[0],zero
	mulsd	%xmm2, %xmm1
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ebp, %xmm0
	mulsd	%xmm2, %xmm1
	mulsd	%xmm1, %xmm0
	mulsd	.LCPI4_2(%rip), %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sdl	(%r12), %xmm1
	divsd	%xmm1, %xmm0
	movl	$.L.str.11, %edi
	movb	$1, %al
	callq	printf
	movq	(%rbx), %rdi
	callq	hipFree
	movq	%r12, %rdi
	callq	free
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z3runIfEvPcT_ii, .Lfunc_end4-_Z3runIfEvPcT_ii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z3runI15HIP_vector_typeIfLj2EEEvPcT_ii
.LCPI5_0:
	.quad	0x3f10000000000000              # double 6.103515625E-5
.LCPI5_1:
	.quad	0x4060000000000000              # double 128
.LCPI5_2:
	.quad	0x4010000000000000              # double 4
	.section	.text._Z3runI15HIP_vector_typeIfLj2EEEvPcT_ii,"axG",@progbits,_Z3runI15HIP_vector_typeIfLj2EEEvPcT_ii,comdat
	.weak	_Z3runI15HIP_vector_typeIfLj2EEEvPcT_ii
	.type	_Z3runI15HIP_vector_typeIfLj2EEEvPcT_ii,@function
_Z3runI15HIP_vector_typeIfLj2EEEvPcT_ii: # @_Z3runI15HIP_vector_typeIfLj2EEEvPcT_ii
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.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	%edx, 12(%rsp)                  # 4-byte Spill
	movl	%esi, %ebp
	movq	%rdi, %r15
	leaq	16(%rsp), %rax
	movsd	%xmm0, (%rax)
	movl	$.L.str.7, %esi
	callq	_Z6concatPKcS0_
	movq	%rax, %r12
	leaq	40(%rsp), %rbx
	movl	$128, %esi
	movq	%rbx, %rdi
	callq	hipMalloc
	movq	(%rbx), %rdi
	xorl	%r14d, %r14d
	movl	$128, %edx
	xorl	%esi, %esi
	callq	hipMemset
	leaq	32(%rsp), %r13
	movq	%r13, %rdi
	movq	%r12, %rsi
	callq	hipModuleLoad
	movq	(%r13), %rsi
	leaq	24(%rsp), %r12
	movl	$.L.str.8, %edx
	movq	%r12, %rdi
	callq	hipModuleGetFunction
	movl	%ebp, %eax
	shll	$7, %eax
	leaq	48(%rsp), %r10
	leaq	16(%rsp), %rcx
	movq	%rcx, (%r10)
	movq	%rbx, 8(%r10)
	movq	(%r12), %rdi
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movl	$1, %esi
	movl	$1, %edx
	movl	$1, %ecx
	movl	$32, %r8d
	movl	$1, %r9d
	pushq	%r14
	.cfi_adjust_cfa_offset 8
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	pushq	%r14
	.cfi_adjust_cfa_offset 8
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	hipModuleLaunchKernel
	addq	$48, %rsp
	.cfi_adjust_cfa_offset -48
	movl	$128, %edi
	callq	malloc
	movq	%rax, %r12
	movq	(%rbx), %rsi
	movl	$128, %edx
	movq	%rax, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	(%r12), %edx
	movl	$.L.str.9, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	cvtsi2ssl	(%r12), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LCPI5_0(%rip), %xmm0
	movl	$.L.str.10, %edi
	movb	$1, %al
	callq	printf
	cvtsi2sdl	12(%rsp), %xmm1         # 4-byte Folded Reload
	movsd	.LCPI5_1(%rip), %xmm2           # xmm2 = mem[0],zero
	mulsd	%xmm2, %xmm1
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ebp, %xmm0
	mulsd	%xmm2, %xmm1
	mulsd	%xmm1, %xmm0
	mulsd	.LCPI5_2(%rip), %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sdl	(%r12), %xmm1
	divsd	%xmm1, %xmm0
	movl	$.L.str.11, %edi
	movb	$1, %al
	callq	printf
	movq	(%rbx), %rdi
	callq	hipFree
	movq	%r12, %rdi
	callq	free
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z3runI15HIP_vector_typeIfLj2EEEvPcT_ii, .Lfunc_end5-_Z3runI15HIP_vector_typeIfLj2EEEvPcT_ii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z3runI15HIP_vector_typeIfLj4EEEvPcT_ii
.LCPI6_0:
	.quad	0x3f10000000000000              # double 6.103515625E-5
.LCPI6_1:
	.quad	0x4060000000000000              # double 128
.LCPI6_2:
	.quad	0x4010000000000000              # double 4
	.section	.text._Z3runI15HIP_vector_typeIfLj4EEEvPcT_ii,"axG",@progbits,_Z3runI15HIP_vector_typeIfLj4EEEvPcT_ii,comdat
	.weak	_Z3runI15HIP_vector_typeIfLj4EEEvPcT_ii
	.type	_Z3runI15HIP_vector_typeIfLj4EEEvPcT_ii,@function
_Z3runI15HIP_vector_typeIfLj4EEEvPcT_ii: # @_Z3runI15HIP_vector_typeIfLj4EEEvPcT_ii
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.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	%edx, 4(%rsp)                   # 4-byte Spill
	movl	%esi, %r14d
	movq	%rdi, %r15
	leaq	48(%rsp), %rbp
	movsd	%xmm0, (%rbp)
	movsd	%xmm1, 8(%rbp)
	movl	$.L.str.7, %esi
	callq	_Z6concatPKcS0_
	movq	%rax, %r12
	leaq	8(%rsp), %rbx
	movl	$128, %esi
	movq	%rbx, %rdi
	callq	hipMalloc
	movq	(%rbx), %rdi
	xorl	%ebx, %ebx
	movl	$128, %edx
	xorl	%esi, %esi
	callq	hipMemset
	leaq	24(%rsp), %r13
	movq	%r13, %rdi
	movq	%r12, %rsi
	callq	hipModuleLoad
	movq	(%r13), %rsi
	leaq	16(%rsp), %r12
	movl	$.L.str.8, %edx
	movq	%r12, %rdi
	callq	hipModuleGetFunction
	movl	%r14d, %eax
	shll	$7, %eax
	leaq	32(%rsp), %r10
	movq	%rbp, (%r10)
	leaq	8(%rsp), %r13
	movq	%r13, 8(%r10)
	movq	(%r12), %rdi
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	movl	$1, %esi
	movl	$1, %edx
	movl	$1, %ecx
	movl	$32, %r8d
	movl	$1, %r9d
	pushq	%rbx
	.cfi_adjust_cfa_offset 8
	pushq	%r10
	.cfi_adjust_cfa_offset 8
	pushq	%rbx
	.cfi_adjust_cfa_offset 8
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	hipModuleLaunchKernel
	addq	$48, %rsp
	.cfi_adjust_cfa_offset -48
	movl	$128, %edi
	callq	malloc
	movq	%rax, %r12
	movq	(%r13), %rsi
	movl	$128, %edx
	movq	%rax, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	(%r12), %edx
	movl	$.L.str.9, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	cvtsi2ssl	(%r12), %xmm0
	cvtss2sd	%xmm0, %xmm0
	mulsd	.LCPI6_0(%rip), %xmm0
	movl	$.L.str.10, %edi
	movb	$1, %al
	callq	printf
	cvtsi2sdl	4(%rsp), %xmm1          # 4-byte Folded Reload
	movsd	.LCPI6_1(%rip), %xmm2           # xmm2 = mem[0],zero
	mulsd	%xmm2, %xmm1
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r14d, %xmm0
	mulsd	%xmm2, %xmm1
	mulsd	%xmm1, %xmm0
	mulsd	.LCPI6_2(%rip), %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2sdl	(%r12), %xmm1
	divsd	%xmm1, %xmm0
	movl	$.L.str.11, %edi
	movb	$1, %al
	callq	printf
	movq	(%r13), %rdi
	callq	hipFree
	movq	%r12, %rdi
	callq	free
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_Z3runI15HIP_vector_typeIfLj4EEEvPcT_ii, .Lfunc_end6-_Z3runI15HIP_vector_typeIfLj4EEEvPcT_ii
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Cuda error in file '%s' in line %i : %s.\n"
	.size	.L.str, 42

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/YanqingWu/openCNN/main/bench/smem/STS/main.hip"
	.size	.L.str.1, 109

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"sts64"
	.size	.L.str.4, 6

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"sts128_0"
	.size	.L.str.5, 9

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"sts128"
	.size	.L.str.6, 7

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"kern"
	.size	.L.str.8, 5

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"%s took %d clocks \n"
	.size	.L.str.9, 20

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Each instruction takes %.2f clocks.\n"
	.size	.L.str.10, 37

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Throughput %.2f bytes/cycle.\n\n"
	.size	.L.str.11, 31

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

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

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

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

	.end_amdgpu_metadata
