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

#define MAX_DATA_SIZE (1 << 27)

typedef unsigned char byte;

const byte sbox[256] = {
	0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
	0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
	0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
	0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
	0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
	0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
	0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
	0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
	0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
	0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
	0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5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cb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
	0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
	0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
	0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
	0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
	0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
	0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
	0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
	0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
	0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
	0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
};

__device__ __constant__
byte gmul2[256] = {
	0x00, 0x02, 0x04, 0x06, 0x08, 0x0a, 0x0c, 0x0e, 0x10, 0x12, 0x14, 0x16, 0x18,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c, 0x9f, 0x9a, 0x99, 0x88, 0x8b, 0x8e, 0x8d, 0x84, 0x87, 0x82, 0x81,
	0x9b, 0x98, 0x9d, 0x9e, 0x97, 0x94, 0x91, 0x92, 0x83, 0x80, 0x85, 0x86, 0x8f, 0x8c, 0x89, 0x8a,
	0xab, 0xa8, 0xad, 0xae, 0xa7, 0xa4, 0xa1, 0xa2, 0xb3, 0xb0, 0xb5, 0xb6, 0xbf, 0xbc, 0xb9, 0xba,
	0xfb, 0xf8, 0xfd, 0xfe, 0xf7, 0xf4, 0xf1, 0xf2, 0xe3, 0xe0, 0xe5, 0xe6, 0xef, 0xec, 0xe9, 0xea,
	0xcb, 0xc8, 0xcd, 0xce, 0xc7, 0xc4, 0xc1, 0xc2, 0xd3, 0xd0, 0xd5, 0xd6, 0xdf, 0xdc, 0xd9, 0xda,
	0x5b, 0x58, 0x5d, 0x5e, 0x57, 0x54, 0x51, 0x52, 0x43, 0x40, 0x45, 0x46, 0x4f, 0x4c, 0x49, 0x4a,
	0x6b, 0x68, 0x6d, 0x6e, 0x67, 0x64, 0x61, 0x62, 0x73, 0x70, 0x75, 0x76, 0x7f, 0x7c, 0x79, 0x7a,
	0x3b, 0x38, 0x3d, 0x3e, 0x37, 0x34, 0x31, 0x32, 0x23, 0x20, 0x25, 0x26, 0x2f, 0x2c, 0x29, 0x2a,
	0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, 0x13, 0x10, 0x15, 0x16, 0x1f, 0x1c, 0x19, 0x1a
};

const byte rcon[11] = {
	0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
};

void keyExpansion(byte *roundKeys, byte *key) {
	byte t[4], tb;
	int k;
	
	for (int i = 0; i < 16; ++i) {
		roundKeys[i] = key[i];
	}
	
	for (int i = 4; i < 11 * 4; ++i) {
		k = (i - 1) * 4;
		t[0] = roundKeys[k + 0];
		t[1] = roundKeys[k + 1];
		t[2] = roundKeys[k + 2];
		t[3] = roundKeys[k + 3];
		
		if (i % 4 == 0) {
			tb = t[0];
			t[0] = t[1];
			t[1] = t[2];
			t[2] = t[3];
			t[3] = tb;
			
			t[0] = sbox[t[0]];
			t[1] = sbox[t[1]];
			t[2] = sbox[t[2]];
			t[3] = sbox[t[3]];
			
			t[0] = t[0] ^ rcon[i / 4];
		}
		
		k = (i - 4) * 4;
		roundKeys[i * 4 + 0] = roundKeys[k + 0] ^ t[0];
		roundKeys[i * 4 + 1] = roundKeys[k + 1] ^ t[1];
		roundKeys[i * 4 + 2] = roundKeys[k + 2] ^ t[2];
		roundKeys[i * 4 + 3] = roundKeys[k + 3] ^ t[3];
	}
}

__device__
void addRoundKey(byte state[4][4], byte *roundKeys, int round) {
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 4; ++j) {
			state[i][j] ^= roundKeys[round * 16 + i * 4 + j];
		}
	}
}

__device__
void subBytes(byte state[4][4]) {
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 4; ++j) {
			state[i][j] = d_sbox[state[i][j]];
		}
	}
}

__device__
void shiftRows(byte state[4][4]) {
	byte t;
	
	t = 		  state[0][1];
	state[0][1] = state[1][1];
	state[1][1] = state[2][1];
	state[2][1] = state[3][1];
	state[3][1] = t;
	
	t = 		  state[0][2];
	state[0][2] = state[2][2];
	state[2][2] = t;
	t = 		  state[1][2];
	state[1][2] = state[3][2];
	state[3][2] = t;
	
	t = 		  state[0][3];
	state[0][3] = state[3][3];
	state[3][3] = state[2][3];
	state[2][3] = state[1][3];
	state[1][3] = t;
}

__device__
void mixColumns(byte state[4][4]) {
	byte t[4];
	
	for (int i = 0; i < 4; ++i) {
		t[0] = gmul2[state[i][0]] 	^ gmul3[state[i][1]] 	^ state[i][2]			^ state[i][3];
		t[1] = state[i][0] 			^ gmul2[state[i][1]] 	^ gmul3[state[i][2]] 	^ state[i][3];
		t[2] = state[i][0] 			^ state[i][1] 			^ gmul2[state[i][2]] 	^ gmul3[state[i][3]];
		t[3] = gmul3[state[i][0]] 	^ state[i][1] 			^ state[i][2] 			^ gmul2[state[i][3]];
		
		for (int j = 0; j < 4; ++j) {
			state[i][j] = t[j];
		}
	}
}

__global__
void encrypt(byte *data, byte *roundKeys, int n) {
	int index = blockIdx.x * blockDim.x + threadIdx.x;
	
	if (index < n) {
		byte state[4][4];
		
		for (int i = 0; i < 16; ++i) {
			state[i / 4][i % 4] = data[index * 16 + i];
		}

		addRoundKey(state, roundKeys, 0);
		
		for (int round = 1; round < 10; ++round) {
			subBytes(state);
			shiftRows(state);
			mixColumns(state);
			addRoundKey(state, roundKeys, round);
		}
		
		subBytes(state);
		shiftRows(state);
		addRoundKey(state, roundKeys, 10);
		
		for (int i = 0; i < 16; ++i) {
			data[index * 16 + i] = state[i / 4][i % 4];
		}
	}
}

void padData(byte *data, int *len) {
	int dataLength = *len;
	
	if (dataLength % 16 > 0) {
		int padSize = 16 - (dataLength % 16);
		data = (byte *) realloc(data, sizeof(byte) * (dataLength + padSize));
		for (int i = 0; i < padSize; ++i) {
			data[dataLength + i] = 0;
		}
		*len = dataLength + padSize;
		printf("Added padding to data\nData size: %d\n", *len);
	}
}

void aes128(byte *data, byte *key, int dataLength) {
	byte roundKeys[11 * 16];
	byte *dData, *dRoundKeys;
	float timeElapsed = 0.0;
	
	keyExpansion(roundKeys, key);
	
	cudaMalloc((void **) &dData, sizeof(byte) * dataLength);
	cudaMalloc((void **) &dRoundKeys, sizeof(byte) * 11 * 16);
	
	cudaMemcpy(dData, data, sizeof(byte) * dataLength, cudaMemcpyHostToDevice);
	cudaMemcpy(dRoundKeys, roundKeys, sizeof(byte) * 11 * 16, cudaMemcpyHostToDevice);
	
	cudaEvent_t start, stop;
	cudaEventCreate(&start);
	cudaEventCreate(&stop);
	
	dim3 nBlocks(1 << 15);
	dim3 nThreads(1 << 10);
	
	cudaEventRecord(start, 0);
	
	encrypt<<<nBlocks, nThreads>>>(dData, dRoundKeys, dataLength / 16);
	
	cudaEventRecord(stop, 0);
	cudaEventSynchronize(stop);
	cudaEventElapsedTime(&timeElapsed, start, stop);
	
	cudaMemcpy(data, dData, dataLength, cudaMemcpyDeviceToHost);
	
	printf("%lf\n", timeElapsed);
	
	cudaFree(dData);
	cudaFree(dRoundKeys);
}

