// Introduction to GPU Programming
// Module 05: Shared and Constant Memory
// Author   : Justin Renga
// Date     : 03/03/2017

// Bibliography (source-list):
// [1] http://cuda-programming.blogspot.com/2013/01/what-is-constant-memory-in-cuda.html
// [2] constant_memory.cu
// [3] shared_memory2.cu

// #includes
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

#define ELEMENT_COUNT 2048

// Declare CONSTANT Memory here:
__constant__ static unsigned int MASKS[2];

// Declare static SHARED Memory here:
__shared__   unsigned int sharedMemory [ELEMENT_COUNT];

// Declare global host data here:
unsigned int initializedRNG;

// ---------------------------------------- DEVICE OPERATIONS -----------------------------------------

// @brief Perform a masking operation based on the evenness of the data
//
// @param [ in] data   An array that contains input data
// @param [out] output An array that contains the resulting data
__global__ void maskBits(const unsigned int*       data,
                               unsigned int* const output)
{
  // Compute the thread index
  const unsigned int threadIndex = (blockIdx.x * blockDim.x) + threadIdx.x;
  
  const unsigned int dataValue = data[threadIndex];
    
  // Apply the appropriate mask value and assign to the output
  output[threadIndex] = dataValue ^ MASKS[dataValue % 2];
}

// @brief Performs an array reversal
//
// @param [   in] The shared memory
// @param [inout] The device memory
// @param [   in] The number of elements
// @param [   in] The current thread index
__device__ void rotateArray(unsigned int* const data,
                            unsigned int* const deviceData,
                            unsigned int        elementCount,
                            unsigned int        threadIndex)
{
  // Get the next appropriately rotated thread index
  unsigned int rotatedIndex = elementCount - threadIndex - 1;
  
  data[threadIndex] = deviceData[rotatedIndex];
  
  __syncthreads();
  
  // Store the newly rotated memory back into global memory
  deviceData[threadIndex] = data[threadIndex];
}

// @brief A kernel function used to flip the contents of an array
__global__ void swapArray(unsigned int* data, const unsigned int elementCount)
{
  // Get the current thread index
  unsigned int threadIndex = (blockIdx.x * blockDim.x) + threadIdx.x;
  
  rotateArray(sharedMemory, data, elementCount, threadIndex);
}

// ----------------------------------------- HOST OPERATIONS -----------------------------------------

// @brief Initialize the Random number generator and ensure it only initializes one time
void initializeRandomNumbers()
{
  if (initializedRNG == 0)
  {
    srand(time(NULL));
    initializedRNG = 1;
  }
}

// @brief Generates a series of random numbers for the provided array, given the number of desired numbers
//        and the maximum (exclusive) value.
//
// @param [inout] data         The data array that will contain the random numbers
// @param [   in] elementCount The number of elements to store in the data array
// @param [   in] max          The maximum random number to use (exclusive)
void generateRandomNumbers(      unsigned int* data,
                           const unsigned int  elementCount,
                           const unsigned int  max)
{
  // Check to make sure the RNG has been initialized
  if (initializedRNG == 0)
  {
    // If not, initialize the RNG
    initializeRandomNumbers();
  }
  for (unsigned int i = 0; i < elementCount; ++i)
  {
    data[i] = rand() % max;
  }
}

// @brief Host function to run the GPU algorithms
//
// @param [in] threadCount Number of threads per block
// @param [in] blockCount  Number of blocks
// @param [in] maskMode    Should the algorithm to run be the mask algorithm?
void runAlgorithm(unsigned int threadCount, unsigned int blockCount, bool maskMode)
{
  static unsigned int elementCount = threadCount * blockCount;
  
  // Declare the device array size
  static unsigned int deviceSize = sizeof(unsigned int) * elementCount;
  
  // Allocate host memory to copy to/from the GPU
  unsigned int* hostInput  = (unsigned int*)malloc(deviceSize);
  unsigned int* hostOutput = (unsigned int*)calloc(elementCount, sizeof(unsigned int));
  
  // Populate the host memory with random numbers from 0 to elementCount - 1
  generateRandomNumbers(hostInput, elementCount, elementCount);
  
  // Allocate global memory for the GPU
  unsigned int* deviceInput;
  unsigned int* deviceOutput;
  
  cudaMalloc((void**)&deviceInput , deviceSize);
  cudaMalloc((void**)&deviceOutput, deviceSize);
  
  // Initialize the device output memory to zero
  cudaMemset(deviceOutput, 0, deviceSize);
  
  // Copy the host input memory to GPU input memory
  cudaMemcpy(deviceInput,  hostInput,  deviceSize, cudaMemcpyHostToDevice);
  
    if (maskMode)
  {
    // Define the constant values for the MASK
    static unsigned int masks[2];
    
    // Mask ZERO: 00000001 00100011 01000101 01100111
    // Mask ONE : 10111111 11101010 11001101 00010110
    masks[0] = 0x01234567;
    masks[1] = 0xBFEACD16;
    
    // Copy the masks symbol from host to constant GPU memory:
    cudaMemcpyToSymbol(MASKS, masks, sizeof(unsigned int) * 2);
    
      // Execute the kernel
    maskBits<<<blockCount, threadCount>>>(deviceInput, deviceOutput);
  }
  else
  {
    swapArray<<<blockCount, threadCount>>>(deviceInput, elementCount);
  
    // Make sure the GPU has completed before copying everything over
    cudaThreadSynchronize();
  }
  
  if (maskMode)
  {
    // Copy memory from device to host for output
    cudaMemcpy(hostOutput, deviceOutput, deviceSize, cudaMemcpyDeviceToHost);
  }
  else
  {
    // Copy memory from device to host for output
    cudaMemcpy(hostOutput, deviceInput, deviceSize, cudaMemcpyDeviceToHost);
  }
  
  // Print the trimmed results (the first and last 4 values)
  for (unsigned int i = 0; i < 4; ++i)
  {
    printf("[INDEX %5u] Input: %4u   Output: %u\n", i, hostInput[i], hostOutput[i]);
  }
  
  printf("\n...Trimmed output...\n\n");
  
  for (unsigned int i = elementCount - 5; i < elementCount; ++i)
  {
    printf("[INDEX %5u] Input: %4u   Output: %u\n", i, hostInput[i], hostOutput[i]);
  }
  
  // Free the device memory
  cudaFree(deviceInput );
  cudaFree(deviceOutput);
  
  // Free the host memory
  free(hostInput);
  free(hostOutput);
  
  hostInput = NULL;
  hostOutput = NULL;
}

