#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>
#include <stdlib.h>
#define D 1000

#define re -0.5
#define im 0.45
#define scale 1.5

__device__ int julia( float x, float y){
	float xj = scale * (float)(D/2 - x)/(D/2);
	float yj = scale * (float)(D/2 - y)/(D/2);

	for( int i=0; i<200; ++i){
		float a = xj;
		float b = yj;
		xj = a*a-b*b+re;
		yj = 2*a*b+im;
	}
	if( xj*xj + yj*yj < 4)
		return 1;
	else
		return 0;
}

__global__ void generuj( int * picture ){
	//sprawdz czy pkt nalezy do zbioru julii
	int i = blockIdx.x;
	int j = threadIdx.x;

	
	if( julia(i, j ) )
		picture[ i * D + j ] = 1;
	else
		picture[ i * D + j ] = 0;
	
}



int main()
{
	FILE *fp;
	if ((fp=fopen("obraz.pbm", "w"))==NULL) {
		printf ("Nie mogê otworzyæ pliku test.txt do zapisu!\n");
		exit(1);
    }

	fprintf( fp, "P1\n%d %d\n", D, D);

	//deklarujê tablicê na karcie graficznej
	int * dev_obraz;
	cudaMalloc( &dev_obraz, sizeof(int) * D *D  );
	
	printf("udalo sie zaalokowac na karcie graficznej\n\n\n");

	//generacja obrazu
	generuj <<< D, D >>> ( dev_obraz );
	printf("funkcja zakonczyla dzialanie\n\n\n");

	//skopiowanie obrazu z karty graficznej

	int ** obraz;

	obraz = (int **) malloc( sizeof(int*)*D );
	
	
	
	for( int i=0; i<D; ++i){
		obraz[i] = (int *) malloc( sizeof(int)*D );
		cudaMemcpy( obraz[i], dev_obraz+i*D, sizeof(int)*D, cudaMemcpyDeviceToHost);
	}
	

	printf("skopiowano z karty graficznej\n\n\n");

	//zapisanie obrazu w formie pbm (P1)
	for(int i=0; i<D; ++i){
		for(int j=0; j<D; ++j)
			fprintf(fp, "%d", obraz[i][j]);
		fprintf(fp, "\n");
	}

	fclose(fp);

	return 0;
}

	.file	"tmpxft_00374838_00000000-6_kernel.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z5juliaff
	.type	_Z5juliaff, @function
_Z5juliaff:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z5juliaff, .-_Z5juliaff
	.globl	_Z26__device_stub__Z7generujPiPi
	.type	_Z26__device_stub__Z7generujPiPi, @function
