/******************************
 * Tisma Miroslav 2006/0395
 * Multiprocesorski sistemi
 * domaci zadatak 6 - 1. zadatak
 *******************************/

/**
 * 1. Sastaviti program koji kvadrira elemente dvodimenzionalne matrice.
 */

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <cuda.h>
#include <stdio.h>
#include <stdlib.h>

#define NUM_OF_GPU_THREADS 256

__global__ void matrixSquare(int *matrix) {
	int idx = blockIdx.x * blockDim.x + threadIdx.x;
	matrix[idx] = matrix[idx] * matrix[idx];
}

int main(int argc, char *argv[]) {
	int i, j, m, n;
	int *h_matrix, *d_matrix;
	FILE *out;

	printf("Matrice ce biti upisane u fajl dz6_1_izl1.in\n");
	printf("Unesite broj vrsta matrice:\n");
	scanf("%d", &m);
	printf("Unesite broj kolona matrice:\n");
	scanf("%d", &n);

	out = fopen("dz6_1_izl1.in", "w");
	if (out == NULL) {
		printf("Greska pri otvaranju fajla!");
		exit(EXIT_FAILURE);
	}

	fprintf(out, "ORIGINALNA MATRICA:\n");

	h_matrix = (int*) malloc(m*n * sizeof(int));
	for (i = 0; i < m*n; i++) {
		if (i % m == 0)
			fprintf(out, "\n");
		h_matrix[i] = -100 + rand() % 200;
		fprintf(out, "%4d ", h_matrix[i]);
	}

	int dimGrid(m*n / NUM_OF_GPU_THREADS + 1);
	int dimBlock(NUM_OF_GPU_THREADS);
	int size = (m*n * sizeof(int) / (dimGrid * dimBlock) + 1) * (dimGrid * dimBlock);

	cudaMalloc((void**)&d_matrix, size);
	cudaMemcpy(d_matrix, h_matrix, m*n * sizeof(int), cudaMemcpyHostToDevice);
	matrixSquare<<<dimGrid, dimBlock>>>(d_matrix);
	
	cudaThreadSynchronize();

	cudaMemcpy(h_matrix, d_matrix, m*n * sizeof(int), cudaMemcpyDeviceToHost);

	fprintf(out, "\n\nKVADRIRANA MATRICA\n\n");
	for (i = 0; i < m; i++) {
		for (j = 0; j < n; j++)
			fprintf(out, "%5d ", h_matrix[i * m + j]);
		fprintf(out, "\n");
	}

	fclose(out);
	cudaFree(d_matrix);

	return EXIT_SUCCESS;
}
	.file	"tmpxft_003564b9_00000000-6_dz6z1.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2030:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2030:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z32__device_stub__Z12matrixSquarePiPi
	.type	_Z32__device_stub__Z12matrixSquarePiPi, @function