// @brief Display the proper program usage
void showUsage()
{
  printf("Invalid arguments provided. Please see the usage below:\n");
  printf("  module_3_jrenga2.exe <bc> <tpb>\n");
  printf("  bc  - The number of blocks to run with. Must be a positive integer.\n");
  printf("  tpb - The number of threads per blocks. Must be a positive integer.\n");
  printf("NOTE: The total number of threads (bc * tpb) must be greater than 64 \n");
  printf("      and less than 2048.\n");
  printf(" ** TERMINATING **\n");
}

// @brief Main Entry-Point
int main(int argc, char* argv[])
{
 // 1. Check the number of arguments.
  if (argc != 3)
  {
    showUsage();
    return EXIT_FAILURE;
  }

  // 2. Attempt to retrieve the integer values of the parameters
  //    (a value less than or equal to 0 is considered invalid)
  int numBlocks = atoi(argv[1]);
  if (numBlocks <= 0)
  {
    showUsage();
    return EXIT_FAILURE;
  }

  int numThreads = atoi(argv[2]);
  if (numThreads <= 0)
  {
    showUsage();
    return EXIT_FAILURE;
  }
  
  int totalThreads = numBlocks * numThreads;

  // 2.5 Check to see if the minimum number of threads has been achieved (64)
  if (totalThreads < 64 || totalThreads > 2048)
  {
    showUsage();
    return EXIT_FAILURE;
  }
  
  // Do some pre-processing to set up the random number generation
  initializedRNG = false;

  initializeRandomNumbers();
  
  printf("Swapping Algorithm (SHARED MEMORY) [BLOCKS = %2d, THREADS/BLOCK = %2d]\n", numBlocks, numThreads);
  printf("********************************************************************\n");
  
  // Run the swapping algorithm using shared memory
  runAlgorithm(numBlocks, numThreads, false);
  
  printf("Masking Algorithm (CONSTANT MEMORY) [BLOCKS = %2d, THREADS/BLOCK = %2d]\n", numBlocks, numThreads);
  printf("*********************************************************************\n");
  
  // Run the masking algorithm using constant memory
  runAlgorithm(numBlocks, numThreads, true);

  return EXIT_SUCCESS;
}

	.file	"tmpxft_0039b16b_00000000-6_module_5_jrenga2.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z11rotateArrayPjS_jj
	.type	_Z11rotateArrayPjS_jj, @function
_Z11rotateArrayPjS_jj:
.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	_Z11rotateArrayPjS_jj, .-_Z11rotateArrayPjS_jj
	.globl	_Z23initializeRandomNumbersv
	.type	_Z23initializeRandomNumbersv, @function
_Z23initializeRandomNumbersv:
.LFB2028:
	.cfi_startproc
	endbr64
	cmpl	$0, initializedRNG(%rip)
	jne	.L7
	pushq	%rax
	.cfi_def_cfa_offset 16
	xorl	%edi, %edi
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	movl	$1, initializedRNG(%rip)
	popq	%rdx
	.cfi_def_cfa_offset 8
	ret
.L7:
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z23initializeRandomNumbersv, .-_Z23initializeRandomNumbersv
	.globl	_Z21generateRandomNumbersPjjj
	.type	_Z21generateRandomNumbersPjjj, @function
_Z21generateRandomNumbersPjjj:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rdi, %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%esi, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 48
	cmpl	$0, initializedRNG(%rip)
	jne	.L12
	call	_Z23initializeRandomNumbersv
.L12:
	xorl	%ebp, %ebp
.L13:
	cmpq	%rbx, %rbp
	je	.L16
	call	rand@PLT
	xorl	%edx, %edx
	divl	%r12d
	movl	%edx, 0(%r13,%rbp,4)
	incq	%rbp
	jmp	.L13
.L16:
	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
.LFE2029:
	.size	_Z21generateRandomNumbersPjjj, .-_Z21generateRandomNumbersPjjj
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Invalid arguments provided. Please see the usage below:\n"
.LC1:
	.string	"  module_3_jrenga2.exe <bc> <tpb>\n"
.LC2:
	.string	"  bc  - The number of blocks to run with. Must be a positive integer.\n"
.LC3:
	.string	"  tpb - The number of threads per blocks. Must be a positive integer.\n"
.LC4:
	.string	"NOTE: The total number of threads (bc * tpb) must be greater than 64 \n"
.LC5:
	.string	"      and less than 2048.\n"
.LC6:
	.string	" ** TERMINATING **\n"
	.text
	.globl	_Z9showUsagev
	.type	_Z9showUsagev, @function
