#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <cuda.h>
#include <curand.h>
#include <curand_kernel.h>

const int SWEEPS = 100;

void printArray(int* arr, int size) {
	for (int i = 0; i < size; i++) {
		printf("%d ", arr[i]);
	}
	printf("\n");
}

int getSize(FILE* fptr) {
	int size = 0;
	int temp;
	while (fscanf(fptr, "%d", &temp) == 1) {
		size++;
	}
	return size;
}

void getArray(FILE* fptr, int* arr) {
	int i = 0;
	while (fscanf(fptr, "%d", &arr[i]) == 1) {
		i++;
	}
}

// CUDA kernel for performing Ising Annealing in parallel
__global__ void isingAnnealingStep(int* d_flat, int* d_places, int* d_state, int* count, int vertices, int N){
    *count = N;
    int vertex = blockDim.x*blockIdx.x + threadIdx.x;
    if(vertex < vertices){
        int sigmaI = d_state[vertex];
        int H = 0;
        for (int i = d_places[vertex]; i < d_places[vertex + 1]; i += 2) {
            int sigmaJ = d_state[d_flat[i]];
            int J = d_flat[i + 1];
            H -= (J * sigmaI * sigmaJ);
        }
        __syncthreads();
        curandState_t random;
        curand_init(0, 0, 0, &random);
        int s = H / sigmaI;
        if (s > 0) {
            d_state[vertex] = -1;
        }
        else if (s < 0) {
            d_state[vertex] = 1;
        }
        else {
            d_state[vertex] = 1 - 2 * (curand(&random) % 2);
        }
        __syncthreads();
        curand_init(0, 0, 0, &random);
        if(*count > 0){
            int index = curand(&random) % vertices;
            if (d_state[index] == 1) {
                d_state[index] = -1;
            }
            else {
                d_state[index] = 1;
            }
            *count--;
        } 
    }
}

// utility function to compute Hamiltonian given a vertex
// ***not used in the parallel implementation***
int computeHamiltonian(int* flat, int* places, int* state, int vertex) {
	int sigmaI = state[vertex];
	int H = 0;
	for (int i = places[vertex]; i < places[vertex + 1]; i += 2) {
		int sigmaJ = state[flat[i]];
		int J = flat[i + 1];
		H -= (J * sigmaI * sigmaJ);
	}
	return H;
}


int main(){
	FILE* fptr;

	// load array $flat 
	fptr = fopen("flat.txt", "r");
	if (fptr == NULL)
	{
		printf("Error!");
		return -1;
	}
	// get number of integers for dynamic memory allocation on host
	int fsize = getSize(fptr);
	printf("Number of integers present in flat.txt: %d\n", fsize);

	// read values in text file to array $flat
	int* flat = (int*)malloc(sizeof(int) * fsize);
	fseek(fptr, 0, SEEK_SET);
	getArray(fptr, flat);

	//printArray(flat, fsize);
	fclose(fptr);

	/**********/

	// load array $places
	fptr = fopen("places.txt", "r");
	if (fptr == NULL)
	{
		printf("Error!");
		return -1;
	}
	// get number of integers for dynamic memory allocation on host
	int psize = getSize(fptr);
	printf("Number of integers present in places.txt: %d\n", psize);

	// read values in text file to array $places
	int* places = (int*)malloc(sizeof(int) * psize);
	fseek(fptr, 0, SEEK_SET);
	getArray(fptr, places);

	//printArray(places, psize);
	fclose(fptr);

	/**********/

	int vertices = psize - 1;
	int* state = (int*)malloc(sizeof(int) * vertices);
    printf("Number of vertices: %d\n", vertices);

	// initialize states randomly
	for (int i = 0; i < vertices; ++i) {
		state[i] = 1 - 2 * (rand() % 2);
	}

    double initial_energy = 0;
	for (int i = 0; i < vertices; i++) {
		int H = computeHamiltonian(flat, places, state, i);
		initial_energy += H;
	}
	printf("Initial energy: %f\n", initial_energy / 2);

    // allocate memory on device
    int* d_flat; 
    int* d_places;
    int* d_state;
    int* count;
    cudaMalloc((void**)&count, sizeof(int));
    cudaMalloc((void**)&d_flat, fsize * sizeof(int));
    cudaMalloc((void**)&d_places, psize*sizeof(int));
    cudaMalloc((void**)&d_state, vertices*sizeof(int));

    cudaMemcpy(d_flat, flat, fsize*sizeof(int), cudaMemcpyHostToDevice);
    cudaMemcpy(d_places, places, psize*sizeof(int), cudaMemcpyHostToDevice);
    cudaMemcpy(d_state, state, vertices*sizeof(int), cudaMemcpyHostToDevice);

    int threads = 1024;
    int blocks = (vertices / 1024) + 1;
    int N = vertices*0.75;
    clock_t begin = clock();
	for (int i = 0; i < SWEEPS; i++) {
        isingAnnealingStep<<<blocks, threads>>>(d_flat, d_places, d_state, count, vertices, N);
        //cudaDeviceSynchronize();
        N *= 0.9;
    }
    clock_t end = clock();
    double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;

    cudaMemcpy(flat, d_flat, fsize*sizeof(int), cudaMemcpyDeviceToHost);
    cudaMemcpy(places, d_places, psize*sizeof(int), cudaMemcpyDeviceToHost);
    cudaMemcpy(state, d_state, vertices*sizeof(int), cudaMemcpyDeviceToHost);

    double final_energy = 0;
	for (int i = 0; i < vertices; i++) {
		int H = computeHamiltonian(flat, places, state, i);
		final_energy += H;
	}
	printf("Final energy: %f\n", final_energy / 2);

    printf("Time taken for parallel Ising Annealing: %f seconds\n", time_spent);

    // store results in txt files
    // $time_spent $initial_energy $final_energy 
    printf("Storing parallel code's results in results.txt...\n");
    fptr = fopen("results.txt", "a");
    fprintf(fptr, "Parallel\t%d\t%f\t%f\t%f\n", vertices, time_spent, initial_energy, final_energy);
    fclose(fptr);
    printf("Finished writing to results.txt\n");

	// free dynamic memory on host and device
	free(flat);
	free(places);
	free(state);
    cudaFree(d_flat);
    cudaFree(d_places);
    cudaFree(d_state);
    
	return 0;
}
	.file	"tmpxft_0038ad0e_00000000-6_ising_annealing_parallel.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2248:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2248:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d "
.LC1:
	.string	"\n"
	.text
	.globl	_Z10printArrayPii
	.type	_Z10printArrayPii, @function
