#include <stdio.h>
#include <stdlib.h>
#include <time.h> 
#include <math.h>
#include <string.h> 
#define TRILLION 1000000000000
#define MILLION 1000000
#define THREADS_PER_BLOCK 1024

#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))



//*************************************
//
//          Kernel Helpers
//
//*************************************

__device__ long long int power_mod_long_device(int x, unsigned long long int y, unsigned long long int p) 
{   
    unsigned long long int longx = x;
    unsigned long long int res = 1;      // Initialize result 

    longx = longx % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) {
            res = (res*longx) % p; 
        }
  
        // y must be even now 
        y = y>>1; // y = y/2 
        longx = (longx*longx) % p;   
    } 
    return res; 
} 



//*************************************
//
//          Kernel
//
//*************************************

__global__ void trial_division_kernel(unsigned long long int n, int *ret, int summod, int max){
    unsigned long long int i = (threadIdx.x + blockIdx.x * blockDim.x);
    // if (i*i <= n){
    //     if (((n % i) == 0) || ((n % (i+2)) == 0))
    //         *ret = 1;
    // }
    long long int sum = 0;
    if (i <= max){
        //sum += nCrModpLucas(n,r,n) * int_pow(a,diff);
        sum += summod;
        sum += power_mod_long_device(i, n, n);
        sum -= i;
        if ((sum % n) != 0){
           *ret = 1;
        }
    }
    
}



//*************************************
//
//			Helper Functions
//
//*************************************

long long combi(int n,int k)
{
    long long ans=1;
    k=k>n-k?n-k:k;
    int j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    //printf("ret %llu \n", ans);
    return ans;
}

long long int power_mod_long(int x, unsigned long long int y, unsigned long long int p) 
{ 	
	unsigned long long int longx = x;
    unsigned long long int res = 1;      // Initialize result 

    longx = longx % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) {
            res = (res*longx) % p; 
        }
  
        // y must be even now 
        y = y>>1; // y = y/2 
        longx = (longx*longx) % p;   
    } 
    return res; 
} 

int int_pow(int base, int exp)
{
    int result = 1;
    while (exp)
    {
        if (exp & 1)
           result *= base;
        exp /= 2;
        base *= base;
    }
    return result;
}