_Z32__device_stub__Z12matrixSquarePiPi:
.LFB2052:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z12matrixSquarePi(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L2:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2052:
	.size	_Z32__device_stub__Z12matrixSquarePiPi, .-_Z32__device_stub__Z12matrixSquarePiPi
	.globl	_Z12matrixSquarePi
	.type	_Z12matrixSquarePi, @function
_Z12matrixSquarePi:
.LFB2053:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z12matrixSquarePiPi
	.cfi_endproc
.LFE2053:
	.size	_Z12matrixSquarePi, .-_Z12matrixSquarePi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Matrice ce biti upisane u fajl dz6_1_izl1.in\n"
.LC1:
	.string	"Unesite broj vrsta matrice:\n"
.LC2:
	.string	"%d"
.LC3:
	.string	"Unesite broj kolona matrice:\n"
.LC4:
	.string	"w"
.LC5:
	.string	"dz6_1_izl1.in"
.LC6:
	.string	"Greska pri otvaranju fajla!"
.LC7:
	.string	"ORIGINALNA MATRICA:\n"
.LC8:
	.string	"\n"
.LC9:
	.string	"%4d "
.LC10:
	.string	"\n\nKVADRIRANA MATRICA\n\n"
.LC11:
	.string	"%5d "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	leaq	.LC2(%rip), %rbx
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%rsp, %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	4(%rsp), %rsi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	leaq	.LC4(%rip), %rsi
	leaq	.LC5(%rip), %rdi
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L9
	movl	$2, %edi
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L9:
	movq	%rax, %rdi
	leaq	.LC7(%rip), %rdx
	movq	%rax, %rbx
	xorl	%eax, %eax
	movl	$2, %esi
	xorl	%r12d, %r12d
	leaq	.LC8(%rip), %r13
	call	__fprintf_chk@PLT
	movl	(%rsp), %edi
	imull	4(%rsp), %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %rbp
.L10:
	movl	(%rsp), %esi
	movl	4(%rsp), %ecx
	movl	%r12d, %eax
	imull	%esi, %ecx
	cmpl	%r12d, %ecx
	jle	.L20
	cltd
	idivl	%esi
	testl	%edx, %edx
	jne	.L11
	movq	%r13, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L11:
	call	rand@PLT
	movl	$200, %ecx
	movl	$2, %esi
	movq	%rbx, %rdi
	cltd
	idivl	%ecx
	xorl	%eax, %eax
	leal	-100(%rdx), %ecx
	leaq	.LC9(%rip), %rdx
	movl	%ecx, 0(%rbp,%r12,4)
	incq	%r12
	call	__fprintf_chk@PLT
	jmp	.L10
.L20:
	movl	%ecx, %eax
	movl	$256, %esi
	leaq	8(%rsp), %rdi
	cltd
	idivl	%esi
	xorl	%edx, %edx
	leal	1(%rax), %r12d
	movslq	%ecx, %rax
	movl	%r12d, %esi
	salq	$2, %rax
	sall	$8, %esi
	movslq	%esi, %rcx
	divq	%rcx
	incq	%rax
	imull	%eax, %esi
	movslq	%esi, %rsi
	call	cudaMalloc@PLT
	movl	(%rsp), %edx
	imull	4(%rsp), %edx
	movq	%rbp, %rsi
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	%r12d, 16(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	$16777217, %edx
	movl	$1, %ecx
	movq	%rax, 20(%rsp)
	movq	16(%rsp), %rdi
	salq	$8, %rdx
	movl	24(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	movq	8(%rsp), %rdi
	call	_Z32__device_stub__Z12matrixSquarePiPi
.L13:
	call	cudaThreadSynchronize@PLT
	movl	(%rsp), %edx
	imull	4(%rsp), %edx
	movq	%rbp, %rdi
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	xorl	%r13d, %r13d
	leaq	.LC11(%rip), %r12
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	$2, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	leaq	.LC10(%rip), %rdx
	call	__fprintf_chk@PLT
.L14:
	cmpl	%r13d, (%rsp)
	jle	.L21
	xorl	%r14d, %r14d
.L16:
	cmpl	%r14d, 4(%rsp)
	jle	.L22
	movl	(%rsp), %eax
	movq	%r12, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	imull	%r13d, %eax
	addl	%r14d, %eax
	incl	%r14d
	cltq
	movl	0(%rbp,%rax,4), %ecx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	jmp	.L16
.L22:
	leaq	.LC8(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%eax, %eax
	incl	%r13d
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L14
.L21:
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	xorl	%eax, %eax
	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
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC12:
	.string	"_Z12matrixSquarePi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2055:
	.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	.LC12(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z12matrixSquarePi(%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
.LFE2055:
	.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:

/******************************
 * Tisma Miroslav 2006/0395
 * Multiprocesorski sistemi
 * domaci zadatak 6 - 1. zadatak
 *******************************/

/**
 * 1. Sastaviti program koji kvadrira elemente dvodimenzionalne matrice.
 */

#include "hip/hip_runtime.h"


#include <stdio.h>
#include <stdlib.h>

#define NUM_OF_GPU_THREADS 256

__global__ void matrixSquare(int *matrix) {
	int idx = blockIdx.x * blockDim.x + threadIdx.x;
	matrix[idx] = matrix[idx] * matrix[idx];
}

int main(int argc, char *argv[]) {
	int i, j, m, n;
	int *h_matrix, *d_matrix;
	FILE *out;

	printf("Matrice ce biti upisane u fajl dz6_1_izl1.in\n");
	printf("Unesite broj vrsta matrice:\n");
	scanf("%d", &m);
	printf("Unesite broj kolona matrice:\n");
	scanf("%d", &n);

	out = fopen("dz6_1_izl1.in", "w");
	if (out == NULL) {
		printf("Greska pri otvaranju fajla!");
		exit(EXIT_FAILURE);
	}

	fprintf(out, "ORIGINALNA MATRICA:\n");

	h_matrix = (int*) malloc(m*n * sizeof(int));
	for (i = 0; i < m*n; i++) {
		if (i % m == 0)
			fprintf(out, "\n");
		h_matrix[i] = -100 + rand() % 200;
		fprintf(out, "%4d ", h_matrix[i]);
	}

	int dimGrid(m*n / NUM_OF_GPU_THREADS + 1);
	int dimBlock(NUM_OF_GPU_THREADS);
	int size = (m*n * sizeof(int) / (dimGrid * dimBlock) + 1) * (dimGrid * dimBlock);

	hipMalloc((void**)&d_matrix, size);
	hipMemcpy(d_matrix, h_matrix, m*n * sizeof(int), hipMemcpyHostToDevice);
	matrixSquare<<<dimGrid, dimBlock>>>(d_matrix);
	
	hipDeviceSynchronize();

	hipMemcpy(h_matrix, d_matrix, m*n * sizeof(int), hipMemcpyDeviceToHost);

	fprintf(out, "\n\nKVADRIRANA MATRICA\n\n");
	for (i = 0; i < m; i++) {
		for (j = 0; j < n; j++)
			fprintf(out, "%5d ", h_matrix[i * m + j]);
		fprintf(out, "\n");
	}

	fclose(out);
	hipFree(d_matrix);

	return EXIT_SUCCESS;
}
	.text
	.file	"dz6z1.hip"
	.globl	_Z27__device_stub__matrixSquarePi # -- Begin function _Z27__device_stub__matrixSquarePi
	.type	_Z27__device_stub__matrixSquarePi,@function
_Z27__device_stub__matrixSquarePi:      # @_Z27__device_stub__matrixSquarePi
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z12matrixSquarePi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z27__device_stub__matrixSquarePi, .Lfunc_end0-_Z27__device_stub__matrixSquarePi
	.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	%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	$24, %rsp
	.cfi_def_cfa_offset 80
	.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	$.Lstr, %edi
	callq	puts@PLT
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	leaq	8(%rsp), %rsi
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	leaq	12(%rsp), %rsi
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	$.L.str.4, %edi
	movl	$.L.str.5, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_16
# %bb.1:
	movq	%rax, %rbx
	movl	$.L.str.7, %edi
	movl	$20, %esi
	movl	$1, %edx
	movq	%rax, %rcx
	callq	fwrite@PLT
	movslq	8(%rsp), %r13
	movslq	12(%rsp), %rbp
	imulq	%r13, %rbp
	movq	%rbp, %r12
	shlq	$2, %r12
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %r14
	testl	%ebp, %ebp
	jle	.LBB1_7
# %bb.2:                                # %.lr.ph.preheader
	xorl	%r15d, %r15d
.LBB1_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%r15d, %eax
	cltd
	idivl	%r13d
	testl	%edx, %edx
	jne	.LBB1_5
# %bb.4:                                #   in Loop: Header=BB1_3 Depth=1
	movl	$10, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
.LBB1_5:                                #   in Loop: Header=BB1_3 Depth=1
	callq	rand
	cltq
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$38, %rcx
	addl	%edx, %ecx
	imull	$200, %ecx, %ecx
	negl	%ecx
	leal	(%rax,%rcx), %edx
	addl	$-100, %edx
	movl	%edx, (%r14,%r15,4)
	movl	$.L.str.9, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r15
	movslq	8(%rsp), %r13
	movslq	12(%rsp), %rbp
	imulq	%r13, %rbp
	cmpq	%rbp, %r15
	jl	.LBB1_3
# %bb.6:                                # %._crit_edge.loopexit
	movq	%rbp, %r12
	shlq	$2, %r12
.LBB1_7:                                # %._crit_edge
	leal	255(%rbp), %r15d
	testl	%ebp, %ebp
	cmovnsl	%ebp, %r15d
	sarl	$8, %r15d
	incl	%r15d
	movl	%r15d, %eax
	shll	$8, %eax
	movslq	%eax, %rcx
	movq	%r12, %rax
	xorl	%edx, %edx
	divq	%rcx
	incl	%eax
	imull	%eax, %ecx
	movslq	%ecx, %rsi
	leaq	16(%rsp), %r12
	movq	%r12, %rdi
	callq	hipMalloc
	movq	(%r12), %rdi
	movslq	8(%rsp), %rax
	movslq	12(%rsp), %rdx
	imulq	%rax, %rdx
	shlq	$2, %rdx
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	btsq	$32, %r15
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$256, %rdx                      # imm = 0x100
	movq	%r15, %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_9
# %bb.8:
	movq	16(%rsp), %rdi
	callq	_Z27__device_stub__matrixSquarePi
.LBB1_9:
	callq	hipDeviceSynchronize
	movq	16(%rsp), %rsi
	movslq	8(%rsp), %rax
	movslq	12(%rsp), %rdx
	imulq	%rax, %rdx
	shlq	$2, %rdx
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movl	$.L.str.10, %edi
	movl	$22, %esi
	movl	$1, %edx
	movq	%rbx, %rcx
	callq	fwrite@PLT
	cmpl	$0, 8(%rsp)
	jle	.LBB1_15
# %bb.10:                               # %.preheader.preheader
	xorl	%ebp, %ebp
.LBB1_11:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_13 Depth 2
	cmpl	$0, 12(%rsp)
	jle	.LBB1_14
# %bb.12:                               # %.lr.ph43.preheader
                                        #   in Loop: Header=BB1_11 Depth=1
	movslq	%ebp, %r15
	xorl	%r12d, %r12d
.LBB1_13:                               # %.lr.ph43
                                        #   Parent Loop BB1_11 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movslq	8(%rsp), %rax
	imulq	%r15, %rax
	addq	%r12, %rax
	movl	(%r14,%rax,4), %edx
	movl	$.L.str.11, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r12
	cmpl	12(%rsp), %r12d
	jl	.LBB1_13
.LBB1_14:                               # %._crit_edge44
                                        #   in Loop: Header=BB1_11 Depth=1
	movl	$10, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	incl	%ebp
	cmpl	8(%rsp), %ebp
	jl	.LBB1_11
.LBB1_15:                               # %._crit_edge46
	movq	%rbx, %rdi
	callq	fclose
	movq	16(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$24, %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
.LBB1_16:
	.cfi_def_cfa_offset 80
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	main, .Lfunc_end1-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	.LBB2_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB2_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z12matrixSquarePi, %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_end2:
	.size	__hip_module_ctor, .Lfunc_end2-__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	.LBB3_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
.LBB3_2:
	retq
.Lfunc_end3:
	.size	__hip_module_dtor, .Lfunc_end3-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z12matrixSquarePi,@object      # @_Z12matrixSquarePi
	.section	.rodata,"a",@progbits
	.globl	_Z12matrixSquarePi
	.p2align	3, 0x0
_Z12matrixSquarePi:
	.quad	_Z27__device_stub__matrixSquarePi
	.size	_Z12matrixSquarePi, 8

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"dz6_1_izl1.in"
	.size	.L.str.4, 14

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

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Greska pri otvaranju fajla!"
	.size	.L.str.6, 28

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"ORIGINALNA MATRICA:\n"
	.size	.L.str.7, 21

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"%4d "
	.size	.L.str.9, 5

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"\n\nKVADRIRANA MATRICA\n\n"
	.size	.L.str.10, 23

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"%5d "
	.size	.L.str.11, 5

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z12matrixSquarePi"
	.size	.L__unnamed_1, 19

	.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	"Matrice ce biti upisane u fajl dz6_1_izl1.in"
	.size	.Lstr, 45

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Unesite broj vrsta matrice:"
	.size	.Lstr.1, 28

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Unesite broj kolona matrice:"
	.size	.Lstr.2, 29

	.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 _Z27__device_stub__matrixSquarePi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z12matrixSquarePi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z12matrixSquarePi      ; -- Begin function _Z12matrixSquarePi
	.globl	_Z12matrixSquarePi
	.p2align	8
	.type	_Z12matrixSquarePi,@function
_Z12matrixSquarePi:                     ; @_Z12matrixSquarePi
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x14
	s_load_b64 s[0:1], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_add_co_u32 v0, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_load_b32 v2, v[0:1], off
	s_waitcnt vmcnt(0)
	v_mul_lo_u32 v2, v2, v2
	global_store_b32 v[0:1], v2, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z12matrixSquarePi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 264
		.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 3
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z12matrixSquarePi, .Lfunc_end0-_Z12matrixSquarePi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 116
; NumSgprs: 18
; NumVgprs: 3
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 3
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         12
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         20
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         22
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         24
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         26
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         28
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         30
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         48
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         72
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 264
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z12matrixSquarePi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z12matrixSquarePi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     3
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