int main() {
	byte key[16];
	byte *data = (byte *) malloc(sizeof(byte) * MAX_DATA_SIZE);
	int dataLength;
	
	FILE *fKey = fopen("key.txt", "rb");
	fread(key, 1, 16, fKey);
	fclose(fKey);
	
	FILE *fData = fopen("payload.txt", "rb");
	dataLength = fread(data, 1, MAX_DATA_SIZE, fData);
	fclose(fData);
	
	printf("Data size: %d\n", dataLength);
	
	padData(data, &dataLength);
	
	printf("Number of blocks: %d\n", dataLength / 16);
	
	aes128(data, key, dataLength);
	
	FILE *f_out = fopen("outcuda.txt", "wb");
	fwrite(data, 1, dataLength, f_out);
	fclose(f_out);
	
	free(data);
}
	.file	"tmpxft_002a79fd_00000000-6_aes.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2037:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2037:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z12keyExpansionPhS_
	.type	_Z12keyExpansionPhS_, @function
_Z12keyExpansionPhS_:
.LFB2027:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
.L3:
	movb	(%rsi,%rax), %dl
	movb	%dl, (%rdi,%rax)
	incq	%rax
	cmpq	$16, %rax
	jne	.L3
	movl	$4, %r8d
	leaq	_ZL4sbox(%rip), %r9
	leaq	_ZL4rcon(%rip), %r10
.L5:
	movzbl	12(%rdi), %esi
	movzbl	13(%rdi), %ecx
	movzbl	14(%rdi), %edx
	movzbl	15(%rdi), %eax
	testl	$3, %r8d
	jne	.L4
	movb	(%r9,%rcx), %r11b
	movb	(%r9,%rdx), %cl
	movb	(%r9,%rax), %dl
	movb	(%r9,%rsi), %al
	movl	%r8d, %esi
	sarl	$2, %esi
	movslq	%esi, %rsi
	xorb	(%r10,%rsi), %r11b
	movl	%r11d, %esi
.L4:
	xorb	(%rdi), %sil
	xorb	1(%rdi), %cl
	incl	%r8d
	addq	$4, %rdi
	xorb	-2(%rdi), %dl
	xorb	-1(%rdi), %al
	movb	%sil, 12(%rdi)
	movb	%cl, 13(%rdi)
	movb	%dl, 14(%rdi)
	movb	%al, 15(%rdi)
	cmpl	$44, %r8d
	jne	.L5
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z12keyExpansionPhS_, .-_Z12keyExpansionPhS_
	.globl	_Z11addRoundKeyPA4_hPhi
	.type	_Z11addRoundKeyPA4_hPhi, @function
_Z11addRoundKeyPA4_hPhi:
.LFB2028:
	.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
.LFE2028:
	.size	_Z11addRoundKeyPA4_hPhi, .-_Z11addRoundKeyPA4_hPhi
	.globl	_Z8subBytesPA4_h
	.type	_Z8subBytesPA4_h, @function
_Z8subBytesPA4_h:
.LFB2029:
	.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
.LFE2029:
	.size	_Z8subBytesPA4_h, .-_Z8subBytesPA4_h
	.globl	_Z9shiftRowsPA4_h
	.type	_Z9shiftRowsPA4_h, @function
_Z9shiftRowsPA4_h:
.LFB2179:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	_Z8subBytesPA4_h
	.cfi_endproc
.LFE2179:
	.size	_Z9shiftRowsPA4_h, .-_Z9shiftRowsPA4_h
	.globl	_Z10mixColumnsPA4_h
	.type	_Z10mixColumnsPA4_h, @function
_Z10mixColumnsPA4_h:
.LFB2181:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	_Z8subBytesPA4_h
	.cfi_endproc
.LFE2181:
	.size	_Z10mixColumnsPA4_h, .-_Z10mixColumnsPA4_h
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Added padding to data\nData size: %d\n"
	.text
	.globl	_Z7padDataPhPi
	.type	_Z7padDataPhPi, @function
_Z7padDataPhPi:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$16, %ecx
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	pushq	%r8
	.cfi_def_cfa_offset 48
	movslq	(%rsi), %rbp
	movl	%ebp, %eax
	cltd
	idivl	%ecx
	testl	%edx, %edx
	jle	.L17
	movl	%ecx, %ebx
	movq	%rsi, %r12
	subl	%edx, %ebx
	leal	0(%rbp,%rbx), %r13d
	movslq	%r13d, %rsi
	call	realloc@PLT
	movl	%ebx, %ecx
	movl	%r13d, %edx
	leaq	.LC0(%rip), %rsi
	addq	%rax, %rbp
	xorl	%eax, %eax
	movq	%rbp, %rdi
	rep stosb
	movl	%r13d, (%r12)
	movl	$2, %edi
	popq	%rcx
	.cfi_remember_state
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
.L17:
	.cfi_restore_state
	popq	%rax
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z7padDataPhPi, .-_Z7padDataPhPi
	.globl	_Z29__device_stub__Z7encryptPhS_iPhS_i
	.type	_Z29__device_stub__Z7encryptPhS_iPhS_i, @function