_Z10printArrayPii:
.LFB2241:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC0(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	xorl	%ebx, %ebx
	pushq	%rcx
	.cfi_def_cfa_offset 48
.L3:
	cmpl	%ebx, %ebp
	jle	.L7
	movl	(%r12,%rbx,4), %edx
	movq	%r13, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incq	%rbx
	call	__printf_chk@PLT
	jmp	.L3
.L7:
	popq	%rdx
	.cfi_def_cfa_offset 40
	leaq	.LC1(%rip), %rsi
	popq	%rbx
	.cfi_def_cfa_offset 32
	movl	$2, %edi
	popq	%rbp
	.cfi_def_cfa_offset 24
	xorl	%eax, %eax
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2241:
	.size	_Z10printArrayPii, .-_Z10printArrayPii
	.section	.rodata.str1.1
.LC2:
	.string	"%d"
	.text
	.globl	_Z7getSizeP8_IO_FILE
	.type	_Z7getSizeP8_IO_FILE, @function
_Z7getSizeP8_IO_FILE:
.LFB2242:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC2(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
.L9:
	xorl	%eax, %eax
	leaq	4(%rsp), %rdx
	movq	%r12, %rsi
	movq	%rbp, %rdi
	call	__isoc23_fscanf@PLT
	decl	%eax
	jne	.L13
	incl	%ebx
	jmp	.L9
.L13:
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	movl	%ebx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2242:
	.size	_Z7getSizeP8_IO_FILE, .-_Z7getSizeP8_IO_FILE
	.globl	_Z8getArrayP8_IO_FILEPi
	.type	_Z8getArrayP8_IO_FILEPi, @function
_Z8getArrayP8_IO_FILEPi:
.LFB2243:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC2(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rsi, %rbx
.L15:
	movq	%rbx, %rdx
	xorl	%eax, %eax
	movq	%r12, %rsi
	movq	%rbp, %rdi
	call	__isoc23_fscanf@PLT
	addq	$4, %rbx
	decl	%eax
	je	.L15
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2243:
	.size	_Z8getArrayP8_IO_FILEPi, .-_Z8getArrayP8_IO_FILEPi
	.globl	_Z18computeHamiltonianPiS_S_i
	.type	_Z18computeHamiltonianPiS_S_i, @function
_Z18computeHamiltonianPiS_S_i:
.LFB2244:
	.cfi_startproc
	endbr64
	movslq	%ecx, %rcx
	movl	(%rdx,%rcx,4), %r9d
	movl	4(%rsi,%rcx,4), %r8d
	movslq	(%rsi,%rcx,4), %rax
	xorl	%ecx, %ecx
.L20:
	cmpl	%eax, %r8d
	jle	.L22
	movslq	(%rdi,%rax,4), %r10
	movl	4(%rdi,%rax,4), %esi
	addq	$2, %rax
	imull	%r9d, %esi
	imull	(%rdx,%r10,4), %esi
	subl	%esi, %ecx
	jmp	.L20
.L22:
	movl	%ecx, %eax
	ret
	.cfi_endproc
.LFE2244:
	.size	_Z18computeHamiltonianPiS_S_i, .-_Z18computeHamiltonianPiS_S_i
	.globl	_Z46__device_stub__Z18isingAnnealingStepPiS_S_S_iiPiS_S_S_ii
	.type	_Z46__device_stub__Z18isingAnnealingStepPiS_S_S_iiPiS_S_S_ii, @function
_Z46__device_stub__Z18isingAnnealingStepPiS_S_S_iiPiS_S_S_ii:
.LFB2270:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 40(%rsp)
	leaq	72(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 24(%rsp)
	leaq	56(%rsp), %rdx
	movq	%rcx, 16(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 12(%rsp)
	movl	%r9d, 8(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z18isingAnnealingStepPiS_S_S_ii(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L23:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L25
	call	__stack_chk_fail@PLT
.L25:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2270:
	.size	_Z46__device_stub__Z18isingAnnealingStepPiS_S_S_iiPiS_S_S_ii, .-_Z46__device_stub__Z18isingAnnealingStepPiS_S_S_iiPiS_S_S_ii
	.globl	_Z18isingAnnealingStepPiS_S_S_ii
	.type	_Z18isingAnnealingStepPiS_S_S_ii, @function
_Z18isingAnnealingStepPiS_S_S_ii:
.LFB2271:
	.cfi_startproc
	endbr64
	jmp	_Z46__device_stub__Z18isingAnnealingStepPiS_S_S_iiPiS_S_S_ii
	.cfi_endproc
.LFE2271:
	.size	_Z18isingAnnealingStepPiS_S_S_ii, .-_Z18isingAnnealingStepPiS_S_S_ii
	.section	.rodata.str1.1
.LC4:
	.string	"r"
.LC5:
	.string	"flat.txt"
.LC6:
	.string	"Error!"
.LC7:
	.string	"Number of integers present in flat.txt: %d\n"
.LC8:
	.string	"places.txt"
.LC9:
	.string	"Number of integers present in places.txt: %d\n"
.LC10:
	.string	"Number of vertices: %d\n"
.LC12:
	.string	"Initial energy: %f\n"
.LC16:
	.string	"Final energy: %f\n"
.LC17:
	.string	"Time taken for parallel Ising Annealing: %f seconds\n"
.LC18:
	.string	"Storing parallel code's results in results.txt...\n"
.LC19:
	.string	"a"
.LC20:
	.string	"results.txt"
.LC21:
	.string	"Parallel\t%d\t%f\t%f\t%f\n"
.LC22:
	.string	"Finished writing to results.txt\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2245:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	.LC5(%rip), %rdi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	.LC4(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r12, %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L29
.L31:
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	orl	$-1, %eax
	jmp	.L28
.L29:
	movq	%rax, %rdi
	movq	%rax, %rbx
	call	_Z7getSizeP8_IO_FILE
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	movslq	%eax, %rbp
	xorl	%eax, %eax
	movl	%ebp, %edx
	call	__printf_chk@PLT
	leaq	0(,%rbp,4), %rax
	movq	%rax, %rdi
	movq	%rax, 24(%rsp)
	call	malloc@PLT
	xorl	%edx, %edx
	xorl	%esi, %esi
	movq	%rbx, %rdi
	movq	%rax, (%rsp)
	call	fseek@PLT
	movq	(%rsp), %rsi
	movq	%rbx, %rdi
	call	_Z8getArrayP8_IO_FILEPi
	movq	%rbx, %rdi
	call	fclose@PLT
	movq	%r12, %rsi
	leaq	.LC8(%rip), %rdi
	call	fopen@PLT
	movq	%rax, %rbp
	testq	%rax, %rax
	je	.L31
	movq	%rax, %rdi
	xorl	%r13d, %r13d
	movl	$2, %r12d
	call	_Z7getSizeP8_IO_FILE
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	movl	%eax, %edx
	movl	%eax, %ebx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movslq	%ebx, %rax
	decl	%ebx
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	xorl	%edx, %edx
	movq	%rbp, %rdi
	xorl	%esi, %esi
	movq	%rax, 8(%rsp)
	call	fseek@PLT
	movq	8(%rsp), %rsi
	movq	%rbp, %rdi
	call	_Z8getArrayP8_IO_FILEPi
	movq	%rbp, %rdi
	call	fclose@PLT
	movq	16(%rsp), %rax
	subq	$4, %rax
	movq	%rax, %rdi
	movq	%rax, 32(%rsp)
	call	malloc@PLT
	movl	%ebx, %edx
	movl	$2, %edi
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rbp
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L32:
	cmpl	%r13d, %ebx
	jle	.L46
	call	rand@PLT
	cltd
	idivl	%r12d
	movl	$1, %eax
	addl	%edx, %edx
	subl	%edx, %eax
	movl	%eax, 0(%rbp,%r13,4)
	incq	%r13
	jmp	.L32
.L46:
	movq	$0x000000000, 40(%rsp)
	xorl	%r11d, %r11d
.L34:
	cmpl	%ebx, %r11d
	jge	.L47
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	%r11d, %ecx
	movq	%rbp, %rdx
	incl	%r11d
	call	_Z18computeHamiltonianPiS_S_i
	cvtsi2sdl	%eax, %xmm0
	addsd	40(%rsp), %xmm0
	movsd	%xmm0, 40(%rsp)
	jmp	.L34
.L47:
	movsd	.LC11(%rip), %xmm0
	mulsd	40(%rsp), %xmm0
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC12(%rip), %rsi
	movl	$100, %r13d
	call	__printf_chk@PLT
	leaq	72(%rsp), %rdi
	movl	$4, %esi
	call	cudaMalloc@PLT
	movq	24(%rsp), %rsi
	leaq	48(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	16(%rsp), %rsi
	leaq	56(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	32(%rsp), %rsi
	leaq	64(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	24(%rsp), %rdx
	movq	(%rsp), %rsi
	movl	$1, %ecx
	movq	48(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdx
	movq	8(%rsp), %rsi
	movl	$1, %ecx
	movq	56(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rdx
	movq	64(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%ebx, %eax
	cvtsi2sdl	%ebx, %xmm0
	movl	$1024, %ecx
	mulsd	.LC13(%rip), %xmm0
	cltd
	idivl	%ecx
	cvttsd2sil	%xmm0, %r14d
	leal	1(%rax), %r15d
	call	clock@PLT
	movq	%rax, %r12
.L37:
	movl	%r15d, 80(%rsp)
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	salq	$10, %rdx
	movl	$1, %ecx
	movq	%rax, 84(%rsp)
	movq	80(%rsp), %rdi
	movl	88(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L36
	movq	72(%rsp), %rcx
	movq	64(%rsp), %rdx
	movl	%r14d, %r9d
	movl	%ebx, %r8d
	movq	56(%rsp), %rsi
	movq	48(%rsp), %rdi
	call	_Z46__device_stub__Z18isingAnnealingStepPiS_S_S_iiPiS_S_S_ii
.L36:
	cvtsi2sdl	%r14d, %xmm0
	mulsd	.LC14(%rip), %xmm0
	cvttsd2sil	%xmm0, %r14d
	decl	%r13d
	jne	.L37
	call	clock@PLT
	movq	24(%rsp), %rdx
	movq	48(%rsp), %rsi
	movl	$2, %ecx
	movq	(%rsp), %rdi
	subq	%r12, %rax
	cvtsi2sdq	%rax, %xmm0
	divsd	.LC15(%rip), %xmm0
	movq	%xmm0, %r12
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdx
	movq	56(%rsp), %rsi
	movl	$2, %ecx
	movq	8(%rsp), %rdi
	call	cudaMemcpy@PLT
	movq	32(%rsp), %rdx
	movq	64(%rsp), %rsi
	movq	%rbp, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	xorl	%r11d, %r11d
	xorps	%xmm2, %xmm2
.L38:
	cmpl	%ebx, %r11d
	jge	.L48
	movq	8(%rsp), %rsi
	movq	(%rsp), %rdi
	movl	%r11d, %ecx
	movq	%rbp, %rdx
	incl	%r11d
	call	_Z18computeHamiltonianPiS_S_i
	cvtsi2sdl	%eax, %xmm0
	addsd	%xmm0, %xmm2
	jmp	.L38
.L48:
	movsd	.LC11(%rip), %xmm0
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movsd	%xmm2, 16(%rsp)
	mulsd	%xmm2, %xmm0
	call	__printf_chk@PLT
	movq	%r12, %xmm0
	leaq	.LC17(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	.LC18(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC19(%rip), %rsi
	leaq	.LC20(%rip), %rdi
	call	fopen@PLT
	movsd	16(%rsp), %xmm2
	movsd	40(%rsp), %xmm1
	movl	%ebx, %ecx
	movq	%r12, %xmm0
	movl	$2, %esi
	movq	%rax, %rdi
	movq	%rax, %r13
	leaq	.LC21(%rip), %rdx
	movb	$3, %al
	call	__fprintf_chk@PLT
	movq	%r13, %rdi
	call	fclose@PLT
	leaq	.LC22(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	(%rsp), %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%eax, %eax
.L28:
	movq	104(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L40
	call	__stack_chk_fail@PLT
.L40:
	addq	$120, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2245:
	.size	main, .-main
	.section	.rodata.str1.1
.LC23:
	.string	"_Z18isingAnnealingStepPiS_S_S_ii"
.LC24:
	.string	"precalc_xorwow_matrix"
.LC25:
	.string	"precalc_xorwow_offset_matrix"
.LC26:
	.string	"mrg32k3aM1"
.LC27:
	.string	"mrg32k3aM2"
.LC28:
	.string	"mrg32k3aM1SubSeq"
.LC29:
	.string	"mrg32k3aM2SubSeq"
.LC30:
	.string	"mrg32k3aM1Seq"
.LC31:
	.string	"mrg32k3aM2Seq"
.LC32:
	.string	"__cr_lgamma_table"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2273:
	.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	.LC23(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z18isingAnnealingStepPiS_S_S_ii(%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	.LC24(%rip), %rdx
	movl	$102400, %r9d
	leaq	_ZL21precalc_xorwow_matrix(%rip), %rsi
	pushq	$0
	.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	$0
	.cfi_def_cfa_offset 32
	leaq	.LC25(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$102400, %r9d
	leaq	_ZL28precalc_xorwow_offset_matrix(%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	$0
	.cfi_def_cfa_offset 32
	leaq	.LC26(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL10mrg32k3aM1(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC27(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL10mrg32k3aM2(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC28(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2016, %r9d
	leaq	_ZL16mrg32k3aM1SubSeq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r11
	.cfi_def_cfa_offset 24
	popq	%rax
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC29(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2016, %r9d
	leaq	_ZL16mrg32k3aM2SubSeq(%rip), %rsi
	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	$0
	.cfi_def_cfa_offset 32
	leaq	.LC30(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL13mrg32k3aM1Seq(%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	$0
	.cfi_def_cfa_offset 32
	leaq	.LC31(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$2304, %r9d
	leaq	_ZL13mrg32k3aM2Seq(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC32(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movl	$72, %r9d
	movq	%rdx, %rcx
	leaq	_ZL17__cr_lgamma_table(%rip), %rsi
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.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
.LFE2273:
	.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	_ZL17__cr_lgamma_table
	.comm	_ZL17__cr_lgamma_table,72,32
	.local	_ZL13mrg32k3aM2Seq
	.comm	_ZL13mrg32k3aM2Seq,2304,32
	.local	_ZL13mrg32k3aM1Seq
	.comm	_ZL13mrg32k3aM1Seq,2304,32
	.local	_ZL16mrg32k3aM2SubSeq
	.comm	_ZL16mrg32k3aM2SubSeq,2016,32
	.local	_ZL16mrg32k3aM1SubSeq
	.comm	_ZL16mrg32k3aM1SubSeq,2016,32
	.local	_ZL10mrg32k3aM2
	.comm	_ZL10mrg32k3aM2,2304,32
	.local	_ZL10mrg32k3aM1
	.comm	_ZL10mrg32k3aM1,2304,32
	.local	_ZL28precalc_xorwow_offset_matrix
	.comm	_ZL28precalc_xorwow_offset_matrix,102400,32
	.local	_ZL21precalc_xorwow_matrix
	.comm	_ZL21precalc_xorwow_matrix,102400,32
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC11:
	.long	0
	.long	1071644672
	.align 8
.LC13:
	.long	0
	.long	1072168960
	.align 8
.LC14:
	.long	-858993459
	.long	1072483532
	.align 8
.LC15:
	.long	0
	.long	1093567616
	.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 <time.h>
#include <hip/hip_runtime.h>
#include <hiprand/hiprand.h>
#include <hiprand/hiprand_kernel.h>

const int SWEEPS = 100;

void printArray(int* arr, int size) {
	for (int i = 0; i < size; i++) {
		printf("%d ", arr[i]);
	}
	printf("\n");
}

int getSize(FILE* fptr) {
	int size = 0;
	int temp;
	while (fscanf(fptr, "%d", &temp) == 1) {
		size++;
	}
	return size;
}

void getArray(FILE* fptr, int* arr) {
	int i = 0;
	while (fscanf(fptr, "%d", &arr[i]) == 1) {
		i++;
	}
}

// CUDA kernel for performing Ising Annealing in parallel
__global__ void isingAnnealingStep(int* d_flat, int* d_places, int* d_state, int* count, int vertices, int N){
    *count = N;
    int vertex = blockDim.x*blockIdx.x + threadIdx.x;
    if(vertex < vertices){
        int sigmaI = d_state[vertex];
        int H = 0;
        for (int i = d_places[vertex]; i < d_places[vertex + 1]; i += 2) {
            int sigmaJ = d_state[d_flat[i]];
            int J = d_flat[i + 1];
            H -= (J * sigmaI * sigmaJ);
        }
        __syncthreads();
        hiprandState_t random;
        hiprand_init(0, 0, 0, &random);
        int s = H / sigmaI;
        if (s > 0) {
            d_state[vertex] = -1;
        }
        else if (s < 0) {
            d_state[vertex] = 1;
        }
        else {
            d_state[vertex] = 1 - 2 * (hiprand(&random) % 2);
        }
        __syncthreads();
        hiprand_init(0, 0, 0, &random);
        if(*count > 0){
            int index = hiprand(&random) % vertices;
            if (d_state[index] == 1) {
                d_state[index] = -1;
            }
            else {
                d_state[index] = 1;
            }
            *count--;
        } 
    }
}

// utility function to compute Hamiltonian given a vertex
// ***not used in the parallel implementation***
int computeHamiltonian(int* flat, int* places, int* state, int vertex) {
	int sigmaI = state[vertex];
	int H = 0;
	for (int i = places[vertex]; i < places[vertex + 1]; i += 2) {
		int sigmaJ = state[flat[i]];
		int J = flat[i + 1];
		H -= (J * sigmaI * sigmaJ);
	}
	return H;
}


int main(){
	FILE* fptr;

	// load array $flat 
	fptr = fopen("flat.txt", "r");
	if (fptr == NULL)
	{
		printf("Error!");
		return -1;
	}
	// get number of integers for dynamic memory allocation on host
	int fsize = getSize(fptr);
	printf("Number of integers present in flat.txt: %d\n", fsize);

	// read values in text file to array $flat
	int* flat = (int*)malloc(sizeof(int) * fsize);
	fseek(fptr, 0, SEEK_SET);
	getArray(fptr, flat);

	//printArray(flat, fsize);
	fclose(fptr);

	/**********/

	// load array $places
	fptr = fopen("places.txt", "r");
	if (fptr == NULL)
	{
		printf("Error!");
		return -1;
	}
	// get number of integers for dynamic memory allocation on host
	int psize = getSize(fptr);
	printf("Number of integers present in places.txt: %d\n", psize);

	// read values in text file to array $places
	int* places = (int*)malloc(sizeof(int) * psize);
	fseek(fptr, 0, SEEK_SET);
	getArray(fptr, places);

	//printArray(places, psize);
	fclose(fptr);

	/**********/

	int vertices = psize - 1;
	int* state = (int*)malloc(sizeof(int) * vertices);
    printf("Number of vertices: %d\n", vertices);

	// initialize states randomly
	for (int i = 0; i < vertices; ++i) {
		state[i] = 1 - 2 * (rand() % 2);
	}

    double initial_energy = 0;
	for (int i = 0; i < vertices; i++) {
		int H = computeHamiltonian(flat, places, state, i);
		initial_energy += H;
	}
	printf("Initial energy: %f\n", initial_energy / 2);

    // allocate memory on device
    int* d_flat; 
    int* d_places;
    int* d_state;
    int* count;
    hipMalloc((void**)&count, sizeof(int));
    hipMalloc((void**)&d_flat, fsize * sizeof(int));
    hipMalloc((void**)&d_places, psize*sizeof(int));
    hipMalloc((void**)&d_state, vertices*sizeof(int));

    hipMemcpy(d_flat, flat, fsize*sizeof(int), hipMemcpyHostToDevice);
    hipMemcpy(d_places, places, psize*sizeof(int), hipMemcpyHostToDevice);
    hipMemcpy(d_state, state, vertices*sizeof(int), hipMemcpyHostToDevice);

    int threads = 1024;
    int blocks = (vertices / 1024) + 1;
    int N = vertices*0.75;
    clock_t begin = clock();
	for (int i = 0; i < SWEEPS; i++) {
        isingAnnealingStep<<<blocks, threads>>>(d_flat, d_places, d_state, count, vertices, N);
        //cudaDeviceSynchronize();
        N *= 0.9;
    }
    clock_t end = clock();
    double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;

    hipMemcpy(flat, d_flat, fsize*sizeof(int), hipMemcpyDeviceToHost);
    hipMemcpy(places, d_places, psize*sizeof(int), hipMemcpyDeviceToHost);
    hipMemcpy(state, d_state, vertices*sizeof(int), hipMemcpyDeviceToHost);

    double final_energy = 0;
	for (int i = 0; i < vertices; i++) {
		int H = computeHamiltonian(flat, places, state, i);
		final_energy += H;
	}
	printf("Final energy: %f\n", final_energy / 2);

    printf("Time taken for parallel Ising Annealing: %f seconds\n", time_spent);

    // store results in txt files
    // $time_spent $initial_energy $final_energy 
    printf("Storing parallel code's results in results.txt...\n");
    fptr = fopen("results.txt", "a");
    fprintf(fptr, "Parallel\t%d\t%f\t%f\t%f\n", vertices, time_spent, initial_energy, final_energy);
    fclose(fptr);
    printf("Finished writing to results.txt\n");

	// free dynamic memory on host and device
	free(flat);
	free(places);
	free(state);
    hipFree(d_flat);
    hipFree(d_places);
    hipFree(d_state);
    
	return 0;
}
	.text
	.file	"ising_annealing_parallel.hip"
	.globl	_Z10printArrayPii               # -- Begin function _Z10printArrayPii
	.type	_Z10printArrayPii,@function
_Z10printArrayPii:                      # @_Z10printArrayPii
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	jle	.LBB0_4
# %bb.1:                                # %.lr.ph.preheader
	pushq	%r15
	.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 %r15, -16
	movq	%rdi, %rbx
	movl	%esi, %r14d
	xorl	%r15d, %r15d
.LBB0_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	(%rbx,%r15,4), %esi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r15
	cmpq	%r15, %r14
	jne	.LBB0_2
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
.LBB0_4:                                # %._crit_edge
	movl	$10, %edi
	jmp	putchar@PLT                     # TAILCALL
.Lfunc_end0:
	.size	_Z10printArrayPii, .Lfunc_end0-_Z10printArrayPii
	.cfi_endproc
                                        # -- End function
	.globl	_Z7getSizeP8_IO_FILE            # -- Begin function _Z7getSizeP8_IO_FILE
	.type	_Z7getSizeP8_IO_FILE,@function
_Z7getSizeP8_IO_FILE:                   # @_Z7getSizeP8_IO_FILE
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rdi, %r14
	movl	$-1, %ebx
	leaq	12(%rsp), %r15
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str.2, %esi
	movq	%r14, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	incl	%ebx
	cmpl	$1, %eax
	je	.LBB1_1
# %bb.2:
	movl	%ebx, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z7getSizeP8_IO_FILE, .Lfunc_end1-_Z7getSizeP8_IO_FILE
	.cfi_endproc
                                        # -- End function
	.globl	_Z8getArrayP8_IO_FILEPi         # -- Begin function _Z8getArrayP8_IO_FILEPi
	.type	_Z8getArrayP8_IO_FILEPi,@function
_Z8getArrayP8_IO_FILEPi:                # @_Z8getArrayP8_IO_FILEPi
	.cfi_startproc
# %bb.0:
	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
	movq	%rdi, %r14
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str.2, %esi
	movq	%r14, %rdi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	addq	$4, %rbx
	cmpl	$1, %eax
	je	.LBB2_1
# %bb.2:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z8getArrayP8_IO_FILEPi, .Lfunc_end2-_Z8getArrayP8_IO_FILEPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z33__device_stub__isingAnnealingStepPiS_S_S_ii # -- Begin function _Z33__device_stub__isingAnnealingStepPiS_S_S_ii
	.type	_Z33__device_stub__isingAnnealingStepPiS_S_S_ii,@function
_Z33__device_stub__isingAnnealingStepPiS_S_S_ii: # @_Z33__device_stub__isingAnnealingStepPiS_S_S_ii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	12(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	8(%rsp), %r8
	movl	%r9d, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%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	$_Z18isingAnnealingStepPiS_S_S_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z33__device_stub__isingAnnealingStepPiS_S_S_ii, .Lfunc_end3-_Z33__device_stub__isingAnnealingStepPiS_S_S_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z18computeHamiltonianPiS_S_i   # -- Begin function _Z18computeHamiltonianPiS_S_i
	.type	_Z18computeHamiltonianPiS_S_i,@function
_Z18computeHamiltonianPiS_S_i:          # @_Z18computeHamiltonianPiS_S_i
	.cfi_startproc
# %bb.0:
	movslq	%ecx, %r8
	movslq	(%rsi,%r8,4), %rcx
	movslq	4(%rsi,%r8,4), %rsi
	xorl	%eax, %eax
	cmpl	%esi, %ecx
	jge	.LBB4_3
# %bb.1:                                # %.lr.ph.preheader
	movl	(%rdx,%r8,4), %r8d
	xorl	%eax, %eax
.LBB4_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movslq	(%rdi,%rcx,4), %r9
	movl	(%rdx,%r9,4), %r9d
	imull	%r8d, %r9d
	imull	4(%rdi,%rcx,4), %r9d
	subl	%r9d, %eax
	addq	$2, %rcx
	cmpq	%rsi, %rcx
	jl	.LBB4_2
.LBB4_3:                                # %._crit_edge
	retq
.Lfunc_end4:
	.size	_Z18computeHamiltonianPiS_S_i, .Lfunc_end4-_Z18computeHamiltonianPiS_S_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI5_0:
	.quad	0x3fe0000000000000              # double 0.5
.LCPI5_1:
	.quad	0x3fe8000000000000              # double 0.75
.LCPI5_2:
	.quad	0x3feccccccccccccd              # double 0.90000000000000002
.LCPI5_3:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	$.L.str.3, %edi
	movl	$.L.str.4, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB5_1
# %bb.2:
	movq	%rax, %r14
	movq	$-4, %r12
	movl	$-1, %ebx
	leaq	16(%rsp), %r15
.LBB5_3:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str.2, %esi
	movq	%r14, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	addq	$4, %r12
	incl	%ebx
	cmpl	$1, %eax
	je	.LBB5_3
# %bb.4:                                # %_Z7getSizeP8_IO_FILE.exit
	movl	$.L.str.6, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	movq	%r12, %rdi
	callq	malloc
	movq	%rax, %rbx
	movq	%r14, %rdi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	fseek
	movq	%rbx, %r15
.LBB5_5:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str.2, %esi
	movq	%r14, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	addq	$4, %r15
	cmpl	$1, %eax
	je	.LBB5_5
# %bb.6:                                # %_Z8getArrayP8_IO_FILEPi.exit
	movq	%r14, %rdi
	callq	fclose
	movl	$.L.str.7, %edi
	movl	$.L.str.4, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB5_1
# %bb.7:
	movq	%rax, %r15
	movl	$-2, %r13d
	movq	$-4, %rbp
	leaq	16(%rsp), %r14
.LBB5_8:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str.2, %esi
	movq	%r15, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	incl	%r13d
	addq	$4, %rbp
	cmpl	$1, %eax
	je	.LBB5_8
# %bb.9:                                # %_Z7getSizeP8_IO_FILE.exit94
	movq	%r13, 32(%rsp)                  # 8-byte Spill
	leal	1(%r13), %esi
	movl	$.L.str.8, %edi
	movl	%esi, 12(%rsp)                  # 4-byte Spill
	xorl	%eax, %eax
	callq	printf
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, %r14
	movq	%r15, %rdi
	xorl	%esi, %esi
	xorl	%edx, %edx
	callq	fseek
	movq	%r14, 56(%rsp)                  # 8-byte Spill
.LBB5_10:                               # =>This Inner Loop Header: Depth=1
	movl	$.L.str.2, %esi
	movq	%r15, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	addq	$4, %r14
	cmpl	$1, %eax
	je	.LBB5_10
# %bb.11:                               # %_Z8getArrayP8_IO_FILEPi.exit97
	movq	%r15, %rdi
	callq	fclose
	leaq	-4(%rbp), %rdi
	movq	%rdi, 72(%rsp)                  # 8-byte Spill
	callq	malloc
	movq	%rax, %r13
	movl	$.L.str.9, %edi
	movq	32(%rsp), %r14                  # 8-byte Reload
	movl	%r14d, %esi
	xorl	%eax, %eax
	callq	printf
	xorpd	%xmm1, %xmm1
	movl	%r14d, %eax
	movq	%rax, 80(%rsp)                  # 8-byte Spill
	cmpl	$2, 12(%rsp)                    # 4-byte Folded Reload
	jb	.LBB5_12
# %bb.31:                               # %.lr.ph.preheader
	xorl	%r14d, %r14d
	movq	56(%rsp), %r15                  # 8-byte Reload
.LBB5_32:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	movq	80(%rsp), %r9                   # 8-byte Reload
	movl	%eax, %ecx
	shrl	$31, %ecx
	addl	%eax, %ecx
	andl	$2147483646, %ecx               # imm = 0x7FFFFFFE
	subl	%ecx, %eax
	addl	%eax, %eax
	movl	$1, %ecx
	subl	%eax, %ecx
	movl	%ecx, (%r13,%r14,4)
	incq	%r14
	cmpq	%r14, %r9
	jne	.LBB5_32
# %bb.13:                               # %.preheader
	cmpl	$2, 12(%rsp)                    # 4-byte Folded Reload
	xorpd	%xmm1, %xmm1
	jb	.LBB5_19
# %bb.14:                               # %.lr.ph114.preheader
	xorl	%eax, %eax
.LBB5_15:                               # %.lr.ph114
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_17 Depth 2
	movslq	(%r15,%rax,4), %rcx
	movslq	4(%r15,%rax,4), %rdx
	movl	$0, %esi
	cmpl	%edx, %ecx
	jge	.LBB5_18
# %bb.16:                               # %.lr.ph.preheader.i
                                        #   in Loop: Header=BB5_15 Depth=1
	movl	(%r13,%rax,4), %edi
	xorl	%esi, %esi
.LBB5_17:                               # %.lr.ph.i
                                        #   Parent Loop BB5_15 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movslq	(%rbx,%rcx,4), %r8
	movl	(%r13,%r8,4), %r8d
	imull	%edi, %r8d
	imull	4(%rbx,%rcx,4), %r8d
	subl	%r8d, %esi
	addq	$2, %rcx
	cmpq	%rdx, %rcx
	jl	.LBB5_17
.LBB5_18:                               # %_Z18computeHamiltonianPiS_S_i.exit
                                        #   in Loop: Header=BB5_15 Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2sd	%esi, %xmm0
	addsd	%xmm0, %xmm1
	incq	%rax
	cmpq	%r9, %rax
	jne	.LBB5_15
	jmp	.LBB5_19
.LBB5_1:
	movl	$.L.str.5, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$-1, %eax
	jmp	.LBB5_30
.LBB5_12:
	movq	56(%rsp), %r15                  # 8-byte Reload
.LBB5_19:                               # %._crit_edge
	movabsq	$4294967296, %rax               # imm = 0x100000000
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	movsd	.LCPI5_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movsd	%xmm1, 104(%rsp)                # 8-byte Spill
	mulsd	%xmm1, %xmm0
	movl	$.L.str.10, %edi
	movb	$1, %al
	callq	printf
	leaq	112(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	48(%rsp), %rdi
	movq	%rbp, %rsi
	callq	hipMalloc
	leaq	40(%rsp), %rdi
	movq	72(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rsi
	callq	hipMalloc
	leaq	16(%rsp), %rax
	movq	(%rax), %rdi
	movq	%rbx, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	48(%rsp), %rax
	movq	(%rax), %rdi
	movq	%r15, %rsi
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	40(%rsp), %rax
	movq	(%rax), %rdi
	movq	%r13, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	32(%rsp), %rax                  # 8-byte Reload
	leal	1023(%rax), %r14d
	testl	%eax, %eax
	cmovnsl	%eax, %r14d
	sarl	$10, %r14d
	incl	%r14d
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	mulsd	.LCPI5_1(%rip), %xmm0
	movsd	%xmm0, 88(%rsp)                 # 8-byte Spill
	callq	clock
	movsd	88(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movq	%rax, 96(%rsp)                  # 8-byte Spill
	btsq	$32, %r14
	movq	%r14, 64(%rsp)                  # 8-byte Spill
	movl	$100, %r15d
	addq	$1024, 24(%rsp)                 # 8-byte Folded Spill
                                        # imm = 0x400
.LBB5_20:                               # =>This Inner Loop Header: Depth=1
	cvttsd2si	%xmm0, %r14d
	movq	64(%rsp), %rdi                  # 8-byte Reload
	movl	$1, %esi
	movq	24(%rsp), %rdx                  # 8-byte Reload
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_22
# %bb.21:                               #   in Loop: Header=BB5_20 Depth=1
	movq	16(%rsp), %rdi
	movq	48(%rsp), %rsi
	movq	40(%rsp), %rdx
	movq	112(%rsp), %rcx
	movq	32(%rsp), %r8                   # 8-byte Reload
                                        # kill: def $r8d killed $r8d killed $r8
	movl	%r14d, %r9d
	callq	_Z33__device_stub__isingAnnealingStepPiS_S_S_ii
.LBB5_22:                               #   in Loop: Header=BB5_20 Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r14d, %xmm0
	mulsd	.LCPI5_2(%rip), %xmm0
	decl	%r15d
	jne	.LBB5_20
# %bb.23:
	callq	clock
	movq	%rax, %r14
	subq	96(%rsp), %r14                  # 8-byte Folded Reload
	movq	16(%rsp), %rsi
	movq	%rbx, %rdi
	movq	%r12, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	48(%rsp), %rsi
	movq	56(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rdi
	movq	%rbp, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	40(%rsp), %rsi
	movq	%r13, %rdi
	movq	72(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r14, %xmm0
	divsd	.LCPI5_3(%rip), %xmm0
	movsd	%xmm0, 24(%rsp)                 # 8-byte Spill
	xorpd	%xmm1, %xmm1
	cmpl	$2, 12(%rsp)                    # 4-byte Folded Reload
	movq	80(%rsp), %r9                   # 8-byte Reload
	jb	.LBB5_29
# %bb.24:                               # %.lr.ph121.preheader
	xorl	%eax, %eax
.LBB5_25:                               # %.lr.ph121
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB5_27 Depth 2
	movslq	(%r15,%rax,4), %rcx
	movslq	4(%r15,%rax,4), %rdx
	movl	$0, %esi
	cmpl	%edx, %ecx
	jge	.LBB5_28
# %bb.26:                               # %.lr.ph.preheader.i101
                                        #   in Loop: Header=BB5_25 Depth=1
	movl	(%r13,%rax,4), %edi
	xorl	%esi, %esi
.LBB5_27:                               # %.lr.ph.i102
                                        #   Parent Loop BB5_25 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movslq	(%rbx,%rcx,4), %r8
	movl	(%r13,%r8,4), %r8d
	imull	%edi, %r8d
	imull	4(%rbx,%rcx,4), %r8d
	subl	%r8d, %esi
	addq	$2, %rcx
	cmpq	%rdx, %rcx
	jl	.LBB5_27
.LBB5_28:                               # %_Z18computeHamiltonianPiS_S_i.exit106
                                        #   in Loop: Header=BB5_25 Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2sd	%esi, %xmm0
	addsd	%xmm0, %xmm1
	incq	%rax
	cmpq	%r9, %rax
	jne	.LBB5_25
.LBB5_29:                               # %._crit_edge122
	movsd	%xmm1, 64(%rsp)                 # 8-byte Spill
	movsd	.LCPI5_0(%rip), %xmm0           # xmm0 = mem[0],zero
	mulsd	%xmm1, %xmm0
	movl	$.L.str.11, %edi
	movb	$1, %al
	callq	printf
	movl	$.L.str.12, %edi
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.L.str.14, %edi
	movl	$.L.str.15, %esi
	callq	fopen
	movq	%rax, %r14
	movl	$.L.str.16, %esi
	movq	%rax, %rdi
	movq	32(%rsp), %rdx                  # 8-byte Reload
                                        # kill: def $edx killed $edx killed $rdx
	movsd	24(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movsd	104(%rsp), %xmm1                # 8-byte Reload
                                        # xmm1 = mem[0],zero
	movsd	64(%rsp), %xmm2                 # 8-byte Reload
                                        # xmm2 = mem[0],zero
	movb	$3, %al
	callq	fprintf
	movq	%r14, %rdi
	callq	fclose
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movq	%rbx, %rdi
	callq	free
	movq	%r15, %rdi
	callq	free
	movq	%r13, %rdi
	callq	free
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	48(%rsp), %rdi
	callq	hipFree
	movq	40(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
.LBB5_30:
	addq	$120, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z18isingAnnealingStepPiS_S_S_ii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__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	.LBB7_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
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%d "
	.size	.L.str, 4

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

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

	.type	.L.str.3,@object                # @.str.3
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.3:
	.asciz	"flat.txt"
	.size	.L.str.3, 9

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"r"
	.size	.L.str.4, 2

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Error!"
	.size	.L.str.5, 7

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Number of integers present in flat.txt: %d\n"
	.size	.L.str.6, 44

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"places.txt"
	.size	.L.str.7, 11

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Number of integers present in places.txt: %d\n"
	.size	.L.str.8, 46

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Number of vertices: %d\n"
	.size	.L.str.9, 24

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Initial energy: %f\n"
	.size	.L.str.10, 20

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Final energy: %f\n"
	.size	.L.str.11, 18

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Time taken for parallel Ising Annealing: %f seconds\n"
	.size	.L.str.12, 53

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"results.txt"
	.size	.L.str.14, 12

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"a"
	.size	.L.str.15, 2

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"Parallel\t%d\t%f\t%f\t%f\n"
	.size	.L.str.16, 22

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z18isingAnnealingStepPiS_S_S_ii"
	.size	.L__unnamed_1, 33

	.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	"Storing parallel code's results in results.txt..."
	.size	.Lstr, 50

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Finished writing to results.txt"
	.size	.Lstr.1, 32

	.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 _Z33__device_stub__isingAnnealingStepPiS_S_S_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z18isingAnnealingStepPiS_S_S_ii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z18isingAnnealingStepPiS_S_S_ii ; -- Begin function _Z18isingAnnealingStepPiS_S_S_ii
	.globl	_Z18isingAnnealingStepPiS_S_S_ii
	.p2align	8
	.type	_Z18isingAnnealingStepPiS_S_S_ii,@function
_Z18isingAnnealingStepPiS_S_S_ii:       ; @_Z18isingAnnealingStepPiS_S_S_ii
; %bb.0:
	s_clause 0x2
	s_load_b32 s10, s[0:1], 0x34
	s_load_b64 s[8:9], s[0:1], 0x20
	s_load_b256 s[0:7], s[0:1], 0x0
	v_mov_b32_e32 v6, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s10, s10, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mad_u64_u32 v[1:2], null, s15, s10, v[0:1]
	v_mov_b32_e32 v0, s9
	s_mov_b32 s9, exec_lo
	global_store_b32 v6, v0, s[6:7]
	v_cmpx_gt_i32_e64 s8, v1
	s_cbranch_execz .LBB0_7
; %bb.1:
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	v_add_co_u32 v2, vcc_lo, s2, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s3, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, s4, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	s_mov_b32 s2, exec_lo
	global_load_b64 v[2:3], v[2:3], off
	global_load_b32 v7, v[0:1], off
	s_waitcnt vmcnt(1)
	v_cmpx_lt_i32_e64 v2, v3
	s_cbranch_execz .LBB0_5
; %bb.2:                                ; %.lr.ph.preheader
	v_ashrrev_i32_e32 v5, 31, v2
	v_mov_b32_e32 v4, v2
	v_mov_b32_e32 v6, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	v_add_co_u32 v4, vcc_lo, v4, s0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v5, vcc_lo
	s_mov_b32 s1, 0
	v_add_co_u32 v4, vcc_lo, v4, 4
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v5, vcc_lo
.LBB0_3:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	global_load_b64 v[8:9], v[4:5], off offset:-4
	v_add_nc_u32_e32 v2, 2, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ge_i32_e64 s0, v2, v3
	s_or_b32 s1, s0, s1
	s_waitcnt vmcnt(0)
	v_ashrrev_i32_e32 v11, 31, v8
	v_mov_b32_e32 v10, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[10:11], 2, v[10:11]
	v_add_co_u32 v10, vcc_lo, s4, v10
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v11, vcc_lo, s5, v11, vcc_lo
	v_add_co_u32 v4, vcc_lo, v4, 8
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v5, vcc_lo
	global_load_b32 v8, v[10:11], off
	s_waitcnt vmcnt(0)
	v_mul_lo_u32 v8, v8, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v8, v8, v9
	v_sub_nc_u32_e32 v6, v6, v8
	s_and_not1_b32 exec_lo, exec_lo, s1
	s_cbranch_execnz .LBB0_3
; %bb.4:                                ; %Flow84
	s_or_b32 exec_lo, exec_lo, s1
.LBB0_5:                                ; %Flow85
	s_delay_alu instid0(SALU_CYCLE_1)
	s_or_b32 exec_lo, exec_lo, s2
	s_waitcnt vmcnt(0)
	v_ashrrev_i32_e32 v2, 31, v7
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_mov_b32 s1, 0
	v_add_nc_u32_e32 v3, v7, v2
	v_ashrrev_i32_e32 v7, 31, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_xor_b32_e32 v3, v3, v2
	v_add_nc_u32_e32 v6, v6, v7
	v_xor_b32_e32 v2, v7, v2
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_4)
	v_cvt_f32_u32_e32 v4, v3
	v_sub_nc_u32_e32 v5, 0, v3
	v_xor_b32_e32 v6, v6, v7
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v4, v4
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v4, 0x4f7ffffe, v4
	v_cvt_u32_f32_e32 v4, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v5, v5, v4
	v_mul_hi_u32 v5, v4, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v4, v4, v5
	v_mul_hi_u32 v4, v6, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v5, v4, v3
	v_sub_nc_u32_e32 v5, v6, v5
	v_add_nc_u32_e32 v6, 1, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v8, v5, v3
	v_cmp_ge_u32_e32 vcc_lo, v5, v3
	v_dual_cndmask_b32 v5, v5, v8 :: v_dual_cndmask_b32 v4, v4, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_ge_u32_e32 vcc_lo, v5, v3
	v_add_nc_u32_e32 v6, 1, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v3, v4, v6, vcc_lo
	v_xor_b32_e32 v3, v3, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v2, v3, v2
	v_cmp_lt_i32_e32 vcc_lo, -1, v2
	v_mov_b32_e32 v2, 0
	v_cndmask_b32_e64 v3, 1, -1, vcc_lo
	global_store_b32 v[0:1], v3, off
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	global_load_b32 v0, v2, s[6:7]
	s_waitcnt vmcnt(0)
	v_cmp_lt_i32_e32 vcc_lo, 0, v0
	s_cbranch_vccz .LBB0_7
; %bb.6:
	v_cvt_f32_u32_e32 v0, s8
	s_sub_i32 s2, 0, s8
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v0, v0
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x4f7ffffe, v0
	v_cvt_u32_f32_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_readfirstlane_b32 s0, v0
	s_mul_i32 s2, s2, s0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s2, s0, s2
	s_add_i32 s0, s0, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s0, s0, 0x62d407df
	s_mul_i32 s0, s0, s8
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_sub_i32 s0, 0x62d407df, s0
	s_sub_i32 s2, s0, s8
	s_cmp_ge_u32 s0, s8
	s_cselect_b32 s0, s2, s0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_sub_i32 s2, s0, s8
	s_cmp_ge_u32 s0, s8
	s_cselect_b32 s0, s2, s0
	s_lshl_b64 s[0:1], s[0:1], 2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_add_u32 s0, s4, s0
	s_addc_u32 s1, s5, s1
	global_load_b32 v0, v2, s[0:1]
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, 1, v0
	v_cndmask_b32_e64 v0, 1, -1, vcc_lo
	global_store_b32 v2, v0, s[0:1]
.LBB0_7:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z18isingAnnealingStepPiS_S_S_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 12
		.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	_Z18isingAnnealingStepPiS_S_S_ii, .Lfunc_end0-_Z18isingAnnealingStepPiS_S_S_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 792
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 12
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

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

	.end_amdgpu_metadata