int power_mod(int x, unsigned int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 


int gcd(int a, int b)
{
    int temp;
    while (b != 0)
    {
        temp = a % b;

        a = b;
        b = temp;
    }
    return a;
}

// step 5 helpers
int eulerPhi(int n){
	int result = 0;
    int k;
    for(k = 1; k <= n; k++)
        result += gcd(k, n) == 1;
    return result;
}

int nCrModpDP(int n, int r, int p) 
{ 
    // The array C is going to store last row of 
    // pascal triangle at the end. And last entry 
    // of last row is nCr 
    int C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; // Top row of Pascal Triangle 
  
    // One by constructs remaining rows of Pascal 
    // Triangle from top to bottom 
    int i, j;
    for ( i = 1; i <= n; i++) 
    { 
        // Fill entries of current row using previous 
        // row values 
        for ( j = MIN(i, r); j > 0; j--) 
  
            // nCj = (n-1)Cj + (n-1)C(j-1); 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
  
// Lucas Theorem based function that returns nCr % p 
// This function works like decimal to binary conversion 
// recursive function.  First we compute last digits of 
// n and r in base p, then recur for remaining digits 
int nCrModpLucas(int n, int r, int p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
   // Compute last digits of n and r in base p 
   int ni = n%p, ri = r%p; 
  
   // Compute result for last digits computed above, and 
   // for remaining digits.  Multiply the two results and 
   // compute the result of multiplication in modulo p. 
   return (nCrModpLucas(n/p, r/p, p) * // Last digits of n and r 
           nCrModpDP(ni, ri, p)) % p;  // Remaining digits 
} 


//*************************************
//
//			AKS ALGORITHM
//
//*************************************

int aks(unsigned long long int n){
	if (n <= 1)
		return 0;

	// step 1 check if perfect power
	int b; double a;
	for (b = 2; b <= log(n)/log(2); b++){
		a = pow(n, 1/(double)b);
		if (a == floor(a))
			return 0;
	}

	// step 2
	// Find the smallest r such that Or(n) > (log2 n)^2
	double maxk = pow((log(n)/log(2)), 2);
	double maxr = MAX(3, pow((log(n)/log(2)), 5));

	int nextR = 1;
	int r, k;
	for (r = 2; (nextR && (r<maxr)); r++){
		nextR = 0;
		for (k = 1; ((!nextR)&& (k <= maxk)); k ++){
			nextR = ((power_mod(n,k,r) == 1)  ||  (power_mod(n,k,r) == 0));
		}
	}
	r --;

	// step 3
	// If 1 < gcd(a,n) < n for some a ≤ r, output composite.
	int i;
	for (i = r; i > 1; i --){
		int g = gcd(i, n);
		if ((g > 1) && (g < n))
			return 0;
	}

	// step 4
	// If n ≤ r, output prime.
	if (n <= r)
		return 1;

	// step 5
	// For a = 1 to sqrt(euler(r)log2(n))
	// if (X+a)n≠ Xn+a (mod Xr − 1,n), output composite;
	int max = floor((log(n)/log(2)) * sqrt(eulerPhi(r)));

	int diff = n-r;
	long long int sum = 0;
	//int inta;
	// this for loop is the crux of the algorithm
	// each value of a is tested after the polynomial division
	// the reason I was able to implement this for even moderate values is becuase the polynomials are of regular form
	// instead of doing the entire polynomial division, notice that the answers are always in regular form,
	// because the polymod eliminates most of the terms
	// the answer in general is a^n + (nCr % n)*a^(n-r) - a
    sum += nCrModpLucas(n,r,n) * int_pow(a,diff);

    int ret= 0;
    int *d_ret;
    cudaMalloc((void **)&d_ret, sizeof(int));   
    
    trial_division_kernel<<<(max + THREADS_PER_BLOCK - 1)/THREADS_PER_BLOCK,THREADS_PER_BLOCK>>>(n, d_ret, sum,max);
    cudaMemcpy(&ret, d_ret, sizeof(int), cudaMemcpyDeviceToHost);   
    if (ret)
        return 0;

	// for (inta=1; inta <= max; inta++){
	// 	sum = 0;
	// 	sum += nCrModpLucas(n,r,n) * int_pow(a,diff);
	// 	sum += power_mod_long(inta, n, n);
	// 	sum -= inta;
	// 	if ((sum % n) != 0){
	// 		//printf("here\n");
	// 		return 0;
	// 	}
	// }

	// step 6
	return 1;


}


//*************************************
//
//			Main
//
//*************************************

int main(void){

	double time_spent = 0.0;
	clock_t begin = clock();

	unsigned long long int i;
	int numprimes = 0;

	// PLEASE NOTE: this algorithm is only verified to work with values < 1,010,000
	// above that overflow errors may occur
	for (i = 1000*1000; i < 1000*1000 + 10000; i++)
		if (aks(i)){
			numprimes ++;
			printf("%llu is prime \n", i);
		}

	clock_t end = clock();
	time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
	printf("Time elpased is %f seconds\n", time_spent);
	printf("In the 1000 trillion range average time %f\n", time_spent/10000);
	printf("number of primes in this range %d\n", numprimes);

}





	.file	"tmpxft_003501a8_00000000-6_aks.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2041:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2041:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z21power_mod_long_deviceiyy
	.type	_Z21power_mod_long_deviceiyy, @function
_Z21power_mod_long_deviceiyy:
.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	_Z21power_mod_long_deviceiyy, .-_Z21power_mod_long_deviceiyy
	.globl	_Z5combiii
	.type	_Z5combiii, @function
_Z5combiii:
.LFB2028:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	movslq	%edi, %r10
	movl	$1, %r8d
	movl	$1, %ecx
	subl	%esi, %eax
	cmpl	%esi, %eax
	cmovle	%eax, %esi
	incl	%edi
	movl	%esi, %r9d
.L5:
	movl	%edi, %eax
	movl	%r8d, %esi
	subl	%r8d, %eax
	cmpl	%r8d, %r9d
	jl	.L12
	cltd
	idivl	%esi
	testl	%edx, %edx
	jne	.L6
	cltq
	imulq	%rax, %rcx
	jmp	.L7
.L6:
	movq	%rcx, %rax
	cqto
	idivq	%r8
	imulq	%r10, %rax
	testq	%rdx, %rdx
	je	.L10
	imulq	%r10, %rcx
	movq	%rcx, %rax
	cqto
	idivq	%r8
.L10:
	movq	%rax, %rcx
.L7:
	incq	%r8
	decq	%r10
	jmp	.L5
.L12:
	movq	%rcx, %rax
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z5combiii, .-_Z5combiii
	.globl	_Z14power_mod_longiyy
	.type	_Z14power_mod_longiyy, @function
_Z14power_mod_longiyy:
.LFB2029:
	.cfi_startproc
	endbr64
	movq	%rdx, %rcx
	movslq	%edi, %rax
	xorl	%edx, %edx
	movl	$1, %edi
	divq	%rcx
	movq	%rdx, %r8
.L14:
	testq	%rsi, %rsi
	je	.L20
	testl	$1, %esi
	je	.L15
	movq	%rdi, %rax
	xorl	%edx, %edx
	imulq	%r8, %rax
	divq	%rcx
	movq	%rdx, %rdi
.L15:
	imulq	%r8, %r8
	xorl	%edx, %edx
	shrq	%rsi
	movq	%r8, %rax
	divq	%rcx
	movq	%rdx, %r8
	jmp	.L14
.L20:
	movq	%rdi, %rax
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z14power_mod_longiyy, .-_Z14power_mod_longiyy
	.globl	_Z7int_powii
	.type	_Z7int_powii, @function
_Z7int_powii:
.LFB2030:
	.cfi_startproc
	endbr64
	movl	%esi, %eax
	movl	$1, %ecx
	movl	$2, %esi
.L22:
	testl	%eax, %eax
	je	.L28
	testb	$1, %al
	je	.L23
	imull	%edi, %ecx
.L23:
	cltd
	imull	%edi, %edi
	idivl	%esi
	jmp	.L22
.L28:
	movl	%ecx, %eax
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z7int_powii, .-_Z7int_powii
	.globl	_Z9power_modiji
	.type	_Z9power_modiji, @function
_Z9power_modiji:
.LFB2031:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	movl	%edx, %ecx
	movl	$1, %edi
	cltd
	idivl	%ecx
	movl	%edx, %r8d
.L30:
	testl	%esi, %esi
	je	.L36
	testl	$1, %esi
	je	.L31
	movl	%edi, %eax
	imull	%r8d, %eax
	cltd
	idivl	%ecx
	movl	%edx, %edi
.L31:
	imull	%r8d, %r8d
	shrl	%esi
	movl	%r8d, %eax
	cltd
	idivl	%ecx
	movl	%edx, %r8d
	jmp	.L30
.L36:
	movl	%edi, %eax
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z9power_modiji, .-_Z9power_modiji
	.globl	_Z3gcdii
	.type	_Z3gcdii, @function
_Z3gcdii:
.LFB2032:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
.L38:
	testl	%esi, %esi
	je	.L40
	cltd
	idivl	%esi
	movl	%esi, %eax
	movl	%edx, %esi
	jmp	.L38
.L40:
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z3gcdii, .-_Z3gcdii
	.globl	_Z8eulerPhii
	.type	_Z8eulerPhii, @function
_Z8eulerPhii:
.LFB2033:
	.cfi_startproc
	endbr64
	movl	$1, %ecx
	xorl	%esi, %esi
.L42:
	cmpl	%edi, %ecx
	jg	.L46
	movl	%edi, %edx
	movl	%ecx, %eax
.L43:
	movl	%edx, %r8d
	cltd
	idivl	%r8d
	movl	%r8d, %eax
	testl	%edx, %edx
	jne	.L43
	decl	%eax
	sete	%al
	incl	%ecx
	movzbl	%al, %eax
	addl	%eax, %esi
	jmp	.L42
.L46:
	movl	%esi, %eax
	ret
	.cfi_endproc
.LFE2033:
	.size	_Z8eulerPhii, .-_Z8eulerPhii
	.globl	_Z9nCrModpDPiii
	.type	_Z9nCrModpDPiii, @function
_Z9nCrModpDPiii:
.LFB2034:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r14
	.cfi_offset 14, -24
	movl	%edi, %r14d
	pushq	%r13
	pushq	%r12
	.cfi_offset 13, -32
	.cfi_offset 12, -40
	movl	%edx, %r12d
	pushq	%rbx
	.cfi_offset 3, -48
	movslq	%esi, %rbx
	leal	1(%rbx), %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	subq	$16, %rsp
	movq	%fs:40, %rax
	movq	%rax, -40(%rbp)
	xorl	%eax, %eax
	leaq	15(%rdx), %rcx
	movq	%rsp, %rsi
	movq	%rcx, %rax
	andq	$-4096, %rcx
	andq	$-16, %rax
	subq	%rcx, %rsi
.L48:
	cmpq	%rsi, %rsp
	je	.L49
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L48
.L49:
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L50
	orq	$0, -8(%rsp,%rax)
.L50:
	leaq	3(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rdx, %rcx
	movq	%rdi, %r13
	andq	$-4, %rdi
	call	__memset_chk@PLT
	shrq	$2, %r13
	movl	$1, %esi
	movl	$1, 0(,%r13,4)
	movq	%rax, %rdi
.L51:
	cmpl	%r14d, %esi
	jg	.L60
	cmpl	%ebx, %esi
	movl	%ebx, %ecx
	cmovle	%esi, %ecx
	movslq	%ecx, %rcx
.L52:
	testl	%ecx, %ecx
	jle	.L61
	movl	-4(%rdi,%rcx,4), %eax
	addl	(%rdi,%rcx,4), %eax
	cltd
	idivl	%r12d
	movl	%edx, (%rdi,%rcx,4)
	decq	%rcx
	jmp	.L52
.L61:
	incl	%esi
	jmp	.L51
.L60:
	movl	(%rdi,%rbx,4), %eax
	movq	-40(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L55
	call	__stack_chk_fail@PLT
.L55:
	leaq	-32(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2034:
	.size	_Z9nCrModpDPiii, .-_Z9nCrModpDPiii
	.globl	_Z12nCrModpLucasiii
	.type	_Z12nCrModpLucasiii, @function
_Z12nCrModpLucasiii:
.LFB2035:
	.cfi_startproc
	endbr64
	testl	%esi, %esi
	je	.L66
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	%edx, %ebx
	pushq	%rax
	.cfi_def_cfa_offset 48
	movl	%edi, %eax
	cltd
	idivl	%ebx
	movl	%eax, %edi
	movl	%esi, %eax
	movl	%edx, %r14d
	cltd
	idivl	%ebx
	movl	%edx, %r15d
	movl	%eax, %esi
	movl	%ebx, %edx
	call	_Z12nCrModpLucasiii
	movl	%ebx, %edx
	movl	%r15d, %esi
	movl	%r14d, %edi
	movl	%eax, %ebp
	call	_Z9nCrModpDPiii
	imull	%ebp, %eax
	cltd
	idivl	%ebx
	movl	%edx, %eax
	popq	%rdx
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
.L66:
	.cfi_restore 3
	.cfi_restore 6
	.cfi_restore 14
	.cfi_restore 15
	movl	$1, %eax
	ret
	.cfi_endproc
.LFE2035:
	.size	_Z12nCrModpLucasiii, .-_Z12nCrModpLucasiii
	.globl	_Z44__device_stub__Z21trial_division_kernelyPiiiyPiii
	.type	_Z44__device_stub__Z21trial_division_kernelyPiiiyPiii, @function
_Z44__device_stub__Z21trial_division_kernelyPiiiyPiii:
.LFB2063:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L71
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z21trial_division_kernelyPiii(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L71:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L73
	call	__stack_chk_fail@PLT
.L73:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2063:
	.size	_Z44__device_stub__Z21trial_division_kernelyPiiiyPiii, .-_Z44__device_stub__Z21trial_division_kernelyPiiiyPiii
	.globl	_Z21trial_division_kernelyPiii
	.type	_Z21trial_division_kernelyPiii, @function
_Z21trial_division_kernelyPiii:
.LFB2064:
	.cfi_startproc
	endbr64
	jmp	_Z44__device_stub__Z21trial_division_kernelyPiiiyPiii
	.cfi_endproc
.LFE2064:
	.size	_Z21trial_division_kernelyPiii, .-_Z21trial_division_kernelyPiii
	.globl	_Z3aksy
	.type	_Z3aksy, @function
_Z3aksy:
.LFB2036:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$72, %rsp
	.cfi_def_cfa_offset 112
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	cmpq	$1, %rdi
	ja	.L114
.L79:
	xorl	%ecx, %ecx
	jmp	.L76
.L114:
	movq	%rdi, %rbx
	movl	$2, %ebp
.L77:
	cvtsi2sdl	%ebp, %xmm2
	testq	%rbx, %rbx
	js	.L81
	cvtsi2sdq	%rbx, %xmm4
	movq	%xmm4, %r13
	jmp	.L82
.L81:
	movq	%rbx, %rax
	movq	%rbx, %rdx
	shrq	%rax
	andl	$1, %edx
	orq	%rdx, %rax
	cvtsi2sdq	%rax, %xmm0
	addsd	%xmm0, %xmm0
	movq	%xmm0, %r13
.L82:
	movq	%r13, %xmm0
	movsd	%xmm2, 8(%rsp)
	call	log@PLT
	movsd	8(%rsp), %xmm2
	divsd	.LC2(%rip), %xmm0
	comisd	%xmm2, %xmm0
	jb	.L116
	movsd	.LC1(%rip), %xmm1
	movq	%r13, %xmm0
	divsd	%xmm2, %xmm1
	call	pow@PLT
	movsd	%xmm0, (%rsp)
	call	trunc@PLT
	ucomisd	(%rsp), %xmm0
	jp	.L103
	je	.L79
.L103:
	incl	%ebp
	jmp	.L77
.L116:
	movq	%r13, %xmm0
	movl	$2, %ebp
	call	log@PLT
	divsd	.LC2(%rip), %xmm0
	mulsd	%xmm0, %xmm0
	movq	%xmm0, %r12
	movq	%r13, %xmm0
	call	log@PLT
	movsd	.LC3(%rip), %xmm1
	divsd	.LC2(%rip), %xmm0
	call	pow@PLT
	movaps	%xmm0, %xmm1
	movsd	.LC0(%rip), %xmm0
	comisd	%xmm1, %xmm0
	ja	.L84
	movq	%r13, %xmm0
	call	log@PLT
	movsd	.LC3(%rip), %xmm1
	divsd	.LC2(%rip), %xmm0
	call	pow@PLT
	comisd	.LC4(%rip), %xmm0
	jbe	.L85
.L84:
	movq	%r12, %xmm5
	comisd	.LC1(%rip), %xmm5
	movl	%ebx, %r10d
	jb	.L113
.L90:
	movl	$1, %r9d
.L89:
	movl	%r9d, %esi
	movl	%ebp, %edx
	movl	%r10d, %edi
	incl	%r9d
	call	_Z9power_modiji
	cmpl	$1, %eax
	jbe	.L102
	cvtsi2sdl	%r9d, %xmm1
	movq	%r12, %xmm6
	comisd	%xmm1, %xmm6
	jnb	.L89
	xorl	%eax, %eax
	jmp	.L88
.L102:
	movl	$1, %eax
.L88:
	incl	%ebp
	testl	%eax, %eax
	je	.L85
	cvtsi2sdl	%ebp, %xmm1
	comisd	%xmm1, %xmm0
	ja	.L90
	jmp	.L85
.L113:
	movl	$3, %ebp
.L85:
	decl	%ebp
	movl	%ebx, %edi
	movl	%ebp, %ecx
.L91:
	cmpl	$1, %ecx
	je	.L117
	movl	%edi, %esi
	movslq	%ecx, %rax
.L92:
	testl	%esi, %esi
	je	.L118
	cltd
	idivl	%esi
	movslq	%esi, %rax
	movl	%edx, %esi
	jmp	.L92
.L118:
	cmpl	$1, %eax
	jle	.L94
	cmpq	%rbx, %rax
	jb	.L79
.L94:
	decl	%ecx
	jmp	.L91
.L117:
	movslq	%ebp, %rax
	cmpq	%rbx, %rax
	jnb	.L76
	movq	%r13, %xmm0
	call	log@PLT
	movl	%ebp, %edi
	divsd	.LC2(%rip), %xmm0
	movsd	%xmm0, 8(%rsp)
	call	_Z8eulerPhii
	cvtsi2sdl	%eax, %xmm0
	call	sqrt@PLT
	mulsd	8(%rsp), %xmm0
	call	floor@PLT
	movl	%ebx, %edx
	movl	%ebx, %edi
	movl	%ebp, %esi
	cvttsd2sil	%xmm0, %r12d
	call	_Z12nCrModpLucasiii
	leaq	24(%rsp), %rdi
	movl	$4, %esi
	movl	%eax, %r13d
	xorl	%eax, %eax
	movl	%eax, 20(%rsp)
	call	cudaMalloc@PLT
	movl	$1024, %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	leal	1023(%r12), %eax
	cltd
	idivl	%ecx
	movl	$4194305, %edx
	movl	$1, %ecx
	salq	$10, %rdx
	movl	%eax, 32(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 36(%rsp)
	movq	32(%rsp), %rdi
	movl	40(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L96
	cvttsd2sil	(%rsp), %edi
	movl	%ebx, %esi
	subl	%ebp, %esi
	call	_Z7int_powii
	movq	24(%rsp), %rsi
	movl	%r12d, %ecx
	movq	%rbx, %rdi
	imull	%r13d, %eax
	movl	%eax, %edx
	call	_Z44__device_stub__Z21trial_division_kernelyPiiiyPiii
.L96:
	movq	24(%rsp), %rsi
	movl	$2, %ecx
	leaq	20(%rsp), %rdi
	movl	$4, %edx
	call	cudaMemcpy@PLT
	xorl	%ecx, %ecx
	cmpl	$0, 20(%rsp)
	sete	%cl
.L76:
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L97
	call	__stack_chk_fail@PLT
.L97:
	addq	$72, %rsp
	.cfi_def_cfa_offset 40
	movl	%ecx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2036:
	.size	_Z3aksy, .-_Z3aksy
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC5:
	.string	"%llu is prime \n"
.LC8:
	.string	"Time elpased is %f seconds\n"
.LC10:
	.string	"In the 1000 trillion range average time %f\n"
.LC11:
	.string	"number of primes in this range %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2038:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	leaq	.LC5(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movl	$1000000, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	call	clock@PLT
	movq	%rax, %r12
.L121:
	movq	%rbx, %rdi
	call	_Z3aksy
	testl	%eax, %eax
	je	.L120
	movq	%rbx, %rdx
	movq	%r13, %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incl	%ebp
	call	__printf_chk@PLT
.L120:
	incq	%rbx
	cmpq	$1010000, %rbx
	jne	.L121
	call	clock@PLT
	xorps	%xmm1, %xmm1
	movl	$2, %edi
	leaq	.LC8(%rip), %rsi
	subq	%r12, %rax
	cvtsi2sdq	%rax, %xmm0
	divsd	.LC6(%rip), %xmm0
	movb	$1, %al
	addsd	%xmm1, %xmm0
	movsd	%xmm0, 8(%rsp)
	call	__printf_chk@PLT
	leaq	.LC10(%rip), %rsi
	movl	$2, %edi
	movb	$1, %al
	movsd	8(%rsp), %xmm0
	divsd	.LC9(%rip), %xmm0
	call	__printf_chk@PLT
	movl	%ebp, %edx
	leaq	.LC11(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	addq	$24, %rsp
	.cfi_def_cfa_offset 40
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2038:
	.size	main, .-main
	.section	.rodata.str1.1
.LC12:
	.string	"_Z21trial_division_kernelyPiii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2066:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC12(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z21trial_division_kernelyPiii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2066:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC0:
	.long	0
	.long	1074266112
	.align 8
.LC1:
	.long	0
	.long	1072693248
	.align 8
.LC2:
	.long	-17155601
	.long	1072049730
	.align 8
.LC3:
	.long	0
	.long	1075052544
	.align 8
.LC4:
	.long	0
	.long	1073741824
	.align 8
.LC6:
	.long	0
	.long	1093567616
	.align 8
.LC9:
	.long	0
	.long	1086556160
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h> 
#include <math.h>
#include <string.h> 
#define TRILLION 1000000000000
#define MILLION 1000000
#define THREADS_PER_BLOCK 1024

#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))



//*************************************
//
//          Kernel Helpers
//
//*************************************

__device__ long long int power_mod_long_device(int x, unsigned long long int y, unsigned long long int p) 
{   
    unsigned long long int longx = x;
    unsigned long long int res = 1;      // Initialize result 

    longx = longx % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) {
            res = (res*longx) % p; 
        }
  
        // y must be even now 
        y = y>>1; // y = y/2 
        longx = (longx*longx) % p;   
    } 
    return res; 
} 



//*************************************
//
//          Kernel
//
//*************************************

__global__ void trial_division_kernel(unsigned long long int n, int *ret, int summod, int max){
    unsigned long long int i = (threadIdx.x + blockIdx.x * blockDim.x);
    // if (i*i <= n){
    //     if (((n % i) == 0) || ((n % (i+2)) == 0))
    //         *ret = 1;
    // }
    long long int sum = 0;
    if (i <= max){
        //sum += nCrModpLucas(n,r,n) * int_pow(a,diff);
        sum += summod;
        sum += power_mod_long_device(i, n, n);
        sum -= i;
        if ((sum % n) != 0){
           *ret = 1;
        }
    }
    
}



//*************************************
//
//			Helper Functions
//
//*************************************

long long combi(int n,int k)
{
    long long ans=1;
    k=k>n-k?n-k:k;
    int j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    //printf("ret %llu \n", ans);
    return ans;
}

long long int power_mod_long(int x, unsigned long long int y, unsigned long long int p) 
{ 	
	unsigned long long int longx = x;
    unsigned long long int res = 1;      // Initialize result 

    longx = longx % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) {
            res = (res*longx) % p; 
        }
  
        // y must be even now 
        y = y>>1; // y = y/2 
        longx = (longx*longx) % p;   
    } 
    return res; 
} 

int int_pow(int base, int exp)
{
    int result = 1;
    while (exp)
    {
        if (exp & 1)
           result *= base;
        exp /= 2;
        base *= base;
    }
    return result;
}

int power_mod(int x, unsigned int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 


int gcd(int a, int b)
{
    int temp;
    while (b != 0)
    {
        temp = a % b;

        a = b;
        b = temp;
    }
    return a;
}

// step 5 helpers
int eulerPhi(int n){
	int result = 0;
    int k;
    for(k = 1; k <= n; k++)
        result += gcd(k, n) == 1;
    return result;
}

int nCrModpDP(int n, int r, int p) 
{ 
    // The array C is going to store last row of 
    // pascal triangle at the end. And last entry 
    // of last row is nCr 
    int C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; // Top row of Pascal Triangle 
  
    // One by constructs remaining rows of Pascal 
    // Triangle from top to bottom 
    int i, j;
    for ( i = 1; i <= n; i++) 
    { 
        // Fill entries of current row using previous 
        // row values 
        for ( j = MIN(i, r); j > 0; j--) 
  
            // nCj = (n-1)Cj + (n-1)C(j-1); 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
  
// Lucas Theorem based function that returns nCr % p 
// This function works like decimal to binary conversion 
// recursive function.  First we compute last digits of 
// n and r in base p, then recur for remaining digits 
int nCrModpLucas(int n, int r, int p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
  
   // Compute last digits of n and r in base p 
   int ni = n%p, ri = r%p; 
  
   // Compute result for last digits computed above, and 
   // for remaining digits.  Multiply the two results and 
   // compute the result of multiplication in modulo p. 
   return (nCrModpLucas(n/p, r/p, p) * // Last digits of n and r 
           nCrModpDP(ni, ri, p)) % p;  // Remaining digits 
} 


//*************************************
//
//			AKS ALGORITHM
//
//*************************************

int aks(unsigned long long int n){
	if (n <= 1)
		return 0;

	// step 1 check if perfect power
	int b; double a;
	for (b = 2; b <= log(n)/log(2); b++){
		a = pow(n, 1/(double)b);
		if (a == floor(a))
			return 0;
	}

	// step 2
	// Find the smallest r such that Or(n) > (log2 n)^2
	double maxk = pow((log(n)/log(2)), 2);
	double maxr = MAX(3, pow((log(n)/log(2)), 5));

	int nextR = 1;
	int r, k;
	for (r = 2; (nextR && (r<maxr)); r++){
		nextR = 0;
		for (k = 1; ((!nextR)&& (k <= maxk)); k ++){
			nextR = ((power_mod(n,k,r) == 1)  ||  (power_mod(n,k,r) == 0));
		}
	}
	r --;

	// step 3
	// If 1 < gcd(a,n) < n for some a ≤ r, output composite.
	int i;
	for (i = r; i > 1; i --){
		int g = gcd(i, n);
		if ((g > 1) && (g < n))
			return 0;
	}

	// step 4
	// If n ≤ r, output prime.
	if (n <= r)
		return 1;

	// step 5
	// For a = 1 to sqrt(euler(r)log2(n))
	// if (X+a)n≠ Xn+a (mod Xr − 1,n), output composite;
	int max = floor((log(n)/log(2)) * sqrt(eulerPhi(r)));

	int diff = n-r;
	long long int sum = 0;
	//int inta;
	// this for loop is the crux of the algorithm
	// each value of a is tested after the polynomial division
	// the reason I was able to implement this for even moderate values is becuase the polynomials are of regular form
	// instead of doing the entire polynomial division, notice that the answers are always in regular form,
	// because the polymod eliminates most of the terms
	// the answer in general is a^n + (nCr % n)*a^(n-r) - a
    sum += nCrModpLucas(n,r,n) * int_pow(a,diff);

    int ret= 0;
    int *d_ret;
    hipMalloc((void **)&d_ret, sizeof(int));   
    
    trial_division_kernel<<<(max + THREADS_PER_BLOCK - 1)/THREADS_PER_BLOCK,THREADS_PER_BLOCK>>>(n, d_ret, sum,max);
    hipMemcpy(&ret, d_ret, sizeof(int), hipMemcpyDeviceToHost);   
    if (ret)
        return 0;

	// for (inta=1; inta <= max; inta++){
	// 	sum = 0;
	// 	sum += nCrModpLucas(n,r,n) * int_pow(a,diff);
	// 	sum += power_mod_long(inta, n, n);
	// 	sum -= inta;
	// 	if ((sum % n) != 0){
	// 		//printf("here\n");
	// 		return 0;
	// 	}
	// }

	// step 6
	return 1;


}


//*************************************
//
//			Main
//
//*************************************

int main(void){

	double time_spent = 0.0;
	clock_t begin = clock();

	unsigned long long int i;
	int numprimes = 0;

	// PLEASE NOTE: this algorithm is only verified to work with values < 1,010,000
	// above that overflow errors may occur
	for (i = 1000*1000; i < 1000*1000 + 10000; i++)
		if (aks(i)){
			numprimes ++;
			printf("%llu is prime \n", i);
		}

	clock_t end = clock();
	time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
	printf("Time elpased is %f seconds\n", time_spent);
	printf("In the 1000 trillion range average time %f\n", time_spent/10000);
	printf("number of primes in this range %d\n", numprimes);

}





	.text
	.file	"aks.hip"
	.globl	_Z36__device_stub__trial_division_kernelyPiii # -- Begin function _Z36__device_stub__trial_division_kernelyPiii
	.type	_Z36__device_stub__trial_division_kernelyPiii,@function
_Z36__device_stub__trial_division_kernelyPiii: # @_Z36__device_stub__trial_division_kernelyPiii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z21trial_division_kernelyPiii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z36__device_stub__trial_division_kernelyPiii, .Lfunc_end0-_Z36__device_stub__trial_division_kernelyPiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z5combiii                      # -- Begin function _Z5combiii
	.type	_Z5combiii,@function
_Z5combiii:                             # @_Z5combiii
	.cfi_startproc
# %bb.0:
	movl	%edi, %r8d
	subl	%esi, %r8d
	cmpl	%esi, %r8d
	cmovgel	%esi, %r8d
	testl	%r8d, %r8d
	jle	.LBB1_1
# %bb.2:                                # %.lr.ph.preheader
	movslq	%edi, %rcx
	incl	%r8d
	movl	$1, %edi
	movl	$1, %esi
.LBB1_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%ecx, %eax
	cltd
	idivl	%edi
	testl	%edx, %edx
	je	.LBB1_4
# %bb.5:                                #   in Loop: Header=BB1_3 Depth=1
	movq	%rsi, %rax
	cqto
	idivq	%rdi
	testq	%rdx, %rdx
	je	.LBB1_6
# %bb.7:                                #   in Loop: Header=BB1_3 Depth=1
	imulq	%rcx, %rsi
	movq	%rsi, %rax
	cqto
	idivq	%rdi
	jmp	.LBB1_8
.LBB1_4:                                #   in Loop: Header=BB1_3 Depth=1
	cltq
	imulq	%rax, %rsi
	jmp	.LBB1_9
.LBB1_6:                                #   in Loop: Header=BB1_3 Depth=1
	imulq	%rcx, %rax
.LBB1_8:                                #   in Loop: Header=BB1_3 Depth=1
	movq	%rax, %rsi
.LBB1_9:                                #   in Loop: Header=BB1_3 Depth=1
	incq	%rdi
	decq	%rcx
	cmpq	%rdi, %r8
	jne	.LBB1_3
	jmp	.LBB1_10
.LBB1_1:
	movl	$1, %esi
.LBB1_10:                               # %._crit_edge
	movq	%rsi, %rax
	retq
.Lfunc_end1:
	.size	_Z5combiii, .Lfunc_end1-_Z5combiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z14power_mod_longiyy           # -- Begin function _Z14power_mod_longiyy
	.type	_Z14power_mod_longiyy,@function
_Z14power_mod_longiyy:                  # @_Z14power_mod_longiyy
	.cfi_startproc
# %bb.0:
	testq	%rsi, %rsi
	je	.LBB2_1
# %bb.2:                                # %.lr.ph.preheader
	movq	%rdx, %rcx
	movslq	%edi, %r8
	movl	$1, %edi
.LBB2_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	%r8, %rax
	xorl	%edx, %edx
	divq	%rcx
	movq	%rdx, %r8
	testb	$1, %sil
	je	.LBB2_5
# %bb.4:                                #   in Loop: Header=BB2_3 Depth=1
	imulq	%r8, %rdi
	movq	%rdi, %rax
	xorl	%edx, %edx
	divq	%rcx
	movq	%rdx, %rdi
.LBB2_5:                                #   in Loop: Header=BB2_3 Depth=1
	movq	%rsi, %rax
	shrq	%rax
	imulq	%r8, %r8
	cmpq	$1, %rsi
	movq	%rax, %rsi
	ja	.LBB2_3
	jmp	.LBB2_6
.LBB2_1:
	movl	$1, %edi
.LBB2_6:                                # %._crit_edge
	movq	%rdi, %rax
	retq
.Lfunc_end2:
	.size	_Z14power_mod_longiyy, .Lfunc_end2-_Z14power_mod_longiyy
	.cfi_endproc
                                        # -- End function
	.globl	_Z7int_powii                    # -- Begin function _Z7int_powii
	.type	_Z7int_powii,@function
_Z7int_powii:                           # @_Z7int_powii
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	je	.LBB3_1
# %bb.2:                                # %.lr.ph.preheader
	movl	$1, %ecx
	movl	$1, %eax
	movl	%esi, %edx
.LBB3_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	testb	$1, %sil
	movl	%edi, %r8d
	cmovel	%ecx, %r8d
	imull	%r8d, %eax
	shrl	$31, %edx
	addl	%esi, %edx
	sarl	%edx
	imull	%edi, %edi
	incl	%esi
	cmpl	$2, %esi
	movl	%edx, %esi
	ja	.LBB3_3
# %bb.4:                                # %._crit_edge
	retq
.LBB3_1:
	movl	$1, %eax
	retq
.Lfunc_end3:
	.size	_Z7int_powii, .Lfunc_end3-_Z7int_powii
	.cfi_endproc
                                        # -- End function
	.globl	_Z9power_modiji                 # -- Begin function _Z9power_modiji
	.type	_Z9power_modiji,@function
_Z9power_modiji:                        # @_Z9power_modiji
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	je	.LBB4_1
# %bb.2:                                # %.lr.ph.preheader
	movl	%edx, %ecx
	movl	%edi, %r8d
	movl	$1, %edi
.LBB4_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%r8d, %eax
	cltd
	idivl	%ecx
	movl	%edx, %r8d
	testb	$1, %sil
	je	.LBB4_5
# %bb.4:                                #   in Loop: Header=BB4_3 Depth=1
	imull	%r8d, %edi
	movl	%edi, %eax
	cltd
	idivl	%ecx
	movl	%edx, %edi
.LBB4_5:                                #   in Loop: Header=BB4_3 Depth=1
	movl	%esi, %eax
	shrl	%eax
	imull	%r8d, %r8d
	cmpl	$1, %esi
	movl	%eax, %esi
	ja	.LBB4_3
	jmp	.LBB4_6
.LBB4_1:
	movl	$1, %edi
.LBB4_6:                                # %._crit_edge
	movl	%edi, %eax
	retq
.Lfunc_end4:
	.size	_Z9power_modiji, .Lfunc_end4-_Z9power_modiji
	.cfi_endproc
                                        # -- End function
	.globl	_Z3gcdii                        # -- Begin function _Z3gcdii
	.type	_Z3gcdii,@function
_Z3gcdii:                               # @_Z3gcdii
	.cfi_startproc
# %bb.0:
	movl	%edi, %eax
	testl	%esi, %esi
	je	.LBB5_1
# %bb.2:                                # %.lr.ph.preheader
	movl	%esi, %edx
.LBB5_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%edx, %ecx
	cltd
	idivl	%ecx
	movl	%ecx, %eax
	testl	%edx, %edx
	jne	.LBB5_3
	jmp	.LBB5_4
.LBB5_1:
	movl	%eax, %ecx
.LBB5_4:                                # %._crit_edge
	movl	%ecx, %eax
	retq
.Lfunc_end5:
	.size	_Z3gcdii, .Lfunc_end5-_Z3gcdii
	.cfi_endproc
                                        # -- End function
	.globl	_Z8eulerPhii                    # -- Begin function _Z8eulerPhii
	.type	_Z8eulerPhii,@function
_Z8eulerPhii:                           # @_Z8eulerPhii
	.cfi_startproc
# %bb.0:
	xorl	%ecx, %ecx
	testl	%edi, %edi
	jle	.LBB6_5
# %bb.1:                                # %.lr.ph.i.preheader.preheader
	movl	$1, %esi
.LBB6_2:                                # %.lr.ph.i.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_3 Depth 2
	movl	%esi, %eax
	movl	%edi, %edx
.LBB6_3:                                # %.lr.ph.i
                                        #   Parent Loop BB6_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%edx, %r8d
	cltd
	idivl	%r8d
	movl	%r8d, %eax
	testl	%edx, %edx
	jne	.LBB6_3
# %bb.4:                                # %_Z3gcdii.exit
                                        #   in Loop: Header=BB6_2 Depth=1
	xorl	%eax, %eax
	cmpl	$1, %r8d
	sete	%al
	addl	%eax, %ecx
	leal	1(%rsi), %eax
	cmpl	%edi, %esi
	movl	%eax, %esi
	jne	.LBB6_2
.LBB6_5:                                # %._crit_edge
	movl	%ecx, %eax
	retq
.Lfunc_end6:
	.size	_Z8eulerPhii, .Lfunc_end6-_Z8eulerPhii
	.cfi_endproc
                                        # -- End function
	.globl	_Z9nCrModpDPiii                 # -- Begin function _Z9nCrModpDPiii
	.type	_Z9nCrModpDPiii,@function
_Z9nCrModpDPiii:                        # @_Z9nCrModpDPiii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	pushq	%rax
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	movl	%edx, %r14d
	movl	%esi, %ebx
	movl	%edi, %r15d
	leal	1(%rbx), %edx
	movq	%rsp, %r12
	movq	%r12, -48(%rbp)                 # 8-byte Spill
	leaq	15(,%rdx,4), %r13
	andq	$-16, %r13
	subq	%r13, %r12
	movq	%r12, %rsp
	negq	%r13
	shlq	$2, %rdx
	movq	%r12, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
	movq	-48(%rbp), %rax                 # 8-byte Reload
	movl	$1, (%rax,%r13)
	testl	%r15d, %r15d
	jle	.LBB7_6
# %bb.1:                                # %.lr.ph20.preheader
	movl	$1, %ecx
.LBB7_2:                                # %.lr.ph20
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB7_4 Depth 2
	cmpl	%ecx, %ebx
	movl	%ecx, %eax
	cmovll	%ebx, %eax
	testl	%ebx, %ebx
	jle	.LBB7_5
# %bb.3:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB7_2 Depth=1
	leal	1(%rax), %esi
	leaq	(%r12,%rax,4), %rdi
.LBB7_4:                                # %.lr.ph
                                        #   Parent Loop BB7_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	-4(%rdi), %eax
	addl	(%rdi), %eax
	cltd
	idivl	%r14d
	movl	%edx, (%rdi)
	addq	$-4, %rdi
	decl	%esi
	cmpl	$1, %esi
	jg	.LBB7_4
.LBB7_5:                                # %._crit_edge
                                        #   in Loop: Header=BB7_2 Depth=1
	leal	1(%rcx), %eax
	cmpl	%r15d, %ecx
	movl	%eax, %ecx
	jne	.LBB7_2
.LBB7_6:                                # %._crit_edge21
	movslq	%ebx, %rax
	movl	(%r12,%rax,4), %eax
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.Lfunc_end7:
	.size	_Z9nCrModpDPiii, .Lfunc_end7-_Z9nCrModpDPiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z12nCrModpLucasiii             # -- Begin function _Z12nCrModpLucasiii
	.type	_Z12nCrModpLucasiii,@function
_Z12nCrModpLucasiii:                    # @_Z12nCrModpLucasiii
	.cfi_startproc
# %bb.0:
	testl	%esi, %esi
	je	.LBB8_1
# %bb.3:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebx
	movl	%edi, %eax
	cltd
	idivl	%ebx
	movl	%edx, %ebp
	movl	%eax, %edi
	movl	%esi, %eax
	cltd
	idivl	%ebx
	movl	%edx, %r14d
	movl	%eax, %esi
	movl	%ebx, %edx
	callq	_Z12nCrModpLucasiii
	movl	%eax, %r15d
	movl	%ebp, %edi
	movl	%r14d, %esi
	movl	%ebx, %edx
	callq	_Z9nCrModpDPiii
	imull	%r15d, %eax
	cltd
	idivl	%ebx
	movl	%edx, %eax
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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
	.cfi_restore %rbx
	.cfi_restore %r14
	.cfi_restore %r15
	.cfi_restore %rbp
	retq
.LBB8_1:
	movl	$1, %eax
	retq
.Lfunc_end8:
	.size	_Z12nCrModpLucasiii, .Lfunc_end8-_Z12nCrModpLucasiii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z3aksy
.LCPI9_0:
	.long	1127219200                      # 0x43300000
	.long	1160773632                      # 0x45300000
	.long	0                               # 0x0
	.long	0                               # 0x0
.LCPI9_1:
	.quad	0x4330000000000000              # double 4503599627370496
	.quad	0x4530000000000000              # double 1.9342813113834067E+25
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI9_2:
	.quad	0x3fe62e42fefa39ef              # double 0.69314718055994529
.LCPI9_3:
	.quad	0x4000000000000000              # double 2
.LCPI9_4:
	.quad	0x3ff0000000000000              # double 1
.LCPI9_5:
	.quad	0x4014000000000000              # double 5
.LCPI9_6:
	.quad	0x4008000000000000              # double 3
	.text
	.globl	_Z3aksy
	.type	_Z3aksy,@function
_Z3aksy:                                # @_Z3aksy
	.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
	subq	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	xorl	%ebp, %ebp
	cmpq	$2, %rdi
	jae	.LBB9_1
.LBB9_47:                               # %.loopexit
	movl	%ebp, %eax
	addq	$64, %rsp
	.cfi_def_cfa_offset 48
	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
.LBB9_1:                                # %.preheader87
	.cfi_def_cfa_offset 112
	movq	%rdi, %rbx
	movq	%rdi, %xmm1
	punpckldq	.LCPI9_0(%rip), %xmm1   # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
	subpd	.LCPI9_1(%rip), %xmm1
	movapd	%xmm1, %xmm0
	unpckhpd	%xmm1, %xmm0                    # xmm0 = xmm0[1],xmm1[1]
	addsd	%xmm1, %xmm0
	movapd	%xmm0, 16(%rsp)                 # 16-byte Spill
	callq	log
	divsd	.LCPI9_2(%rip), %xmm0
	ucomisd	.LCPI9_3(%rip), %xmm0
                                        # implicit-def: $r12d
	jb	.LBB9_6
# %bb.2:                                # %.lr.ph.preheader
	movsd	.LCPI9_3(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	$3, %r14d
.LBB9_4:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movsd	.LCPI9_4(%rip), %xmm1           # xmm1 = mem[0],zero
	divsd	%xmm0, %xmm1
	movapd	16(%rsp), %xmm0                 # 16-byte Reload
	callq	pow
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	callq	floor@PLT
	movsd	8(%rsp), %xmm1                  # 8-byte Reload
                                        # xmm1 = mem[0],zero
	ucomisd	%xmm0, %xmm1
	jne	.LBB9_3
	jnp	.LBB9_47
.LBB9_3:                                #   in Loop: Header=BB9_4 Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2sd	%r14d, %xmm0
	movsd	%xmm0, 56(%rsp)                 # 8-byte Spill
	movapd	16(%rsp), %xmm0                 # 16-byte Reload
	callq	log
	divsd	.LCPI9_2(%rip), %xmm0
	incl	%r14d
	movsd	56(%rsp), %xmm1                 # 8-byte Reload
                                        # xmm1 = mem[0],zero
	ucomisd	%xmm1, %xmm0
	movapd	%xmm1, %xmm0
	jae	.LBB9_4
# %bb.5:                                # %._crit_edge.loopexit
	cvttsd2si	8(%rsp), %r12d          # 8-byte Folded Reload
.LBB9_6:                                # %._crit_edge
	movaps	16(%rsp), %xmm0                 # 16-byte Reload
	callq	log
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movapd	16(%rsp), %xmm0                 # 16-byte Reload
	callq	log
	divsd	.LCPI9_2(%rip), %xmm0
	movsd	.LCPI9_5(%rip), %xmm1           # xmm1 = mem[0],zero
	callq	pow
	movapd	%xmm0, %xmm1
	movsd	.LCPI9_6(%rip), %xmm0           # xmm0 = mem[0],zero
	ucomisd	%xmm1, %xmm0
	ja	.LBB9_8
# %bb.7:
	movapd	16(%rsp), %xmm0                 # 16-byte Reload
	callq	log
	divsd	.LCPI9_2(%rip), %xmm0
	movsd	.LCPI9_5(%rip), %xmm1           # xmm1 = mem[0],zero
	callq	pow
	movl	$1, %r14d
	ucomisd	.LCPI9_3(%rip), %xmm0
	jbe	.LBB9_32
.LBB9_8:                                # %.preheader.lr.ph
	movsd	8(%rsp), %xmm3                  # 8-byte Reload
                                        # xmm3 = mem[0],zero
	divsd	.LCPI9_2(%rip), %xmm3
	mulsd	%xmm3, %xmm3
	movl	$2, %eax
	movsd	.LCPI9_4(%rip), %xmm1           # xmm1 = mem[0],zero
.LBB9_9:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB9_11 Depth 2
                                        #       Child Loop BB9_12 Depth 3
                                        #       Child Loop BB9_18 Depth 3
	movl	%eax, %r14d
	ucomisd	%xmm1, %xmm3
	jb	.LBB9_25
# %bb.10:                               # %.lr.ph95.preheader
                                        #   in Loop: Header=BB9_9 Depth=1
	movl	$1, %edi
.LBB9_11:                               # %.lr.ph95
                                        #   Parent Loop BB9_9 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB9_12 Depth 3
                                        #       Child Loop BB9_18 Depth 3
	movl	%ebx, %esi
	movl	$1, %ecx
	movl	%edi, %r8d
.LBB9_12:                               # %.lr.ph.i
                                        #   Parent Loop BB9_9 Depth=1
                                        #     Parent Loop BB9_11 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	%esi, %eax
	cltd
	idivl	%r14d
	movl	%edx, %esi
	testb	$1, %r8b
	je	.LBB9_14
# %bb.13:                               #   in Loop: Header=BB9_12 Depth=3
	imull	%esi, %ecx
	movl	%ecx, %eax
	cltd
	idivl	%r14d
	movl	%edx, %ecx
.LBB9_14:                               #   in Loop: Header=BB9_12 Depth=3
	movl	%r8d, %eax
	shrl	%eax
	imull	%esi, %esi
	cmpl	$1, %r8d
	movl	%eax, %r8d
	ja	.LBB9_12
# %bb.15:                               # %_Z9power_modiji.exit
                                        #   in Loop: Header=BB9_11 Depth=2
	cmpl	$1, %ecx
	je	.LBB9_16
# %bb.17:                               # %.lr.ph.i70.preheader
                                        #   in Loop: Header=BB9_11 Depth=2
	movl	$1, %ecx
	movl	%ebx, %esi
	movl	%edi, %r8d
.LBB9_18:                               # %.lr.ph.i70
                                        #   Parent Loop BB9_9 Depth=1
                                        #     Parent Loop BB9_11 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	%esi, %eax
	cltd
	idivl	%r14d
	movl	%edx, %esi
	testb	$1, %r8b
	je	.LBB9_20
# %bb.19:                               #   in Loop: Header=BB9_18 Depth=3
	imull	%esi, %ecx
	movl	%ecx, %eax
	cltd
	idivl	%r14d
	movl	%edx, %ecx
.LBB9_20:                               #   in Loop: Header=BB9_18 Depth=3
	movl	%r8d, %eax
	shrl	%eax
	imull	%esi, %esi
	cmpl	$1, %r8d
	movl	%eax, %r8d
	ja	.LBB9_18
# %bb.21:                               #   in Loop: Header=BB9_11 Depth=2
	testl	%ecx, %ecx
	sete	%al
	je	.LBB9_23
# %bb.22:                               #   in Loop: Header=BB9_11 Depth=2
	incl	%edi
	xorps	%xmm2, %xmm2
	cvtsi2sd	%edi, %xmm2
	ucomisd	%xmm2, %xmm3
	jae	.LBB9_11
	jmp	.LBB9_23
.LBB9_16:                               #   in Loop: Header=BB9_9 Depth=1
	movb	$1, %al
.LBB9_23:                               # %._crit_edge96
                                        #   in Loop: Header=BB9_9 Depth=1
	testb	%al, %al
	je	.LBB9_25
# %bb.24:                               # %._crit_edge96
                                        #   in Loop: Header=BB9_9 Depth=1
	leal	1(%r14), %eax
	xorps	%xmm2, %xmm2
	cvtsi2sd	%eax, %xmm2
	ucomisd	%xmm2, %xmm0
	ja	.LBB9_9
.LBB9_25:                               # %.lr.ph103
	movl	%r14d, %ecx
.LBB9_27:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB9_29 Depth 2
	movl	%ecx, %esi
	testl	%ebx, %ebx
	je	.LBB9_30
# %bb.28:                               # %.lr.ph.i79.preheader
                                        #   in Loop: Header=BB9_27 Depth=1
	movl	%ecx, %eax
	movl	%ebx, %edx
.LBB9_29:                               # %.lr.ph.i79
                                        #   Parent Loop BB9_27 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%edx, %esi
	cltd
	idivl	%esi
	movl	%esi, %eax
	testl	%edx, %edx
	jne	.LBB9_29
.LBB9_30:                               # %_Z3gcdii.exit
                                        #   in Loop: Header=BB9_27 Depth=1
	cmpl	$2, %esi
	jl	.LBB9_26
# %bb.31:                               # %_Z3gcdii.exit
                                        #   in Loop: Header=BB9_27 Depth=1
	movl	%esi, %eax
	cmpq	%rbx, %rax
	jb	.LBB9_47
.LBB9_26:                               #   in Loop: Header=BB9_27 Depth=1
	leal	-1(%rcx), %eax
	cmpl	$3, %ecx
	movl	%eax, %ecx
	jge	.LBB9_27
.LBB9_32:                               # %._crit_edge104
	movl	%r14d, %eax
	movl	$1, %ebp
	cmpq	%rbx, %rax
	jae	.LBB9_47
# %bb.33:
	movapd	16(%rsp), %xmm0                 # 16-byte Reload
	callq	log
	movapd	%xmm0, %xmm2
	xorl	%ecx, %ecx
	movl	$1, %esi
.LBB9_34:                               # %.lr.ph.i.preheader.i
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB9_35 Depth 2
	movl	%esi, %eax
	movl	%r14d, %edx
.LBB9_35:                               # %.lr.ph.i.i
                                        #   Parent Loop BB9_34 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	%edx, %edi
	cltd
	idivl	%edi
	movl	%edi, %eax
	testl	%edx, %edx
	jne	.LBB9_35
# %bb.36:                               # %_Z3gcdii.exit.i
                                        #   in Loop: Header=BB9_34 Depth=1
	xorl	%eax, %eax
	cmpl	$1, %edi
	sete	%al
	addl	%eax, %ecx
	leal	1(%rsi), %eax
	cmpl	%r14d, %esi
	movl	%eax, %esi
	jne	.LBB9_34
# %bb.37:                               # %_Z8eulerPhii.exit
	divsd	.LCPI9_2(%rip), %xmm2
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ecx, %xmm0
	xorpd	%xmm1, %xmm1
	ucomisd	%xmm1, %xmm0
	jb	.LBB9_39
# %bb.38:
	sqrtsd	%xmm0, %xmm0
	jmp	.LBB9_40
.LBB9_39:                               # %call.sqrt
	movsd	%xmm2, 16(%rsp)                 # 8-byte Spill
	callq	sqrt
	movsd	16(%rsp), %xmm2                 # 8-byte Reload
                                        # xmm2 = mem[0],zero
.LBB9_40:                               # %_Z8eulerPhii.exit.split
	mulsd	%xmm0, %xmm2
	movapd	%xmm2, %xmm0
	callq	floor@PLT
	cvttsd2si	%xmm0, %r15d
	movl	%ebx, %edi
	movl	%r14d, %esi
	movl	%ebx, %edx
	callq	_Z12nCrModpLucasiii
	movl	%eax, %ebp
	movl	%ebx, %eax
	subl	%r14d, %eax
	je	.LBB9_41
# %bb.42:                               # %.lr.ph.i81.preheader
	movl	$1, %ecx
	movl	$1, %r14d
	movl	%eax, %edx
.LBB9_43:                               # %.lr.ph.i81
                                        # =>This Inner Loop Header: Depth=1
	testb	$1, %al
	movl	%r12d, %esi
	cmovel	%ecx, %esi
	imull	%esi, %r14d
	shrl	$31, %edx
	addl	%eax, %edx
	sarl	%edx
	imull	%r12d, %r12d
	incl	%eax
	cmpl	$2, %eax
	movl	%edx, %eax
	ja	.LBB9_43
	jmp	.LBB9_44
.LBB9_41:
	movl	$1, %r14d
.LBB9_44:                               # %_Z7int_powii.exit
	movl	$0, 44(%rsp)
	leaq	48(%rsp), %rdi
	movl	$4, %esi
	callq	hipMalloc
	leal	1023(%r15), %eax
	leal	2046(%r15), %edi
	testl	%eax, %eax
	cmovnsl	%eax, %edi
	sarl	$10, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$1024, %rdx                     # imm = 0x400
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB9_46
# %bb.45:
	imull	%ebp, %r14d
	movq	48(%rsp), %rsi
	movq	%rbx, %rdi
	movl	%r14d, %edx
	movl	%r15d, %ecx
	callq	_Z36__device_stub__trial_division_kernelyPiii
.LBB9_46:
	movq	48(%rsp), %rsi
	leaq	44(%rsp), %rbx
	movl	$4, %edx
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	xorl	%ebp, %ebp
	cmpl	$0, (%rbx)
	sete	%bpl
	jmp	.LBB9_47
.Lfunc_end9:
	.size	_Z3aksy, .Lfunc_end9-_Z3aksy
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI10_0:
	.quad	0x412e848000000000              # double 1.0E+6
.LCPI10_1:
	.quad	0x40c3880000000000              # double 1.0E+4
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%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
	movl	$1000000, %r15d                 # imm = 0xF4240
	callq	clock
	movq	%rax, %r14
	xorl	%ebx, %ebx
.LBB10_1:                               # =>This Inner Loop Header: Depth=1
	movq	%r15, %rdi
	callq	_Z3aksy
	testl	%eax, %eax
	je	.LBB10_3
# %bb.2:                                #   in Loop: Header=BB10_1 Depth=1
	incl	%ebx
	movl	$.L.str, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
.LBB10_3:                               #   in Loop: Header=BB10_1 Depth=1
	incq	%r15
	cmpq	$1010000, %r15                  # imm = 0xF6950
	jne	.LBB10_1
# %bb.4:
	callq	clock
	subq	%r14, %rax
	cvtsi2sd	%rax, %xmm1
	divsd	.LCPI10_0(%rip), %xmm1
	xorpd	%xmm0, %xmm0
	addsd	%xmm1, %xmm0
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	divsd	.LCPI10_1(%rip), %xmm0
	movl	$.L.str.2, %edi
	movb	$1, %al
	callq	printf
	movl	$.L.str.3, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	xorl	%eax, %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_end10:
	.size	main, .Lfunc_end10-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	.LBB11_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB11_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z21trial_division_kernelyPiii, %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_end11:
	.size	__hip_module_ctor, .Lfunc_end11-__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	.LBB12_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
.LBB12_2:
	retq
.Lfunc_end12:
	.size	__hip_module_dtor, .Lfunc_end12-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z21trial_division_kernelyPiii,@object # @_Z21trial_division_kernelyPiii
	.section	.rodata,"a",@progbits
	.globl	_Z21trial_division_kernelyPiii
	.p2align	3, 0x0
_Z21trial_division_kernelyPiii:
	.quad	_Z36__device_stub__trial_division_kernelyPiii
	.size	_Z21trial_division_kernelyPiii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%llu is prime \n"
	.size	.L.str, 16

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Time elpased is %f seconds\n"
	.size	.L.str.1, 28

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"In the 1000 trillion range average time %f\n"
	.size	.L.str.2, 44

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"number of primes in this range %d\n"
	.size	.L.str.3, 35

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z21trial_division_kernelyPiii"
	.size	.L__unnamed_1, 31

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z36__device_stub__trial_division_kernelyPiii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z21trial_division_kernelyPiii
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z21trial_division_kernelyPiii ; -- Begin function _Z21trial_division_kernelyPiii
	.globl	_Z21trial_division_kernelyPiii
	.p2align	8
	.type	_Z21trial_division_kernelyPiii,@function
_Z21trial_division_kernelyPiii:         ; @_Z21trial_division_kernelyPiii
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x24
	s_load_b64 s[2:3], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_ashr_i32 s5, s3, 31
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_mov_b32_e32 v2, 0
	s_mov_b32 s4, s3
	s_mov_b32 s3, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_ge_u64_e64 s[4:5], v[1:2]
	s_cbranch_execz .LBB0_9
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	v_cvt_f32_u32_e32 v0, s4
	v_cvt_f32_u32_e32 v7, s5
	s_cmp_eq_u64 s[4:5], 0
	s_cbranch_scc1 .LBB0_6
; %bb.2:                                ; %.lr.ph.preheader.i
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_fmamk_f32 v2, v7, 0x4f800000, v0
	s_mov_b32 s1, 0
	s_mov_b64 s[8:9], s[4:5]
	v_rcp_f32_e32 v2, v2
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v2, 0x5f7ffffc, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v3, 0x2f800000, v2
	v_trunc_f32_e32 v5, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_4)
	v_dual_mov_b32 v3, 1 :: v_dual_fmamk_f32 v6, v5, 0xcf800000, v2
	v_ashrrev_i32_e32 v2, 31, v1
	v_cvt_u32_f32_e32 v8, v5
	v_mov_b32_e32 v4, 0
	v_cvt_u32_f32_e32 v9, v6
	s_delay_alu instid0(VALU_DEP_4)
	v_dual_mov_b32 v6, v2 :: v_dual_mov_b32 v5, v1
.LBB0_3:                                ; %.lr.ph.i
                                        ; =>This Inner Loop Header: Depth=1
	s_sub_u32 s0, 0, s4
	s_subb_u32 s3, 0, s5
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_mul_hi_u32 v2, s0, v9
	v_mul_lo_u32 v10, s0, v8
	v_mul_lo_u32 v11, s3, v9
	v_add_nc_u32_e32 v2, v2, v10
	v_mul_lo_u32 v10, s0, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v2, v2, v11
	v_mul_hi_u32 v11, v9, v10
	s_delay_alu instid0(VALU_DEP_2)
	v_mul_lo_u32 v12, v9, v2
	v_mul_hi_u32 v13, v9, v2
	v_mul_hi_u32 v14, v8, v10
	v_mul_lo_u32 v10, v8, v10
	v_mul_hi_u32 v15, v8, v2
	v_mul_lo_u32 v2, v8, v2
	v_add_co_u32 v11, vcc_lo, v11, v12
	v_add_co_ci_u32_e32 v12, vcc_lo, 0, v13, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v10, vcc_lo, v11, v10
	v_add_co_ci_u32_e32 v10, vcc_lo, v12, v14, vcc_lo
	v_add_co_ci_u32_e32 v11, vcc_lo, 0, v15, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, v10, v2
	v_add_co_ci_u32_e32 v10, vcc_lo, 0, v11, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, v9, v2
	v_add_co_ci_u32_e32 v10, vcc_lo, v8, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_mul_hi_u32 v11, s0, v2
	v_mul_lo_u32 v13, s3, v2
	v_mul_lo_u32 v12, s0, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v11, v11, v12
	v_mul_lo_u32 v12, s0, v2
	v_add_nc_u32_e32 v11, v11, v13
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_hi_u32 v13, v2, v12
	v_mul_lo_u32 v14, v2, v11
	v_mul_hi_u32 v15, v2, v11
	v_mul_hi_u32 v16, v10, v12
	v_mul_lo_u32 v12, v10, v12
	v_mul_hi_u32 v17, v10, v11
	v_mul_lo_u32 v11, v10, v11
	v_add_co_u32 v13, vcc_lo, v13, v14
	v_add_co_ci_u32_e32 v14, vcc_lo, 0, v15, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v12, vcc_lo, v13, v12
	v_add_co_ci_u32_e32 v12, vcc_lo, v14, v16, vcc_lo
	v_add_co_ci_u32_e32 v13, vcc_lo, 0, v17, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v11, vcc_lo, v12, v11
	v_add_co_ci_u32_e32 v12, vcc_lo, 0, v13, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, v2, v11
	v_add_co_ci_u32_e32 v16, vcc_lo, v10, v12, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_mul_hi_u32 v17, v5, v2
	v_mad_u64_u32 v[12:13], null, v6, v2, 0
	v_mad_u64_u32 v[10:11], null, v5, v16, 0
	v_mad_u64_u32 v[14:15], null, v6, v16, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v2, vcc_lo, v17, v10
	v_add_co_ci_u32_e32 v10, vcc_lo, 0, v11, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, v2, v12
	v_add_co_ci_u32_e32 v2, vcc_lo, v10, v13, vcc_lo
	v_add_co_ci_u32_e32 v10, vcc_lo, 0, v15, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, v2, v14
	v_add_co_ci_u32_e32 v12, vcc_lo, 0, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_mul_lo_u32 v13, s5, v2
	v_mad_u64_u32 v[10:11], null, s4, v2, 0
	v_mul_lo_u32 v2, s4, v12
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_sub_co_u32 v5, vcc_lo, v5, v10
	v_add3_u32 v2, v11, v2, v13
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v11, v6, v2
	v_subrev_co_ci_u32_e64 v10, s0, s5, v11, vcc_lo
	v_sub_co_ci_u32_e32 v2, vcc_lo, v6, v2, vcc_lo
	v_sub_co_u32 v6, vcc_lo, v5, s4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_subrev_co_ci_u32_e64 v11, s0, 0, v10, vcc_lo
	v_cmp_le_u32_e64 s0, s4, v5
	v_subrev_co_ci_u32_e32 v10, vcc_lo, s5, v10, vcc_lo
	v_cmp_le_u32_e32 vcc_lo, s5, v2
	v_cndmask_b32_e64 v12, 0, -1, s0
	v_cmp_le_u32_e64 s0, s4, v6
	v_cndmask_b32_e64 v15, 0, -1, vcc_lo
	v_cmp_eq_u32_e32 vcc_lo, s5, v11
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cndmask_b32_e64 v13, 0, -1, s0
	v_cmp_le_u32_e64 s0, s5, v11
	v_cndmask_b32_e64 v14, 0, -1, s0
	v_cmp_eq_u32_e64 s0, s5, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_cndmask_b32_e32 v13, v14, v13, vcc_lo
	v_sub_co_u32 v14, vcc_lo, v6, s4
	v_subrev_co_ci_u32_e32 v10, vcc_lo, 0, v10, vcc_lo
	v_cmp_ne_u32_e32 vcc_lo, 0, v13
	v_cndmask_b32_e64 v12, v15, v12, s0
	s_and_b32 s0, s8, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	s_cmp_eq_u64 s[0:1], 0
	v_cndmask_b32_e32 v10, v11, v10, vcc_lo
	v_cndmask_b32_e32 v6, v6, v14, vcc_lo
	v_cmp_ne_u32_e32 vcc_lo, 0, v12
	v_cndmask_b32_e32 v2, v2, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_3)
	v_cndmask_b32_e32 v10, v5, v6, vcc_lo
	s_cbranch_scc1 .LBB0_5
; %bb.4:                                ;   in Loop: Header=BB0_3 Depth=1
	s_sub_u32 s0, 0, s4
	s_subb_u32 s3, 0, s5
	v_mul_hi_u32 v5, s0, v9
	v_mul_lo_u32 v6, s0, v8
	v_mul_lo_u32 v11, s3, v9
	v_mul_lo_u32 v17, v10, v4
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v5, v5, v6
	v_mul_lo_u32 v6, s0, v9
	v_add_nc_u32_e32 v5, v5, v11
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_hi_u32 v11, v9, v6
	v_mul_lo_u32 v12, v9, v5
	v_mul_hi_u32 v13, v9, v5
	v_mul_hi_u32 v14, v8, v6
	v_mul_lo_u32 v6, v8, v6
	v_mul_hi_u32 v15, v8, v5
	v_mul_lo_u32 v5, v8, v5
	v_add_co_u32 v11, vcc_lo, v11, v12
	v_add_co_ci_u32_e32 v12, vcc_lo, 0, v13, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, v11, v6
	v_add_co_ci_u32_e32 v6, vcc_lo, v12, v14, vcc_lo
	v_add_co_ci_u32_e32 v11, vcc_lo, 0, v15, vcc_lo
	v_mul_lo_u32 v15, v2, v3
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v5, vcc_lo, v6, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, 0, v11, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v11, vcc_lo, v9, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, v8, v6, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_mul_hi_u32 v5, s0, v11
	v_mul_lo_u32 v13, s3, v11
	v_mul_lo_u32 v12, s0, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v5, v5, v12
	v_mul_lo_u32 v12, s0, v11
	v_add_nc_u32_e32 v5, v5, v13
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_hi_u32 v13, v11, v12
	v_mul_lo_u32 v14, v11, v5
	v_mul_hi_u32 v16, v11, v5
	v_mul_hi_u32 v4, v6, v12
	v_mul_lo_u32 v12, v6, v12
	v_mul_hi_u32 v18, v6, v5
	v_add_co_u32 v13, vcc_lo, v13, v14
	v_add_co_ci_u32_e32 v14, vcc_lo, 0, v16, vcc_lo
	v_mul_lo_u32 v16, v6, v5
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v5, vcc_lo, v13, v12
	v_add_co_ci_u32_e32 v12, vcc_lo, v14, v4, vcc_lo
	v_add_co_ci_u32_e32 v13, vcc_lo, 0, v18, vcc_lo
	v_mad_u64_u32 v[4:5], null, v10, v3, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v3, vcc_lo, v12, v16
	v_add_co_ci_u32_e32 v12, vcc_lo, 0, v13, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, v11, v3
	v_add_co_ci_u32_e32 v16, vcc_lo, v6, v12, vcc_lo
	v_add3_u32 v15, v5, v17, v15
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_mul_hi_u32 v17, v4, v3
	v_mad_u64_u32 v[5:6], null, v4, v16, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_mad_u64_u32 v[11:12], null, v15, v3, 0
	v_mad_u64_u32 v[13:14], null, v15, v16, 0
	v_add_co_u32 v3, vcc_lo, v17, v5
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v6, vcc_lo
	v_add_co_u32 v3, vcc_lo, v3, v11
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, v5, v12, vcc_lo
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v14, vcc_lo
	v_add_co_u32 v3, vcc_lo, v3, v13
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v11, vcc_lo, 0, v5, vcc_lo
	v_mul_lo_u32 v12, s5, v3
	v_mad_u64_u32 v[5:6], null, s4, v3, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v3, s4, v11
	v_sub_co_u32 v5, vcc_lo, v4, v5
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add3_u32 v3, v6, v3, v12
	v_sub_nc_u32_e32 v6, v15, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_subrev_co_ci_u32_e64 v4, s0, s5, v6, vcc_lo
	v_sub_co_ci_u32_e32 v3, vcc_lo, v15, v3, vcc_lo
	v_sub_co_u32 v6, vcc_lo, v5, s4
	v_subrev_co_ci_u32_e64 v11, s0, 0, v4, vcc_lo
	v_cmp_le_u32_e64 s0, s4, v5
	v_subrev_co_ci_u32_e32 v4, vcc_lo, s5, v4, vcc_lo
	v_cmp_le_u32_e32 vcc_lo, s5, v3
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v12, 0, -1, s0
	v_cmp_le_u32_e64 s0, s4, v6
	v_cndmask_b32_e64 v15, 0, -1, vcc_lo
	v_cmp_eq_u32_e32 vcc_lo, s5, v11
	v_cndmask_b32_e64 v13, 0, -1, s0
	v_cmp_le_u32_e64 s0, s5, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v14, 0, -1, s0
	v_cmp_eq_u32_e64 s0, s5, v3
	v_cndmask_b32_e32 v13, v14, v13, vcc_lo
	v_sub_co_u32 v14, vcc_lo, v6, s4
	v_subrev_co_ci_u32_e32 v4, vcc_lo, 0, v4, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cmp_ne_u32_e32 vcc_lo, 0, v13
	v_cndmask_b32_e64 v12, v15, v12, s0
	v_cndmask_b32_e32 v4, v11, v4, vcc_lo
	v_cndmask_b32_e32 v6, v6, v14, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_ne_u32_e32 vcc_lo, 0, v12
	v_dual_cndmask_b32 v4, v3, v4 :: v_dual_cndmask_b32 v3, v5, v6
.LBB0_5:                                ;   in Loop: Header=BB0_3 Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v2, v10, v2
	v_mad_u64_u32 v[5:6], null, v10, v10, 0
	v_cmp_gt_u64_e64 s0, s[8:9], 1
	s_lshr_b64 s[8:9], s[8:9], 1
	s_and_b32 vcc_lo, exec_lo, s0
	s_delay_alu instid0(VALU_DEP_2)
	v_add3_u32 v6, v6, v2, v2
	s_cbranch_vccnz .LBB0_3
	s_branch .LBB0_7
.LBB0_6:
	v_mov_b32_e32 v3, 1
	v_mov_b32_e32 v4, 0
.LBB0_7:                                ; %_Z21power_mod_long_deviceiyy.exit
	v_fmamk_f32 v0, v7, 0x4f800000, v0
	s_ashr_i32 s0, s2, 31
	s_sub_u32 s1, 0, s4
	s_subb_u32 s3, 0, s5
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v0, v0
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x5f7ffffc, v0
	v_mul_f32_e32 v2, 0x2f800000, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_trunc_f32_e32 v2, v2
	v_fmamk_f32 v0, v2, 0xcf800000, v0
	v_cvt_u32_f32_e32 v2, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cvt_u32_f32_e32 v0, v0
	v_mul_lo_u32 v5, s1, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_hi_u32 v6, s1, v0
	v_mul_lo_u32 v7, s3, v0
	v_add_nc_u32_e32 v5, v6, v5
	v_mul_lo_u32 v6, s1, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v5, v5, v7
	v_mul_hi_u32 v7, v0, v6
	s_delay_alu instid0(VALU_DEP_2)
	v_mul_lo_u32 v8, v0, v5
	v_mul_hi_u32 v9, v0, v5
	v_mul_hi_u32 v10, v2, v6
	v_mul_lo_u32 v6, v2, v6
	v_mul_hi_u32 v11, v2, v5
	v_mul_lo_u32 v5, v2, v5
	v_add_co_u32 v7, vcc_lo, v7, v8
	v_add_co_ci_u32_e32 v8, vcc_lo, 0, v9, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, v7, v6
	v_add_co_ci_u32_e32 v6, vcc_lo, v8, v10, vcc_lo
	v_add_co_ci_u32_e32 v7, vcc_lo, 0, v11, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v5, vcc_lo, v6, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, 0, v7, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, v0, v5
	v_add_co_ci_u32_e32 v2, vcc_lo, v2, v6, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_mul_hi_u32 v5, s1, v0
	v_mul_lo_u32 v7, s3, v0
	v_mul_lo_u32 v6, s1, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_add_nc_u32_e32 v5, v5, v6
	v_mul_lo_u32 v6, s1, v0
	v_sub_co_u32 v1, s1, s2, v1
	v_add_nc_u32_e32 v5, v5, v7
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_hi_u32 v7, v0, v6
	v_mul_lo_u32 v8, v0, v5
	v_mul_hi_u32 v9, v0, v5
	v_mul_hi_u32 v10, v2, v6
	v_mul_lo_u32 v6, v2, v6
	v_mul_hi_u32 v11, v2, v5
	v_mul_lo_u32 v5, v2, v5
	v_add_co_u32 v7, vcc_lo, v7, v8
	v_add_co_ci_u32_e32 v8, vcc_lo, 0, v9, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, v7, v6
	v_add_co_ci_u32_e32 v6, vcc_lo, v8, v10, vcc_lo
	v_add_co_ci_u32_e32 v7, vcc_lo, 0, v11, vcc_lo
	v_sub_co_ci_u32_e64 v8, null, s0, 0, s1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v5, vcc_lo, v6, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, 0, v7, vcc_lo
	v_add_co_u32 v7, vcc_lo, v1, v3
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v5, s0, v0, v5
	v_add_co_ci_u32_e64 v6, s0, v2, v6, s0
	v_add_co_ci_u32_e32 v8, vcc_lo, v8, v4, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_mul_hi_u32 v9, v7, v5
	v_mad_u64_u32 v[0:1], null, v7, v6, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_mad_u64_u32 v[2:3], null, v8, v5, 0
	v_mad_u64_u32 v[4:5], null, v8, v6, 0
	v_add_co_u32 v0, vcc_lo, v9, v0
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, 0, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, v0, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v0, vcc_lo, v1, v3, vcc_lo
	v_add_co_ci_u32_e32 v1, vcc_lo, 0, v5, vcc_lo
	v_add_co_u32 v2, vcc_lo, v0, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v1, vcc_lo
	v_mul_lo_u32 v4, s5, v2
	v_mad_u64_u32 v[0:1], null, s4, v2, 0
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v2, s4, v3
	v_sub_co_u32 v0, vcc_lo, v7, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add3_u32 v1, v1, v2, v4
	v_sub_nc_u32_e32 v2, v8, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_subrev_co_ci_u32_e64 v2, s0, s5, v2, vcc_lo
	v_sub_co_ci_u32_e32 v1, vcc_lo, v8, v1, vcc_lo
	v_sub_co_u32 v3, vcc_lo, v0, s4
	v_subrev_co_ci_u32_e64 v4, s0, 0, v2, vcc_lo
	v_cmp_le_u32_e64 s0, s4, v0
	v_subrev_co_ci_u32_e32 v2, vcc_lo, s5, v2, vcc_lo
	v_cmp_le_u32_e32 vcc_lo, s5, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v5, 0, -1, s0
	v_cmp_le_u32_e64 s0, s4, v3
	v_cndmask_b32_e64 v8, 0, -1, vcc_lo
	v_cmp_eq_u32_e32 vcc_lo, s5, v4
	v_cndmask_b32_e64 v6, 0, -1, s0
	v_cmp_le_u32_e64 s0, s5, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v7, 0, -1, s0
	v_cmp_eq_u32_e64 s0, s5, v1
	v_cndmask_b32_e32 v6, v7, v6, vcc_lo
	v_sub_co_u32 v7, vcc_lo, v3, s4
	v_subrev_co_ci_u32_e32 v2, vcc_lo, 0, v2, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_cmp_ne_u32_e32 vcc_lo, 0, v6
	v_cndmask_b32_e64 v5, v8, v5, s0
	v_dual_cndmask_b32 v2, v4, v2 :: v_dual_cndmask_b32 v3, v3, v7
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_ne_u32_e32 vcc_lo, 0, v5
	v_dual_cndmask_b32 v1, v1, v2 :: v_dual_cndmask_b32 v0, v0, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_ne_u64_e32 vcc_lo, 0, v[0:1]
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_9
; %bb.8:
	v_dual_mov_b32 v0, 0 :: v_dual_mov_b32 v1, 1
	global_store_b32 v0, v1, s[6:7]
.LBB0_9:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z21trial_division_kernelyPiii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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 19
		.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	_Z21trial_division_kernelyPiii, .Lfunc_end0-_Z21trial_division_kernelyPiii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 2448
; NumSgprs: 18
; NumVgprs: 19
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 19
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

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

	.end_amdgpu_metadata