_Z29__device_stub__Z7encryptPhS_iPhS_i:
.LFB2059:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L20
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z7encryptPhS_i(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L20:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L22
	call	__stack_chk_fail@PLT
.L22:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2059:
	.size	_Z29__device_stub__Z7encryptPhS_iPhS_i, .-_Z29__device_stub__Z7encryptPhS_iPhS_i
	.globl	_Z7encryptPhS_i
	.type	_Z7encryptPhS_i, @function
_Z7encryptPhS_i:
.LFB2060:
	.cfi_startproc
	endbr64
	jmp	_Z29__device_stub__Z7encryptPhS_iPhS_i
	.cfi_endproc
.LFE2060:
	.size	_Z7encryptPhS_i, .-_Z7encryptPhS_i
	.section	.rodata.str1.1
.LC2:
	.string	"%lf\n"
	.text
	.globl	_Z6aes128PhS_i
	.type	_Z6aes128PhS_i, @function
_Z6aes128PhS_i:
.LFB2033:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movslq	%edx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$264, %rsp
	.cfi_def_cfa_offset 304
	movq	%fs:40, %rax
	movq	%rax, 248(%rsp)
	xorl	%eax, %eax
	leaq	72(%rsp), %r13
	movl	$0x00000000, 12(%rsp)
	movq	%r13, %rdi
	call	_Z12keyExpansionPhS_
	leaq	16(%rsp), %rdi
	movq	%r12, %rsi
	call	cudaMalloc@PLT
	leaq	24(%rsp), %rdi
	movl	$176, %esi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rdi
	movq	%r12, %rdx
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	movl	$1, %ecx
	movq	%r13, %rsi
	movl	$176, %edx
	call	cudaMemcpy@PLT
	leaq	32(%rsp), %rdi
	call	cudaEventCreate@PLT
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	$131073, %eax
	xorl	%esi, %esi
	movq	32(%rsp), %rdi
	salq	$15, %rax
	movl	$1, 56(%rsp)
	movq	%rax, 48(%rsp)
	subq	$31744, %rax
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	cudaEventRecord@PLT
	movl	68(%rsp), %ecx
	movl	56(%rsp), %esi
	xorl	%r9d, %r9d
	movq	60(%rsp), %rdx
	movq	48(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L26
	movl	%r12d, %eax
	movl	$16, %ecx
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdi
	cltd
	idivl	%ecx
	movl	%eax, %edx
	call	_Z29__device_stub__Z7encryptPhS_iPhS_i
.L26:
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	40(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	leaq	12(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	16(%rsp), %rsi
	movq	%r12, %rdx
	movq	%rbp, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	cvtss2sd	12(%rsp), %xmm0
	call	__printf_chk@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	248(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$264, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2033:
	.size	_Z6aes128PhS_i, .-_Z6aes128PhS_i
	.section	.rodata.str1.1
.LC3:
	.string	"rb"
.LC4:
	.string	"key.txt"
.LC5:
	.string	"payload.txt"
.LC6:
	.string	"Data size: %d\n"
.LC7:
	.string	"Number of blocks: %d\n"
.LC8:
	.string	"wb"
.LC9:
	.string	"outcuda.txt"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2034:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$134217728, %edi
	leaq	.LC3(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %r12
	call	malloc@PLT
	movq	%r13, %rsi
	leaq	.LC4(%rip), %rdi
	movq	%rax, %rbx
	call	fopen@PLT
	movl	$16, %ecx
	movl	$1, %edx
	movq	%r12, %rdi
	movq	%rax, %r8
	movq	%rax, %rbp
	movl	$16, %esi
	call	__fread_chk@PLT
	movq	%rbp, %rdi
	call	fclose@PLT
	movq	%r13, %rsi
	leaq	.LC5(%rip), %rdi
	call	fopen@PLT
	movl	$134217728, %ecx
	movl	$1, %edx
	movq	%rbx, %rdi
	movq	%rax, %r8
	movl	$134217728, %esi
	movq	%rax, %rbp
	call	__fread_chk@PLT
	movq	%rbp, %rdi
	movl	%eax, %r13d
	movl	%eax, 4(%rsp)
	call	fclose@PLT
	movl	%r13d, %edx
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC6(%rip), %rsi
	call	__printf_chk@PLT
	leaq	4(%rsp), %rsi
	movq	%rbx, %rdi
	call	_Z7padDataPhPi
	movl	4(%rsp), %ebp
	movl	$16, %ecx
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	movl	%ebp, %eax
	cltd
	idivl	%ecx
	movl	%eax, %edx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%ebp, %edx
	movq	%r12, %rsi
	movq	%rbx, %rdi
	call	_Z6aes128PhS_i
	leaq	.LC8(%rip), %rsi
	leaq	.LC9(%rip), %rdi
	call	fopen@PLT
	movslq	%ebp, %rdx
	movl	$1, %esi
	movq	%rbx, %rdi
	movq	%rax, %r12
	movq	%rax, %rcx
	call	fwrite@PLT
	movq	%r12, %rdi
	call	fclose@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	24(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$40, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2034:
	.size	main, .-main
	.section	.rodata.str1.1
.LC10:
	.string	"_Z7encryptPhS_i"
.LC11:
	.string	"d_sbox"
.LC12:
	.string	"gmul2"
.LC13:
	.string	"gmul3"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2062:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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	.LC10(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z7encryptPhS_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC11(%rip), %rdx
	movl	$256, %r9d
	leaq	_ZL6d_sbox(%rip), %rsi
	pushq	$1
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC12(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$256, %r9d
	leaq	_ZL5gmul2(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC13(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movl	$256, %r9d
	movq	%rdx, %rcx
	leaq	_ZL5gmul3(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%r8
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2062:
	.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
	.section	.rodata
	.align 8
	.type	_ZL4rcon, @object
	.size	_ZL4rcon, 11
_ZL4rcon:
	.ascii	"\215\001\002\004\b\020 @\200\0336"
	.local	_ZL5gmul3
	.comm	_ZL5gmul3,256,32
	.local	_ZL5gmul2
	.comm	_ZL5gmul2,256,32
	.local	_ZL6d_sbox
	.comm	_ZL6d_sbox,256,32
	.align 32
	.type	_ZL4sbox, @object
	.size	_ZL4sbox, 256
_ZL4sbox:
	.string	"c|w{\362ko\3050\001g+\376\327\253v\312\202\311}\372YG\360\255\324\242\257\234\244r\300\267\375\223&6?\367\3144\245\345\361q\3301\025\004\307#\303\030\226\005\232\007\022\200\342\353'\262u\t\203,\032\033nZ\240R;\326\263)\343/\204S\321"
	.ascii	"\355 \374\261[j\313\2769JLX\317\320\357\252\373CM3\205E\371\002"
	.ascii	"\177P<\237\250Q\243@\217\222\2358\365\274\266\332!\020\377\363"
	.ascii	"\322\315\f\023\354_\227D\027\304\247~=d]\031s`\201O\334\"*\220"
	.ascii	"\210F\356\270\024\336^\013\333\3402:\nI\006$\\\302\323\254b\221"
	.ascii	"\225\344y\347\3107m\215\325N\251lV\364\352ez\256\b\272x%.\034"
	.ascii	"\246\264\306\350\335t\037K\275\213\212p>\265fH\003\366\016a5"
	.ascii	"W\271\206\301\035\236\341\370\230\021i\331\216\224\233\036\207"
	.ascii	"\351\316U(\337\214\241\211\r\277\346BhA\231-\017\260T\273\026"
	.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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hip/hip_runtime.h>

#define MAX_DATA_SIZE (1 << 27)

typedef unsigned char byte;

const byte sbox[256] = {
	0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
	0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
	0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
	0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
	0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
	0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
	0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
	0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
	0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
	0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
	0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
	0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
	0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
	0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
	0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
	0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
};

__device__ __constant__
byte d_sbox[256] = {
	0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
	0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
	0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
	0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
	0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
	0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
	0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
	0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
	0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
	0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
	0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
	0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
	0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
	0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
	0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
	0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
};

__device__ __constant__
byte gmul2[256] = {
	0x00, 0x02, 0x04, 0x06, 0x08,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 0xb7, 0xb2, 0xb1,
	0x90, 0x93, 0x96, 0x95, 0x9c, 0x9f, 0x9a, 0x99, 0x88, 0x8b, 0x8e, 0x8d, 0x84, 0x87, 0x82, 0x81,
	0x9b, 0x98, 0x9d, 0x9e, 0x97, 0x94, 0x91, 0x92, 0x83, 0x80, 0x85, 0x86, 0x8f, 0x8c, 0x89, 0x8a,
	0xab, 0xa8, 0xad, 0xae, 0xa7, 0xa4, 0xa1, 0xa2, 0xb3, 0xb0, 0xb5, 0xb6, 0xbf, 0xbc, 0xb9, 0xba,
	0xfb, 0xf8, 0xfd, 0xfe, 0xf7, 0xf4, 0xf1, 0xf2, 0xe3, 0xe0, 0xe5, 0xe6, 0xef, 0xec, 0xe9, 0xea,
	0xcb, 0xc8, 0xcd, 0xce, 0xc7, 0xc4, 0xc1, 0xc2, 0xd3, 0xd0, 0xd5, 0xd6, 0xdf, 0xdc, 0xd9, 0xda,
	0x5b, 0x58, 0x5d, 0x5e, 0x57, 0x54, 0x51, 0x52, 0x43, 0x40, 0x45, 0x46, 0x4f, 0x4c, 0x49, 0x4a,
	0x6b, 0x68, 0x6d, 0x6e, 0x67, 0x64, 0x61, 0x62, 0x73, 0x70, 0x75, 0x76, 0x7f, 0x7c, 0x79, 0x7a,
	0x3b, 0x38, 0x3d, 0x3e, 0x37, 0x34, 0x31, 0x32, 0x23, 0x20, 0x25, 0x26, 0x2f, 0x2c, 0x29, 0x2a,
	0x0b, 0x08, 0x0d, 0x0e, 0x07, 0x04, 0x01, 0x02, 0x13, 0x10, 0x15, 0x16, 0x1f, 0x1c, 0x19, 0x1a
};

const byte rcon[11] = {
	0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36
};

void keyExpansion(byte *roundKeys, byte *key) {
	byte t[4], tb;
	int k;
	
	for (int i = 0; i < 16; ++i) {
		roundKeys[i] = key[i];
	}
	
	for (int i = 4; i < 11 * 4; ++i) {
		k = (i - 1) * 4;
		t[0] = roundKeys[k + 0];
		t[1] = roundKeys[k + 1];
		t[2] = roundKeys[k + 2];
		t[3] = roundKeys[k + 3];
		
		if (i % 4 == 0) {
			tb = t[0];
			t[0] = t[1];
			t[1] = t[2];
			t[2] = t[3];
			t[3] = tb;
			
			t[0] = sbox[t[0]];
			t[1] = sbox[t[1]];
			t[2] = sbox[t[2]];
			t[3] = sbox[t[3]];
			
			t[0] = t[0] ^ rcon[i / 4];
		}
		
		k = (i - 4) * 4;
		roundKeys[i * 4 + 0] = roundKeys[k + 0] ^ t[0];
		roundKeys[i * 4 + 1] = roundKeys[k + 1] ^ t[1];
		roundKeys[i * 4 + 2] = roundKeys[k + 2] ^ t[2];
		roundKeys[i * 4 + 3] = roundKeys[k + 3] ^ t[3];
	}
}

__device__
void addRoundKey(byte state[4][4], byte *roundKeys, int round) {
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 4; ++j) {
			state[i][j] ^= roundKeys[round * 16 + i * 4 + j];
		}
	}
}

__device__
void subBytes(byte state[4][4]) {
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 4; ++j) {
			state[i][j] = d_sbox[state[i][j]];
		}
	}
}

__device__
void shiftRows(byte state[4][4]) {
	byte t;
	
	t = 		  state[0][1];
	state[0][1] = state[1][1];
	state[1][1] = state[2][1];
	state[2][1] = state[3][1];
	state[3][1] = t;
	
	t = 		  state[0][2];
	state[0][2] = state[2][2];
	state[2][2] = t;
	t = 		  state[1][2];
	state[1][2] = state[3][2];
	state[3][2] = t;
	
	t = 		  state[0][3];
	state[0][3] = state[3][3];
	state[3][3] = state[2][3];
	state[2][3] = state[1][3];
	state[1][3] = t;
}

__device__
void mixColumns(byte state[4][4]) {
	byte t[4];
	
	for (int i = 0; i < 4; ++i) {
		t[0] = gmul2[state[i][0]] 	^ gmul3[state[i][1]] 	^ state[i][2]			^ state[i][3];
		t[1] = state[i][0] 			^ gmul2[state[i][1]] 	^ gmul3[state[i][2]] 	^ state[i][3];
		t[2] = state[i][0] 			^ state[i][1] 			^ gmul2[state[i][2]] 	^ gmul3[state[i][3]];
		t[3] = gmul3[state[i][0]] 	^ state[i][1] 			^ state[i][2] 			^ gmul2[state[i][3]];
		
		for (int j = 0; j < 4; ++j) {
			state[i][j] = t[j];
		}
	}
}

__global__
void encrypt(byte *data, byte *roundKeys, int n) {
	int index = blockIdx.x * blockDim.x + threadIdx.x;
	
	if (index < n) {
		byte state[4][4];
		
		for (int i = 0; i < 16; ++i) {
			state[i / 4][i % 4] = data[index * 16 + i];
		}

		addRoundKey(state, roundKeys, 0);
		
		for (int round = 1; round < 10; ++round) {
			subBytes(state);
			shiftRows(state);
			mixColumns(state);
			addRoundKey(state, roundKeys, round);
		}
		
		subBytes(state);
		shiftRows(state);
		addRoundKey(state, roundKeys, 10);
		
		for (int i = 0; i < 16; ++i) {
			data[index * 16 + i] = state[i / 4][i % 4];
		}
	}
}

void padData(byte *data, int *len) {
	int dataLength = *len;
	
	if (dataLength % 16 > 0) {
		int padSize = 16 - (dataLength % 16);
		data = (byte *) realloc(data, sizeof(byte) * (dataLength + padSize));
		for (int i = 0; i < padSize; ++i) {
			data[dataLength + i] = 0;
		}
		*len = dataLength + padSize;
		printf("Added padding to data\nData size: %d\n", *len);
	}
}

void aes128(byte *data, byte *key, int dataLength) {
	byte roundKeys[11 * 16];
	byte *dData, *dRoundKeys;
	float timeElapsed = 0.0;
	
	keyExpansion(roundKeys, key);
	
	hipMalloc((void **) &dData, sizeof(byte) * dataLength);
	hipMalloc((void **) &dRoundKeys, sizeof(byte) * 11 * 16);
	
	hipMemcpy(dData, data, sizeof(byte) * dataLength, hipMemcpyHostToDevice);
	hipMemcpy(dRoundKeys, roundKeys, sizeof(byte) * 11 * 16, hipMemcpyHostToDevice);
	
	hipEvent_t start, stop;
	hipEventCreate(&start);
	hipEventCreate(&stop);
	
	dim3 nBlocks(1 << 15);
	dim3 nThreads(1 << 10);
	
	hipEventRecord(start, 0);
	
	encrypt<<<nBlocks, nThreads>>>(dData, dRoundKeys, dataLength / 16);
	
	hipEventRecord(stop, 0);
	hipEventSynchronize(stop);
	hipEventElapsedTime(&timeElapsed, start, stop);
	
	hipMemcpy(data, dData, dataLength, hipMemcpyDeviceToHost);
	
	printf("%lf\n", timeElapsed);
	
	hipFree(dData);
	hipFree(dRoundKeys);
}

int main() {
	byte key[16];
	byte *data = (byte *) malloc(sizeof(byte) * MAX_DATA_SIZE);
	int dataLength;
	
	FILE *fKey = fopen("key.txt", "rb");
	fread(key, 1, 16, fKey);
	fclose(fKey);
	
	FILE *fData = fopen("payload.txt", "rb");
	dataLength = fread(data, 1, MAX_DATA_SIZE, fData);
	fclose(fData);
	
	printf("Data size: %d\n", dataLength);
	
	padData(data, &dataLength);
	
	printf("Number of blocks: %d\n", dataLength / 16);
	
	aes128(data, key, dataLength);
	
	FILE *f_out = fopen("outcuda.txt", "wb");
	fwrite(data, 1, dataLength, f_out);
	fclose(f_out);
	
	free(data);
}
	.text
	.file	"aes.hip"
	.globl	_Z12keyExpansionPhS_            # -- Begin function _Z12keyExpansionPhS_
	.type	_Z12keyExpansionPhS_,@function
_Z12keyExpansionPhS_:                   # @_Z12keyExpansionPhS_
	.cfi_startproc
# %bb.0:
	xorl	%eax, %eax
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
	movb	(%rsi,%rax), %cl
	movb	%cl, (%rdi,%rax)
	incq	%rax
	cmpq	$16, %rax
	jne	.LBB0_1
# %bb.2:                                # %.preheader
	movl	$4, %eax
.LBB0_3:                                # =>This Inner Loop Header: Depth=1
	movb	-4(%rdi,%rax,4), %r8b
	movb	-3(%rdi,%rax,4), %sil
	movb	-2(%rdi,%rax,4), %dl
	movb	-1(%rdi,%rax,4), %cl
	testb	$3, %al
	jne	.LBB0_5
# %bb.4:                                #   in Loop: Header=BB0_3 Depth=1
	movzbl	%r8b, %r8d
	movzbl	%sil, %r9d
	movzbl	%dl, %edx
	movzbl	%cl, %ecx
	movb	_ZL4sbox(%rdx), %sil
	movb	_ZL4sbox(%rcx), %dl
	movb	_ZL4sbox(%r8), %cl
	movl	%eax, %r8d
	shrl	$2, %r8d
	movb	_ZL4rcon(%r8), %r8b
	xorb	_ZL4sbox(%r9), %r8b
.LBB0_5:                                #   in Loop: Header=BB0_3 Depth=1
	xorb	-16(%rdi,%rax,4), %r8b
	movb	%r8b, (%rdi,%rax,4)
	xorb	-15(%rdi,%rax,4), %sil
	movb	%sil, 1(%rdi,%rax,4)
	xorb	-14(%rdi,%rax,4), %dl
	movb	%dl, 2(%rdi,%rax,4)
	xorb	-13(%rdi,%rax,4), %cl
	movb	%cl, 3(%rdi,%rax,4)
	incq	%rax
	cmpq	$44, %rax
	jne	.LBB0_3
# %bb.6:
	retq
.Lfunc_end0:
	.size	_Z12keyExpansionPhS_, .Lfunc_end0-_Z12keyExpansionPhS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z22__device_stub__encryptPhS_i # -- Begin function _Z22__device_stub__encryptPhS_i
	.type	_Z22__device_stub__encryptPhS_i,@function
_Z22__device_stub__encryptPhS_i:        # @_Z22__device_stub__encryptPhS_i
	.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	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%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	$_Z7encryptPhS_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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	_Z22__device_stub__encryptPhS_i, .Lfunc_end1-_Z22__device_stub__encryptPhS_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z7padDataPhPi                  # -- Begin function _Z7padDataPhPi
	.type	_Z7padDataPhPi,@function
_Z7padDataPhPi:                         # @_Z7padDataPhPi
	.cfi_startproc
# %bb.0:
	movl	(%rsi), %eax
	leal	15(%rax), %edx
	testl	%eax, %eax
	cmovnsl	%eax, %edx
	andl	$-16, %edx
	movl	%eax, %ecx
	subl	%edx, %ecx
	testl	%ecx, %ecx
	jle	.LBB2_1
# %bb.2:                                # %._crit_edge
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rsi, %rbx
	subl	%ecx, %eax
	addl	$16, %eax
	movslq	%eax, %r14
	movq	%r14, %rsi
	callq	realloc
	movl	%r14d, (%rbx)
	movl	$.L.str, %edi
	movl	%r14d, %esi
	xorl	%eax, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.LBB2_1:
	.cfi_restore %rbx
	.cfi_restore %r14
	retq
.Lfunc_end2:
	.size	_Z7padDataPhPi, .Lfunc_end2-_Z7padDataPhPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z6aes128PhS_i                  # -- Begin function _Z6aes128PhS_i
	.type	_Z6aes128PhS_i,@function
_Z6aes128PhS_i:                         # @_Z6aes128PhS_i
	.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	$232, %rsp
	.cfi_def_cfa_offset 288
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %r15d
	movq	%rdi, %rbx
	movl	$0, 28(%rsp)
	leaq	48(%rsp), %r12
	movq	%r12, %rdi
	callq	_Z12keyExpansionPhS_
	movslq	%r15d, %r14
	leaq	16(%rsp), %r13
	movq	%r13, %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	leaq	32(%rsp), %rbp
	movl	$176, %esi
	movq	%rbp, %rdi
	callq	hipMalloc
	movq	(%r13), %rdi
	movq	%rbx, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	(%rbp), %rdi
	movl	$176, %edx
	movq	%r12, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	40(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventCreate
	leaq	8(%rsp), %rdi
	callq	hipEventCreate
	movq	(%r12), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movabsq	$4294968320, %rdx               # imm = 0x100000400
	leaq	31744(%rdx), %rdi
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_2
# %bb.1:
	movq	16(%rsp), %rdi
	movq	32(%rsp), %rsi
	leal	15(%r15), %edx
	testl	%r15d, %r15d
	cmovnsl	%r15d, %edx
	sarl	$4, %edx
	callq	_Z22__device_stub__encryptPhS_i
.LBB3_2:
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	8(%rsp), %rdi
	callq	hipEventSynchronize
	movq	40(%rsp), %rsi
	movq	8(%rsp), %rdx
	leaq	28(%rsp), %r15
	movq	%r15, %rdi
	callq	hipEventElapsedTime
	movq	16(%rsp), %rsi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	cvtss2sd	(%r15), %xmm0
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	32(%rsp), %rdi
	callq	hipFree
	addq	$232, %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_end3:
	.size	_Z6aes128PhS_i, .Lfunc_end3-_Z6aes128PhS_i
	.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	$32, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	$134217728, %edi                # imm = 0x8000000
	callq	malloc
	movq	%rax, %rbx
	movl	$.L.str.2, %edi
	movl	$.L.str.3, %esi
	callq	fopen
	movq	%rax, %r15
	leaq	16(%rsp), %r14
	movl	$1, %esi
	movl	$16, %edx
	movq	%r14, %rdi
	movq	%rax, %rcx
	callq	fread
	movq	%r15, %rdi
	callq	fclose
	movl	$.L.str.4, %edi
	movl	$.L.str.3, %esi
	callq	fopen
	movq	%rax, %r15
	movl	$1, %esi
	movl	$134217728, %edx                # imm = 0x8000000
	movq	%rbx, %rdi
	movq	%rax, %rcx
	callq	fread
	movq	%rax, %r12
	leaq	12(%rsp), %r13
	movl	%r12d, (%r13)
	movq	%r15, %rdi
	callq	fclose
	movl	$.L.str.5, %edi
	movl	%r12d, %esi
	xorl	%eax, %eax
	callq	printf
	movq	%rbx, %rdi
	movq	%r13, %rsi
	callq	_Z7padDataPhPi
	movl	(%r13), %r15d
	leal	15(%r15), %esi
	testl	%r15d, %r15d
	cmovnsl	%r15d, %esi
	sarl	$4, %esi
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	movq	%rbx, %rdi
	movq	%r14, %rsi
	movl	%r15d, %edx
	callq	_Z6aes128PhS_i
	movl	$.L.str.7, %edi
	movl	$.L.str.8, %esi
	callq	fopen
	movq	%rax, %r14
	movslq	%r15d, %rdx
	movl	$1, %esi
	movq	%rbx, %rdi
	movq	%rax, %rcx
	callq	fwrite
	movq	%r14, %rdi
	callq	fclose
	movq	%rbx, %rdi
	callq	free
	xorl	%eax, %eax
	addq	$32, %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
.Lfunc_end4:
	.size	main, .Lfunc_end4-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:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	subq	$32, %rsp
	.cfi_adjust_cfa_offset 32
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z7encryptPhS_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
	movl	$d_sbox, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movl	$256, %r9d                      # imm = 0x100
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	__hipRegisterVar
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	$gmul2, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movl	$256, %r9d                      # imm = 0x100
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	__hipRegisterVar
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	$gmul3, %esi
	movl	$.L__unnamed_4, %edx
	movl	$.L__unnamed_4, %ecx
	movl	$256, %r9d                      # imm = 0x100
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_adjust_cfa_offset 8
	pushq	$1
	.cfi_adjust_cfa_offset 8
	callq	__hipRegisterVar
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movl	$__hip_module_dtor, %edi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__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	.LBB6_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
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	d_sbox,@object                  # @d_sbox
	.local	d_sbox
	.comm	d_sbox,256,16
	.type	gmul2,@object                   # @gmul2
	.local	gmul2
	.comm	gmul2,256,16
	.type	gmul3,@object                   # @gmul3
	.local	gmul3
	.comm	gmul3,256,16
	.type	_ZL4sbox,@object                # @_ZL4sbox
	.section	.rodata,"a",@progbits
	.p2align	4, 0x0
_ZL4sbox:
	.ascii	"c|w{\362ko\3050\001g+\376\327\253v\312\202\311}\372YG\360\255\324\242\257\234\244r\300\267\375\223&6?\367\3144\245\345\361q\3301\025\004\307#\303\030\226\005\232\007\022\200\342\353'\262u\t\203,\032\033nZ\240R;\326\263)\343/\204S\321\000\355 \374\261[j\313\2769JLX\317\320\357\252\373CM3\205E\371\002\177P<\237\250Q\243@\217\222\2358\365\274\266\332!\020\377\363\322\315\f\023\354_\227D\027\304\247~=d]\031s`\201O\334\"*\220\210F\356\270\024\336^\013\333\3402:\nI\006$\\\302\323\254b\221\225\344y\347\3107m\215\325N\251lV\364\352ez\256\b\272x%.\034\246\264\306\350\335t\037K\275\213\212p>\265fH\003\366\016a5W\271\206\301\035\236\341\370\230\021i\331\216\224\233\036\207\351\316U(\337\214\241\211\r\277\346BhA\231-\017\260T\273\026"
	.size	_ZL4sbox, 256

	.type	_ZL4rcon,@object                # @_ZL4rcon
_ZL4rcon:
	.ascii	"\215\001\002\004\b\020 @\200\0336"
	.size	_ZL4rcon, 11

	.type	_Z7encryptPhS_i,@object         # @_Z7encryptPhS_i
	.globl	_Z7encryptPhS_i
	.p2align	3, 0x0
_Z7encryptPhS_i:
	.quad	_Z22__device_stub__encryptPhS_i
	.size	_Z7encryptPhS_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Added padding to data\nData size: %d\n"
	.size	.L.str, 37

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"%lf\n"
	.size	.L.str.1, 5

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"key.txt"
	.size	.L.str.2, 8

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"payload.txt"
	.size	.L.str.4, 12

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Data size: %d\n"
	.size	.L.str.5, 15

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Number of blocks: %d\n"
	.size	.L.str.6, 22

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"outcuda.txt"
	.size	.L.str.7, 12

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"wb"
	.size	.L.str.8, 3

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z7encryptPhS_i"
	.size	.L__unnamed_1, 16

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"d_sbox"
	.size	.L__unnamed_2, 7

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"gmul2"
	.size	.L__unnamed_3, 6

	.type	.L__unnamed_4,@object           # @3
.L__unnamed_4:
	.asciz	"gmul3"
	.size	.L__unnamed_4, 6

	.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

	.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__encryptPhS_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym d_sbox
	.addrsig_sym gmul2
	.addrsig_sym gmul3
	.addrsig_sym _Z7encryptPhS_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z7encryptPhS_i         ; -- Begin function _Z7encryptPhS_i
	.globl	_Z7encryptPhS_i
	.p2align	8
	.type	_Z7encryptPhS_i,@function
_Z7encryptPhS_i:                        ; @_Z7encryptPhS_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[2:3], 0x24
	s_load_b32 s5, s[2:3], 0x10
	v_and_b32_e32 v1, 0x3ff, v0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_mad_u64_u32 v[2:3], null, s15, s4, v[1:2]
	s_mov_b32 s4, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s5, v2
	s_cbranch_execz .LBB0_31
; %bb.1:
	s_load_b64 s[4:5], s[0:1], 0x4
	s_load_b128 s[0:3], s[2:3], 0x0
	v_bfe_u32 v5, v0, 10, 10
	v_lshlrev_b32_e32 v2, 4, v2
	v_bfe_u32 v4, v0, 20, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s4, s4, 16
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s6, s4, s5
	v_mul_lo_u32 v3, s6, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_4)
	v_mad_u32_u24 v0, v5, s5, v3
	v_ashrrev_i32_e32 v3, 31, v2
	v_add_co_u32 v2, vcc_lo, s0, v2
	v_mul_u32_u24_e32 v5, s5, v5
	v_add_lshl_u32 v0, v0, v4, 4
	s_delay_alu instid0(VALU_DEP_4)
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v3, vcc_lo
	s_mov_b64 s[0:1], 0
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, v2, s0
	v_add_co_ci_u32_e32 v7, vcc_lo, s1, v3, vcc_lo
	global_load_u8 v6, v[6:7], off
	v_add_nc_u32_e32 v7, s0, v0
	s_add_u32 s0, s0, 1
	s_addc_u32 s1, s1, 0
	s_cmp_lg_u32 s0, 16
	s_waitcnt vmcnt(0)
	ds_store_b8 v7, v6
	s_cbranch_scc1 .LBB0_2
; %bb.3:                                ; %.preheader.i.preheader
	v_mul_lo_u32 v1, v1, s5
	v_lshlrev_b32_e32 v5, 4, v5
	v_lshlrev_b32_e32 v4, 4, v4
	s_mov_b32 s6, 0
	s_mov_b64 s[0:1], s[2:3]
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v1, v1, s4
	v_lshlrev_b32_e32 v1, 4, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add3_u32 v1, v1, v5, v4
	v_dual_mov_b32 v4, 0 :: v_dual_mov_b32 v5, v1
.LBB0_4:                                ; %.preheader.i
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_5 Depth 2
	s_mov_b64 s[4:5], s[0:1]
	s_mov_b32 s7, 0
.LBB0_5:                                ;   Parent Loop BB0_4 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	global_load_u8 v6, v4, s[4:5]
	v_add_nc_u32_e32 v7, s7, v5
	s_add_i32 s7, s7, 1
	s_add_u32 s4, s4, 1
	s_addc_u32 s5, s5, 0
	s_cmp_eq_u32 s7, 4
	ds_load_u8 v8, v7
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_xor_b32_e32 v6, v8, v6
	ds_store_b8 v7, v6
	s_cbranch_scc0 .LBB0_5
; %bb.6:                                ;   in Loop: Header=BB0_4 Depth=1
	s_add_i32 s6, s6, 1
	v_add_nc_u32_e32 v5, 4, v5
	s_add_u32 s0, s0, 4
	s_addc_u32 s1, s1, 0
	s_cmp_lg_u32 s6, 4
	s_cbranch_scc1 .LBB0_4
; %bb.7:                                ; %_Z11addRoundKeyPA4_hPhi.exit.preheader
	v_mov_b32_e32 v4, 0
	s_add_u32 s0, s2, 16
	s_addc_u32 s1, s3, 0
	s_mov_b32 s8, 1
.LBB0_8:                                ; %.preheader.i34.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_9 Depth 2
                                        ;       Child Loop BB0_10 Depth 3
                                        ;     Child Loop BB0_13 Depth 2
                                        ;       Child Loop BB0_14 Depth 3
                                        ;     Child Loop BB0_17 Depth 2
                                        ;       Child Loop BB0_18 Depth 3
	v_mov_b32_e32 v5, v1
	s_mov_b32 s4, 0
.LBB0_9:                                ; %.preheader.i34
                                        ;   Parent Loop BB0_8 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB0_10 Depth 3
	s_mov_b32 s5, 0
.LBB0_10:                               ;   Parent Loop BB0_8 Depth=1
                                        ;     Parent Loop BB0_9 Depth=2
                                        ; =>    This Inner Loop Header: Depth=3
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_add_nc_u32_e32 v8, s5, v5
	s_getpc_b64 s[6:7]
	s_add_u32 s6, s6, d_sbox@rel32@lo+4
	s_addc_u32 s7, s7, d_sbox@rel32@hi+12
	s_add_i32 s5, s5, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	s_cmp_eq_u32 s5, 4
	ds_load_u8 v6, v8
	s_waitcnt lgkmcnt(0)
	v_and_b32_e32 v6, 0xffff, v6
	v_add_co_u32 v6, s6, v6, s6
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v7, null, 0, s7, s6
	global_load_u8 v6, v[6:7], off
	s_waitcnt vmcnt(0)
	ds_store_b8 v8, v6
	s_cbranch_scc0 .LBB0_10
; %bb.11:                               ;   in Loop: Header=BB0_9 Depth=2
	v_add_nc_u32_e32 v5, 4, v5
	s_add_i32 s4, s4, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s4, 4
	s_cbranch_scc0 .LBB0_9
; %bb.12:                               ; %_Z8subBytesPA4_h.exit39
                                        ;   in Loop: Header=BB0_8 Depth=1
	ds_load_u16 v6, v0 offset:2
	ds_load_u16 v7, v0 offset:14
	ds_load_u16 v8, v0 offset:10
	ds_load_u16 v9, v0 offset:6
	ds_load_u8 v10, v0 offset:5
	ds_load_u8 v11, v0 offset:9
	ds_load_u8 v12, v0 offset:13
	ds_load_u8 v13, v0 offset:1
	v_mov_b32_e32 v5, v0
	s_mov_b32 s6, 0
	s_waitcnt lgkmcnt(7)
	v_and_b32_e32 v14, 0xffffff00, v6
	s_waitcnt lgkmcnt(6)
	v_and_b32_e32 v15, 0xff, v7
	s_waitcnt lgkmcnt(5)
	v_and_b32_e32 v16, 0xff, v8
	v_and_b32_e32 v7, 0xffffff00, v7
	v_and_b32_e32 v8, 0xffffff00, v8
	s_waitcnt lgkmcnt(4)
	v_and_b32_e32 v17, 0xff, v9
	v_and_b32_e32 v6, 0xff, v6
	v_and_b32_e32 v9, 0xffffff00, v9
	v_or_b32_e32 v7, v16, v7
	s_waitcnt lgkmcnt(3)
	ds_store_b8 v0, v10 offset:1
	v_or_b32_e32 v8, v17, v8
	v_or_b32_e32 v10, v15, v14
	v_or_b32_e32 v6, v6, v9
	s_waitcnt lgkmcnt(3)
	ds_store_b8 v0, v11 offset:5
	s_waitcnt lgkmcnt(3)
	ds_store_b8 v0, v12 offset:9
	ds_store_b16 v0, v7 offset:2
	ds_store_b16 v0, v8 offset:14
	s_waitcnt lgkmcnt(5)
	ds_store_b8 v0, v13 offset:13
	ds_store_b16 v0, v6 offset:10
	ds_store_b16 v0, v10 offset:6
.LBB0_13:                               ;   Parent Loop BB0_8 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB0_14 Depth 3
	v_lshl_add_u32 v6, s6, 2, v0
	s_getpc_b64 s[4:5]
	s_add_u32 s4, s4, gmul2@rel32@lo+4
	s_addc_u32 s5, s5, gmul2@rel32@hi+12
	s_getpc_b64 s[10:11]
	s_add_u32 s10, s10, gmul3@rel32@lo+4
	s_addc_u32 s11, s11, gmul3@rel32@hi+12
	ds_load_b32 v18, v6
	s_waitcnt lgkmcnt(0)
	v_and_b32_e32 v16, 0xff, v18
	v_bfe_u32 v10, v18, 8, 8
	v_bfe_u32 v14, v18, 16, 8
	v_lshrrev_b32_e32 v19, 24, v18
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v6, s7, v16, s4
	v_add_co_ci_u32_e64 v7, null, 0, s5, s7
	v_add_co_u32 v8, s7, v10, s10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v9, null, 0, s11, s7
	v_add_co_u32 v10, s7, v10, s4
	v_add_co_ci_u32_e64 v11, null, 0, s5, s7
	v_add_co_u32 v12, s7, v14, s10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e64 v13, null, 0, s11, s7
	v_add_co_u32 v14, s7, v14, s4
	v_add_co_ci_u32_e64 v15, null, 0, s5, s7
	v_add_co_u32 v16, s7, v16, s10
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v17, null, 0, s11, s7
	global_load_u8 v6, v[6:7], off
	global_load_u8 v7, v[8:9], off
	global_load_u8 v8, v[10:11], off
	global_load_u8 v9, v[12:13], off
	global_load_u8 v10, v[14:15], off
	s_clause 0x1
	global_load_u8 v11, v19, s[10:11]
	global_load_u8 v12, v19, s[4:5]
	global_load_u8 v13, v[16:17], off
	v_lshrrev_b32_e32 v14, 16, v18
	v_lshrrev_b32_e32 v15, 8, v18
	s_mov_b64 s[4:5], 0
	s_waitcnt vmcnt(6)
	v_xor_b32_e32 v6, v7, v6
	s_waitcnt vmcnt(4)
	v_xor_b32_e32 v7, v8, v9
	s_waitcnt vmcnt(2)
	v_xor_b32_e32 v8, v10, v11
	v_xor_b32_e32 v6, v6, v14
	s_waitcnt vmcnt(0)
	v_xor_b32_e32 v9, v13, v12
	v_xor_b32_e32 v7, v7, v18
	v_xor_b32_e32 v8, v8, v18
	v_xor_b32_e32 v6, v6, v19
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_xor_b32_e32 v9, v9, v15
	v_xor_b32_e32 v7, v7, v19
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_xor_b32_e32 v8, v8, v15
	v_and_b32_e32 v6, 0xff, v6
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_xor_b32_e32 v9, v9, v14
	v_lshlrev_b16 v7, 8, v7
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_and_b32_e32 v8, 0xff, v8
	v_lshlrev_b16 v9, 8, v9
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_or_b32_e32 v6, v6, v7
	v_or_b32_e32 v7, v8, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_and_b32_e32 v6, 0xffff, v6
	v_lshlrev_b32_e32 v7, 16, v7
	s_delay_alu instid0(VALU_DEP_1)
	v_or_b32_e32 v6, v6, v7
	v_mov_b32_e32 v7, v5
.LBB0_14:                               ;   Parent Loop BB0_8 Depth=1
                                        ;     Parent Loop BB0_13 Depth=2
                                        ; =>    This Inner Loop Header: Depth=3
	s_lshl_b32 s7, s4, 3
	s_add_u32 s4, s4, 1
	s_delay_alu instid0(VALU_DEP_2)
	v_lshrrev_b32_e32 v8, s7, v6
	s_addc_u32 s5, s5, 0
	s_cmp_eq_u32 s4, 4
	ds_store_b8 v7, v8
	v_add_nc_u32_e32 v7, 1, v7
	s_cbranch_scc0 .LBB0_14
; %bb.15:                               ;   in Loop: Header=BB0_13 Depth=2
	v_add_nc_u32_e32 v5, 4, v5
	s_add_i32 s6, s6, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s6, 4
	s_cbranch_scc0 .LBB0_13
; %bb.16:                               ; %_Z10mixColumnsPA4_h.exit
                                        ;   in Loop: Header=BB0_8 Depth=1
	v_mov_b32_e32 v5, v1
	s_mov_b32 s9, 0
	s_mov_b64 s[4:5], s[0:1]
.LBB0_17:                               ; %.preheader.i41
                                        ;   Parent Loop BB0_8 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB0_18 Depth 3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_mov_b64 s[6:7], s[4:5]
	s_mov_b32 s10, 0
.LBB0_18:                               ;   Parent Loop BB0_8 Depth=1
                                        ;     Parent Loop BB0_17 Depth=2
                                        ; =>    This Inner Loop Header: Depth=3
	global_load_u8 v6, v4, s[6:7]
	v_add_nc_u32_e32 v7, s10, v5
	s_add_i32 s10, s10, 1
	s_add_u32 s6, s6, 1
	s_addc_u32 s7, s7, 0
	s_cmp_eq_u32 s10, 4
	ds_load_u8 v8, v7
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_xor_b32_e32 v6, v8, v6
	ds_store_b8 v7, v6
	s_cbranch_scc0 .LBB0_18
; %bb.19:                               ;   in Loop: Header=BB0_17 Depth=2
	s_add_i32 s9, s9, 1
	v_add_nc_u32_e32 v5, 4, v5
	s_add_u32 s4, s4, 4
	s_addc_u32 s5, s5, 0
	s_cmp_eq_u32 s9, 4
	s_cbranch_scc0 .LBB0_17
; %bb.20:                               ; %_Z11addRoundKeyPA4_hPhi.exit46
                                        ;   in Loop: Header=BB0_8 Depth=1
	s_add_i32 s8, s8, 1
	s_add_u32 s0, s0, 16
	s_addc_u32 s1, s1, 0
	s_cmp_lg_u32 s8, 10
	s_cbranch_scc1 .LBB0_8
; %bb.21:                               ; %.preheader.i26.preheader
	v_mov_b32_e32 v4, v1
	s_mov_b32 s0, 0
.LBB0_22:                               ; %.preheader.i26
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_23 Depth 2
	s_mov_b32 s1, 0
.LBB0_23:                               ;   Parent Loop BB0_22 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_add_nc_u32_e32 v7, s1, v4
	s_getpc_b64 s[4:5]
	s_add_u32 s4, s4, d_sbox@rel32@lo+4
	s_addc_u32 s5, s5, d_sbox@rel32@hi+12
	s_add_i32 s1, s1, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	s_cmp_eq_u32 s1, 4
	ds_load_u8 v5, v7
	s_waitcnt lgkmcnt(0)
	v_and_b32_e32 v5, 0xffff, v5
	v_add_co_u32 v5, s4, v5, s4
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v6, null, 0, s5, s4
	global_load_u8 v5, v[5:6], off
	s_waitcnt vmcnt(0)
	ds_store_b8 v7, v5
	s_cbranch_scc0 .LBB0_23
; %bb.24:                               ;   in Loop: Header=BB0_22 Depth=1
	v_add_nc_u32_e32 v4, 4, v4
	s_add_i32 s0, s0, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s0, 4
	s_cbranch_scc0 .LBB0_22
; %bb.25:                               ; %_Z8subBytesPA4_h.exit
	ds_load_u16 v5, v0 offset:2
	ds_load_u16 v6, v0 offset:14
	ds_load_u16 v7, v0 offset:10
	ds_load_u16 v8, v0 offset:6
	ds_load_u8 v9, v0 offset:5
	ds_load_u8 v10, v0 offset:9
	ds_load_u8 v11, v0 offset:13
	ds_load_u8 v12, v0 offset:1
	v_mov_b32_e32 v4, 0
	s_add_u32 s0, s2, 0xa0
	s_mov_b32 s4, 0
	s_addc_u32 s1, s3, 0
	s_waitcnt lgkmcnt(7)
	v_and_b32_e32 v13, 0xffffff00, v5
	s_waitcnt lgkmcnt(6)
	v_and_b32_e32 v14, 0xff, v6
	s_waitcnt lgkmcnt(5)
	v_and_b32_e32 v15, 0xff, v7
	v_and_b32_e32 v6, 0xffffff00, v6
	v_and_b32_e32 v7, 0xffffff00, v7
	s_waitcnt lgkmcnt(4)
	v_and_b32_e32 v16, 0xff, v8
	v_and_b32_e32 v5, 0xff, v5
	v_and_b32_e32 v8, 0xffffff00, v8
	v_or_b32_e32 v6, v15, v6
	s_waitcnt lgkmcnt(3)
	ds_store_b8 v0, v9 offset:1
	v_or_b32_e32 v7, v16, v7
	v_or_b32_e32 v9, v14, v13
	v_or_b32_e32 v5, v5, v8
	s_waitcnt lgkmcnt(3)
	ds_store_b8 v0, v10 offset:5
	s_waitcnt lgkmcnt(3)
	ds_store_b8 v0, v11 offset:9
	ds_store_b16 v0, v6 offset:2
	ds_store_b16 v0, v7 offset:14
	s_waitcnt lgkmcnt(5)
	ds_store_b8 v0, v12 offset:13
	ds_store_b16 v0, v5 offset:10
	ds_store_b16 v0, v9 offset:6
.LBB0_26:                               ; %.preheader.i28
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_27 Depth 2
	s_mov_b64 s[2:3], s[0:1]
	s_mov_b32 s5, 0
.LBB0_27:                               ;   Parent Loop BB0_26 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	global_load_u8 v5, v4, s[2:3]
	v_add_nc_u32_e32 v6, s5, v1
	s_add_i32 s5, s5, 1
	s_add_u32 s2, s2, 1
	s_addc_u32 s3, s3, 0
	s_cmp_eq_u32 s5, 4
	ds_load_u8 v7, v6
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_xor_b32_e32 v5, v7, v5
	ds_store_b8 v6, v5
	s_cbranch_scc0 .LBB0_27
; %bb.28:                               ;   in Loop: Header=BB0_26 Depth=1
	s_add_i32 s4, s4, 1
	v_add_nc_u32_e32 v1, 4, v1
	s_add_u32 s0, s0, 4
	s_addc_u32 s1, s1, 0
	s_cmp_lg_u32 s4, 4
	s_cbranch_scc1 .LBB0_26
; %bb.29:                               ; %_Z11addRoundKeyPA4_hPhi.exit33.preheader
	s_mov_b64 s[0:1], 0
.LBB0_30:                               ; %_Z11addRoundKeyPA4_hPhi.exit33
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1)
	v_add_nc_u32_e32 v1, s0, v0
	v_add_co_u32 v4, vcc_lo, v2, s0
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v3, vcc_lo
	ds_load_u8 v1, v1
	s_add_u32 s0, s0, 1
	s_addc_u32 s1, s1, 0
	s_cmp_lg_u32 s0, 16
	s_waitcnt lgkmcnt(0)
	global_store_b8 v[4:5], v1, off
	s_cbranch_scc1 .LBB0_30
.LBB0_31:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z7encryptPhS_i
		.amdhsa_group_segment_fixed_size 16384
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 1
		.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 2
		.amdhsa_next_free_vgpr 20
		.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	_Z7encryptPhS_i, .Lfunc_end0-_Z7encryptPhS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1956
; NumSgprs: 18
; NumVgprs: 20
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 16384 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 20
; 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: 2
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.protected	d_sbox                  ; @d_sbox
	.type	d_sbox,@object
	.data
	.globl	d_sbox
	.p2align	4, 0x0
d_sbox:
	.ascii	"c|w{\362ko\3050\001g+\376\327\253v\312\202\311}\372YG\360\255\324\242\257\234\244r\300\267\375\223&6?\367\3144\245\345\361q\3301\025\004\307#\303\030\226\005\232\007\022\200\342\353'\262u\t\203,\032\033nZ\240R;\326\263)\343/\204S\321\000\355 \374\261[j\313\2769JLX\317\320\357\252\373CM3\205E\371\002\177P<\237\250Q\243@\217\222\2358\365\274\266\332!\020\377\363\322\315\f\023\354_\227D\027\304\247~=d]\031s`\201O\334\"*\220\210F\356\270\024\336^\013\333\3402:\nI\006$\\\302\323\254b\221\225\344y\347\3107m\215\325N\251lV\364\352ez\256\b\272x%.\034\246\264\306\350\335t\037K\275\213\212p>\265fH\003\366\016a5W\271\206\301\035\236\341\370\230\021i\331\216\224\233\036\207\351\316U(\337\214\241\211\r\277\346BhA\231-\017\260T\273\026"
	.size	d_sbox, 256

	.protected	gmul2                   ; @gmul2
	.type	gmul2,@object
	.globl	gmul2
	.p2align	4, 0x0
gmul2:
	.ascii	"\000\002\004\006\b\n\f\016\020\022\024\026\030\032\034\036 \"$&(*,.02468:<>@BDFHJLNPRTVXZ\\^`bdfhjlnprtvxz|~\200\202\204\206\210\212\214\216\220\222\224\226\230\232\234\236\240\242\244\246\250\252\254\256\260\262\264\266\270\272\274\276\300\302\304\306\310\312\314\316\320\322\324\326\330\332\334\336\340\342\344\346\350\352\354\356\360\362\364\366\370\372\374\376\033\031\037\035\023\021\027\025\013\t\017\r\003\001\007\005;9?=3175+)/-#!'%[Y_]SQWUKIOMCAGE{y\177}sqwukiomcage\233\231\237\235\223\221\227\225\213\211\217\215\203\201\207\205\273\271\277\275\263\261\267\265\253\251\257\255\243\241\247\245\333\331\337\335\323\321\327\325\313\311\317\315\303\301\307\305\373\371\377\375\363\361\367\365\353\351\357\355\343\341\347\345"
	.size	gmul2, 256

	.protected	gmul3                   ; @gmul3
	.type	gmul3,@object
	.globl	gmul3
	.p2align	4, 0x0
gmul3:
	.ascii	"\000\003\006\005\f\017\n\t\030\033\036\035\024\027\022\0210365<?:9(+.-$'\"!`cfelojix{~}twrqPSVU\\_ZYHKNMDGBA\300\303\306\305\314\317\312\311\330\333\336\335\324\327\322\321\360\363\366\365\374\377\372\371\350\353\356\355\344\347\342\341\240\243\246\245\254\257\252\251\270\273\276\275\264\267\262\261\220\223\226\225\234\237\232\231\210\213\216\215\204\207\202\201\233\230\235\236\227\224\221\222\203\200\205\206\217\214\211\212\253\250\255\256\247\244\241\242\263\260\265\266\277\274\271\272\373\370\375\376\367\364\361\362\343\340\345\346\357\354\351\352\313\310\315\316\307\304\301\302\323\320\325\326\337\334\331\332[X]^WTQRC@EFOLIJkhmngdabspuv\177|yz;8=>7412# %&/,)*\013\b\r\016\007\004\001\002\023\020\025\026\037\034\031\032"
	.size	gmul3, 256

	.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 d_sbox
	.addrsig_sym gmul2
	.addrsig_sym gmul3
	.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
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 16384
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z7encryptPhS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z7encryptPhS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     20
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