_Z9showUsagev:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC1(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	popq	%rdx
	.cfi_def_cfa_offset 8
	movl	$2, %edi
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2031:
	.size	_Z9showUsagev, .-_Z9showUsagev
	.globl	_Z30__device_stub__Z8maskBitsPKjPjPKjPj
	.type	_Z30__device_stub__Z8maskBitsPKjPjPKjPj, @function
_Z30__device_stub__Z8maskBitsPKjPjPKjPj:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L19
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z8maskBitsPKjPj(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L19:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z30__device_stub__Z8maskBitsPKjPjPKjPj, .-_Z30__device_stub__Z8maskBitsPKjPjPKjPj
	.globl	_Z8maskBitsPKjPj
	.type	_Z8maskBitsPKjPj, @function
_Z8maskBitsPKjPj:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z30__device_stub__Z8maskBitsPKjPjPKjPj
	.cfi_endproc
.LFE2058:
	.size	_Z8maskBitsPKjPj, .-_Z8maskBitsPKjPj
	.globl	_Z29__device_stub__Z9swapArrayPjjPjj
	.type	_Z29__device_stub__Z9swapArrayPjjPjj, @function
_Z29__device_stub__Z9swapArrayPjjPjj:
.LFB2059:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movl	%esi, 4(%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z9swapArrayPjj(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L24:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2059:
	.size	_Z29__device_stub__Z9swapArrayPjjPjj, .-_Z29__device_stub__Z9swapArrayPjjPjj
	.globl	_Z9swapArrayPjj
	.type	_Z9swapArrayPjj, @function
_Z9swapArrayPjj:
.LFB2060:
	.cfi_startproc
	endbr64
	jmp	_Z29__device_stub__Z9swapArrayPjjPjj
	.cfi_endproc
.LFE2060:
	.size	_Z9swapArrayPjj, .-_Z9swapArrayPjj
	.section	.rodata.str1.1
.LC7:
	.string	"[INDEX %5u] Input: %4u   Output: %u\n"
.LC8:
	.string	"\n...Trimmed output...\n\n"
	.text
	.globl	_Z12runAlgorithmjjb
	.type	_Z12runAlgorithmjjb, @function
_Z12runAlgorithmjjb:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%edx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%edi, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%esi, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	movb	_ZGVZ12runAlgorithmjjbE12elementCount(%rip), %al
	testb	%al, %al
	jne	.L31
	leaq	_ZGVZ12runAlgorithmjjbE12elementCount(%rip), %rbx
	movq	%rbx, %rdi
	call	__cxa_guard_acquire@PLT
	testl	%eax, %eax
	je	.L31
	movl	%r13d, %eax
	movq	%rbx, %rdi
	imull	%r12d, %eax
	movl	%eax, _ZZ12runAlgorithmjjbE12elementCount(%rip)
	call	__cxa_guard_release@PLT
.L31:
	movb	_ZGVZ12runAlgorithmjjbE10deviceSize(%rip), %al
	testb	%al, %al
	jne	.L34
	leaq	_ZGVZ12runAlgorithmjjbE10deviceSize(%rip), %rbx
	movq	%rbx, %rdi
	call	__cxa_guard_acquire@PLT
	testl	%eax, %eax
	je	.L34
	movl	_ZZ12runAlgorithmjjbE12elementCount(%rip), %eax
	movq	%rbx, %rdi
	sall	$2, %eax
	movl	%eax, _ZZ12runAlgorithmjjbE10deviceSize(%rip)
	call	__cxa_guard_release@PLT
.L34:
	movl	_ZZ12runAlgorithmjjbE10deviceSize(%rip), %edi
	call	malloc@PLT
	movl	_ZZ12runAlgorithmjjbE12elementCount(%rip), %edi
	movl	$4, %esi
	movq	%rax, %rbp
	movq	%rdi, %r15
	call	calloc@PLT
	movl	%r15d, %edx
	movl	%r15d, %esi
	movq	%rbp, %rdi
	movq	%rax, %rbx
	call	_Z21generateRandomNumbersPjjj
	movl	_ZZ12runAlgorithmjjbE10deviceSize(%rip), %esi
	movq	%rsp, %rdi
	call	cudaMalloc@PLT
	movl	_ZZ12runAlgorithmjjbE10deviceSize(%rip), %esi
	leaq	8(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	_ZZ12runAlgorithmjjbE10deviceSize(%rip), %edx
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaMemset@PLT
	movl	_ZZ12runAlgorithmjjbE10deviceSize(%rip), %edx
	movq	(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	testb	%r14b, %r14b
	je	.L36
	xorl	%ecx, %ecx
	movl	$1, %r8d
	movabsq	$-4617652973522959001, %rax
	movl	$8, %edx
	leaq	_ZZ12runAlgorithmjjbE5masks(%rip), %rsi
	leaq	_ZL5MASKS(%rip), %rdi
	movq	%rax, _ZZ12runAlgorithmjjbE5masks(%rip)
	call	cudaMemcpyToSymbol@PLT
	movl	%r13d, 28(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	%r12d, 16(%rsp)
	movq	%rax, 32(%rsp)
	movl	36(%rsp), %ecx
	movq	%rax, 20(%rsp)
	movq	28(%rsp), %rdx
	movq	16(%rsp), %rdi
	movl	24(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L37
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdi
	call	_Z30__device_stub__Z8maskBitsPKjPjPKjPj
.L37:
	movl	_ZZ12runAlgorithmjjbE10deviceSize(%rip), %edx
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	jmp	.L53
.L36:
	movabsq	$4294967297, %rax
	movl	%r13d, 28(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%rax, 32(%rsp)
	movl	36(%rsp), %ecx
	movq	%rax, 20(%rsp)
	movq	28(%rsp), %rdx
	movl	%r12d, 16(%rsp)
	movl	24(%rsp), %esi
	movq	16(%rsp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L39
	movl	_ZZ12runAlgorithmjjbE12elementCount(%rip), %esi
	movq	(%rsp), %rdi
	call	_Z29__device_stub__Z9swapArrayPjjPjj
.L39:
	call	cudaThreadSynchronize@PLT
	movl	_ZZ12runAlgorithmjjbE10deviceSize(%rip), %edx
	movq	(%rsp), %rsi
	movl	$2, %ecx
.L53:
	movq	%rbx, %rdi
	xorl	%r12d, %r12d
	leaq	.LC7(%rip), %r13
	call	cudaMemcpy@PLT
.L40:
	movl	0(%rbp,%r12,4), %ecx
	movl	(%rbx,%r12,4), %r8d
	movl	%r12d, %edx
	movq	%r13, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%r12
	call	__printf_chk@PLT
	cmpq	$4, %r12
	jne	.L40
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	_ZZ12runAlgorithmjjbE12elementCount(%rip), %eax
	leal	-5(%rax), %r12d
.L41:
	cmpl	_ZZ12runAlgorithmjjbE12elementCount(%rip), %r12d
	jnb	.L54
	movl	%r12d, %eax
	movl	%r12d, %edx
	movq	%r13, %rsi
	movl	$2, %edi
	movl	0(%rbp,%rax,4), %ecx
	movl	(%rbx,%rax,4), %r8d
	xorl	%eax, %eax
	incl	%r12d
	call	__printf_chk@PLT
	jmp	.L41
.L54:
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L43
	call	__stack_chk_fail@PLT
.L43:
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	free@PLT
	.cfi_endproc
.LFE2030:
	.size	_Z12runAlgorithmjjb, .-_Z12runAlgorithmjjb
	.section	.rodata.str1.1
.LC9:
	.string	"Swapping Algorithm (SHARED MEMORY) [BLOCKS = %2d, THREADS/BLOCK = %2d]\n"
.LC10:
	.string	"********************************************************************\n"
.LC11:
	.string	"Masking Algorithm (CONSTANT MEMORY) [BLOCKS = %2d, THREADS/BLOCK = %2d]\n"
.LC12:
	.string	"*********************************************************************\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2032:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	pushq	%r8
	.cfi_def_cfa_offset 32
	cmpl	$3, %edi
	je	.L56
.L58:
	call	_Z9showUsagev
	movl	$1, %eax
	jmp	.L55
.L56:
	movq	8(%rsi), %rdi
	movq	%rsi, %rbp
	call	atoi@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jle	.L58
	movq	16(%rbp), %rdi
	call	atoi@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	jle	.L58
	movl	%ebx, %eax
	imull	%ebp, %eax
	subl	$64, %eax
	cmpl	$1984, %eax
	ja	.L58
	xorl	%ecx, %ecx
	movl	%ecx, initializedRNG(%rip)
	call	_Z23initializeRandomNumbersv
	movl	%ebp, %ecx
	movl	%ebx, %edx
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%edx, %edx
	movl	%ebp, %esi
	movl	%ebx, %edi
	call	_Z12runAlgorithmjjb
	movl	%ebp, %ecx
	movl	%ebx, %edx
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edx
	movl	%ebp, %esi
	movl	%ebx, %edi
	call	_Z12runAlgorithmjjb
	xorl	%eax, %eax
.L55:
	popq	%rdx
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2032:
	.size	main, .-main
	.section	.rodata.str1.1
.LC13:
	.string	"_Z9swapArrayPjj"
.LC14:
	.string	"_Z8maskBitsPKjPj"
.LC15:
	.string	"MASKS"
	.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	.LC13(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z9swapArrayPjj(%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	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC14(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z8maskBitsPKjPj(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	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	.LC15(%rip), %rdx
	movl	$8, %r9d
	leaq	_ZL5MASKS(%rip), %rsi
	pushq	$1
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.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
	.local	_ZZ12runAlgorithmjjbE5masks
	.comm	_ZZ12runAlgorithmjjbE5masks,8,8
	.local	_ZGVZ12runAlgorithmjjbE10deviceSize
	.comm	_ZGVZ12runAlgorithmjjbE10deviceSize,8,8
	.local	_ZZ12runAlgorithmjjbE10deviceSize
	.comm	_ZZ12runAlgorithmjjbE10deviceSize,4,4
	.local	_ZGVZ12runAlgorithmjjbE12elementCount
	.comm	_ZGVZ12runAlgorithmjjbE12elementCount,8,8
	.local	_ZZ12runAlgorithmjjbE12elementCount
	.comm	_ZZ12runAlgorithmjjbE12elementCount,4,4
	.globl	initializedRNG
	.bss
	.align 4
	.type	initializedRNG, @object
	.size	initializedRNG, 4
initializedRNG:
	.zero	4
	.local	_ZL5MASKS
	.comm	_ZL5MASKS,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:

// Introduction to GPU Programming
// Module 05: Shared and Constant Memory
// Author   : Justin Renga
// Date     : 03/03/2017

// Bibliography (source-list):
// [1] http://cuda-programming.blogspot.com/2013/01/what-is-constant-memory-in-cuda.html
// [2] constant_memory.cu
// [3] shared_memory2.cu

// #includes

#include <hip/hip_runtime.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

#define ELEMENT_COUNT 2048

// Declare CONSTANT Memory here:
__constant__ static unsigned int MASKS[2];

// Declare static SHARED Memory here:
__shared__   unsigned int sharedMemory [ELEMENT_COUNT];

// Declare global host data here:
unsigned int initializedRNG;

// ---------------------------------------- DEVICE OPERATIONS -----------------------------------------

// @brief Perform a masking operation based on the evenness of the data
//
// @param [ in] data   An array that contains input data
// @param [out] output An array that contains the resulting data
__global__ void maskBits(const unsigned int*       data,
                               unsigned int* const output)
{
  // Compute the thread index
  const unsigned int threadIndex = (blockIdx.x * blockDim.x) + threadIdx.x;
  
  const unsigned int dataValue = data[threadIndex];
    
  // Apply the appropriate mask value and assign to the output
  output[threadIndex] = dataValue ^ MASKS[dataValue % 2];
}

// @brief Performs an array reversal
//
// @param [   in] The shared memory
// @param [inout] The device memory
// @param [   in] The number of elements
// @param [   in] The current thread index
__device__ void rotateArray(unsigned int* const data,
                            unsigned int* const deviceData,
                            unsigned int        elementCount,
                            unsigned int        threadIndex)
{
  // Get the next appropriately rotated thread index
  unsigned int rotatedIndex = elementCount - threadIndex - 1;
  
  data[threadIndex] = deviceData[rotatedIndex];
  
  __syncthreads();
  
  // Store the newly rotated memory back into global memory
  deviceData[threadIndex] = data[threadIndex];
}

// @brief A kernel function used to flip the contents of an array
__global__ void swapArray(unsigned int* data, const unsigned int elementCount)
{
  // Get the current thread index
  unsigned int threadIndex = (blockIdx.x * blockDim.x) + threadIdx.x;
  
  rotateArray(sharedMemory, data, elementCount, threadIndex);
}

// ----------------------------------------- HOST OPERATIONS -----------------------------------------

// @brief Initialize the Random number generator and ensure it only initializes one time
void initializeRandomNumbers()
{
  if (initializedRNG == 0)
  {
    srand(time(NULL));
    initializedRNG = 1;
  }
}

// @brief Generates a series of random numbers for the provided array, given the number of desired numbers
//        and the maximum (exclusive) value.
//
// @param [inout] data         The data array that will contain the random numbers
// @param [   in] elementCount The number of elements to store in the data array
// @param [   in] max          The maximum random number to use (exclusive)
void generateRandomNumbers(      unsigned int* data,
                           const unsigned int  elementCount,
                           const unsigned int  max)
{
  // Check to make sure the RNG has been initialized
  if (initializedRNG == 0)
  {
    // If not, initialize the RNG
    initializeRandomNumbers();
  }
  for (unsigned int i = 0; i < elementCount; ++i)
  {
    data[i] = rand() % max;
  }
}

// @brief Host function to run the GPU algorithms
//
// @param [in] threadCount Number of threads per block
// @param [in] blockCount  Number of blocks
// @param [in] maskMode    Should the algorithm to run be the mask algorithm?
void runAlgorithm(unsigned int threadCount, unsigned int blockCount, bool maskMode)
{
  static unsigned int elementCount = threadCount * blockCount;
  
  // Declare the device array size
  static unsigned int deviceSize = sizeof(unsigned int) * elementCount;
  
  // Allocate host memory to copy to/from the GPU
  unsigned int* hostInput  = (unsigned int*)malloc(deviceSize);
  unsigned int* hostOutput = (unsigned int*)calloc(elementCount, sizeof(unsigned int));
  
  // Populate the host memory with random numbers from 0 to elementCount - 1
  generateRandomNumbers(hostInput, elementCount, elementCount);
  
  // Allocate global memory for the GPU
  unsigned int* deviceInput;
  unsigned int* deviceOutput;
  
  hipMalloc((void**)&deviceInput , deviceSize);
  hipMalloc((void**)&deviceOutput, deviceSize);
  
  // Initialize the device output memory to zero
  hipMemset(deviceOutput, 0, deviceSize);
  
  // Copy the host input memory to GPU input memory
  hipMemcpy(deviceInput,  hostInput,  deviceSize, hipMemcpyHostToDevice);
  
    if (maskMode)
  {
    // Define the constant values for the MASK
    static unsigned int masks[2];
    
    // Mask ZERO: 00000001 00100011 01000101 01100111
    // Mask ONE : 10111111 11101010 11001101 00010110
    masks[0] = 0x01234567;
    masks[1] = 0xBFEACD16;
    
    // Copy the masks symbol from host to constant GPU memory:
    hipMemcpyToSymbol(HIP_SYMBOL(MASKS), masks, sizeof(unsigned int) * 2);
    
      // Execute the kernel
    maskBits<<<blockCount, threadCount>>>(deviceInput, deviceOutput);
  }
  else
  {
    swapArray<<<blockCount, threadCount>>>(deviceInput, elementCount);
  
    // Make sure the GPU has completed before copying everything over
    hipDeviceSynchronize();
  }
  
  if (maskMode)
  {
    // Copy memory from device to host for output
    hipMemcpy(hostOutput, deviceOutput, deviceSize, hipMemcpyDeviceToHost);
  }
  else
  {
    // Copy memory from device to host for output
    hipMemcpy(hostOutput, deviceInput, deviceSize, hipMemcpyDeviceToHost);
  }
  
  // Print the trimmed results (the first and last 4 values)
  for (unsigned int i = 0; i < 4; ++i)
  {
    printf("[INDEX %5u] Input: %4u   Output: %u\n", i, hostInput[i], hostOutput[i]);
  }
  
  printf("\n...Trimmed output...\n\n");
  
  for (unsigned int i = elementCount - 5; i < elementCount; ++i)
  {
    printf("[INDEX %5u] Input: %4u   Output: %u\n", i, hostInput[i], hostOutput[i]);
  }
  
  // Free the device memory
  hipFree(deviceInput );
  hipFree(deviceOutput);
  
  // Free the host memory
  free(hostInput);
  free(hostOutput);
  
  hostInput = NULL;
  hostOutput = NULL;
}

// @brief Display the proper program usage
void showUsage()
{
  printf("Invalid arguments provided. Please see the usage below:\n");
  printf("  module_3_jrenga2.exe <bc> <tpb>\n");
  printf("  bc  - The number of blocks to run with. Must be a positive integer.\n");
  printf("  tpb - The number of threads per blocks. Must be a positive integer.\n");
  printf("NOTE: The total number of threads (bc * tpb) must be greater than 64 \n");
  printf("      and less than 2048.\n");
  printf(" ** TERMINATING **\n");
}

// @brief Main Entry-Point
int main(int argc, char* argv[])
{
 // 1. Check the number of arguments.
  if (argc != 3)
  {
    showUsage();
    return EXIT_FAILURE;
  }

  // 2. Attempt to retrieve the integer values of the parameters
  //    (a value less than or equal to 0 is considered invalid)
  int numBlocks = atoi(argv[1]);
  if (numBlocks <= 0)
  {
    showUsage();
    return EXIT_FAILURE;
  }

  int numThreads = atoi(argv[2]);
  if (numThreads <= 0)
  {
    showUsage();
    return EXIT_FAILURE;
  }
  
  int totalThreads = numBlocks * numThreads;

  // 2.5 Check to see if the minimum number of threads has been achieved (64)
  if (totalThreads < 64 || totalThreads > 2048)
  {
    showUsage();
    return EXIT_FAILURE;
  }
  
  // Do some pre-processing to set up the random number generation
  initializedRNG = false;

  initializeRandomNumbers();
  
  printf("Swapping Algorithm (SHARED MEMORY) [BLOCKS = %2d, THREADS/BLOCK = %2d]\n", numBlocks, numThreads);
  printf("********************************************************************\n");
  
  // Run the swapping algorithm using shared memory
  runAlgorithm(numBlocks, numThreads, false);
  
  printf("Masking Algorithm (CONSTANT MEMORY) [BLOCKS = %2d, THREADS/BLOCK = %2d]\n", numBlocks, numThreads);
  printf("*********************************************************************\n");
  
  // Run the masking algorithm using constant memory
  runAlgorithm(numBlocks, numThreads, true);

  return EXIT_SUCCESS;
}

	.text
	.file	"module_5_jrenga2.hip"
	.globl	_Z23__device_stub__maskBitsPKjPj # -- Begin function _Z23__device_stub__maskBitsPKjPj
	.type	_Z23__device_stub__maskBitsPKjPj,@function
_Z23__device_stub__maskBitsPKjPj:       # @_Z23__device_stub__maskBitsPKjPj
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.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)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z8maskBitsPKjPj, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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	_Z23__device_stub__maskBitsPKjPj, .Lfunc_end0-_Z23__device_stub__maskBitsPKjPj
	.cfi_endproc
                                        # -- End function
	.globl	_Z24__device_stub__swapArrayPjj # -- Begin function _Z24__device_stub__swapArrayPjj
	.type	_Z24__device_stub__swapArrayPjj,@function
_Z24__device_stub__swapArrayPjj:        # @_Z24__device_stub__swapArrayPjj
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.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)
	leaq	4(%rsp), %rcx
	movl	%esi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%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	$_Z9swapArrayPjj, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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	_Z24__device_stub__swapArrayPjj, .Lfunc_end1-_Z24__device_stub__swapArrayPjj
	.cfi_endproc
                                        # -- End function
	.globl	_Z23initializeRandomNumbersv    # -- Begin function _Z23initializeRandomNumbersv
	.type	_Z23initializeRandomNumbersv,@function
_Z23initializeRandomNumbersv:           # @_Z23initializeRandomNumbersv
	.cfi_startproc
# %bb.0:
	cmpl	$0, initializedRNG(%rip)
	je	.LBB2_1
# %bb.2:
	retq
.LBB2_1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	movl	$1, initializedRNG(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z23initializeRandomNumbersv, .Lfunc_end2-_Z23initializeRandomNumbersv
	.cfi_endproc
                                        # -- End function
	.globl	_Z21generateRandomNumbersPjjj   # -- Begin function _Z21generateRandomNumbersPjjj
	.type	_Z21generateRandomNumbersPjjj,@function
_Z21generateRandomNumbersPjjj:          # @_Z21generateRandomNumbersPjjj
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebx
	movl	%esi, %ebp
	movq	%rdi, %r14
	cmpl	$0, initializedRNG(%rip)
	jne	.LBB3_2
# %bb.1:
	callq	_Z23initializeRandomNumbersv
.LBB3_2:
	testl	%ebp, %ebp
	je	.LBB3_5
# %bb.3:                                # %.lr.ph.preheader
	movl	%ebp, %r15d
	xorl	%r12d, %r12d
.LBB3_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorl	%edx, %edx
	divl	%ebx
	movl	%edx, (%r14,%r12,4)
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB3_4
.LBB3_5:                                # %._crit_edge
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z21generateRandomNumbersPjjj, .Lfunc_end3-_Z21generateRandomNumbersPjjj
	.cfi_endproc
                                        # -- End function
	.globl	_Z12runAlgorithmjjb             # -- Begin function _Z12runAlgorithmjjb
	.type	_Z12runAlgorithmjjb,@function
_Z12runAlgorithmjjb:                    # @_Z12runAlgorithmjjb
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %r12d
	movl	%esi, %r15d
	movl	%edi, %ebx
	movb	_ZGVZ12runAlgorithmjjbE12elementCount(%rip), %al
	testb	%al, %al
	je	.LBB4_1
.LBB4_3:
	movl	%ebx, 4(%rsp)                   # 4-byte Spill
	movb	_ZGVZ12runAlgorithmjjbE10deviceSize(%rip), %al
	testb	%al, %al
	je	.LBB4_4
.LBB4_6:
	movl	_ZZ12runAlgorithmjjbE10deviceSize(%rip), %edi
	callq	malloc
	movq	%rax, %rbx
	movl	_ZZ12runAlgorithmjjbE12elementCount(%rip), %r13d
	movl	$4, %esi
	movq	%r13, %rdi
	callq	calloc
	movq	%rax, %r14
	movq	%rbx, %rdi
	movl	%r13d, %esi
	movl	%r13d, %edx
	callq	_Z21generateRandomNumbersPjjj
	movl	_ZZ12runAlgorithmjjbE10deviceSize(%rip), %esi
	leaq	8(%rsp), %r13
	movq	%r13, %rdi
	callq	hipMalloc
	movl	_ZZ12runAlgorithmjjbE10deviceSize(%rip), %esi
	leaq	16(%rsp), %rbp
	movq	%rbp, %rdi
	callq	hipMalloc
	movq	(%rbp), %rdi
	movl	_ZZ12runAlgorithmjjbE10deviceSize(%rip), %edx
	xorl	%esi, %esi
	callq	hipMemset
	movq	(%r13), %rdi
	movl	_ZZ12runAlgorithmjjbE10deviceSize(%rip), %edx
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	testb	%r12b, %r12b
	je	.LBB4_10
# %bb.7:
	movabsq	$-4617652973522959001, %rax     # imm = 0xBFEACD1601234567
	movq	%rax, _ZZ12runAlgorithmjjbE5masks(%rip)
	movl	$_ZL5MASKS, %edi
	movl	$_ZZ12runAlgorithmjjbE5masks, %esi
	movl	$8, %edx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	movl	%r15d, %edi
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %rdi
	movl	4(%rsp), %edx                   # 4-byte Reload
	orq	%rax, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_8
# %bb.9:
	movq	8(%rsp), %rdi
	movq	16(%rsp), %rsi
	callq	_Z23__device_stub__maskBitsPKjPj
.LBB4_8:
	movq	%rbp, %r13
	jmp	.LBB4_13
.LBB4_10:
	movl	%r15d, %edi
	movabsq	$4294967296, %rax               # imm = 0x100000000
	orq	%rax, %rdi
	movl	4(%rsp), %edx                   # 4-byte Reload
	orq	%rax, %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_12
# %bb.11:
	movq	8(%rsp), %rdi
	movl	_ZZ12runAlgorithmjjbE12elementCount(%rip), %esi
	callq	_Z24__device_stub__swapArrayPjj
.LBB4_12:
	callq	hipDeviceSynchronize
.LBB4_13:
	movq	(%r13), %rsi
	movl	_ZZ12runAlgorithmjjbE10deviceSize(%rip), %edx
	movq	%r14, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	xorl	%r15d, %r15d
.LBB4_14:                               # =>This Inner Loop Header: Depth=1
	movl	(%rbx,%r15,4), %edx
	movl	(%r14,%r15,4), %ecx
	movl	$.L.str, %edi
	movl	%r15d, %esi
	xorl	%eax, %eax
	callq	printf
	incq	%r15
	cmpq	$4, %r15
	jne	.LBB4_14
# %bb.15:
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	_ZZ12runAlgorithmjjbE12elementCount(%rip), %r15d
	cmpl	$5, %r15d
	jb	.LBB4_18
# %bb.16:                               # %.lr.ph.preheader
	addl	$-5, %r15d
.LBB4_17:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	(%rbx,%r15,4), %edx
	movl	(%r14,%r15,4), %ecx
	movl	$.L.str, %edi
	movl	%r15d, %esi
	xorl	%eax, %eax
	callq	printf
	incq	%r15
	movl	_ZZ12runAlgorithmjjbE12elementCount(%rip), %eax
	cmpq	%rax, %r15
	jb	.LBB4_17
.LBB4_18:                               # %._crit_edge
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	%rbx, %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB4_1:
	.cfi_def_cfa_offset 80
	movl	$_ZGVZ12runAlgorithmjjbE12elementCount, %edi
	callq	__cxa_guard_acquire
	testl	%eax, %eax
	je	.LBB4_3
# %bb.2:
	movl	%r15d, %eax
	imull	%ebx, %eax
	movl	%eax, _ZZ12runAlgorithmjjbE12elementCount(%rip)
	movl	$_ZGVZ12runAlgorithmjjbE12elementCount, %edi
	callq	__cxa_guard_release
	jmp	.LBB4_3
.LBB4_4:
	movl	$_ZGVZ12runAlgorithmjjbE10deviceSize, %edi
	callq	__cxa_guard_acquire
	testl	%eax, %eax
	je	.LBB4_6
# %bb.5:
	movl	_ZZ12runAlgorithmjjbE12elementCount(%rip), %eax
	shll	$2, %eax
	movl	%eax, _ZZ12runAlgorithmjjbE10deviceSize(%rip)
	movl	$_ZGVZ12runAlgorithmjjbE10deviceSize, %edi
	callq	__cxa_guard_release
	jmp	.LBB4_6
.Lfunc_end4:
	.size	_Z12runAlgorithmjjb, .Lfunc_end4-_Z12runAlgorithmjjb
	.cfi_endproc
                                        # -- End function
	.globl	_Z9showUsagev                   # -- Begin function _Z9showUsagev
	.type	_Z9showUsagev,@function
_Z9showUsagev:                          # @_Z9showUsagev
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	movl	$.Lstr.5, %edi
	callq	puts@PLT
	movl	$.Lstr.6, %edi
	callq	puts@PLT
	movl	$.Lstr.7, %edi
	popq	%rax
	.cfi_def_cfa_offset 8
	jmp	puts@PLT                        # TAILCALL
.Lfunc_end5:
	.size	_Z9showUsagev, .Lfunc_end5-_Z9showUsagev
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	cmpl	$3, %edi
	jne	.LBB6_1
# %bb.2:
	movq	%rsi, %r14
	movq	8(%rsi), %rdi
	callq	atoi
	testl	%eax, %eax
	jle	.LBB6_1
# %bb.3:
	movl	%eax, %ebx
	movq	16(%r14), %rdi
	callq	atoi
	testl	%eax, %eax
	jle	.LBB6_1
# %bb.4:
	movl	%eax, %ebp
	imull	%ebx, %eax
	addl	$-2049, %eax                    # imm = 0xF7FF
	cmpl	$-1986, %eax                    # imm = 0xF83E
	ja	.LBB6_5
.LBB6_1:
	callq	_Z9showUsagev
	movl	$1, %r14d
.LBB6_6:
	movl	%r14d, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB6_5:
	.cfi_def_cfa_offset 32
	movl	$0, initializedRNG(%rip)
	callq	_Z23initializeRandomNumbersv
	xorl	%r14d, %r14d
	movl	$.L.str.9, %edi
	movl	%ebx, %esi
	movl	%ebp, %edx
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.8, %edi
	callq	puts@PLT
	movl	%ebx, %edi
	movl	%ebp, %esi
	xorl	%edx, %edx
	callq	_Z12runAlgorithmjjb
	movl	$.L.str.11, %edi
	movl	%ebx, %esi
	movl	%ebp, %edx
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.9, %edi
	callq	puts@PLT
	movl	%ebx, %edi
	movl	%ebp, %esi
	movl	$1, %edx
	callq	_Z12runAlgorithmjjb
	jmp	.LBB6_6
.Lfunc_end6:
	.size	main, .Lfunc_end6-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z8maskBitsPKjPj, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z9swapArrayPjj, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$0, 8(%rsp)
	movl	$1, (%rsp)
	movl	$_ZL5MASKS, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movl	$8, %r9d
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	callq	__hipRegisterVar
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	initializedRNG,@object          # @initializedRNG
	.bss
	.globl	initializedRNG
	.p2align	2, 0x0
initializedRNG:
	.long	0                               # 0x0
	.size	initializedRNG, 4

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

	.type	_Z9swapArrayPjj,@object         # @_Z9swapArrayPjj
	.globl	_Z9swapArrayPjj
	.p2align	3, 0x0
_Z9swapArrayPjj:
	.quad	_Z24__device_stub__swapArrayPjj
	.size	_Z9swapArrayPjj, 8

	.type	_ZZ12runAlgorithmjjbE12elementCount,@object # @_ZZ12runAlgorithmjjbE12elementCount
	.local	_ZZ12runAlgorithmjjbE12elementCount
	.comm	_ZZ12runAlgorithmjjbE12elementCount,4,4
	.type	_ZGVZ12runAlgorithmjjbE12elementCount,@object # @_ZGVZ12runAlgorithmjjbE12elementCount
	.local	_ZGVZ12runAlgorithmjjbE12elementCount
	.comm	_ZGVZ12runAlgorithmjjbE12elementCount,8,8
	.type	_ZZ12runAlgorithmjjbE10deviceSize,@object # @_ZZ12runAlgorithmjjbE10deviceSize
	.local	_ZZ12runAlgorithmjjbE10deviceSize
	.comm	_ZZ12runAlgorithmjjbE10deviceSize,4,4
	.type	_ZGVZ12runAlgorithmjjbE10deviceSize,@object # @_ZGVZ12runAlgorithmjjbE10deviceSize
	.local	_ZGVZ12runAlgorithmjjbE10deviceSize
	.comm	_ZGVZ12runAlgorithmjjbE10deviceSize,8,8
	.type	_ZZ12runAlgorithmjjbE5masks,@object # @_ZZ12runAlgorithmjjbE5masks
	.local	_ZZ12runAlgorithmjjbE5masks
	.comm	_ZZ12runAlgorithmjjbE5masks,8,4
	.type	_ZL5MASKS,@object               # @_ZL5MASKS
	.local	_ZL5MASKS
	.comm	_ZL5MASKS,8,4
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"[INDEX %5u] Input: %4u   Output: %u\n"
	.size	.L.str, 37

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Swapping Algorithm (SHARED MEMORY) [BLOCKS = %2d, THREADS/BLOCK = %2d]\n"
	.size	.L.str.9, 72

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Masking Algorithm (CONSTANT MEMORY) [BLOCKS = %2d, THREADS/BLOCK = %2d]\n"
	.size	.L.str.11, 73

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z8maskBitsPKjPj"
	.size	.L__unnamed_1, 17

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z9swapArrayPjj"
	.size	.L__unnamed_2, 16

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_ZL5MASKS"
	.size	.L__unnamed_3, 10

	.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	"\n...Trimmed output...\n"
	.size	.Lstr, 23

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Invalid arguments provided. Please see the usage below:"
	.size	.Lstr.1, 56

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"  module_3_jrenga2.exe <bc> <tpb>"
	.size	.Lstr.2, 34

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"  bc  - The number of blocks to run with. Must be a positive integer."
	.size	.Lstr.3, 70

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"  tpb - The number of threads per blocks. Must be a positive integer."
	.size	.Lstr.4, 70

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"NOTE: The total number of threads (bc * tpb) must be greater than 64 "
	.size	.Lstr.5, 70

	.type	.Lstr.6,@object                 # @str.6
.Lstr.6:
	.asciz	"      and less than 2048."
	.size	.Lstr.6, 26

	.type	.Lstr.7,@object                 # @str.7
.Lstr.7:
	.asciz	" ** TERMINATING **"
	.size	.Lstr.7, 19

	.type	.Lstr.8,@object                 # @str.8
.Lstr.8:
	.asciz	"********************************************************************"
	.size	.Lstr.8, 69

	.type	.Lstr.9,@object                 # @str.9
.Lstr.9:
	.asciz	"*********************************************************************"
	.size	.Lstr.9, 70

	.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 _Z23__device_stub__maskBitsPKjPj
	.addrsig_sym _Z24__device_stub__swapArrayPjj
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z8maskBitsPKjPj
	.addrsig_sym _Z9swapArrayPjj
	.addrsig_sym _ZGVZ12runAlgorithmjjbE12elementCount
	.addrsig_sym _ZGVZ12runAlgorithmjjbE10deviceSize
	.addrsig_sym _ZZ12runAlgorithmjjbE5masks
	.addrsig_sym _ZL5MASKS
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z8maskBitsPKjPj        ; -- Begin function _Z8maskBitsPKjPj
	.globl	_Z8maskBitsPKjPj
	.p2align	8
	.type	_Z8maskBitsPKjPj,@function
_Z8maskBitsPKjPj:                       ; @_Z8maskBitsPKjPj
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_mov_b32_e32 v2, 0
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v1, vcc_lo
	s_getpc_b64 s[0:1]
	s_add_u32 s0, s0, _ZL5MASKS@gotpcrel32@lo+4
	s_addc_u32 s1, s1, _ZL5MASKS@gotpcrel32@hi+12
	v_add_co_u32 v0, vcc_lo, s2, v0
	global_load_b32 v2, v[2:3], off
	s_load_b64 s[0:1], s[0:1], 0x0
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	s_waitcnt vmcnt(0)
	v_and_b32_e32 v3, 1, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_lshlrev_b32_e32 v3, 2, v3
	s_waitcnt lgkmcnt(0)
	global_load_b32 v3, v3, s[0:1]
	s_waitcnt vmcnt(0)
	v_xor_b32_e32 v2, v3, v2
	global_store_b32 v[0:1], v2, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z8maskBitsPKjPj
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 4
		.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	_Z8maskBitsPKjPj, .Lfunc_end0-_Z8maskBitsPKjPj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 176
; NumSgprs: 18
; NumVgprs: 4
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 4
; 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
	.protected	_Z9swapArrayPjj         ; -- Begin function _Z9swapArrayPjj
	.globl	_Z9swapArrayPjj
	.p2align	8
	.type	_Z9swapArrayPjj,@function
_Z9swapArrayPjj:                        ; @_Z9swapArrayPjj
; %bb.0:
	s_clause 0x2
	s_load_b32 s2, s[0:1], 0x1c
	s_load_b32 s3, s[0:1], 0x8
	s_load_b64 s[0:1], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	v_mov_b32_e32 v3, 0
	v_xad_u32 v2, v1, -1, s3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[4:5], 2, v[2:3]
	v_lshlrev_b32_e32 v2, 2, v1
	v_add_co_u32 v4, vcc_lo, s0, v4
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v5, vcc_lo
	global_load_b32 v0, v[4:5], off
	s_waitcnt vmcnt(0)
	ds_store_b32 v2, v0
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	ds_load_b32 v4, v2
	v_mov_b32_e32 v2, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_add_co_u32 v0, vcc_lo, s0, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_waitcnt lgkmcnt(0)
	global_store_b32 v[0:1], v4, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z9swapArrayPjj
		.amdhsa_group_segment_fixed_size 8192
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.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 6
		.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_end1:
	.size	_Z9swapArrayPjj, .Lfunc_end1-_Z9swapArrayPjj
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 196
; NumSgprs: 18
; NumVgprs: 6
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 8192 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 6
; 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	_ZL5MASKS,@object               ; @_ZL5MASKS
	.section	.bss,"aw",@nobits
	.globl	_ZL5MASKS
	.p2align	2, 0x0
_ZL5MASKS:
	.zero	8
	.size	_ZL5MASKS, 8

	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.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 _ZL5MASKS
	.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:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z8maskBitsPKjPj
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z8maskBitsPKjPj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     4
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 8192
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z9swapArrayPjj
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z9swapArrayPjj.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     6
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