_Z26__device_stub__Z7generujPiPi:
.LFB2053:
	.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	.L4
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z7generujPi(%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
.L4:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L6
	call	__stack_chk_fail@PLT
.L6:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z26__device_stub__Z7generujPiPi, .-_Z26__device_stub__Z7generujPiPi
	.globl	_Z7generujPi
	.type	_Z7generujPi, @function
_Z7generujPi:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z26__device_stub__Z7generujPiPi
	.cfi_endproc
.LFE2054:
	.size	_Z7generujPi, .-_Z7generujPi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"w"
.LC1:
	.string	"obraz.pbm"
.LC2:
	.string	"Nie mog\303\252 otworzy\303\246 pliku test.txt do zapisu!\n"
.LC3:
	.string	"P1\n%d %d\n"
.LC4:
	.string	"udalo sie zaalokowac na karcie graficznej\n\n\n"
.LC5:
	.string	"funkcja zakonczyla dzialanie\n\n\n"
.LC6:
	.string	"skopiowano z karty graficznej\n\n\n"
.LC7:
	.string	"%d"
.LC8:
	.string	"\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC0(%rip), %rsi
	leaq	.LC1(%rip), %rdi
	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
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L11
	movl	$2, %edi
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L11:
	movl	$1000, %ecx
	movq	%rax, %rdi
	movl	$2, %esi
	movq	%rax, %rbx
	movl	$1000, %r8d
	leaq	.LC3(%rip), %rdx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	leaq	8(%rsp), %rdi
	movl	$4000000, %esi
	call	cudaMalloc@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$536871037, %edi
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	salq	$3, %rdi
	movl	$1, %ecx
	movl	$1, %esi
	movl	$1, 36(%rsp)
	movq	%rdi, %rdx
	movq	%rdi, 28(%rsp)
	movq	%rdi, 16(%rsp)
	movl	$1, 24(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L12
	movq	8(%rsp), %rdi
	call	_Z26__device_stub__Z7generujPiPi
.L12:
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebp, %ebp
	call	__printf_chk@PLT
	movl	$8000, %edi
	call	malloc@PLT
	movq	%rax, %r13
.L13:
	movl	$4000, %edi
	call	malloc@PLT
	movl	$2, %ecx
	movl	$4000, %edx
	movq	%rax, 0(%r13,%rbp,8)
	imulq	$4000, %rbp, %rsi
	movq	%rax, %rdi
	addq	8(%rsp), %rsi
	incq	%rbp
	call	cudaMemcpy@PLT
	cmpq	$1000, %rbp
	jne	.L13
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%r12d, %r12d
	call	__printf_chk@PLT
	leaq	.LC7(%rip), %r14
.L14:
	xorl	%ebp, %ebp
.L15:
	movq	0(%r13,%r12,8), %rax
	movq	%r14, %rdx
	movl	$2, %esi
	movq	%rbx, %rdi
	movl	(%rax,%rbp), %ecx
	xorl	%eax, %eax
	addq	$4, %rbp
	call	__fprintf_chk@PLT
	cmpq	$4000, %rbp
	jne	.L15
	leaq	.LC8(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%eax, %eax
	incq	%r12
	movl	$2, %esi
	call	__fprintf_chk@PLT
	cmpq	$1000, %r12
	jne	.L14
	movq	%rbx, %rdi
	call	fclose@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
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC9:
	.string	"_Z7generujPi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2056:
	.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	.LC9(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z7generujPi(%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
.LFE2056:
	.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>
#define D 1000

#define re -0.5
#define im 0.45
#define scale 1.5

__device__ int julia( float x, float y){
	float xj = scale * (float)(D/2 - x)/(D/2);
	float yj = scale * (float)(D/2 - y)/(D/2);

	for( int i=0; i<200; ++i){
		float a = xj;
		float b = yj;
		xj = a*a-b*b+re;
		yj = 2*a*b+im;
	}
	if( xj*xj + yj*yj < 4)
		return 1;
	else
		return 0;
}

__global__ void generuj( int * picture ){
	//sprawdz czy pkt nalezy do zbioru julii
	int i = blockIdx.x;
	int j = threadIdx.x;

	
	if( julia(i, j ) )
		picture[ i * D + j ] = 1;
	else
		picture[ i * D + j ] = 0;
	
}



int main()
{
	FILE *fp;
	if ((fp=fopen("obraz.pbm", "w"))==NULL) {
		printf ("Nie mogê otworzyæ pliku test.txt do zapisu!\n");
		exit(1);
    }

	fprintf( fp, "P1\n%d %d\n", D, D);

	//deklarujê tablicê na karcie graficznej
	int * dev_obraz;
	hipMalloc( &dev_obraz, sizeof(int) * D *D  );
	
	printf("udalo sie zaalokowac na karcie graficznej\n\n\n");

	//generacja obrazu
	generuj <<< D, D >>> ( dev_obraz );
	printf("funkcja zakonczyla dzialanie\n\n\n");

	//skopiowanie obrazu z karty graficznej

	int ** obraz;

	obraz = (int **) malloc( sizeof(int*)*D );
	
	
	
	for( int i=0; i<D; ++i){
		obraz[i] = (int *) malloc( sizeof(int)*D );
		hipMemcpy( obraz[i], dev_obraz+i*D, sizeof(int)*D, hipMemcpyDeviceToHost);
	}
	

	printf("skopiowano z karty graficznej\n\n\n");

	//zapisanie obrazu w formie pbm (P1)
	for(int i=0; i<D; ++i){
		for(int j=0; j<D; ++j)
			fprintf(fp, "%d", obraz[i][j]);
		fprintf(fp, "\n");
	}

	fclose(fp);

	return 0;
}

	.text
	.file	"kernel.hip"
	.globl	_Z22__device_stub__generujPi    # -- Begin function _Z22__device_stub__generujPi
	.type	_Z22__device_stub__generujPi,@function
_Z22__device_stub__generujPi:           # @_Z22__device_stub__generujPi
	.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	$_Z7generujPi, %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	_Z22__device_stub__generujPi, .Lfunc_end0-_Z22__device_stub__generujPi
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_10
# %bb.1:
	movq	%rax, %rbx
	movl	$.L.str.3, %esi
	movq	%rax, %rdi
	movl	$1000, %edx                     # imm = 0x3E8
	movl	$1000, %ecx                     # imm = 0x3E8
	xorl	%eax, %eax
	callq	fprintf
	leaq	8(%rsp), %rdi
	movl	$4000000, %esi                  # imm = 0x3D0900
	callq	hipMalloc
	movl	$.Lstr, %edi
	callq	puts@PLT
	movabsq	$4294968296, %rdi               # imm = 0x1000003E8
	movl	$1, %esi
	movq	%rdi, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_3
# %bb.2:
	movq	8(%rsp), %rdi
	callq	_Z22__device_stub__generujPi
.LBB1_3:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$8000, %edi                     # imm = 0x1F40
	callq	malloc
	movq	%rax, %r14
	xorl	%r15d, %r15d
	movq	%rax, %r12
.LBB1_4:                                # =>This Inner Loop Header: Depth=1
	movl	$4000, %edi                     # imm = 0xFA0
	callq	malloc
	movq	%rax, (%r12)
	movq	8(%rsp), %rsi
	addq	%r15, %rsi
	movl	$4000, %edx                     # imm = 0xFA0
	movq	%rax, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	addq	$4000, %r15                     # imm = 0xFA0
	addq	$8, %r12
	cmpq	$4000000, %r15                  # imm = 0x3D0900
	jne	.LBB1_4
# %bb.5:
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	xorl	%r15d, %r15d
.LBB1_6:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_7 Depth 2
	movq	(%r14,%r15,8), %r12
	xorl	%r13d, %r13d
.LBB1_7:                                #   Parent Loop BB1_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r12,%r13,4), %edx
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%r13
	cmpq	$1000, %r13                     # imm = 0x3E8
	jne	.LBB1_7
# %bb.8:                                #   in Loop: Header=BB1_6 Depth=1
	movl	$10, %edi
	movq	%rbx, %rsi
	callq	fputc@PLT
	incq	%r15
	cmpq	$1000, %r15                     # imm = 0x3E8
	jne	.LBB1_6
# %bb.9:
	movq	%rbx, %rdi
	callq	fclose
	xorl	%eax, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB1_10:
	.cfi_def_cfa_offset 64
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	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	$_Z7generujPi, %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	_Z7generujPi,@object            # @_Z7generujPi
	.section	.rodata,"a",@progbits
	.globl	_Z7generujPi
	.p2align	3, 0x0
_Z7generujPi:
	.quad	_Z22__device_stub__generujPi
	.size	_Z7generujPi, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"obraz.pbm"
	.size	.L.str, 10

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

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"P1\n%d %d\n"
	.size	.L.str.3, 10

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z7generujPi"
	.size	.L__unnamed_1, 13

	.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	"udalo sie zaalokowac na karcie graficznej\n\n"
	.size	.Lstr, 44

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"funkcja zakonczyla dzialanie\n\n"
	.size	.Lstr.1, 31

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"skopiowano z karty graficznej\n\n"
	.size	.Lstr.2, 32

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Nie mog\303\252 otworzy\303\246 pliku test.txt do zapisu!"
	.size	.Lstr.3, 46

	.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 _Z22__device_stub__generujPi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z7generujPi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z7generujPi            ; -- Begin function _Z7generujPi
	.globl	_Z7generujPi
	.p2align	8
	.type	_Z7generujPi,@function
_Z7generujPi:                           ; @_Z7generujPi
; %bb.0:
	v_cvt_f32_i32_e32 v1, s15
	v_cvt_f32_i32_e32 v2, v0
	s_movk_i32 s4, 0xc8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_f32_e32 v1, 0x43fa0000, v1
	v_sub_f32_e32 v3, 0x43fa0000, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cvt_f64_f32_e32 v[1:2], v1
	v_cvt_f64_f32_e32 v[3:4], v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f64 v[1:2], 0x3ff80000, v[1:2]
	v_mul_f64 v[3:4], 0x3ff80000, v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_scale_f64 v[5:6], null, 0x407f4000, 0x407f4000, v[1:2]
	v_div_scale_f64 v[7:8], null, 0x407f4000, 0x407f4000, v[3:4]
	v_div_scale_f64 v[17:18], vcc_lo, v[1:2], 0x407f4000, v[1:2]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_rcp_f64_e32 v[9:10], v[5:6]
	v_rcp_f64_e32 v[11:12], v[7:8]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[13:14], -v[5:6], v[9:10], 1.0
	v_fma_f64 v[15:16], -v[7:8], v[11:12], 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[9:10], v[9:10], v[13:14], v[9:10]
	v_fma_f64 v[11:12], v[11:12], v[15:16], v[11:12]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[13:14], -v[5:6], v[9:10], 1.0
	v_fma_f64 v[15:16], -v[7:8], v[11:12], 1.0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_fma_f64 v[9:10], v[9:10], v[13:14], v[9:10]
	v_div_scale_f64 v[13:14], s2, v[3:4], 0x407f4000, v[3:4]
	v_fma_f64 v[11:12], v[11:12], v[15:16], v[11:12]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f64 v[15:16], v[17:18], v[9:10]
	v_mul_f64 v[19:20], v[13:14], v[11:12]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f64 v[5:6], -v[5:6], v[15:16], v[17:18]
	v_fma_f64 v[7:8], -v[7:8], v[19:20], v[13:14]
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_div_fmas_f64 v[5:6], v[5:6], v[9:10], v[15:16]
	s_mov_b32 vcc_lo, s2
	s_mov_b32 s2, 0xcccccccd
	v_div_fmas_f64 v[7:8], v[7:8], v[11:12], v[19:20]
	s_mov_b32 s3, 0x3fdccccc
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_fixup_f64 v[1:2], v[5:6], 0x407f4000, v[1:2]
	v_div_fixup_f64 v[3:4], v[7:8], 0x407f4000, v[3:4]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cvt_f32_f64_e32 v1, v[1:2]
	v_cvt_f32_f64_e32 v2, v[3:4]
.LBB0_1:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_f32_e32 v3, v1, v1
	v_mul_f32_e32 v5, v2, v2
	s_add_i32 s4, s4, -1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	s_cmp_lg_u32 s4, 0
	v_mul_f32_e32 v3, v2, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_fma_f32 v1, v1, v1, -v5
	v_cvt_f64_f32_e32 v[3:4], v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_f32_e32 v1, -0.5, v1
	v_add_f64 v[3:4], v[3:4], s[2:3]
	s_delay_alu instid0(VALU_DEP_1)
	v_cvt_f32_f64_e32 v2, v[3:4]
	s_cbranch_scc1 .LBB0_1
; %bb.2:                                ; %_Z5juliaff.exit
	s_load_b64 s[0:1], s[0:1], 0x0
	v_mad_u64_u32 v[3:4], null, 0x3e8, s15, v[0:1]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v5, v2, v2
	v_fmac_f32_e32 v5, v1, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v4, 31, v3
	v_lshlrev_b64 v[2:3], 2, v[3:4]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s0, v2
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v3, vcc_lo
	v_cmp_gt_f32_e32 vcc_lo, 4.0, v5
	v_cndmask_b32_e64 v2, 0, 1, vcc_lo
	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 _Z7generujPi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 8
		.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 21
		.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	_Z7generujPi, .Lfunc_end0-_Z7generujPi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 508
; NumSgprs: 18
; NumVgprs: 21
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 21
; 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
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 8
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7generujPi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7generujPi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     21
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
