#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <device_launch_parameters.h>
#include <device_functions.h>

// Function that catches errors

// Function that catches the error
void testCUDA(cudaError_t error, const char *file, int line)  {

        if (error != cudaSuccess) {
           printf("There is an error in file %s at line %d\n", file, line);
       exit(EXIT_FAILURE);
        }
}

// Has to be defined in the compilation in order to get the correct value of the
// macros __FILE__ and __LINE__
#define testCUDA(error) (testCUDA(error, __FILE__ , __LINE__))

// Global variables

#define d 10
#define N 10
#define P 55

#define NUMBER_BLOCKS 512
#define THREADS_PER_BLOCKS 4*d

// Function that performs the product of Jacobi rotations
/* This function will be performed N times by N different blocks */

__global__ void Compute_all_rotations(float *J, float *A, float *out, const int *pos_i, const int *pos_j){

    __shared__ float temp[4 * d] ;  // variable that is to be shared by the threads in the block
    int block_j = blockDim.x * 4 * P ;
    int idx_J;
    int idx_A;
    int idx_out;

    for (int p=0 ; p<P ; p++) {
        // index = threadIdx.x + blockIdx.x*blockDim.x ;

        // Perform multiplications
        if (threadIdx.x % 4 == 0 ) {
            idx_J = 0 + 4 * p + block_j;
            idx_A = blockIdx.x * d * d + d * pos_i[p] + floorf(threadIdx.x / 4);
        }

        else if (threadIdx.x % 4 == 1 ) {
            idx_J = 1 + 4 * p + block_j;
            idx_A = blockIdx.x * d * d + d * pos_j[p] + floorf(threadIdx.x / 4);
        }

        else if (threadIdx.x % 4 == 2 ) {
            idx_J = 2 + 4 * p + block_j;
            idx_A = blockIdx.x * d * d + d * pos_i[p] + floorf(threadIdx.x / 4);
        }

        else if (threadIdx.x % 4 == 3 ) {
            idx_J = 3 + 4 * p + block_j;
            idx_A = blockIdx.x * d * d + d * pos_j[p] + floorf(threadIdx.x / 4);
        }

        temp[threadIdx.x] = J[idx_J] * A[idx_A] ;

        __syncthreads(); // synchronize threads

        // Perform additions

        if (threadIdx.x % 2 == 0){
            if (threadIdx.x % 4 == 0){
                idx_out = blockIdx.x * d * d + d * pos_i[p] + floorf(threadIdx.x / 4);
            }

            else if (threadIdx.x % 4 == 2){
                idx_out = blockIdx.x * d * d + d * pos_j[p] + floorf(threadIdx.x / 4);
            }
            out[idx_out] = temp[threadIdx.x] + temp[threadIdx.x + 1] ;
        }

        __syncthreads();  // synchronize threads
    }

}


// The folowing function reads the data stored in csv files and stores it in arrays

void read_file(const char * fname, float *array, int pos){

    FILE *file;
    char tampon[sizeof(float)];
    int actuel = 0;
    char c;
    int count;

    file = fopen (fname, "r");
    while ((c = fgetc(file)) != EOF) {
        if (c == ';' || c == '\n') {
            array[pos + count] = atof(tampon);
            actuel = 0;
            memset(tampon, 0, sizeof tampon);

        } else {
            tampon[actuel++] = c;
        }
    }

    printf("TEST\n");
    fclose (file);
}

void get_data(float *J, float *A){

    char fname[100] = {0};

    for (int n = 0 ; n<N ; n++){
        for (int p = 0 ; p<P ; p++){
            snprintf (fname, 100, "files/%i/J_%i.txt", n, p);
            read_file (fname, J, P*n*4 + 4*p);
        }

        snprintf (fname, 100, "files/%i/A.txt", n);
        read_file (fname, A, n*d*d);
    }
}


void write_result(float* out){

    FILE *file;
    const char* str = "; ";
    char fname[100] = {0};

    for (int n=0 ; n<N ; n++) {
        snprintf (fname, 100, "files/%i/out.txt", n);
        file = fopen(fname, "w");

        for (int i=0 ; i<d ; i++) {
            for (int j=0 ; j<d ; j++) {
                if (j == d-1) {
                  str = "\n";
                }

                fprintf(file, "%f %s", out[n*d*d + i*d +j], str);
                str = "; ";
            }
        }
        fclose(file);
    }
}

void positions(int* pos_i, int* pos_j){
    int shift = 0;

    for(int i=0 ; i<P ; i++){
        pos_i[i] = floor((i + shift) / d);
        pos_j[i] = (i + shift) % d;

        if((i + shift) % d == d-1){
            shift++;
        }
    }
}

int main(){

    // Properties of our GPUs

    cudaDeviceProp prop ;
    int count ;
    cudaGetDeviceCount(&count) ;

    for(int i=0 ; i<count ; i++) {
        cudaGetDeviceProperties(&prop, i) ;
        printf("Taille totale de la mémoire globale %ld\n", prop.totalGlobalMem) ;
    }

    // Define J A and out


    float J [P*4*d*N];
    float A [d*d*N];
    float out [d*d*N];

    get_data(J, A);

    // device copies

    float d_J [P*4*d*N];
    float d_A [d*d*N];
    float d_out [d*d*N];

    int size = sizeof(float);

    testCUDA(cudaMalloc((void **)&d_J, size));
    testCUDA(cudaMalloc((void **)&d_A, size));
    testCUDA(cudaMalloc((void **)&d_out, size));

    testCUDA(cudaMemcpy(d_A, &A, size, cudaMemcpyHostToDevice));
    testCUDA(cudaMemcpy(d_J, &J, size, cudaMemcpyHostToDevice));

    // Define pos_i et pos_j

    int pos_i [P];
    int pos_j [P];

    int *d_pos_i, *d_pos_j;

    size = sizeof(int);

    testCUDA(cudaMalloc((void **)&d_pos_i, size));
    testCUDA(cudaMalloc((void **)&d_pos_j, size));

    positions(pos_i, pos_j);

    testCUDA(cudaMemcpy(d_pos_i, &pos_j, size, cudaMemcpyHostToDevice));
    testCUDA(cudaMemcpy(d_pos_j, &pos_i, size, cudaMemcpyHostToDevice));

    // Timer definition and start

    float TimerV;
    cudaEvent_t start, stop;
    testCUDA(cudaEventCreate(&start));
    testCUDA(cudaEventCreate(&stop));
    testCUDA(cudaEventRecord(start, 0));

    // Computing rotations

    Compute_all_rotations<<<1,1>>>(d_J, d_A, d_out, d_pos_i, d_pos_j);

    // Stopping timer

    testCUDA(cudaEventRecord(stop, 0));
    testCUDA(cudaEventSynchronize(stop));
    testCUDA(cudaEventElapsedTime(&TimerV, start, stop));
    printf("Exectudtion time: %f ms\n", TimerV);

    // Copying and saving result

    testCUDA(cudaMemcpy(&out, d_out, sizeof(float), cudaMemcpyDeviceToHost));
    write_result(out);

    // Cleanup

    testCUDA(cudaFree(d_A));
    testCUDA(cudaFree(d_J));
    testCUDA(cudaFree(d_out));
    testCUDA(cudaFree(d_pos_i));
    testCUDA(cudaFree(d_pos_j));
    testCUDA(cudaFree(start));
    testCUDA(cudaFree(stop));

    return 0;
}
	.file	"tmpxft_0027bd4d_00000000-6_version1.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"There is an error in file %s at line %d\n"
	.text
	.globl	_Z8testCUDA9cudaErrorPKci
	.type	_Z8testCUDA9cudaErrorPKci, @function
_Z8testCUDA9cudaErrorPKci:
.LFB2027:
	.cfi_startproc
	endbr64
	testl	%edi, %edi
	je	.L2
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	%edx, %ecx
	movl	$2, %edi
	movq	%rsi, %rdx
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rsi
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L2:
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z8testCUDA9cudaErrorPKci, .-_Z8testCUDA9cudaErrorPKci
	.section	.rodata.str1.1
.LC1:
	.string	"r"
.LC2:
	.string	"TEST\n"
	.text
	.globl	_Z9read_filePKcPfi
	.type	_Z9read_filePKcPfi, @function
_Z9read_filePKcPfi:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	xorl	%r14d, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	movq	%rsi, %rbp
	leaq	.LC1(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %r13
	call	fopen@PLT
	movq	%rax, %rbx
.L9:
	movq	%rbx, %rdi
	call	fgetc@PLT
	cmpb	$-1, %al
	je	.L17
	cmpb	$59, %al
	je	.L15
	cmpb	$10, %al
	jne	.L10
.L15:
	movq	%r13, %rdi
	xorl	%r14d, %r14d
	call	atof@PLT
	movslq	%r12d, %rax
	xorl	%ecx, %ecx
	cvtsd2ss	%xmm0, %xmm0
	movl	%ecx, 0(%r13)
	movss	%xmm0, 0(%rbp,%rax,4)
	jmp	.L9
.L10:
	movslq	%r14d, %rdx
	incl	%r14d
	movb	%al, 4(%rsp,%rdx)
	jmp	.L9
.L17:
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rsi
	call	__printf_chk@PLT
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$16, %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
.LFE2028:
	.size	_Z9read_filePKcPfi, .-_Z9read_filePKcPfi
	.section	.rodata.str1.1
.LC3:
	.string	"files/%i/J_%i.txt"
.LC4:
	.string	"files/%i/A.txt"
	.text
	.globl	_Z8get_dataPfS_
	.type	_Z8get_dataPfS_, @function
_Z8get_dataPfS_:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$25, %ecx
	leaq	.LC3(%rip), %r15
	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
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %rdi
	rep stosl
	leaq	20(%rsp), %rax
	movq	%rax, 8(%rsp)
.L19:
	imull	$220, %ebx, %r12d
	xorl	%ebp, %ebp
.L20:
	pushq	%rax
	.cfi_def_cfa_offset 200
	movl	%ebx, %r9d
	movq	%r15, %r8
	movl	$100, %ecx
	pushq	%rbp
	.cfi_def_cfa_offset 208
	movq	24(%rsp), %rdi
	movl	$2, %edx
	movl	$100, %esi
	xorl	%eax, %eax
	incl	%ebp
	call	__snprintf_chk@PLT
	popq	%rdx
	.cfi_def_cfa_offset 200
	popq	%rcx
	.cfi_def_cfa_offset 192
	movl	%r12d, %edx
	movq	8(%rsp), %rdi
	movq	%r13, %rsi
	addl	$4, %r12d
	call	_Z9read_filePKcPfi
	cmpl	$55, %ebp
	jne	.L20
	movq	8(%rsp), %rdi
	movl	%ebx, %r9d
	movl	$100, %ecx
	xorl	%eax, %eax
	leaq	.LC4(%rip), %r8
	movl	$2, %edx
	movl	$100, %esi
	call	__snprintf_chk@PLT
	imull	$100, %ebx, %edx
	movq	8(%rsp), %rdi
	movq	%r14, %rsi
	incl	%ebx
	call	_Z9read_filePKcPfi
	cmpl	$10, %ebx
	jne	.L19
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	addq	$136, %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
.LFE2029:
	.size	_Z8get_dataPfS_, .-_Z8get_dataPfS_
	.section	.rodata.str1.1
.LC5:
	.string	"; "
.LC6:
	.string	"\n"
.LC7:
	.string	"files/%i/out.txt"
.LC8:
	.string	"w"
.LC9:
	.string	"%f %s"
	.text
	.globl	_Z12write_resultPf
	.type	_Z12write_resultPf, @function
_Z12write_resultPf:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$25, %ecx
	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
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	20(%rsp), %rdi
	rep stosl
	leaq	20(%rsp), %rax
	movq	%rax, (%rsp)
.L30:
	movq	(%rsp), %rdi
	leaq	.LC7(%rip), %r8
	movl	%ebx, %r9d
	xorl	%eax, %eax
	movl	$100, %ecx
	movl	$2, %edx
	movl	$100, %esi
	xorl	%r14d, %r14d
	call	__snprintf_chk@PLT
	movq	(%rsp), %rdi
	leaq	.LC8(%rip), %rsi
	leaq	.LC6(%rip), %r15
	call	fopen@PLT
	imulq	$400, %rbx, %r8
	movq	%rax, %rdi
	leaq	(%r12,%r8), %r13
.L26:
	xorl	%ebp, %ebp
.L28:
	cmpq	$9, %rbp
	movl	$2, %esi
	movb	$1, %al
	movq	%rdi, 8(%rsp)
	leaq	.LC5(%rip), %rcx
	cvtss2sd	0(%r13,%rbp,4), %xmm0
	leaq	.LC9(%rip), %rdx
	cmove	%r15, %rcx
	incq	%rbp
	call	__fprintf_chk@PLT
	cmpq	$10, %rbp
	movq	8(%rsp), %rdi
	jne	.L28
	incl	%r14d
	addq	$40, %r13
	cmpl	$10, %r14d
	jne	.L26
	call	fclose@PLT
	incq	%rbx
	cmpq	$10, %rbx
	jne	.L30
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L31
	call	__stack_chk_fail@PLT
.L31:
	addq	$136, %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
.LFE2030:
	.size	_Z12write_resultPf, .-_Z12write_resultPf
	.globl	_Z9positionsPiS_
	.type	_Z9positionsPiS_, @function
_Z9positionsPiS_:
.LFB2031:
	.cfi_startproc
	endbr64
	xorl	%ecx, %ecx
	xorl	%r8d, %r8d
	movl	$10, %r9d
.L38:
	leal	(%r8,%rcx), %eax
	cltd
	idivl	%r9d
	movl	%eax, (%rdi,%rcx,4)
	movl	%edx, (%rsi,%rcx,4)
	cmpl	$9, %edx
	jne	.L37
	incl	%r8d
.L37:
	incq	%rcx
	cmpq	$55, %rcx
	jne	.L38
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z9positionsPiS_, .-_Z9positionsPiS_
	.globl	_Z51__device_stub__Z21Compute_all_rotationsPfS_S_PKiS1_PfS_S_PKiS1_
	.type	_Z51__device_stub__Z21Compute_all_rotationsPfS_S_PKiS1_PfS_S_PKiS1_, @function
_Z51__device_stub__Z21Compute_all_rotationsPfS_S_PKiS1_PfS_S_PKiS1_:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	56(%rsp), %rcx
	movq	%r8, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L40
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z21Compute_all_rotationsPfS_S_PKiS1_(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L40:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L42
	call	__stack_chk_fail@PLT
.L42:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z51__device_stub__Z21Compute_all_rotationsPfS_S_PKiS1_PfS_S_PKiS1_, .-_Z51__device_stub__Z21Compute_all_rotationsPfS_S_PKiS1_PfS_S_PKiS1_
	.globl	_Z21Compute_all_rotationsPfS_S_PKiS1_
	.type	_Z21Compute_all_rotationsPfS_S_PKiS1_, @function
_Z21Compute_all_rotationsPfS_S_PKiS1_:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z51__device_stub__Z21Compute_all_rotationsPfS_S_PKiS1_PfS_S_PKiS1_
	.cfi_endproc
.LFE2058:
	.size	_Z21Compute_all_rotationsPfS_S_PKiS1_, .-_Z21Compute_all_rotationsPfS_S_PKiS1_
	.section	.rodata.str1.1
.LC10:
	.string	"Taille totale de la m\303\251moire globale %ld\n"
.LC11:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/JbRemy/GPU_programming/master/version1.cu"
.LC12:
	.string	"Exectudtion time: %f ms\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	leaq	-192512(%rsp), %r11
	.cfi_def_cfa 11, 192568
.LPSRL0:
	subq	$4096, %rsp
	orq	$0, (%rsp)
	cmpq	%r11, %rsp
	jne	.LPSRL0
	.cfi_def_cfa_register 7
	subq	$1048, %rsp
	.cfi_def_cfa_offset 193616
	xorl	%ebx, %ebx
	leaq	.LC10(%rip), %rbp
	movq	%fs:40, %rax
	movq	%rax, 193544(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
.L46:
	cmpl	%ebx, 12(%rsp)
	jle	.L51
	movl	%ebx, %esi
	leaq	512(%rsp), %rdi
	incl	%ebx
	call	cudaGetDeviceProperties_v2@PLT
	movq	%rbp, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	movq	800(%rsp), %rdx
	call	__printf_chk@PLT
	jmp	.L46
.L51:
	leaq	17544(%rsp), %r14
	leaq	1544(%rsp), %r15
	movq	%r14, %rdi
	movq	%r15, %rsi
	leaq	105544(%rsp), %r12
	call	_Z8get_dataPfS_
	movl	$4, %esi
	movq	%r12, %rdi
	leaq	.LC11(%rip), %rbx
	call	cudaMalloc@PLT
	movl	$199, %edx
	movq	%rbx, %rsi
	leaq	9544(%rsp), %r13
	movl	%eax, %edi
	leaq	13544(%rsp), %rbp
	call	_Z8testCUDA9cudaErrorPKci
	movl	$4, %esi
	movq	%r13, %rdi
	call	cudaMalloc@PLT
	movl	$200, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movl	$4, %esi
	movq	%rbp, %rdi
	call	cudaMalloc@PLT
	movl	$201, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movl	$1, %ecx
	movq	%r15, %rsi
	movq	%r13, %rdi
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movl	$203, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movl	$1, %ecx
	movq	%r14, %rsi
	movq	%r12, %rdi
	movl	$4, %edx
	leaq	72(%rsp), %r14
	call	cudaMemcpy@PLT
	movl	$204, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	leaq	16(%rsp), %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	movl	$215, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	leaq	24(%rsp), %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	movl	$216, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	leaq	292(%rsp), %rsi
	movq	%r14, %rdi
	call	_Z9positionsPiS_
	movq	16(%rsp), %rdi
	movl	$1, %ecx
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movl	$220, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%r14, %rsi
	movl	$4, %edx
	call	cudaMemcpy@PLT
	movl	$221, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	$227, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	$228, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	$229, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movl	$1, 68(%rsp)
	movq	%rdi, %rdx
	movq	%rdi, 60(%rsp)
	movq	%rdi, 48(%rsp)
	movl	$1, 56(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L48
	movq	24(%rsp), %r8
	movq	16(%rsp), %rcx
	movq	%rbp, %rdx
	movq	%r13, %rsi
	movq	%r12, %rdi
	call	_Z51__device_stub__Z21Compute_all_rotationsPfS_S_PKiS1_PfS_S_PKiS1_
.L48:
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	leaq	5544(%rsp), %r14
	call	cudaEventRecord@PLT
	movl	$237, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movq	40(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movl	$238, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	leaq	60(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movl	$239, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	60(%rsp), %xmm0
	call	__printf_chk@PLT
	movl	$2, %ecx
	movl	$4, %edx
	movq	%rbp, %rsi
	movq	%r14, %rdi
	call	cudaMemcpy@PLT
	movl	$244, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movq	%r14, %rdi
	call	_Z12write_resultPf
	movq	%r13, %rdi
	call	cudaFree@PLT
	movl	$249, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movq	%r12, %rdi
	call	cudaFree@PLT
	movl	$250, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movq	%rbp, %rdi
	call	cudaFree@PLT
	movl	$251, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movl	$252, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movl	$253, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movq	32(%rsp), %rdi
	call	cudaFree@PLT
	movl	$254, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movq	40(%rsp), %rdi
	call	cudaFree@PLT
	movl	$255, %edx
	movq	%rbx, %rsi
	movl	%eax, %edi
	call	_Z8testCUDA9cudaErrorPKci
	movq	193544(%rsp), %rax
	subq	%fs:40, %rax
	je	.L49
	call	__stack_chk_fail@PLT
.L49:
	addq	$193560, %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
.LFE2032:
	.size	main, .-main
	.section	.rodata.str1.1
.LC13:
	.string	"_Z21Compute_all_rotationsPfS_S_PKiS1_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC13(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z21Compute_all_rotationsPfS_S_PKiS1_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2060:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#include <hip/device_functions.h>

// Function that catches errors

// Function that catches the error
void testCUDA(hipError_t error, const char *file, int line)  {

        if (error != hipSuccess) {
           printf("There is an error in file %s at line %d\n", file, line);
       exit(EXIT_FAILURE);
        }
}

// Has to be defined in the compilation in order to get the correct value of the
// macros __FILE__ and __LINE__
#define testCUDA(error) (testCUDA(error, __FILE__ , __LINE__))

// Global variables

#define d 10
#define N 10
#define P 55

#define NUMBER_BLOCKS 512
#define THREADS_PER_BLOCKS 4*d

// Function that performs the product of Jacobi rotations
/* This function will be performed N times by N different blocks */

__global__ void Compute_all_rotations(float *J, float *A, float *out, const int *pos_i, const int *pos_j){

    __shared__ float temp[4 * d] ;  // variable that is to be shared by the threads in the block
    int block_j = blockDim.x * 4 * P ;
    int idx_J;
    int idx_A;
    int idx_out;

    for (int p=0 ; p<P ; p++) {
        // index = threadIdx.x + blockIdx.x*blockDim.x ;

        // Perform multiplications
        if (threadIdx.x % 4 == 0 ) {
            idx_J = 0 + 4 * p + block_j;
            idx_A = blockIdx.x * d * d + d * pos_i[p] + floorf(threadIdx.x / 4);
        }

        else if (threadIdx.x % 4 == 1 ) {
            idx_J = 1 + 4 * p + block_j;
            idx_A = blockIdx.x * d * d + d * pos_j[p] + floorf(threadIdx.x / 4);
        }

        else if (threadIdx.x % 4 == 2 ) {
            idx_J = 2 + 4 * p + block_j;
            idx_A = blockIdx.x * d * d + d * pos_i[p] + floorf(threadIdx.x / 4);
        }

        else if (threadIdx.x % 4 == 3 ) {
            idx_J = 3 + 4 * p + block_j;
            idx_A = blockIdx.x * d * d + d * pos_j[p] + floorf(threadIdx.x / 4);
        }

        temp[threadIdx.x] = J[idx_J] * A[idx_A] ;

        __syncthreads(); // synchronize threads

        // Perform additions

        if (threadIdx.x % 2 == 0){
            if (threadIdx.x % 4 == 0){
                idx_out = blockIdx.x * d * d + d * pos_i[p] + floorf(threadIdx.x / 4);
            }

            else if (threadIdx.x % 4 == 2){
                idx_out = blockIdx.x * d * d + d * pos_j[p] + floorf(threadIdx.x / 4);
            }
            out[idx_out] = temp[threadIdx.x] + temp[threadIdx.x + 1] ;
        }

        __syncthreads();  // synchronize threads
    }

}


// The folowing function reads the data stored in csv files and stores it in arrays

void read_file(const char * fname, float *array, int pos){

    FILE *file;
    char tampon[sizeof(float)];
    int actuel = 0;
    char c;
    int count;

    file = fopen (fname, "r");
    while ((c = fgetc(file)) != EOF) {
        if (c == ';' || c == '\n') {
            array[pos + count] = atof(tampon);
            actuel = 0;
            memset(tampon, 0, sizeof tampon);

        } else {
            tampon[actuel++] = c;
        }
    }

    printf("TEST\n");
    fclose (file);
}

void get_data(float *J, float *A){

    char fname[100] = {0};

    for (int n = 0 ; n<N ; n++){
        for (int p = 0 ; p<P ; p++){
            snprintf (fname, 100, "files/%i/J_%i.txt", n, p);
            read_file (fname, J, P*n*4 + 4*p);
        }

        snprintf (fname, 100, "files/%i/A.txt", n);
        read_file (fname, A, n*d*d);
    }
}


void write_result(float* out){

    FILE *file;
    const char* str = "; ";
    char fname[100] = {0};

    for (int n=0 ; n<N ; n++) {
        snprintf (fname, 100, "files/%i/out.txt", n);
        file = fopen(fname, "w");

        for (int i=0 ; i<d ; i++) {
            for (int j=0 ; j<d ; j++) {
                if (j == d-1) {
                  str = "\n";
                }

                fprintf(file, "%f %s", out[n*d*d + i*d +j], str);
                str = "; ";
            }
        }
        fclose(file);
    }
}

void positions(int* pos_i, int* pos_j){
    int shift = 0;

    for(int i=0 ; i<P ; i++){
        pos_i[i] = floor((i + shift) / d);
        pos_j[i] = (i + shift) % d;

        if((i + shift) % d == d-1){
            shift++;
        }
    }
}

int main(){

    // Properties of our GPUs

    hipDeviceProp_t prop ;
    int count ;
    hipGetDeviceCount(&count) ;

    for(int i=0 ; i<count ; i++) {
        hipGetDeviceProperties(&prop, i) ;
        printf("Taille totale de la mémoire globale %ld\n", prop.totalGlobalMem) ;
    }

    // Define J A and out


    float J [P*4*d*N];
    float A [d*d*N];
    float out [d*d*N];

    get_data(J, A);

    // device copies

    float d_J [P*4*d*N];
    float d_A [d*d*N];
    float d_out [d*d*N];

    int size = sizeof(float);

    testCUDA(hipMalloc((void **)&d_J, size));
    testCUDA(hipMalloc((void **)&d_A, size));
    testCUDA(hipMalloc((void **)&d_out, size));

    testCUDA(hipMemcpy(d_A, &A, size, hipMemcpyHostToDevice));
    testCUDA(hipMemcpy(d_J, &J, size, hipMemcpyHostToDevice));

    // Define pos_i et pos_j

    int pos_i [P];
    int pos_j [P];

    int *d_pos_i, *d_pos_j;

    size = sizeof(int);

    testCUDA(hipMalloc((void **)&d_pos_i, size));
    testCUDA(hipMalloc((void **)&d_pos_j, size));

    positions(pos_i, pos_j);

    testCUDA(hipMemcpy(d_pos_i, &pos_j, size, hipMemcpyHostToDevice));
    testCUDA(hipMemcpy(d_pos_j, &pos_i, size, hipMemcpyHostToDevice));

    // Timer definition and start

    float TimerV;
    hipEvent_t start, stop;
    testCUDA(hipEventCreate(&start));
    testCUDA(hipEventCreate(&stop));
    testCUDA(hipEventRecord(start, 0));

    // Computing rotations

    Compute_all_rotations<<<1,1>>>(d_J, d_A, d_out, d_pos_i, d_pos_j);

    // Stopping timer

    testCUDA(hipEventRecord(stop, 0));
    testCUDA(hipEventSynchronize(stop));
    testCUDA(hipEventElapsedTime(&TimerV, start, stop));
    printf("Exectudtion time: %f ms\n", TimerV);

    // Copying and saving result

    testCUDA(hipMemcpy(&out, d_out, sizeof(float), hipMemcpyDeviceToHost));
    write_result(out);

    // Cleanup

    testCUDA(hipFree(d_A));
    testCUDA(hipFree(d_J));
    testCUDA(hipFree(d_out));
    testCUDA(hipFree(d_pos_i));
    testCUDA(hipFree(d_pos_j));
    testCUDA(hipFree(start));
    testCUDA(hipFree(stop));

    return 0;
}
	.text
	.file	"version1.hip"
	.globl	_Z8testCUDA10hipError_tPKci     # -- Begin function _Z8testCUDA10hipError_tPKci
	.type	_Z8testCUDA10hipError_tPKci,@function
_Z8testCUDA10hipError_tPKci:            # @_Z8testCUDA10hipError_tPKci
	.cfi_startproc
# %bb.0:
	testl	%edi, %edi
	jne	.LBB0_2
# %bb.1:
	retq
.LBB0_2:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z8testCUDA10hipError_tPKci, .Lfunc_end0-_Z8testCUDA10hipError_tPKci
	.cfi_endproc
                                        # -- End function
	.globl	_Z36__device_stub__Compute_all_rotationsPfS_S_PKiS1_ # -- Begin function _Z36__device_stub__Compute_all_rotationsPfS_S_PKiS1_
	.type	_Z36__device_stub__Compute_all_rotationsPfS_S_PKiS1_,@function
_Z36__device_stub__Compute_all_rotationsPfS_S_PKiS1_: # @_Z36__device_stub__Compute_all_rotationsPfS_S_PKiS1_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	24(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z21Compute_all_rotationsPfS_S_PKiS1_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z36__device_stub__Compute_all_rotationsPfS_S_PKiS1_, .Lfunc_end1-_Z36__device_stub__Compute_all_rotationsPfS_S_PKiS1_
	.cfi_endproc
                                        # -- End function
	.globl	_Z9read_filePKcPfi              # -- Begin function _Z9read_filePKcPfi
	.type	_Z9read_filePKcPfi,@function
_Z9read_filePKcPfi:                     # @_Z9read_filePKcPfi
	.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	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	$.L.str.1, %esi
	callq	fopen
	movq	%rax, %r14
	xorl	%ebp, %ebp
	leaq	4(%rsp), %r15
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	callq	fgetc
	cmpb	$10, %al
	je	.LBB2_6
# %bb.2:                                #   in Loop: Header=BB2_1 Depth=1
	movzbl	%al, %ecx
	cmpl	$59, %ecx
	je	.LBB2_6
# %bb.3:                                #   in Loop: Header=BB2_1 Depth=1
	cmpl	$255, %ecx
	je	.LBB2_5
# %bb.4:                                #   in Loop: Header=BB2_1 Depth=1
	movslq	%ebp, %rcx
	incl	%ebp
	movb	%al, 4(%rsp,%rcx)
	jmp	.LBB2_1
.LBB2_6:                                #   in Loop: Header=BB2_1 Depth=1
	movq	%r15, %rdi
	callq	atof
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rbx)
	movl	$0, 4(%rsp)
	xorl	%ebp, %ebp
	jmp	.LBB2_1
.LBB2_5:
	movl	$.Lstr, %edi
	callq	puts@PLT
	movq	%r14, %rdi
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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
	jmp	fclose                          # TAILCALL
.Lfunc_end2:
	.size	_Z9read_filePKcPfi, .Lfunc_end2-_Z9read_filePKcPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z8get_dataPfS_                 # -- Begin function _Z8get_dataPfS_
	.type	_Z8get_dataPfS_,@function
_Z8get_dataPfS_:                        # @_Z8get_dataPfS_
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	xorps	%xmm0, %xmm0
	movq	%rsp, %r15
	movaps	%xmm0, 80(%r15)
	movaps	%xmm0, 64(%r15)
	movaps	%xmm0, 48(%r15)
	movaps	%xmm0, 32(%r15)
	movaps	%xmm0, 16(%r15)
	movaps	%xmm0, (%r15)
	movl	$0, 96(%r15)
	xorl	%ebp, %ebp
.LBB3_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_2 Depth 2
	xorl	%r12d, %r12d
.LBB3_2:                                #   Parent Loop BB3_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$100, %esi
	movl	$.L.str.3, %edx
	movq	%r15, %rdi
	movl	%ebp, %ecx
	movl	%r12d, %r8d
	xorl	%eax, %eax
	callq	snprintf
	movq	%r15, %rdi
	movq	%r14, %rsi
	callq	_Z9read_filePKcPfi
	incl	%r12d
	cmpl	$55, %r12d
	jne	.LBB3_2
# %bb.3:                                #   in Loop: Header=BB3_1 Depth=1
	movl	$100, %esi
	movl	$.L.str.4, %edx
	movq	%r15, %rdi
	movl	%ebp, %ecx
	xorl	%eax, %eax
	callq	snprintf
	movq	%r15, %rdi
	movq	%rbx, %rsi
	callq	_Z9read_filePKcPfi
	incl	%ebp
	cmpl	$10, %ebp
	jne	.LBB3_1
# %bb.4:
	addq	$112, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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_end3:
	.size	_Z8get_dataPfS_, .Lfunc_end3-_Z8get_dataPfS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z12write_resultPf              # -- Begin function _Z12write_resultPf
	.type	_Z12write_resultPf,@function
_Z12write_resultPf:                     # @_Z12write_resultPf
	.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	$120, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdi, %rbx
	xorps	%xmm0, %xmm0
	leaq	16(%rsp), %rax
	movaps	%xmm0, 80(%rax)
	movaps	%xmm0, 64(%rax)
	movaps	%xmm0, 48(%rax)
	movaps	%xmm0, 32(%rax)
	movaps	%xmm0, 16(%rax)
	movaps	%xmm0, (%rax)
	movl	$0, 96(%rax)
	movl	$.L.str.8, %r13d
	xorl	%r15d, %r15d
.LBB4_1:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_2 Depth 2
                                        #       Child Loop BB4_3 Depth 3
	movl	$100, %esi
	movl	$.L.str.6, %edx
	leaq	16(%rsp), %r14
	movq	%r14, %rdi
	movl	%r15d, %ecx
	xorl	%eax, %eax
	callq	snprintf
	movl	$.L.str.7, %esi
	movq	%r14, %rdi
	callq	fopen
	movq	%rax, %r12
	movq	%rbx, 8(%rsp)                   # 8-byte Spill
	movq	%rbx, %rbp
	xorl	%r14d, %r14d
.LBB4_2:                                # %.preheader
                                        #   Parent Loop BB4_1 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB4_3 Depth 3
	movq	$-10, %rax
	movq	$-10, %rbx
.LBB4_3:                                #   Parent Loop BB4_1 Depth=1
                                        #     Parent Loop BB4_2 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	incq	%rbx
	movl	$.L.str.5, %edx
	cmoveq	%r13, %rdx
	xorps	%xmm0, %xmm0
	cvtss2sd	40(%rbp,%rax,4), %xmm0
	movl	$.L.str.9, %esi
	movq	%r12, %rdi
	movb	$1, %al
	callq	fprintf
	movq	%rbx, %rax
	testq	%rbx, %rbx
	jne	.LBB4_3
# %bb.4:                                #   in Loop: Header=BB4_2 Depth=2
	incq	%r14
	addq	$40, %rbp
	cmpq	$10, %r14
	jne	.LBB4_2
# %bb.5:                                #   in Loop: Header=BB4_1 Depth=1
	movq	%r12, %rdi
	callq	fclose
	incq	%r15
	movq	8(%rsp), %rbx                   # 8-byte Reload
	addq	$400, %rbx                      # imm = 0x190
	cmpq	$10, %r15
	jne	.LBB4_1
# %bb.6:
	addq	$120, %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	_Z12write_resultPf, .Lfunc_end4-_Z12write_resultPf
	.cfi_endproc
                                        # -- End function
	.globl	_Z9positionsPiS_                # -- Begin function _Z9positionsPiS_
	.type	_Z9positionsPiS_,@function
_Z9positionsPiS_:                       # @_Z9positionsPiS_
	.cfi_startproc
# %bb.0:
	xorl	%eax, %eax
	movl	$3435973837, %ecx               # imm = 0xCCCCCCCD
	xorl	%edx, %edx
.LBB5_1:                                # =>This Inner Loop Header: Depth=1
	leal	(%rdx,%rax), %r8d
	imulq	%rcx, %r8
	shrq	$35, %r8
	movl	%r8d, (%rdi,%rax,4)
	addl	%r8d, %r8d
	leal	(%r8,%r8,4), %r8d
	movl	%edx, %r9d
	subl	%r8d, %r9d
	addl	%eax, %r9d
	subl	%edx, %r8d
	addl	$9, %r8d
	movl	%r9d, (%rsi,%rax,4)
	xorl	%r9d, %r9d
	cmpl	%eax, %r8d
	sete	%r9b
	addl	%edx, %r9d
	incq	%rax
	movl	%r9d, %edx
	cmpq	$55, %rax
	jne	.LBB5_1
# %bb.2:
	retq
.Lfunc_end5:
	.size	_Z9positionsPiS_, .Lfunc_end5-_Z9positionsPiS_
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$193976, %rsp                   # imm = 0x2F5B8
	.cfi_def_cfa_offset 194000
	.cfi_offset %rbx, -24
	.cfi_offset %rbp, -16
	leaq	44(%rsp), %rbx
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	cmpl	$0, (%rbx)
	jle	.LBB6_3
# %bb.1:                                # %.lr.ph
	leaq	496(%rsp), %rbx
	xorl	%ebp, %ebp
.LBB6_2:                                # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	hipGetDevicePropertiesR0600
	movq	784(%rsp), %rsi
	movl	$.L.str.10, %edi
	xorl	%eax, %eax
	callq	printf
	incl	%ebp
	cmpl	44(%rsp), %ebp
	jl	.LBB6_2
.LBB6_3:                                # %._crit_edge
	leaq	105968(%rsp), %rdi
	leaq	13968(%rsp), %rsi
	callq	_Z8get_dataPfS_
	leaq	17968(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_4
# %bb.6:                                # %_Z8testCUDA10hipError_tPKci.exit
	leaq	5968(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_7
# %bb.8:                                # %_Z8testCUDA10hipError_tPKci.exit15
	leaq	1968(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_9
# %bb.10:                               # %_Z8testCUDA10hipError_tPKci.exit17
	leaq	5968(%rsp), %rdi
	leaq	13968(%rsp), %rsi
	movl	$4, %edx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_11
# %bb.12:                               # %_Z8testCUDA10hipError_tPKci.exit19
	leaq	17968(%rsp), %rdi
	leaq	105968(%rsp), %rsi
	movl	$4, %edx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_13
# %bb.14:                               # %_Z8testCUDA10hipError_tPKci.exit21
	leaq	32(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_15
# %bb.16:                               # %_Z8testCUDA10hipError_tPKci.exit23
	leaq	24(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_54
# %bb.17:                               # %_Z8testCUDA10hipError_tPKci.exit25.preheader
	xorl	%eax, %eax
	movl	$3435973837, %ecx               # imm = 0xCCCCCCCD
	xorl	%edx, %edx
.LBB6_18:                               # %_Z8testCUDA10hipError_tPKci.exit25
                                        # =>This Inner Loop Header: Depth=1
	leal	(%rdx,%rax), %esi
	imulq	%rcx, %rsi
	shrq	$35, %rsi
	movl	%esi, 272(%rsp,%rax,4)
	addl	%esi, %esi
	leal	(%rsi,%rsi,4), %esi
	movl	%edx, %edi
	subl	%esi, %edi
	addl	%eax, %edi
	movl	%edi, 48(%rsp,%rax,4)
	xorl	%esi, %esi
	cmpl	$9, %edi
	sete	%sil
	addl	%edx, %esi
	incq	%rax
	movl	%esi, %edx
	cmpq	$55, %rax
	jne	.LBB6_18
# %bb.19:                               # %_Z9positionsPiS_.exit
	movq	32(%rsp), %rdi
	leaq	48(%rsp), %rsi
	movl	$4, %edx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_20
# %bb.21:                               # %_Z8testCUDA10hipError_tPKci.exit27
	movq	24(%rsp), %rdi
	leaq	272(%rsp), %rsi
	movl	$4, %edx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_22
# %bb.23:                               # %_Z8testCUDA10hipError_tPKci.exit29
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB6_24
# %bb.25:                               # %_Z8testCUDA10hipError_tPKci.exit31
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB6_26
# %bb.27:                               # %_Z8testCUDA10hipError_tPKci.exit33
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB6_28
# %bb.29:                               # %_Z8testCUDA10hipError_tPKci.exit35
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movl	$1, %esi
	movq	%rdi, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_31
# %bb.30:
	movq	32(%rsp), %rcx
	movq	24(%rsp), %r8
	leaq	17968(%rsp), %rdi
	leaq	5968(%rsp), %rsi
	leaq	1968(%rsp), %rdx
	callq	_Z36__device_stub__Compute_all_rotationsPfS_S_PKiS1_
.LBB6_31:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB6_32
# %bb.33:                               # %_Z8testCUDA10hipError_tPKci.exit37
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	testl	%eax, %eax
	jne	.LBB6_34
# %bb.35:                               # %_Z8testCUDA10hipError_tPKci.exit39
	movq	16(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	40(%rsp), %rdi
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB6_36
# %bb.37:                               # %_Z8testCUDA10hipError_tPKci.exit41
	cvtss2sd	40(%rsp), %xmm0
	movl	$.L.str.12, %edi
	movb	$1, %al
	callq	printf
	leaq	9968(%rsp), %rdi
	leaq	1968(%rsp), %rsi
	movl	$4, %edx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_38
# %bb.39:                               # %_Z8testCUDA10hipError_tPKci.exit43
	leaq	9968(%rsp), %rdi
	callq	_Z12write_resultPf
	leaq	5968(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB6_40
# %bb.41:                               # %_Z8testCUDA10hipError_tPKci.exit45
	leaq	17968(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB6_42
# %bb.43:                               # %_Z8testCUDA10hipError_tPKci.exit47
	leaq	1968(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB6_44
# %bb.45:                               # %_Z8testCUDA10hipError_tPKci.exit49
	movq	32(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB6_46
# %bb.47:                               # %_Z8testCUDA10hipError_tPKci.exit51
	movq	24(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB6_48
# %bb.49:                               # %_Z8testCUDA10hipError_tPKci.exit53
	movq	16(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB6_50
# %bb.51:                               # %_Z8testCUDA10hipError_tPKci.exit55
	movq	8(%rsp), %rdi
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB6_52
# %bb.53:                               # %_Z8testCUDA10hipError_tPKci.exit57
	xorl	%eax, %eax
	addq	$193976, %rsp                   # imm = 0x2F5B8
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB6_4:
	.cfi_def_cfa_offset 194000
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$201, %edx
	jmp	.LBB6_5
.LBB6_7:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$202, %edx
	jmp	.LBB6_5
.LBB6_9:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$203, %edx
	jmp	.LBB6_5
.LBB6_11:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$205, %edx
	jmp	.LBB6_5
.LBB6_13:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$206, %edx
	jmp	.LBB6_5
.LBB6_15:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$217, %edx
	jmp	.LBB6_5
.LBB6_54:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$218, %edx
	jmp	.LBB6_5
.LBB6_20:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$222, %edx
	jmp	.LBB6_5
.LBB6_22:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$223, %edx
	jmp	.LBB6_5
.LBB6_24:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$229, %edx
	jmp	.LBB6_5
.LBB6_26:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$230, %edx
	jmp	.LBB6_5
.LBB6_28:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$231, %edx
	jmp	.LBB6_5
.LBB6_32:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$239, %edx
	jmp	.LBB6_5
.LBB6_34:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$240, %edx
	jmp	.LBB6_5
.LBB6_36:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$241, %edx
	jmp	.LBB6_5
.LBB6_38:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$246, %edx
	jmp	.LBB6_5
.LBB6_40:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$251, %edx
	jmp	.LBB6_5
.LBB6_42:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$252, %edx
	jmp	.LBB6_5
.LBB6_44:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$253, %edx
	jmp	.LBB6_5
.LBB6_46:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$254, %edx
	jmp	.LBB6_5
.LBB6_48:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$255, %edx
	jmp	.LBB6_5
.LBB6_50:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$256, %edx                      # imm = 0x100
	jmp	.LBB6_5
.LBB6_52:
	movl	$.L.str, %edi
	movl	$.L.str.11, %esi
	movl	$257, %edx                      # imm = 0x101
.LBB6_5:
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end6:
	.size	main, .Lfunc_end6-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z21Compute_all_rotationsPfS_S_PKiS1_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"There is an error in file %s at line %d\n"
	.size	.L.str, 41

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

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

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"files/%i/J_%i.txt"
	.size	.L.str.3, 18

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"files/%i/A.txt"
	.size	.L.str.4, 15

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

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"files/%i/out.txt"
	.size	.L.str.6, 17

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"\n"
	.size	.L.str.8, 2

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"%f %s"
	.size	.L.str.9, 6

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Taille totale de la m\303\251moire globale %ld\n"
	.size	.L.str.10, 42

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/JbRemy/GPU_programming/master/version1.hip"
	.size	.L.str.11, 105

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Exectudtion time: %f ms\n"
	.size	.L.str.12, 25

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z21Compute_all_rotationsPfS_S_PKiS1_"
	.size	.L__unnamed_1, 38

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"TEST"
	.size	.Lstr, 5

	.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 _Z36__device_stub__Compute_all_rotationsPfS_S_PKiS1_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z21Compute_all_rotationsPfS_S_PKiS1_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z21Compute_all_rotationsPfS_S_PKiS1_ ; -- Begin function _Z21Compute_all_rotationsPfS_S_PKiS1_
	.globl	_Z21Compute_all_rotationsPfS_S_PKiS1_
	.p2align	8
	.type	_Z21Compute_all_rotationsPfS_S_PKiS1_,@function
_Z21Compute_all_rotationsPfS_S_PKiS1_:  ; @_Z21Compute_all_rotationsPfS_S_PKiS1_
; %bb.0:
	s_clause 0x2
	s_load_b256 s[4:11], s[0:1], 0x0
	s_load_b32 s12, s[0:1], 0x34
	s_load_b64 s[2:3], s[0:1], 0x20
	v_and_b32_e32 v3, 3, v0
	v_and_b32_e32 v1, 1, v0
	v_lshlrev_b32_e32 v4, 2, v0
	v_lshrrev_b32_e32 v0, 2, v0
	s_mov_b32 s16, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_eq_u32_e64 s0, 0, v1
	v_cvt_f32_ubyte0_e32 v5, v0
                                        ; implicit-def: $vgpr0
	s_waitcnt lgkmcnt(0)
	v_dual_mov_b32 v1, s11 :: v_dual_mov_b32 v2, s10
	v_cmp_eq_u32_e64 s1, 0, v3
	v_cmp_ne_u32_e32 vcc_lo, 0, v3
	s_and_b32 s13, s12, 0xffff
	s_mul_i32 s12, s15, 0x64
	s_mulk_i32 s13, 0xdc
	v_cndmask_b32_e64 v6, s3, v1, s1
	v_cndmask_b32_e64 v7, s2, v2, s1
	s_mov_b64 s[14:15], 0
.LBB0_1:                                ; =>This Inner Loop Header: Depth=1
                                        ; implicit-def: $vgpr8
                                        ; implicit-def: $vgpr1_vgpr2
	s_and_saveexec_b32 s1, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s17, exec_lo, s1
	s_cbranch_execz .LBB0_11
; %bb.2:                                ; %NodeBlock
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_lshl_b32 s18, s16, 2
	s_mov_b32 s19, exec_lo
                                        ; implicit-def: $vgpr8
                                        ; implicit-def: $vgpr1_vgpr2
	v_cmpx_lt_i32_e32 1, v3
	s_xor_b32 s19, exec_lo, s19
	s_cbranch_execz .LBB0_8
; %bb.3:                                ; %LeafBlock
                                        ;   in Loop: Header=BB0_1 Depth=1
	v_cmp_ne_u32_e64 s1, 2, v3
                                        ; implicit-def: $sgpr20
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_saveexec_b32 s21, s1
	s_xor_b32 s1, exec_lo, s21
; %bb.4:                                ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 s20, s18, 3
; %bb.5:                                ; %Flow71
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_or_saveexec_b32 s1, s1
	v_dual_mov_b32 v8, s20 :: v_dual_mov_b32 v1, s2
	v_mov_b32_e32 v2, s3
	s_xor_b32 exec_lo, exec_lo, s1
; %bb.6:                                ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 s20, s18, 2
	s_delay_alu instid0(SALU_CYCLE_1)
	v_dual_mov_b32 v1, s10 :: v_dual_mov_b32 v8, s20
	v_mov_b32_e32 v2, s11
; %bb.7:                                ; %Flow72
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
.LBB0_8:                                ; %Flow73
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_and_not1_saveexec_b32 s1, s19
; %bb.9:                                ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 s18, s18, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	v_dual_mov_b32 v1, s2 :: v_dual_mov_b32 v8, s18
	v_mov_b32_e32 v2, s3
; %bb.10:                               ; %Flow74
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
.LBB0_11:                               ; %Flow75
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_and_not1_saveexec_b32 s1, s17
; %bb.12:                               ; %._crit_edge
                                        ;   in Loop: Header=BB0_1 Depth=1
	v_dual_mov_b32 v1, s10 :: v_dual_mov_b32 v2, s11
	v_mov_b32_e32 v8, s14
; %bb.13:                               ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v1, s1, v1, s14
	v_add_co_ci_u32_e64 v2, s1, s15, v2, s1
	global_load_b32 v9, v[1:2], off
	s_waitcnt vmcnt(0)
	v_mad_u64_u32 v[1:2], null, v9, 10, s[12:13]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_f32_u32_e32 v1, v1
	v_dual_add_f32 v2, v5, v1 :: v_dual_add_nc_u32 v1, s13, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cvt_i32_f32_e32 v8, v2
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v9, 31, v8
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[8:9], 2, v[8:9]
	v_add_co_u32 v1, s1, s4, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v2, s1, s5, v2, s1
	v_add_co_u32 v8, s1, s6, v8
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v9, s1, s7, v9, s1
	global_load_b32 v1, v[1:2], off
	global_load_b32 v2, v[8:9], off
	s_waitcnt vmcnt(0)
	v_mul_f32_e32 v1, v1, v2
	ds_store_b32 v4, v1
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s17, s0
	s_cbranch_execz .LBB0_21
; %bb.14:                               ; %NodeBlock67
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_mov_b32 s18, 0
	s_mov_b32 s19, exec_lo
	v_cmpx_lt_i32_e32 1, v3
	s_xor_b32 s19, exec_lo, s19
; %bb.15:                               ; %LeafBlock65
                                        ;   in Loop: Header=BB0_1 Depth=1
	v_cmp_eq_u32_e64 s1, 2, v3
	s_delay_alu instid0(VALU_DEP_1)
	s_and_b32 s18, s1, exec_lo
; %bb.16:                               ; %Flow
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_and_not1_saveexec_b32 s19, s19
; %bb.17:                               ; %LeafBlock63
                                        ;   in Loop: Header=BB0_1 Depth=1
	v_cmp_eq_u32_e64 s1, 0, v3
	s_and_not1_b32 s18, s18, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_b32 s1, s1, exec_lo
	s_or_b32 s18, s18, s1
; %bb.18:                               ; %Flow69
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s19
	s_and_saveexec_b32 s19, s18
	s_cbranch_execz .LBB0_20
; %bb.19:                               ; %.sink.split
                                        ;   in Loop: Header=BB0_1 Depth=1
	v_add_co_u32 v0, s1, v7, s14
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v1, s1, s15, v6, s1
	global_load_b32 v2, v[0:1], off
	s_waitcnt vmcnt(0)
	v_mad_u64_u32 v[0:1], null, v2, 10, s[12:13]
	v_cvt_f32_u32_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f32_e32 v0, v5, v0
	v_cvt_i32_f32_e32 v0, v0
.LBB0_20:                               ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s19
	ds_load_2addr_b32 v[8:9], v4 offset1:1
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[0:1]
	v_add_co_u32 v1, s1, s8, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v2, s1, s9, v2, s1
	s_waitcnt lgkmcnt(0)
	v_add_f32_e32 v8, v8, v9
	global_store_b32 v[1:2], v8, off
.LBB0_21:                               ; %Flow70
                                        ;   in Loop: Header=BB0_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s17
	s_add_i32 s16, s16, 1
	s_add_u32 s14, s14, 4
	s_addc_u32 s15, s15, 0
	s_cmpk_eq_i32 s14, 0xdc
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc0 .LBB0_1
; %bb.22:
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z21Compute_all_rotationsPfS_S_PKiS1_
		.amdhsa_group_segment_fixed_size 160
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 10
		.amdhsa_next_free_sgpr 22
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z21Compute_all_rotationsPfS_S_PKiS1_, .Lfunc_end0-_Z21Compute_all_rotationsPfS_S_PKiS1_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 708
; NumSgprs: 24
; NumVgprs: 10
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 160 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 24
; NumVGPRsForWavesPerEU: 10
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 160
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z21Compute_all_rotationsPfS_S_PKiS1_
    .private_segment_fixed_size: 0
    .sgpr_count:     24
    .sgpr_spill_count: 0
    .symbol:         _Z21Compute_all_rotationsPfS_S_PKiS1_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     10
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
