#include <assert.h>
#include <cuda.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

static char* program_name;

// Just defination
__global__ void Jacobi(int** a, const int** b, const int N) {
  int i = blockIdx.x * blockDim.x + threadIdx.x;
  int j = blockIdx.y * blockDim.y + threadIdx.y;
  if (i < N && j < N) {
    a[i][j] = 0.8 * (b[i + 1][j] + b[i + 1][j] + b[i][j + 1] + b[i][j + 1]);
  }
}

// Usage
void print_usage(FILE* stream, int exit_code) {
  fprintf(stream, "Usage:  %s options\n", program_name);
  fprintf(stream,
          "  -h  --help             Display this usage information.\n"
          "  -f  --file filename    File containing coefficient matrix.\n"
          "  -i  --Ni int           Number of elements in Y direction "
          "(default=512).\n"
          "  -j  --Nj int           Number of elements in X direction "
          "(default=512).\n"
          "  -n  --iterations int   Number of iterations (default=10000).\n"
          "  -k  --kernel [1,2]     1: unoptimized, 2: optimized kernel "
          "(default).\n"
          "  -t  --tilesize int     Size of each thread block in kernel 2 "
          "(default=4).\n");
  exit(exit_code);
}

// Host version of the Jacobi method
void jacobiOnHost(float* x_next, float* A, float* x_now, float* b, int Ni,
                  int Nj) {
  int i, j;
  float sigma;

  for (i = 0; i < Ni; i++) {
    sigma = 0.0;
    for (j = 0; j < Nj; j++) {
      if (i != j) sigma += A[i * Nj + j] * x_now[j];
    }
    x_next[i] = (b[i] - sigma) / A[i * Nj + i];
  }
}

// Device version of the Jacobi method
__global__ void jacobiOnDevice(float* x_next, float* A, float* x_now, float* b,
                               int Ni, int Nj) {
  float sigma = 0.0;
  int idx = threadIdx.x;
  for (int j = 0; j < Nj; j++) {
    if (idx != j) sigma += A[idx * Nj + j] * x_now[j];
  }
  x_next[idx] = (b[idx] - sigma) / A[idx * Nj + idx];
}

// Optimized device version of the Jacobi method
__global__ void jacobiOptimizedOnDevice(float* x_next, float* A, float* x_now,
                                        float* b, int Ni, int Nj) {
  // Optimization step 1: tiling
  int idx = blockIdx.x * blockDim.x + threadIdx.x;

  if (idx < Ni) {
    float sigma = 0.0;

    // Optimization step 2: store index in register
    // Multiplication is not executed in every iteration.
    int idx_Ai = idx * Nj;

    // Tried to use prefetching, but then the result is terribly wrong and I
    // don't know why..
    /*
    float curr_A = A[idx_Ai];
    float nxt_A;
    //printf("idx=%d\n",idx);
    for (int j=0; j<Nj-1; j++)
    {
        if (idx != j)
            nxt_A = A[idx_Ai + j + 1];
            sigma += curr_A * x_now[j];
            //sigma += A[idx_Ai + j] * x_now[j];
            curr_A = nxt_A;
            //printf("curr_A=%f\n",curr_A);
    }
    if (idx != Nj-1)
        sigma += nxt_A * x_now[Nj-1];
    x_next[idx] = (b[idx] - sigma) / A[idx_Ai + idx];
    */

    for (int j = 0; j < Nj; j++)
      if (idx != j) sigma += A[idx_Ai + j] * x_now[j];

    // Tried to use loop-ennrolling, but also here this gives a wrong result..
    /*
    for (int j=0; j<Nj/4; j+=4)
    {
        if (idx != j)
        {
            sigma += A[idx_Ai + j] * x_now[j];
        }
        if (idx != j+1)
        {
            sigma += A[idx_Ai + j+1] * x_now[j+1];
        }
        if (idx != j+2)
        {
           sigma += A[idx_Ai + j+2] * x_now[j+2];
        }
        if (idx != j+3)
        {
            sigma += A[idx_Ai + j+3] * x_now[j+3];
        }
    }*/

    x_next[idx] = (b[idx] - sigma) / A[idx_Ai + idx];
  }
}

// device selection (copied from previous assignment)
static void selectGpu(int* gpu_num, int* num_devs) {
  // gpu_num: (I/O): I: Default choice,
  //                 O: best device, changed only if more than one device
  // num_devs: (O)   Number of found devices.
  int best = *gpu_num;

  cudaGetDeviceCount(num_devs);
  if (*num_devs > 1) {
    int dev_num;
    int max_cores = 0;

    for (dev_num = 0; dev_num < *num_devs; dev_num++) {
      cudaDeviceProp dev_properties;

      cudaGetDeviceProperties(&dev_properties, dev_num);
      if (max_cores < dev_properties.multiProcessorCount) {
        max_cores = dev_properties.multiProcessorCount;
        best = dev_num;
      }
    }
    *gpu_num = best;
  }
}

// device test (copied from previous assignment)
static void testDevice(int devID) {
  // Check if we can run. Maybe do something more...
  cudaDeviceProp deviceProp;

  cudaGetDeviceProperties(&deviceProp, devID);
  if (deviceProp.major == 9999 &&
      deviceProp.minor == 9999) { /* Simulated device. */
    printf("There is no device supporting CUDA.\n");
    // cudaThreadExit();
  } else
    printf("Using GPU device number %d.\n", devID);
}

int main(int argc, char* argv[]) {
  // initialize timing variables
  time_t start, end, start_h, end_h, start_d, end_d;
  float t_full, t_host, t_dev;

  start = clock();

  // initialize data variables
  float *x_now, *x_next, *A, *b, *x_h, *x_d;
  float *x_now_d, *x_next_d, *A_d, *b_d;

  // initialize parameter variables
  int N, Ni, Nj, iter, kernel, tileSize;
  int ch;
  int i, k;
  char* fname;
  FILE* file;

  // Argument parsing
  static struct option long_options[] = {
      {"file", required_argument, NULL, 'f'},
      {"Ni", optional_argument, NULL, 'i'},
      {"Nj", optional_argument, NULL, 'j'},
      {"iterations", optional_argument, NULL, 'n'},
      {"kernel", optional_argument, NULL, 'k'},
      {"tilesize", optional_argument, NULL, 't'},
      {"help", optional_argument, NULL, 'h'},
      {NULL, 0, NULL, 0}};

  program_name = argv[0];
  Ni = 512, Nj = 512, iter = 10000, kernel = 2, tileSize = 4;
  ch = 0;

  while ((ch = getopt_long(argc, argv, "f:i:j:n:k:h", long_options, NULL)) !=
         -1) {
    switch (ch) {
      case 'f':
        fname = optarg;
        break;
      case 'i':
        Ni = atoi(optarg);
        break;
      case 'j':
        Nj = atoi(optarg);
        break;
      case 'n':
        iter = atoi(optarg);
        break;
      case 'k':
        kernel = atoi(optarg);
        break;
      case 't':
        tileSize = atoi(optarg);
        break;
      case 'h':
        print_usage(stderr, 1);
        exit(EXIT_FAILURE);
      case '?':
        print_usage(stderr, 1);
        exit(EXIT_FAILURE);
      default:
        abort();
    }
  }

  N = Ni * Nj;

  printf("\nRunning Jacobi method:\n");
  printf("======================\n\n");
  printf("Coefficient matrix given in file: \n%s\n\n", fname);
  printf("Parameters:\n");
  printf("N=%d, Ni=%d, Nj=%d, ", N, Ni, Nj);
  printf("iterations=%d, kernel=%d, tilesize=%d\n", iter, kernel, tileSize);

  // Allocate memory on host
  x_next = (float*)malloc(Ni * sizeof(float));
  A = (float*)malloc(N * sizeof(float));
  x_now = (float*)malloc(Ni * sizeof(float));
  b = (float*)malloc(Ni * sizeof(float));
  x_h = (float*)malloc(Ni * sizeof(float));
  x_d = (float*)malloc(Ni * sizeof(float));

  // Initialize result vector x
  for (i = 0; i < Ni; i++) {
    x_now[i] = 0;
    x_next[i] = 0;
  }

  // Read coefficient matrix from file
  file = fopen(fname, "r");
  if (file == NULL) exit(EXIT_FAILURE);
  char* line;
  size_t len = 0;
  i = 0;
  while ((getline(&line, &len, file)) != -1) {
    if (i < N)
      A[i] = atof(line);
    else
      b[i - N] = atof(line);
    i++;
  }

  start_h = clock();

  // Run "iter" iterations of the Jacobi method on HOST
  for (k = 0; k < iter; k++) {
    if (k % 2)
      jacobiOnHost(x_now, A, x_next, b, Ni, Nj);
    else
      jacobiOnHost(x_next, A, x_now, b, Ni, Nj);
    // for (i=0; i<Nj; i++)
    //    x_now[i] = x_next[i];
  }

  end_h = clock();

  // Save result from host in x_h
  for (i = 0; i < Nj; i++) x_h[i] = x_next[i];

  // Re-initialize result vector x for device computation
  for (i = 0; i < Ni; i++) {
    x_now[i] = 0;
    x_next[i] = 0;
  }

  // Check available device.
  int devID = 0, num_devs = 1;
  selectGpu(&devID, &num_devs);
  testDevice(devID);

  // Allocate memory on the device
  assert(cudaSuccess == cudaMalloc((void**)&x_next_d, Ni * sizeof(float)));
  assert(cudaSuccess == cudaMalloc((void**)&A_d, N * sizeof(float)));
  assert(cudaSuccess == cudaMalloc((void**)&x_now_d, Ni * sizeof(float)));
  assert(cudaSuccess == cudaMalloc((void**)&b_d, Ni * sizeof(float)));

  // Copy data -> device
  cudaMemcpy(x_next_d, x_next, sizeof(float) * Ni, cudaMemcpyHostToDevice);
  cudaMemcpy(A_d, A, sizeof(float) * N, cudaMemcpyHostToDevice);
  cudaMemcpy(x_now_d, x_now, sizeof(float) * Ni, cudaMemcpyHostToDevice);
  cudaMemcpy(b_d, b, sizeof(float) * Ni, cudaMemcpyHostToDevice);

  // Compute grid and block size.
  // Un-optimized kernel
  int blockSize = Ni;
  int nBlocks = 1;

  // Optimized kernel
  int nTiles = Ni / tileSize + (Ni % tileSize == 0 ? 0 : 1);
  int gridHeight = Nj / tileSize + (Nj % tileSize == 0 ? 0 : 1);
  int gridWidth = Ni / tileSize + (Ni % tileSize == 0 ? 0 : 1);
  printf("w=%d, h=%d\n", gridWidth, gridHeight);
  dim3 dGrid(gridHeight, gridWidth), dBlock(tileSize, tileSize);

  start_d = clock();

  // Run "iter" iterations of the Jacobi method on DEVICE
  if (kernel == 1) {
    printf("Using un-optimized kernel.\n");
    for (k = 0; k < iter; k++) {
      if (k % 2)
        jacobiOnDevice<<<nBlocks, blockSize>>>(x_now_d, A_d, x_next_d, b_d, Ni,
                                               Nj);
      else
        jacobiOnDevice<<<nBlocks, blockSize>>>(x_next_d, A_d, x_now_d, b_d, Ni,
                                               Nj);
      // cudaMemcpy(x_now_d, x_next_d, sizeof(float)*Ni,
      // cudaMemcpyDeviceToDevice);
    }
  } else {
    printf("Using optimized kernel.\n");
    for (k = 0; k < iter; k++) {
      if (k % 2)
        jacobiOptimizedOnDevice<<<nTiles, tileSize>>>(x_now_d, A_d, x_next_d,
                                                      b_d, Ni, Nj);
      else
        jacobiOptimizedOnDevice<<<nTiles, tileSize>>>(x_next_d, A_d, x_now_d,
                                                      b_d, Ni, Nj);
      // cudaMemcpy(x_now_d, x_next_d, sizeof(float)*Ni,
      // cudaMemcpyDeviceToDevice);
    }
  }

  end_d = clock();

  // Data <- device
  cudaMemcpy(x_d, x_next_d, sizeof(float) * Ni, cudaMemcpyDeviceToHost);

  // Free memory
  free(x_next);
  free(A);
  free(x_now);
  free(b);
  cudaFree(x_next_d);
  cudaFree(A_d);
  cudaFree(x_now_d);
  cudaFree(b_d);

  end = clock();

  printf("\nResult after %d iterations:\n", iter);
  float err = 0.0;
  for (i = 0; i < Ni; i++) {
    // printf("x_h[%d]=%f\n",i,x_h[i]);
    // printf("x_d[%d]=%f\n",i,x_d[i]);
    err += abs(x_h[i] - x_d[i]) / Ni;
  }
  printf("x_h[%d]=%f\n", 0, x_h[0]);
  printf("x_d[%d]=%f\n", 0, x_d[0]);
  t_full = ((float)end - (float)start) / CLOCKS_PER_SEC;
  t_host = ((float)end_h - (float)start_h) / CLOCKS_PER_SEC;
  t_dev = ((float)end_d - (float)start_d) / CLOCKS_PER_SEC;
  printf("\nTiming:\nFull: %f\nHost: %f\nDevice: %f\n\n", t_full, t_host,
         t_dev);
  printf("Relative error: %f\n", err);

  printf("\nProgram terminated successfully.\n");
  return 0;
}
	.file	"tmpxft_002f0997_00000000-6_jacobian.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2034:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2034:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Usage:  %s options\n"
.LC1:
	.ascii	"  -h  --help             Display this usage information.\n  "
	.ascii	"-f  --file filename    File containing coefficient matrix.\n"
	.ascii	"  -i  --Ni int           Number of elements in Y direction ("
	.ascii	"default=512).\n  -j  --Nj int           Numb"
	.string	"er of elements in X direction (default=512).\n  -n  --iterations int   Number of iterations (default=10000).\n  -k  --kernel [1,2]     1: unoptimized, 2: optimized kernel (default).\n  -t  --tilesize int     Size of each thread block in kernel 2 (default=4).\n"
	.text
	.globl	_Z11print_usageP8_IO_FILEi
	.type	_Z11print_usageP8_IO_FILEi, @function
_Z11print_usageP8_IO_FILEi:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC0(%rip), %rdx
	movl	%esi, %ebp
	xorl	%eax, %eax
	movl	$2, %esi
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	movq	_ZL12program_name(%rip), %rcx
	movq	%rdi, 8(%rsp)
	call	__fprintf_chk@PLT
	movq	8(%rsp), %rdi
	leaq	.LC1(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movl	%ebp, %edi
	call	exit@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z11print_usageP8_IO_FILEi, .-_Z11print_usageP8_IO_FILEi
	.globl	_Z12jacobiOnHostPfS_S_S_ii
	.type	_Z12jacobiOnHostPfS_S_S_ii, @function
_Z12jacobiOnHostPfS_S_S_ii:
.LFB2028:
	.cfi_startproc
	endbr64
	movslq	%r9d, %rax
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rdi, %r10
	movq	%rdx, %r11
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	xorl	%edi, %edi
	leaq	4(,%rax,4), %r12
	xorl	%eax, %eax
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rcx, %rbx
	movq	%rsi, %rcx
.L5:
	movl	%eax, %r13d
	cmpl	%eax, %r8d
	jle	.L12
	xorl	%edx, %edx
	xorps	%xmm1, %xmm1
.L8:
	cmpl	%edx, %r9d
	jle	.L13
	cmpl	%r13d, %edx
	je	.L6
	leal	(%rdi,%rdx), %ebp
	movslq	%ebp, %rbp
	movss	(%rsi,%rbp,4), %xmm0
	mulss	(%r11,%rdx,4), %xmm0
	addss	%xmm0, %xmm1
.L6:
	incq	%rdx
	jmp	.L8
.L13:
	movss	(%rbx,%rax,4), %xmm0
	addl	%r9d, %edi
	subss	%xmm1, %xmm0
	divss	(%rcx), %xmm0
	addq	%r12, %rcx
	movss	%xmm0, (%r10,%rax,4)
	incq	%rax
	jmp	.L5
.L12:
	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
.LFE2028:
	.size	_Z12jacobiOnHostPfS_S_S_ii, .-_Z12jacobiOnHostPfS_S_S_ii
	.globl	_Z31__device_stub__Z6JacobiPPiPPKiiPPiPPKii
	.type	_Z31__device_stub__Z6JacobiPPiPPKiiPPiPPKii, @function
_Z31__device_stub__Z6JacobiPPiPPKiiPPiPPKii:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L14
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z6JacobiPPiPPKii(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L14:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L16
	call	__stack_chk_fail@PLT
.L16:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z31__device_stub__Z6JacobiPPiPPKiiPPiPPKii, .-_Z31__device_stub__Z6JacobiPPiPPKiiPPiPPKii
	.globl	_Z6JacobiPPiPPKii
	.type	_Z6JacobiPPiPPKii, @function
_Z6JacobiPPiPPKii:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z6JacobiPPiPPKiiPPiPPKii
	.cfi_endproc
.LFE2057:
	.size	_Z6JacobiPPiPPKii, .-_Z6JacobiPPiPPKii
	.globl	_Z42__device_stub__Z14jacobiOnDevicePfS_S_S_iiPfS_S_S_ii
	.type	_Z42__device_stub__Z14jacobiOnDevicePfS_S_S_iiPfS_S_S_ii, @function
_Z42__device_stub__Z14jacobiOnDevicePfS_S_S_iiPfS_S_S_ii:
.LFB2058:
	.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	.L19
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z14jacobiOnDevicePfS_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
.L19:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z42__device_stub__Z14jacobiOnDevicePfS_S_S_iiPfS_S_S_ii, .-_Z42__device_stub__Z14jacobiOnDevicePfS_S_S_iiPfS_S_S_ii
	.globl	_Z14jacobiOnDevicePfS_S_S_ii
	.type	_Z14jacobiOnDevicePfS_S_S_ii, @function
_Z14jacobiOnDevicePfS_S_S_ii:
.LFB2059:
	.cfi_startproc
	endbr64
	jmp	_Z42__device_stub__Z14jacobiOnDevicePfS_S_S_iiPfS_S_S_ii
	.cfi_endproc
.LFE2059:
	.size	_Z14jacobiOnDevicePfS_S_S_ii, .-_Z14jacobiOnDevicePfS_S_S_ii
	.globl	_Z51__device_stub__Z23jacobiOptimizedOnDevicePfS_S_S_iiPfS_S_S_ii
	.type	_Z51__device_stub__Z23jacobiOptimizedOnDevicePfS_S_S_iiPfS_S_S_ii, @function
_Z51__device_stub__Z23jacobiOptimizedOnDevicePfS_S_S_iiPfS_S_S_ii:
.LFB2060:
	.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	.L24
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z23jacobiOptimizedOnDevicePfS_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
.L24:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2060:
	.size	_Z51__device_stub__Z23jacobiOptimizedOnDevicePfS_S_S_iiPfS_S_S_ii, .-_Z51__device_stub__Z23jacobiOptimizedOnDevicePfS_S_S_iiPfS_S_S_ii
	.globl	_Z23jacobiOptimizedOnDevicePfS_S_S_ii
	.type	_Z23jacobiOptimizedOnDevicePfS_S_S_ii, @function
_Z23jacobiOptimizedOnDevicePfS_S_S_ii:
.LFB2061:
	.cfi_startproc
	endbr64
	jmp	_Z51__device_stub__Z23jacobiOptimizedOnDevicePfS_S_S_iiPfS_S_S_ii
	.cfi_endproc
.LFE2061:
	.size	_Z23jacobiOptimizedOnDevicePfS_S_S_ii, .-_Z23jacobiOptimizedOnDevicePfS_S_S_ii
	.section	.rodata.str1.1
.LC3:
	.string	"f:i:j:n:k:h"
.LC4:
	.string	"\nRunning Jacobi method:\n"
.LC5:
	.string	"======================\n\n"
.LC6:
	.string	"Coefficient matrix given in file: \n%s\n\n"
.LC7:
	.string	"Parameters:\n"
.LC8:
	.string	"N=%d, Ni=%d, Nj=%d, "
.LC9:
	.string	"iterations=%d, kernel=%d, tilesize=%d\n"
.LC10:
	.string	"r"
.LC11:
	.string	"There is no device supporting CUDA.\n"
.LC12:
	.string	"Using GPU device number %d.\n"
.LC13:
	.string	"w=%d, h=%d\n"
.LC14:
	.string	"Using un-optimized kernel.\n"
.LC15:
	.string	"\nResult after %d iterations:\n"
.LC16:
	.string	"Using optimized kernel.\n"
.LC18:
	.string	"x_h[%d]=%f\n"
.LC19:
	.string	"x_d[%d]=%f\n"
.LC21:
	.string	"\nTiming:\nFull: %f\nHost: %f\nDevice: %f\n\n"
.LC22:
	.string	"Relative error: %f\n"
.LC23:
	.string	"\nProgram terminated successfully.\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	leaq	_ZZ4mainE12long_options(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%edi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	$4, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	$512, %ebx
	subq	$1208, %rsp
	.cfi_def_cfa_offset 1264
	movq	%fs:40, %rax
	movq	%rax, 1192(%rsp)
	xorl	%eax, %eax
	call	clock@PLT
	movl	$2, 52(%rsp)
	movq	%rax, 80(%rsp)
	movq	(%r12), %rax
	movl	$10000, 48(%rsp)
	movq	%rax, _ZL12program_name(%rip)
	movl	$512, 8(%rsp)
.L30:
	xorl	%r8d, %r8d
	movq	%r15, %rcx
	leaq	.LC3(%rip), %rdx
	movq	%r12, %rsi
	movl	%r14d, %edi
	call	getopt_long@PLT
	cmpl	$-1, %eax
	je	.L91
	cmpl	$63, %eax
	je	.L31
	subl	$102, %eax
	cmpl	$14, %eax
	ja	.L32
	leaq	.L34(%rip), %rdx
	movslq	(%rdx,%rax,4), %rax
	addq	%rdx, %rax
	notrack jmp	*%rax
	.section	.rodata
	.align 4
	.align 4
.L34:
	.long	.L39-.L34
	.long	.L32-.L34
	.long	.L31-.L34
	.long	.L38-.L34
	.long	.L37-.L34
	.long	.L36-.L34
	.long	.L32-.L34
	.long	.L32-.L34
	.long	.L35-.L34
	.long	.L32-.L34
	.long	.L32-.L34
	.long	.L32-.L34
	.long	.L32-.L34
	.long	.L32-.L34
	.long	.L33-.L34
	.section	.text.startup
.L39:
	movq	optarg(%rip), %r13
	jmp	.L30
.L38:
	movq	optarg(%rip), %rdi
	call	atoi@PLT
	movl	%eax, %ebx
	jmp	.L30
.L37:
	movq	optarg(%rip), %rdi
	call	atoi@PLT
	movl	%eax, 8(%rsp)
	jmp	.L30
.L35:
	movq	optarg(%rip), %rdi
	call	atoi@PLT
	movl	%eax, 48(%rsp)
	jmp	.L30
.L36:
	movq	optarg(%rip), %rdi
	call	atoi@PLT
	movl	%eax, 52(%rsp)
	jmp	.L30
.L33:
	movq	optarg(%rip), %rdi
	call	atoi@PLT
	movl	%eax, %ebp
	jmp	.L30
.L31:
	movq	1192(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L90
	movq	stderr(%rip), %rdi
	movl	$1, %esi
	call	_Z11print_usageP8_IO_FILEi
.L32:
	call	abort@PLT
.L91:
	movl	8(%rsp), %r14d
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	imull	%ebx, %r14d
	movq	%r13, %rdx
	xorl	%eax, %eax
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	8(%rsp), %r8d
	movl	%ebx, %ecx
	movl	%r14d, %edx
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	52(%rsp), %ecx
	movl	48(%rsp), %edx
	movl	%ebp, %r8d
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movslq	%ebx, %rax
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, 16(%rsp)
	call	malloc@PLT
	movq	%rax, %r12
	movslq	%r14d, %rax
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, 72(%rsp)
	call	malloc@PLT
	movq	16(%rsp), %rdi
	movq	%rax, 32(%rsp)
	call	malloc@PLT
	movq	16(%rsp), %rdi
	movq	%rax, 24(%rsp)
	call	malloc@PLT
	movq	16(%rsp), %rdi
	movq	%rax, 40(%rsp)
	call	malloc@PLT
	movq	16(%rsp), %rdi
	movq	%rax, 56(%rsp)
	call	malloc@PLT
	movq	%rax, 64(%rsp)
	xorl	%eax, %eax
.L43:
	cmpl	%eax, %ebx
	jle	.L92
	movq	24(%rsp), %rcx
	movl	$0x00000000, (%r12,%rax,4)
	movl	$0x00000000, (%rcx,%rax,4)
	incq	%rax
	jmp	.L43
.L92:
	movq	%r13, %rdi
	leaq	.LC10(%rip), %rsi
	call	fopen@PLT
	movq	%rax, %r13
	testq	%rax, %rax
	jne	.L45
	movl	$1, %edi
	call	exit@PLT
.L45:
	xorl	%eax, %eax
	xorl	%r15d, %r15d
	movq	%rax, 128(%rsp)
	leaq	128(%rsp), %rax
	movq	%rax, 88(%rsp)
.L46:
	movq	88(%rsp), %rsi
	leaq	120(%rsp), %rdi
	movq	%r13, %rdx
	call	getline@PLT
	incq	%rax
	je	.L93
	movq	120(%rsp), %rdi
	call	atof@PLT
	cvtsd2ss	%xmm0, %xmm0
	cmpl	%r15d, %r14d
	jle	.L47
	movq	32(%rsp), %rax
	movss	%xmm0, (%rax,%r15,4)
	jmp	.L48
.L47:
	movl	%r15d, %eax
	movq	40(%rsp), %rcx
	subl	%r14d, %eax
	cltq
	movss	%xmm0, (%rcx,%rax,4)
.L48:
	incq	%r15
	jmp	.L46
.L93:
	call	clock@PLT
	xorl	%r13d, %r13d
	movq	%rax, 88(%rsp)
.L50:
	cmpl	%r13d, 48(%rsp)
	jle	.L94
	movl	8(%rsp), %r9d
	movq	40(%rsp), %rcx
	movl	%ebx, %r8d
	testl	$1, %r13d
	je	.L51
	movq	32(%rsp), %rsi
	movq	24(%rsp), %rdi
	movq	%r12, %rdx
	jmp	.L87
.L51:
	movq	24(%rsp), %rdx
	movq	32(%rsp), %rsi
	movq	%r12, %rdi
.L87:
	call	_Z12jacobiOnHostPfS_S_S_ii
	incl	%r13d
	jmp	.L50
.L94:
	call	clock@PLT
	movq	%rax, 96(%rsp)
	xorl	%eax, %eax
.L54:
	cmpl	%eax, 8(%rsp)
	jle	.L95
	movss	(%r12,%rax,4), %xmm0
	movq	56(%rsp), %rcx
	movss	%xmm0, (%rcx,%rax,4)
	incq	%rax
	jmp	.L54
.L95:
	xorl	%eax, %eax
.L56:
	cmpl	%eax, %ebx
	jle	.L96
	movq	24(%rsp), %rcx
	movl	$0x00000000, (%r12,%rax,4)
	movl	$0x00000000, (%rcx,%rax,4)
	incq	%rax
	jmp	.L56
.L96:
	leaq	116(%rsp), %rdi
	movl	$1, 116(%rsp)
	xorl	%r14d, %r14d
	call	cudaGetDeviceCount@PLT
	cmpl	$1, 116(%rsp)
	jle	.L59
	leaq	160(%rsp), %rax
	xorl	%r13d, %r13d
	xorl	%r15d, %r15d
	xorl	%r14d, %r14d
	movq	%rax, 104(%rsp)
.L58:
	cmpl	116(%rsp), %r15d
	jge	.L59
	movq	104(%rsp), %rdi
	movl	%r15d, %esi
	call	cudaGetDeviceProperties_v2@PLT
	movl	548(%rsp), %eax
	cmpl	%r13d, %eax
	jg	.L82
	movl	%r13d, %eax
	jmp	.L60
.L82:
	movl	%r15d, %r14d
.L60:
	incl	%r15d
	movl	%eax, %r13d
	jmp	.L58
.L59:
	leaq	160(%rsp), %rdi
	movl	%r14d, %esi
	call	cudaGetDeviceProperties_v2@PLT
	movabsq	$42945378002703, %rax
	cmpq	%rax, 520(%rsp)
	jne	.L62
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L63
.L62:
	movl	%r14d, %edx
	leaq	.LC12(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L63:
	movq	16(%rsp), %rdx
	xorl	%edi, %edi
	movl	$1, %ecx
	movq	%r12, %rsi
	call	cudaMemcpy@PLT
	movq	72(%rsp), %rdx
	movq	32(%rsp), %rsi
	xorl	%edi, %edi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdx
	movq	24(%rsp), %rsi
	xorl	%edi, %edi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	16(%rsp), %rdx
	movq	40(%rsp), %rsi
	xorl	%edi, %edi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	%ebx, %eax
	movl	$2, %edi
	leaq	.LC13(%rip), %rsi
	cltd
	idivl	%ebp
	cmpl	$1, %edx
	sbbl	$-1, %eax
	movl	%eax, %r13d
	movl	8(%rsp), %eax
	cltd
	idivl	%ebp
	cmpl	$1, %edx
	movl	%r13d, %edx
	sbbl	$-1, %eax
	movl	%eax, %ecx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	call	clock@PLT
	cmpl	$1, 52(%rsp)
	movq	%rax, 72(%rsp)
	jne	.L64
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%r13d, %r13d
	call	__printf_chk@PLT
	movabsq	$4294967297, %rbp
.L65:
	cmpl	%r13d, 48(%rsp)
	jle	.L78
	movl	%ebx, 148(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%rbp, %rdi
	movq	%rbp, 152(%rsp)
	movl	$1, %esi
	movl	156(%rsp), %ecx
	movq	%rbp, 136(%rsp)
	movq	148(%rsp), %rdx
	movl	$1, 144(%rsp)
	testl	$1, %r13d
	je	.L66
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L68
	xorl	%edi, %edi
	movl	8(%rsp), %r9d
	movl	%ebx, %r8d
	xorl	%edx, %edx
	movq	%rdi, %rcx
	jmp	.L88
.L66:
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L68
	xorl	%edi, %edi
	movl	8(%rsp), %r9d
	movl	%ebx, %r8d
	movq	%rdi, %rcx
	movq	%rdi, %rdx
.L88:
	movq	%rdi, %rsi
	call	_Z42__device_stub__Z14jacobiOnDevicePfS_S_S_iiPfS_S_S_ii
.L68:
	incl	%r13d
	jmp	.L65
.L64:
	leaq	.LC16(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%r14d, %r14d
	call	__printf_chk@PLT
	movabsq	$4294967297, %r15
.L72:
	cmpl	%r14d, 48(%rsp)
	jg	.L77
.L78:
	call	clock@PLT
	xorl	%r10d, %r10d
	movq	16(%rsp), %rdx
	movq	64(%rsp), %rdi
	movq	%r10, %rsi
	movl	$2, %ecx
	movq	%r10, 8(%rsp)
	movq	%rax, %rbp
	call	cudaMemcpy@PLT
	movq	%r12, %rdi
	call	free@PLT
	movq	32(%rsp), %rdi
	call	free@PLT
	movq	24(%rsp), %rdi
	call	free@PLT
	movq	40(%rsp), %rdi
	call	free@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	xorl	%edi, %edi
	call	cudaFree@PLT
	xorl	%edi, %edi
	call	cudaFree@PLT
	xorl	%edi, %edi
	call	cudaFree@PLT
	call	clock@PLT
	movl	48(%rsp), %edx
	movl	$2, %edi
	leaq	.LC15(%rip), %rsi
	movq	%rax, %r12
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%eax, %eax
	xorps	%xmm3, %xmm3
	movss	.LC17(%rip), %xmm1
	jmp	.L71
.L77:
	movq	%r15, 152(%rsp)
	xorl	%r9d, %r9d
	movl	156(%rsp), %ecx
	xorl	%r8d, %r8d
	movq	%r15, 140(%rsp)
	movl	144(%rsp), %esi
	movl	%ebp, 148(%rsp)
	movq	148(%rsp), %rdx
	movl	%r13d, 136(%rsp)
	movq	136(%rsp), %rdi
	testl	$1, %r14d
	je	.L73
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L75
	xorl	%edi, %edi
	movl	8(%rsp), %r9d
	movl	%ebx, %r8d
	xorl	%edx, %edx
	movq	%rdi, %rcx
	jmp	.L89
.L73:
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L75
	xorl	%edi, %edi
	movl	8(%rsp), %r9d
	movl	%ebx, %r8d
	movq	%rdi, %rcx
	movq	%rdi, %rdx
.L89:
	movq	%rdi, %rsi
	call	_Z51__device_stub__Z23jacobiOptimizedOnDevicePfS_S_S_iiPfS_S_S_ii
.L75:
	incl	%r14d
	jmp	.L72
.L71:
	cmpl	%eax, %ebx
	jle	.L97
	movq	56(%rsp), %rdx
	movq	64(%rsp), %rcx
	cvtsi2ssl	%ebx, %xmm2
	movss	(%rdx,%rax,4), %xmm0
	subss	(%rcx,%rax,4), %xmm0
	incq	%rax
	andps	%xmm1, %xmm0
	divss	%xmm2, %xmm0
	addss	%xmm0, %xmm3
	jmp	.L71
.L97:
	movq	56(%rsp), %rax
	xorl	%edx, %edx
	movl	$2, %edi
	leaq	.LC18(%rip), %rsi
	movss	%xmm3, 8(%rsp)
	cvtss2sd	(%rax), %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	movq	64(%rsp), %rax
	xorl	%edx, %edx
	leaq	.LC19(%rip), %rsi
	movl	$2, %edi
	cvtss2sd	(%rax), %xmm0
	movb	$1, %al
	call	__printf_chk@PLT
	cvtsi2ssq	72(%rsp), %xmm0
	movb	$3, %al
	movss	.LC20(%rip), %xmm4
	cvtsi2ssq	%rbp, %xmm2
	leaq	.LC21(%rip), %rsi
	movl	$2, %edi
	cvtsi2ssq	96(%rsp), %xmm1
	cvtsi2ssq	80(%rsp), %xmm5
	subss	%xmm0, %xmm2
	cvtsi2ssq	88(%rsp), %xmm0
	divss	%xmm4, %xmm2
	subss	%xmm0, %xmm1
	cvtsi2ssq	%r12, %xmm0
	subss	%xmm5, %xmm0
	divss	%xmm4, %xmm1
	cvtss2sd	%xmm2, %xmm2
	divss	%xmm4, %xmm0
	cvtss2sd	%xmm1, %xmm1
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	$2, %edi
	movb	$1, %al
	movss	8(%rsp), %xmm3
	leaq	.LC22(%rip), %rsi
	cvtss2sd	%xmm3, %xmm0
	call	__printf_chk@PLT
	xorl	%eax, %eax
	leaq	.LC23(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	1192(%rsp), %rax
	subq	%fs:40, %rax
	je	.L80
.L90:
	call	__stack_chk_fail@PLT
.L80:
	addq	$1208, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.LFE2031:
	.size	main, .-main
	.section	.rodata.str1.1
.LC24:
	.string	"_Z23jacobiOptimizedOnDevicePfS_S_S_ii"
.LC25:
	.string	"_Z14jacobiOnDevicePfS_S_S_ii"
.LC26:
	.string	"_Z6JacobiPPiPPKii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2063:
	.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	.LC24(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z23jacobiOptimizedOnDevicePfS_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	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC25(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z14jacobiOnDevicePfS_S_S_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC26(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z6JacobiPPiPPKii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.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
.LFE2063:
	.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.str1.1
.LC27:
	.string	"file"
.LC28:
	.string	"Ni"
.LC29:
	.string	"Nj"
.LC30:
	.string	"iterations"
.LC31:
	.string	"kernel"
.LC32:
	.string	"tilesize"
.LC33:
	.string	"help"
	.section	.data.rel.local,"aw"
	.align 32
	.type	_ZZ4mainE12long_options, @object
	.size	_ZZ4mainE12long_options, 256
_ZZ4mainE12long_options:
	.quad	.LC27
	.long	1
	.zero	4
	.quad	0
	.long	102
	.zero	4
	.quad	.LC28
	.long	2
	.zero	4
	.quad	0
	.long	105
	.zero	4
	.quad	.LC29
	.long	2
	.zero	4
	.quad	0
	.long	106
	.zero	4
	.quad	.LC30
	.long	2
	.zero	4
	.quad	0
	.long	110
	.zero	4
	.quad	.LC31
	.long	2
	.zero	4
	.quad	0
	.long	107
	.zero	4
	.quad	.LC32
	.long	2
	.zero	4
	.quad	0
	.long	116
	.zero	4
	.quad	.LC33
	.long	2
	.zero	4
	.quad	0
	.long	104
	.zero	4
	.quad	0
	.long	0
	.zero	4
	.quad	0
	.long	0
	.zero	4
	.local	_ZL12program_name
	.comm	_ZL12program_name,8,8
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC17:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC20:
	.long	1232348160
	.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 <assert.h>
#include <hip/hip_runtime.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

static char* program_name;

// Just defination
__global__ void Jacobi(int** a, const int** b, const int N) {
  int i = blockIdx.x * blockDim.x + threadIdx.x;
  int j = blockIdx.y * blockDim.y + threadIdx.y;
  if (i < N && j < N) {
    a[i][j] = 0.8 * (b[i + 1][j] + b[i + 1][j] + b[i][j + 1] + b[i][j + 1]);
  }
}

// Usage
void print_usage(FILE* stream, int exit_code) {
  fprintf(stream, "Usage:  %s options\n", program_name);
  fprintf(stream,
          "  -h  --help             Display this usage information.\n"
          "  -f  --file filename    File containing coefficient matrix.\n"
          "  -i  --Ni int           Number of elements in Y direction "
          "(default=512).\n"
          "  -j  --Nj int           Number of elements in X direction "
          "(default=512).\n"
          "  -n  --iterations int   Number of iterations (default=10000).\n"
          "  -k  --kernel [1,2]     1: unoptimized, 2: optimized kernel "
          "(default).\n"
          "  -t  --tilesize int     Size of each thread block in kernel 2 "
          "(default=4).\n");
  exit(exit_code);
}

// Host version of the Jacobi method
void jacobiOnHost(float* x_next, float* A, float* x_now, float* b, int Ni,
                  int Nj) {
  int i, j;
  float sigma;

  for (i = 0; i < Ni; i++) {
    sigma = 0.0;
    for (j = 0; j < Nj; j++) {
      if (i != j) sigma += A[i * Nj + j] * x_now[j];
    }
    x_next[i] = (b[i] - sigma) / A[i * Nj + i];
  }
}

// Device version of the Jacobi method
__global__ void jacobiOnDevice(float* x_next, float* A, float* x_now, float* b,
                               int Ni, int Nj) {
  float sigma = 0.0;
  int idx = threadIdx.x;
  for (int j = 0; j < Nj; j++) {
    if (idx != j) sigma += A[idx * Nj + j] * x_now[j];
  }
  x_next[idx] = (b[idx] - sigma) / A[idx * Nj + idx];
}

// Optimized device version of the Jacobi method
__global__ void jacobiOptimizedOnDevice(float* x_next, float* A, float* x_now,
                                        float* b, int Ni, int Nj) {
  // Optimization step 1: tiling
  int idx = blockIdx.x * blockDim.x + threadIdx.x;

  if (idx < Ni) {
    float sigma = 0.0;

    // Optimization step 2: store index in register
    // Multiplication is not executed in every iteration.
    int idx_Ai = idx * Nj;

    // Tried to use prefetching, but then the result is terribly wrong and I
    // don't know why..
    /*
    float curr_A = A[idx_Ai];
    float nxt_A;
    //printf("idx=%d\n",idx);
    for (int j=0; j<Nj-1; j++)
    {
        if (idx != j)
            nxt_A = A[idx_Ai + j + 1];
            sigma += curr_A * x_now[j];
            //sigma += A[idx_Ai + j] * x_now[j];
            curr_A = nxt_A;
            //printf("curr_A=%f\n",curr_A);
    }
    if (idx != Nj-1)
        sigma += nxt_A * x_now[Nj-1];
    x_next[idx] = (b[idx] - sigma) / A[idx_Ai + idx];
    */

    for (int j = 0; j < Nj; j++)
      if (idx != j) sigma += A[idx_Ai + j] * x_now[j];

    // Tried to use loop-ennrolling, but also here this gives a wrong result..
    /*
    for (int j=0; j<Nj/4; j+=4)
    {
        if (idx != j)
        {
            sigma += A[idx_Ai + j] * x_now[j];
        }
        if (idx != j+1)
        {
            sigma += A[idx_Ai + j+1] * x_now[j+1];
        }
        if (idx != j+2)
        {
           sigma += A[idx_Ai + j+2] * x_now[j+2];
        }
        if (idx != j+3)
        {
            sigma += A[idx_Ai + j+3] * x_now[j+3];
        }
    }*/

    x_next[idx] = (b[idx] - sigma) / A[idx_Ai + idx];
  }
}

// device selection (copied from previous assignment)
static void selectGpu(int* gpu_num, int* num_devs) {
  // gpu_num: (I/O): I: Default choice,
  //                 O: best device, changed only if more than one device
  // num_devs: (O)   Number of found devices.
  int best = *gpu_num;

  hipGetDeviceCount(num_devs);
  if (*num_devs > 1) {
    int dev_num;
    int max_cores = 0;

    for (dev_num = 0; dev_num < *num_devs; dev_num++) {
      hipDeviceProp_t dev_properties;

      hipGetDeviceProperties(&dev_properties, dev_num);
      if (max_cores < dev_properties.multiProcessorCount) {
        max_cores = dev_properties.multiProcessorCount;
        best = dev_num;
      }
    }
    *gpu_num = best;
  }
}

// device test (copied from previous assignment)
static void testDevice(int devID) {
  // Check if we can run. Maybe do something more...
  hipDeviceProp_t deviceProp;

  hipGetDeviceProperties(&deviceProp, devID);
  if (deviceProp.major == 9999 &&
      deviceProp.minor == 9999) { /* Simulated device. */
    printf("There is no device supporting CUDA.\n");
    // cudaThreadExit();
  } else
    printf("Using GPU device number %d.\n", devID);
}

int main(int argc, char* argv[]) {
  // initialize timing variables
  time_t start, end, start_h, end_h, start_d, end_d;
  float t_full, t_host, t_dev;

  start = clock();

  // initialize data variables
  float *x_now, *x_next, *A, *b, *x_h, *x_d;
  float *x_now_d, *x_next_d, *A_d, *b_d;

  // initialize parameter variables
  int N, Ni, Nj, iter, kernel, tileSize;
  int ch;
  int i, k;
  char* fname;
  FILE* file;

  // Argument parsing
  static struct option long_options[] = {
      {"file", required_argument, NULL, 'f'},
      {"Ni", optional_argument, NULL, 'i'},
      {"Nj", optional_argument, NULL, 'j'},
      {"iterations", optional_argument, NULL, 'n'},
      {"kernel", optional_argument, NULL, 'k'},
      {"tilesize", optional_argument, NULL, 't'},
      {"help", optional_argument, NULL, 'h'},
      {NULL, 0, NULL, 0}};

  program_name = argv[0];
  Ni = 512, Nj = 512, iter = 10000, kernel = 2, tileSize = 4;
  ch = 0;

  while ((ch = getopt_long(argc, argv, "f:i:j:n:k:h", long_options, NULL)) !=
         -1) {
    switch (ch) {
      case 'f':
        fname = optarg;
        break;
      case 'i':
        Ni = atoi(optarg);
        break;
      case 'j':
        Nj = atoi(optarg);
        break;
      case 'n':
        iter = atoi(optarg);
        break;
      case 'k':
        kernel = atoi(optarg);
        break;
      case 't':
        tileSize = atoi(optarg);
        break;
      case 'h':
        print_usage(stderr, 1);
        exit(EXIT_FAILURE);
      case '?':
        print_usage(stderr, 1);
        exit(EXIT_FAILURE);
      default:
        abort();
    }
  }

  N = Ni * Nj;

  printf("\nRunning Jacobi method:\n");
  printf("======================\n\n");
  printf("Coefficient matrix given in file: \n%s\n\n", fname);
  printf("Parameters:\n");
  printf("N=%d, Ni=%d, Nj=%d, ", N, Ni, Nj);
  printf("iterations=%d, kernel=%d, tilesize=%d\n", iter, kernel, tileSize);

  // Allocate memory on host
  x_next = (float*)malloc(Ni * sizeof(float));
  A = (float*)malloc(N * sizeof(float));
  x_now = (float*)malloc(Ni * sizeof(float));
  b = (float*)malloc(Ni * sizeof(float));
  x_h = (float*)malloc(Ni * sizeof(float));
  x_d = (float*)malloc(Ni * sizeof(float));

  // Initialize result vector x
  for (i = 0; i < Ni; i++) {
    x_now[i] = 0;
    x_next[i] = 0;
  }

  // Read coefficient matrix from file
  file = fopen(fname, "r");
  if (file == NULL) exit(EXIT_FAILURE);
  char* line;
  size_t len = 0;
  i = 0;
  while ((getline(&line, &len, file)) != -1) {
    if (i < N)
      A[i] = atof(line);
    else
      b[i - N] = atof(line);
    i++;
  }

  start_h = clock();

  // Run "iter" iterations of the Jacobi method on HOST
  for (k = 0; k < iter; k++) {
    if (k % 2)
      jacobiOnHost(x_now, A, x_next, b, Ni, Nj);
    else
      jacobiOnHost(x_next, A, x_now, b, Ni, Nj);
    // for (i=0; i<Nj; i++)
    //    x_now[i] = x_next[i];
  }

  end_h = clock();

  // Save result from host in x_h
  for (i = 0; i < Nj; i++) x_h[i] = x_next[i];

  // Re-initialize result vector x for device computation
  for (i = 0; i < Ni; i++) {
    x_now[i] = 0;
    x_next[i] = 0;
  }

  // Check available device.
  int devID = 0, num_devs = 1;
  selectGpu(&devID, &num_devs);
  testDevice(devID);

  // Allocate memory on the device
  assert(hipSuccess == hipMalloc((void**)&x_next_d, Ni * sizeof(float)));
  assert(hipSuccess == hipMalloc((void**)&A_d, N * sizeof(float)));
  assert(hipSuccess == hipMalloc((void**)&x_now_d, Ni * sizeof(float)));
  assert(hipSuccess == hipMalloc((void**)&b_d, Ni * sizeof(float)));

  // Copy data -> device
  hipMemcpy(x_next_d, x_next, sizeof(float) * Ni, hipMemcpyHostToDevice);
  hipMemcpy(A_d, A, sizeof(float) * N, hipMemcpyHostToDevice);
  hipMemcpy(x_now_d, x_now, sizeof(float) * Ni, hipMemcpyHostToDevice);
  hipMemcpy(b_d, b, sizeof(float) * Ni, hipMemcpyHostToDevice);

  // Compute grid and block size.
  // Un-optimized kernel
  int blockSize = Ni;
  int nBlocks = 1;

  // Optimized kernel
  int nTiles = Ni / tileSize + (Ni % tileSize == 0 ? 0 : 1);
  int gridHeight = Nj / tileSize + (Nj % tileSize == 0 ? 0 : 1);
  int gridWidth = Ni / tileSize + (Ni % tileSize == 0 ? 0 : 1);
  printf("w=%d, h=%d\n", gridWidth, gridHeight);
  dim3 dGrid(gridHeight, gridWidth), dBlock(tileSize, tileSize);

  start_d = clock();

  // Run "iter" iterations of the Jacobi method on DEVICE
  if (kernel == 1) {
    printf("Using un-optimized kernel.\n");
    for (k = 0; k < iter; k++) {
      if (k % 2)
        jacobiOnDevice<<<nBlocks, blockSize>>>(x_now_d, A_d, x_next_d, b_d, Ni,
                                               Nj);
      else
        jacobiOnDevice<<<nBlocks, blockSize>>>(x_next_d, A_d, x_now_d, b_d, Ni,
                                               Nj);
      // cudaMemcpy(x_now_d, x_next_d, sizeof(float)*Ni,
      // cudaMemcpyDeviceToDevice);
    }
  } else {
    printf("Using optimized kernel.\n");
    for (k = 0; k < iter; k++) {
      if (k % 2)
        jacobiOptimizedOnDevice<<<nTiles, tileSize>>>(x_now_d, A_d, x_next_d,
                                                      b_d, Ni, Nj);
      else
        jacobiOptimizedOnDevice<<<nTiles, tileSize>>>(x_next_d, A_d, x_now_d,
                                                      b_d, Ni, Nj);
      // cudaMemcpy(x_now_d, x_next_d, sizeof(float)*Ni,
      // cudaMemcpyDeviceToDevice);
    }
  }

  end_d = clock();

  // Data <- device
  hipMemcpy(x_d, x_next_d, sizeof(float) * Ni, hipMemcpyDeviceToHost);

  // Free memory
  free(x_next);
  free(A);
  free(x_now);
  free(b);
  hipFree(x_next_d);
  hipFree(A_d);
  hipFree(x_now_d);
  hipFree(b_d);

  end = clock();

  printf("\nResult after %d iterations:\n", iter);
  float err = 0.0;
  for (i = 0; i < Ni; i++) {
    // printf("x_h[%d]=%f\n",i,x_h[i]);
    // printf("x_d[%d]=%f\n",i,x_d[i]);
    err += abs(x_h[i] - x_d[i]) / Ni;
  }
  printf("x_h[%d]=%f\n", 0, x_h[0]);
  printf("x_d[%d]=%f\n", 0, x_d[0]);
  t_full = ((float)end - (float)start) / CLOCKS_PER_SEC;
  t_host = ((float)end_h - (float)start_h) / CLOCKS_PER_SEC;
  t_dev = ((float)end_d - (float)start_d) / CLOCKS_PER_SEC;
  printf("\nTiming:\nFull: %f\nHost: %f\nDevice: %f\n\n", t_full, t_host,
         t_dev);
  printf("Relative error: %f\n", err);

  printf("\nProgram terminated successfully.\n");
  return 0;
}
	.text
	.file	"jacobian.hip"
	.globl	_Z21__device_stub__JacobiPPiPPKii # -- Begin function _Z21__device_stub__JacobiPPiPPKii
	.type	_Z21__device_stub__JacobiPPiPPKii,@function
_Z21__device_stub__JacobiPPiPPKii:      # @_Z21__device_stub__JacobiPPiPPKii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z6JacobiPPiPPKii, %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	_Z21__device_stub__JacobiPPiPPKii, .Lfunc_end0-_Z21__device_stub__JacobiPPiPPKii
	.cfi_endproc
                                        # -- End function
	.globl	_Z11print_usageP8_IO_FILEi      # -- Begin function _Z11print_usageP8_IO_FILEi
	.type	_Z11print_usageP8_IO_FILEi,@function
_Z11print_usageP8_IO_FILEi:             # @_Z11print_usageP8_IO_FILEi
	.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
	movl	%esi, %ebx
	movq	%rdi, %r14
	movq	_ZL12program_name(%rip), %rdx
	movl	$.L.str, %esi
	xorl	%eax, %eax
	callq	fprintf
	movl	$.L.str.1, %edi
	movl	$477, %esi                      # imm = 0x1DD
	movl	$1, %edx
	movq	%r14, %rcx
	callq	fwrite@PLT
	movl	%ebx, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z11print_usageP8_IO_FILEi, .Lfunc_end1-_Z11print_usageP8_IO_FILEi
	.cfi_endproc
                                        # -- End function
	.globl	_Z12jacobiOnHostPfS_S_S_ii      # -- Begin function _Z12jacobiOnHostPfS_S_S_ii
	.type	_Z12jacobiOnHostPfS_S_S_ii,@function
_Z12jacobiOnHostPfS_S_S_ii:             # @_Z12jacobiOnHostPfS_S_S_ii
	.cfi_startproc
# %bb.0:
                                        # kill: def $r9d killed $r9d def $r9
	testl	%r8d, %r8d
	jle	.LBB2_10
# %bb.1:                                # %.preheader.lr.ph
	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
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	leal	1(%r9), %eax
	movl	%r8d, %r8d
	movl	%r9d, %r10d
	xorl	%r11d, %r11d
	xorl	%ebx, %ebx
.LBB2_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_5 Depth 2
	testl	%r9d, %r9d
	jle	.LBB2_3
# %bb.4:                                # %.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	%r11d, %r14d
	leaq	(%rsi,%r14,4), %r14
	xorps	%xmm0, %xmm0
	xorl	%r15d, %r15d
.LBB2_5:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	cmpq	%r15, %rbx
	je	.LBB2_7
# %bb.6:                                #   in Loop: Header=BB2_5 Depth=2
	movss	(%r14,%r15,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	mulss	(%rdx,%r15,4), %xmm1
	addss	%xmm1, %xmm0
.LBB2_7:                                #   in Loop: Header=BB2_5 Depth=2
	incq	%r15
	cmpq	%r15, %r10
	jne	.LBB2_5
	jmp	.LBB2_8
.LBB2_3:                                #   in Loop: Header=BB2_2 Depth=1
	xorps	%xmm0, %xmm0
.LBB2_8:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	movss	(%rcx,%rbx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	subss	%xmm0, %xmm1
	movl	%eax, %ebp
	imull	%ebx, %ebp
	movslq	%ebp, %r14
	divss	(%rsi,%r14,4), %xmm1
	movss	%xmm1, (%rdi,%rbx,4)
	incq	%rbx
	addl	%r9d, %r11d
	cmpq	%r8, %rbx
	jne	.LBB2_2
# %bb.9:
	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
.LBB2_10:                               # %._crit_edge31
	retq
.Lfunc_end2:
	.size	_Z12jacobiOnHostPfS_S_S_ii, .Lfunc_end2-_Z12jacobiOnHostPfS_S_S_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z29__device_stub__jacobiOnDevicePfS_S_S_ii # -- Begin function _Z29__device_stub__jacobiOnDevicePfS_S_S_ii
	.type	_Z29__device_stub__jacobiOnDevicePfS_S_S_ii,@function
_Z29__device_stub__jacobiOnDevicePfS_S_S_ii: # @_Z29__device_stub__jacobiOnDevicePfS_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	$_Z14jacobiOnDevicePfS_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	_Z29__device_stub__jacobiOnDevicePfS_S_S_ii, .Lfunc_end3-_Z29__device_stub__jacobiOnDevicePfS_S_S_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z38__device_stub__jacobiOptimizedOnDevicePfS_S_S_ii # -- Begin function _Z38__device_stub__jacobiOptimizedOnDevicePfS_S_S_ii
	.type	_Z38__device_stub__jacobiOptimizedOnDevicePfS_S_S_ii,@function
_Z38__device_stub__jacobiOptimizedOnDevicePfS_S_S_ii: # @_Z38__device_stub__jacobiOptimizedOnDevicePfS_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	$_Z23jacobiOptimizedOnDevicePfS_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_end4:
	.size	_Z38__device_stub__jacobiOptimizedOnDevicePfS_S_S_ii, .Lfunc_end4-_Z38__device_stub__jacobiOptimizedOnDevicePfS_S_S_ii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI5_0:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI5_1:
	.long	0x49742400                      # float 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	$1624, %rsp                     # imm = 0x658
	.cfi_def_cfa_offset 1680
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	%edi, %ebp
	callq	clock
	movq	%rax, %r15
	movq	(%rbx), %rax
	movq	%rax, _ZL12program_name(%rip)
	movl	$512, 24(%rsp)                  # 4-byte Folded Spill
                                        # imm = 0x200
	movl	$10000, 28(%rsp)                # 4-byte Folded Spill
                                        # imm = 0x2710
	movl	$2, 20(%rsp)                    # 4-byte Folded Spill
	movl	$4, %r14d
                                        # implicit-def: $r12
	movl	$512, %r13d                     # imm = 0x200
.LBB5_1:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str.9, %edx
	movl	$_ZZ4mainE12long_options, %ecx
	movl	%ebp, %edi
	movq	%rbx, %rsi
	xorl	%r8d, %r8d
	callq	getopt_long
                                        # kill: def $eax killed $eax def $rax
	cmpl	$105, %eax
	jne	.LBB5_2
# %bb.7:                                #   in Loop: Header=BB5_1 Depth=1
	movq	optarg(%rip), %rdi
	callq	atoi
	movl	%eax, %r13d
	jmp	.LBB5_1
.LBB5_2:                                #   in Loop: Header=BB5_1 Depth=1
	leal	-102(%rax), %ecx
	cmpl	$14, %ecx
	ja	.LBB5_3
# %bb.53:                               #   in Loop: Header=BB5_1 Depth=1
	jmpq	*.LJTI5_0(,%rcx,8)
.LBB5_6:                                #   in Loop: Header=BB5_1 Depth=1
	movq	optarg(%rip), %r12
	jmp	.LBB5_1
.LBB5_11:                               #   in Loop: Header=BB5_1 Depth=1
	movq	optarg(%rip), %rdi
	callq	atoi
	movl	%eax, %r14d
	jmp	.LBB5_1
.LBB5_8:                                #   in Loop: Header=BB5_1 Depth=1
	movq	optarg(%rip), %rdi
	callq	atoi
	movl	%eax, 24(%rsp)                  # 4-byte Spill
	jmp	.LBB5_1
.LBB5_9:                                #   in Loop: Header=BB5_1 Depth=1
	movq	optarg(%rip), %rdi
	callq	atoi
	movl	%eax, 28(%rsp)                  # 4-byte Spill
	jmp	.LBB5_1
.LBB5_10:                               #   in Loop: Header=BB5_1 Depth=1
	movq	optarg(%rip), %rdi
	callq	atoi
	movl	%eax, 20(%rsp)                  # 4-byte Spill
	jmp	.LBB5_1
.LBB5_3:
	movq	%r15, 136(%rsp)                 # 8-byte Spill
	cmpl	$-1, %eax
	jne	.LBB5_4
# %bb.13:
	movl	%r13d, %ebx
	movl	24(%rsp), %ebp                  # 4-byte Reload
	imull	%ebp, %ebx
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$.L.str.12, %edi
	movq	%r12, 80(%rsp)                  # 8-byte Spill
	movq	%r12, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$.L.str.14, %edi
	movl	%ebx, %esi
	movl	%r13d, %edx
	movl	%ebp, %ecx
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.15, %edi
	movl	28(%rsp), %esi                  # 4-byte Reload
	movl	20(%rsp), %edx                  # 4-byte Reload
	movl	%r14d, 44(%rsp)                 # 4-byte Spill
	movl	%r14d, %ecx
	xorl	%eax, %eax
	callq	printf
	movslq	%r13d, %r14
	leaq	(,%r14,4), %rbp
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, %r15
	movslq	%ebx, %rax
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	leaq	(,%rax,4), %rdi
	movq	%rdi, 48(%rsp)                  # 8-byte Spill
	callq	malloc
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, 96(%rsp)                  # 8-byte Spill
	movq	%rbp, 112(%rsp)                 # 8-byte Spill
	movq	%rbp, %rdi
	callq	malloc
	movq	%rax, 128(%rsp)                 # 8-byte Spill
	movl	%r13d, %ebp
	testl	%r14d, %r14d
	jle	.LBB5_15
# %bb.14:                               # %.lr.ph.preheader
	leaq	(,%rbp,4), %rbx
	movq	%r12, %rdi
	xorl	%esi, %esi
	movq	%rbx, %rdx
	callq	memset@PLT
	movq	%r15, %rdi
	xorl	%esi, %esi
	movq	%rbx, %rdx
	callq	memset@PLT
.LBB5_15:                               # %._crit_edge
	movq	%r12, 8(%rsp)                   # 8-byte Spill
	movq	%r15, 56(%rsp)                  # 8-byte Spill
	movq	%rbp, 88(%rsp)                  # 8-byte Spill
	movl	%r13d, 4(%rsp)                  # 4-byte Spill
	movl	$.L.str.16, %esi
	movq	80(%rsp), %rdi                  # 8-byte Reload
	callq	fopen
	testq	%rax, %rax
	je	.LBB5_54
# %bb.16:
	movq	%rax, %rbp
	leaq	144(%rsp), %rsi
	movq	$0, (%rsi)
	leaq	120(%rsp), %rdi
	movq	%rax, %rdx
	callq	getline
	cmpq	$-1, %rax
	movq	72(%rsp), %rbx                  # 8-byte Reload
	je	.LBB5_19
# %bb.17:                               # %.lr.ph268.preheader
	movq	32(%rsp), %r12                  # 8-byte Reload
	subq	48(%rsp), %r12                  # 8-byte Folded Reload
	xorl	%r14d, %r14d
	leaq	144(%rsp), %r13
	movq	64(%rsp), %r15                  # 8-byte Reload
.LBB5_18:                               # %.lr.ph268
                                        # =>This Inner Loop Header: Depth=1
	movq	120(%rsp), %rdi
	callq	atof
	cmpq	%rbx, %r14
	cvtsd2ss	%xmm0, %xmm0
	movq	%r12, %rax
	cmovlq	%r15, %rax
	movss	%xmm0, (%rax)
	incq	%r14
	leaq	120(%rsp), %rdi
	movq	%r13, %rsi
	movq	%rbp, %rdx
	callq	getline
	addq	$4, %r12
	addq	$4, %r15
	cmpq	$-1, %rax
	jne	.LBB5_18
.LBB5_19:                               # %._crit_edge269
	callq	clock
	movq	%rax, 80(%rsp)                  # 8-byte Spill
	movl	28(%rsp), %r12d                 # 4-byte Reload
	testl	%r12d, %r12d
	movl	4(%rsp), %ebp                   # 4-byte Reload
	movl	24(%rsp), %r15d                 # 4-byte Reload
	movq	56(%rsp), %r14                  # 8-byte Reload
	movq	64(%rsp), %r13                  # 8-byte Reload
	jle	.LBB5_25
# %bb.20:                               # %.lr.ph272.preheader
	xorl	%ebx, %ebx
.LBB5_21:                               # %.lr.ph272
                                        # =>This Inner Loop Header: Depth=1
	testb	$1, %bl
	jne	.LBB5_22
# %bb.23:                               #   in Loop: Header=BB5_21 Depth=1
	movq	%r14, %rdi
	movq	%r13, %rsi
	movq	8(%rsp), %rdx                   # 8-byte Reload
	jmp	.LBB5_24
.LBB5_22:                               #   in Loop: Header=BB5_21 Depth=1
	movq	8(%rsp), %rdi                   # 8-byte Reload
	movq	%r13, %rsi
	movq	%r14, %rdx
.LBB5_24:                               #   in Loop: Header=BB5_21 Depth=1
	movq	32(%rsp), %rcx                  # 8-byte Reload
	movl	%ebp, %r8d
	movl	%r15d, %r9d
	callq	_Z12jacobiOnHostPfS_S_S_ii
	incl	%ebx
	cmpl	%ebx, %r12d
	jne	.LBB5_21
.LBB5_25:                               # %._crit_edge273
	callq	clock
	movq	%rax, 72(%rsp)                  # 8-byte Spill
	testl	%r15d, %r15d
	jle	.LBB5_27
# %bb.26:                               # %.lr.ph276.preheader
	movl	%r15d, %edx
	shlq	$2, %rdx
	movq	96(%rsp), %rdi                  # 8-byte Reload
	movq	%r14, %rsi
	callq	memcpy@PLT
.LBB5_27:                               # %.preheader
	testl	%ebp, %ebp
	movq	8(%rsp), %rdi                   # 8-byte Reload
	jle	.LBB5_29
# %bb.28:                               # %.lr.ph278.preheader
	movq	88(%rsp), %rax                  # 8-byte Reload
	leaq	(,%rax,4), %rbx
	xorl	%esi, %esi
	movq	%rbx, %rdx
	callq	memset@PLT
	movq	%r14, %rdi
	xorl	%esi, %esi
	movq	%rbx, %rdx
	callq	memset@PLT
.LBB5_29:                               # %._crit_edge279
	leaq	108(%rsp), %rbx
	movl	$1, (%rbx)
	movq	%rbx, %rdi
	callq	hipGetDeviceCount
	xorl	%ebp, %ebp
	cmpl	$2, (%rbx)
	jl	.LBB5_32
# %bb.30:                               # %.lr.ph.i
	xorl	%r14d, %r14d
	leaq	152(%rsp), %rbx
	xorl	%r13d, %r13d
	xorl	%ebp, %ebp
.LBB5_31:                               # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movl	%r13d, %esi
	callq	hipGetDevicePropertiesR0600
	movl	540(%rsp), %eax
	cmpl	%eax, %r14d
	cmovll	%r13d, %ebp
	cmovlel	%eax, %r14d
	incl	%r13d
	cmpl	108(%rsp), %r13d
	jl	.LBB5_31
.LBB5_32:                               # %_ZL9selectGpuPiS_.exit
	leaq	152(%rsp), %rbx
	movq	%rbx, %rdi
	movl	%ebp, %esi
	callq	hipGetDevicePropertiesR0600
	cmpl	$9999, 360(%rbx)                # imm = 0x270F
	jne	.LBB5_35
# %bb.33:                               # %_ZL9selectGpuPiS_.exit
	cmpl	$9999, 516(%rsp)                # imm = 0x270F
	jne	.LBB5_35
# %bb.34:
	movl	$.Lstr.6, %edi
	callq	puts@PLT
	jmp	.LBB5_36
.LBB5_35:
	movl	$.L.str.27, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
.LBB5_36:                               # %_ZL10testDevicei.exit
	movl	4(%rsp), %ebx                   # 4-byte Reload
	movl	44(%rsp), %r14d                 # 4-byte Reload
	movq	56(%rsp), %rsi                  # 8-byte Reload
	movq	112(%rsp), %r13                 # 8-byte Reload
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	64(%rsp), %rsi                  # 8-byte Reload
	movq	48(%rsp), %rdx                  # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	movq	8(%rsp), %rsi                   # 8-byte Reload
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	32(%rsp), %rsi                  # 8-byte Reload
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	%ebx, %eax
	cltd
	idivl	%r14d
	movl	%eax, %ebp
	cmpl	$1, %edx
	sbbl	$-1, %ebp
	movl	%r15d, %eax
	cltd
	idivl	%r14d
	cmpl	$1, %edx
	sbbl	$-1, %eax
	movl	$.L.str.17, %edi
	movl	%ebp, %esi
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	printf
	callq	clock
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	cmpl	$1, 20(%rsp)                    # 4-byte Folded Reload
	jne	.LBB5_42
# %bb.37:
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	testl	%r12d, %r12d
	jle	.LBB5_47
# %bb.38:                               # %.lr.ph285
	movabsq	$4294967296, %rbx               # imm = 0x100000000
	movq	88(%rsp), %r13                  # 8-byte Reload
	btsq	$32, %r13
	incq	%rbx
	movl	%r12d, %ebp
.LBB5_39:                               # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_41
# %bb.40:                               # %.sink.split
                                        #   in Loop: Header=BB5_39 Depth=1
	movl	4(%rsp), %r8d                   # 4-byte Reload
	movl	%r15d, %r9d
	callq	_Z29__device_stub__jacobiOnDevicePfS_S_S_ii
.LBB5_41:                               #   in Loop: Header=BB5_39 Depth=1
	decl	%ebp
	jne	.LBB5_39
	jmp	.LBB5_47
.LBB5_42:
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	testl	%r12d, %r12d
	jle	.LBB5_47
# %bb.43:                               # %.lr.ph282
	movl	%ebp, %ebp
	btsq	$32, %rbp
	movl	%r14d, %ebx
	btsq	$32, %rbx
	movl	%r12d, %r14d
.LBB5_44:                               # =>This Inner Loop Header: Depth=1
	movq	%rbp, %rdi
	movl	$1, %esi
	movq	%rbx, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_46
# %bb.45:                               # %.sink.split343
                                        #   in Loop: Header=BB5_44 Depth=1
	movl	4(%rsp), %r8d                   # 4-byte Reload
	movl	%r15d, %r9d
	callq	_Z38__device_stub__jacobiOptimizedOnDevicePfS_S_S_ii
.LBB5_46:                               #   in Loop: Header=BB5_44 Depth=1
	decl	%r14d
	jne	.LBB5_44
.LBB5_47:                               # %.loopexit
	callq	clock
	movq	%rax, %r15
	movq	128(%rsp), %r14                 # 8-byte Reload
	movq	%r14, %rdi
	movq	112(%rsp), %rdx                 # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	movq	56(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	64(%rsp), %rdi                  # 8-byte Reload
	callq	free
	movq	8(%rsp), %rdi                   # 8-byte Reload
	callq	free
	movq	32(%rsp), %rdi                  # 8-byte Reload
	callq	free
	callq	hipFree
	callq	hipFree
	callq	hipFree
	callq	hipFree
	callq	clock
	movq	%rax, %rbx
	movl	$.L.str.20, %edi
	movl	%r12d, %esi
	xorl	%eax, %eax
	callq	printf
	movl	4(%rsp), %eax                   # 4-byte Reload
	testl	%eax, %eax
	jle	.LBB5_48
# %bb.49:                               # %.lr.ph289
	cvtsi2ss	%eax, %xmm0
	xorps	%xmm1, %xmm1
	xorl	%eax, %eax
	movaps	.LCPI5_0(%rip), %xmm2           # xmm2 = [NaN,NaN,NaN,NaN]
	movq	96(%rsp), %rcx                  # 8-byte Reload
	movq	88(%rsp), %rdx                  # 8-byte Reload
.LBB5_50:                               # =>This Inner Loop Header: Depth=1
	movss	(%rcx,%rax,4), %xmm3            # xmm3 = mem[0],zero,zero,zero
	subss	(%r14,%rax,4), %xmm3
	andps	%xmm2, %xmm3
	divss	%xmm0, %xmm3
	addss	%xmm3, %xmm1
	incq	%rax
	cmpq	%rax, %rdx
	jne	.LBB5_50
# %bb.51:                               # %._crit_edge290.loopexit
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	jmp	.LBB5_52
.LBB5_48:
	xorps	%xmm0, %xmm0
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movq	96(%rsp), %rcx                  # 8-byte Reload
.LBB5_52:                               # %._crit_edge290
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rcx), %xmm0
	movl	$.L.str.21, %edi
	xorl	%esi, %esi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14), %xmm0
	movl	$.L.str.22, %edi
	xorl	%esi, %esi
	movb	$1, %al
	callq	printf
	xorps	%xmm0, %xmm0
	cvtsi2ss	%rbx, %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2ssq	136(%rsp), %xmm1        # 8-byte Folded Reload
	subss	%xmm1, %xmm0
	movss	.LCPI5_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
	divss	%xmm1, %xmm0
	xorps	%xmm2, %xmm2
	cvtsi2ssq	72(%rsp), %xmm2         # 8-byte Folded Reload
	xorps	%xmm3, %xmm3
	cvtsi2ssq	80(%rsp), %xmm3         # 8-byte Folded Reload
	subss	%xmm3, %xmm2
	divss	%xmm1, %xmm2
	xorps	%xmm3, %xmm3
	cvtsi2ss	%r15, %xmm3
	cvtsi2ssq	48(%rsp), %xmm4         # 8-byte Folded Reload
	subss	%xmm4, %xmm3
	divss	%xmm1, %xmm3
	cvtss2sd	%xmm0, %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	%xmm2, %xmm1
	xorps	%xmm2, %xmm2
	cvtss2sd	%xmm3, %xmm2
	movl	$.L.str.23, %edi
	movb	$3, %al
	callq	printf
	movl	$.L.str.24, %edi
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	movl	$.Lstr.5, %edi
	callq	puts@PLT
	xorl	%eax, %eax
	addq	$1624, %rsp                     # imm = 0x658
	.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
.LBB5_4:
	.cfi_def_cfa_offset 1680
	cmpl	$63, %eax
	jne	.LBB5_12
.LBB5_5:
	movq	stderr(%rip), %rdi
	movl	$1, %esi
	callq	_Z11print_usageP8_IO_FILEi
.LBB5_12:
	callq	abort
.LBB5_54:
	movl	$1, %edi
	callq	exit
.Lfunc_end5:
	.size	main, .Lfunc_end5-main
	.cfi_endproc
	.section	.rodata,"a",@progbits
	.p2align	3, 0x0
.LJTI5_0:
	.quad	.LBB5_6
	.quad	.LBB5_12
	.quad	.LBB5_5
	.quad	.LBB5_12
	.quad	.LBB5_8
	.quad	.LBB5_10
	.quad	.LBB5_12
	.quad	.LBB5_12
	.quad	.LBB5_9
	.quad	.LBB5_12
	.quad	.LBB5_12
	.quad	.LBB5_12
	.quad	.LBB5_12
	.quad	.LBB5_12
	.quad	.LBB5_11
                                        # -- End function
	.text
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6JacobiPPiPPKii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z14jacobiOnDevicePfS_S_S_ii, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z23jacobiOptimizedOnDevicePfS_S_S_ii, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.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	_Z6JacobiPPiPPKii,@object       # @_Z6JacobiPPiPPKii
	.section	.rodata,"a",@progbits
	.globl	_Z6JacobiPPiPPKii
	.p2align	3, 0x0
_Z6JacobiPPiPPKii:
	.quad	_Z21__device_stub__JacobiPPiPPKii
	.size	_Z6JacobiPPiPPKii, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Usage:  %s options\n"
	.size	.L.str, 20

	.type	_ZL12program_name,@object       # @_ZL12program_name
	.local	_ZL12program_name
	.comm	_ZL12program_name,8,8
	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"  -h  --help             Display this usage information.\n  -f  --file filename    File containing coefficient matrix.\n  -i  --Ni int           Number of elements in Y direction (default=512).\n  -j  --Nj int           Number of elements in X direction (default=512).\n  -n  --iterations int   Number of iterations (default=10000).\n  -k  --kernel [1,2]     1: unoptimized, 2: optimized kernel (default).\n  -t  --tilesize int     Size of each thread block in kernel 2 (default=4).\n"
	.size	.L.str.1, 478

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

	.type	_Z23jacobiOptimizedOnDevicePfS_S_S_ii,@object # @_Z23jacobiOptimizedOnDevicePfS_S_S_ii
	.globl	_Z23jacobiOptimizedOnDevicePfS_S_S_ii
	.p2align	3, 0x0
_Z23jacobiOptimizedOnDevicePfS_S_S_ii:
	.quad	_Z38__device_stub__jacobiOptimizedOnDevicePfS_S_S_ii
	.size	_Z23jacobiOptimizedOnDevicePfS_S_S_ii, 8

	.type	_ZZ4mainE12long_options,@object # @_ZZ4mainE12long_options
	.data
	.p2align	4, 0x0
_ZZ4mainE12long_options:
	.quad	.L.str.2
	.long	1                               # 0x1
	.zero	4
	.quad	0
	.long	102                             # 0x66
	.zero	4
	.quad	.L.str.3
	.long	2                               # 0x2
	.zero	4
	.quad	0
	.long	105                             # 0x69
	.zero	4
	.quad	.L.str.4
	.long	2                               # 0x2
	.zero	4
	.quad	0
	.long	106                             # 0x6a
	.zero	4
	.quad	.L.str.5
	.long	2                               # 0x2
	.zero	4
	.quad	0
	.long	110                             # 0x6e
	.zero	4
	.quad	.L.str.6
	.long	2                               # 0x2
	.zero	4
	.quad	0
	.long	107                             # 0x6b
	.zero	4
	.quad	.L.str.7
	.long	2                               # 0x2
	.zero	4
	.quad	0
	.long	116                             # 0x74
	.zero	4
	.quad	.L.str.8
	.long	2                               # 0x2
	.zero	4
	.quad	0
	.long	104                             # 0x68
	.zero	4
	.zero	32
	.size	_ZZ4mainE12long_options, 256

	.type	.L.str.2,@object                # @.str.2
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.2:
	.asciz	"file"
	.size	.L.str.2, 5

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

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"iterations"
	.size	.L.str.5, 11

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"kernel"
	.size	.L.str.6, 7

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"tilesize"
	.size	.L.str.7, 9

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"help"
	.size	.L.str.8, 5

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"f:i:j:n:k:h"
	.size	.L.str.9, 12

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Coefficient matrix given in file: \n%s\n\n"
	.size	.L.str.12, 40

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"N=%d, Ni=%d, Nj=%d, "
	.size	.L.str.14, 21

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"iterations=%d, kernel=%d, tilesize=%d\n"
	.size	.L.str.15, 39

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

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"w=%d, h=%d\n"
	.size	.L.str.17, 12

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"\nResult after %d iterations:\n"
	.size	.L.str.20, 30

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"x_h[%d]=%f\n"
	.size	.L.str.21, 12

	.type	.L.str.22,@object               # @.str.22
.L.str.22:
	.asciz	"x_d[%d]=%f\n"
	.size	.L.str.22, 12

	.type	.L.str.23,@object               # @.str.23
.L.str.23:
	.asciz	"\nTiming:\nFull: %f\nHost: %f\nDevice: %f\n\n"
	.size	.L.str.23, 40

	.type	.L.str.24,@object               # @.str.24
.L.str.24:
	.asciz	"Relative error: %f\n"
	.size	.L.str.24, 20

	.type	.L.str.27,@object               # @.str.27
.L.str.27:
	.asciz	"Using GPU device number %d.\n"
	.size	.L.str.27, 29

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6JacobiPPiPPKii"
	.size	.L__unnamed_1, 18

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z14jacobiOnDevicePfS_S_S_ii"
	.size	.L__unnamed_2, 29

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z23jacobiOptimizedOnDevicePfS_S_S_ii"
	.size	.L__unnamed_3, 38

	.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	"\nRunning Jacobi method:"
	.size	.Lstr, 24

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"======================\n"
	.size	.Lstr.1, 24

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Parameters:"
	.size	.Lstr.2, 12

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Using optimized kernel."
	.size	.Lstr.3, 24

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"Using un-optimized kernel."
	.size	.Lstr.4, 27

	.type	.Lstr.5,@object                 # @str.5
.Lstr.5:
	.asciz	"\nProgram terminated successfully."
	.size	.Lstr.5, 34

	.type	.Lstr.6,@object                 # @str.6
.Lstr.6:
	.asciz	"There is no device supporting CUDA."
	.size	.Lstr.6, 36

	.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 _Z21__device_stub__JacobiPPiPPKii
	.addrsig_sym _Z29__device_stub__jacobiOnDevicePfS_S_S_ii
	.addrsig_sym _Z38__device_stub__jacobiOptimizedOnDevicePfS_S_S_ii
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z6JacobiPPiPPKii
	.addrsig_sym _Z14jacobiOnDevicePfS_S_S_ii
	.addrsig_sym _Z23jacobiOptimizedOnDevicePfS_S_S_ii
	.addrsig_sym _ZZ4mainE12long_options
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6JacobiPPiPPKii       ; -- Begin function _Z6JacobiPPiPPKii
	.globl	_Z6JacobiPPiPPKii
	.p2align	8
	.type	_Z6JacobiPPiPPKii,@function
_Z6JacobiPPiPPKii:                      ; @_Z6JacobiPPiPPKii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b32 s3, s[0:1], 0x10
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v4, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s4, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, s14, s2, v[1:2]
	v_mad_u64_u32 v[0:1], null, s15, s4, v[4:5]
	s_mov_b32 s2, exec_lo
	v_max_i32_e32 v1, v2, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[0:3], s[0:1], 0x0
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[6:7], 3, v[2:3]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v1, vcc_lo, s2, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v2, vcc_lo, s3, v7, vcc_lo
	global_load_b128 v[2:5], v[1:2], off
	v_ashrrev_i32_e32 v1, 31, v0
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v4, vcc_lo, v4, v0
	v_add_co_ci_u32_e32 v5, vcc_lo, v5, v1, vcc_lo
	v_add_co_u32 v2, vcc_lo, v2, v0
	v_add_co_ci_u32_e32 v3, vcc_lo, v3, v1, vcc_lo
	flat_load_b32 v4, v[4:5]
	global_load_b32 v5, v[2:3], off offset:4
	v_add_co_u32 v2, vcc_lo, s0, v6
	v_add_co_ci_u32_e32 v3, vcc_lo, s1, v7, vcc_lo
	s_mov_b32 s0, 0x9999999a
	s_mov_b32 s1, 0x3fe99999
	global_load_b64 v[2:3], v[2:3], off
	s_waitcnt vmcnt(1) lgkmcnt(0)
	v_add_lshl_u32 v4, v5, v4, 1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_cvt_f64_i32_e32 v[4:5], v4
	s_waitcnt vmcnt(0)
	v_add_co_u32 v0, vcc_lo, v2, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, v3, v1, vcc_lo
	v_mul_f64 v[4:5], v[4:5], s[0:1]
	s_delay_alu instid0(VALU_DEP_1)
	v_cvt_i32_f64_e32 v4, v[4:5]
	global_store_b32 v[0:1], v4, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6JacobiPPiPPKii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 14
		.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 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 8
		.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	_Z6JacobiPPiPPKii, .Lfunc_end0-_Z6JacobiPPiPPKii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 316
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.protected	_Z14jacobiOnDevicePfS_S_S_ii ; -- Begin function _Z14jacobiOnDevicePfS_S_S_ii
	.globl	_Z14jacobiOnDevicePfS_S_S_ii
	.p2align	8
	.type	_Z14jacobiOnDevicePfS_S_S_ii,@function
_Z14jacobiOnDevicePfS_S_S_ii:           ; @_Z14jacobiOnDevicePfS_S_S_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s8, s[0:1], 0x24
	s_load_b256 s[0:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s8, 1
	s_cbranch_scc1 .LBB1_5
; %bb.1:                                ; %.lr.ph
	v_mov_b32_e32 v2, 0
	v_mul_lo_u32 v1, v0, s8
	v_mov_b32_e32 v4, v0
	s_mov_b32 s9, s8
	s_delay_alu instid0(VALU_DEP_3)
	v_mov_b32_e32 v3, v2
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s10, exec_lo
	s_delay_alu instid0(VALU_DEP_2)
	v_cmpx_ne_u32_e32 0, v4
	s_cbranch_execz .LBB1_4
; %bb.3:                                ;   in Loop: Header=BB1_2 Depth=1
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 2, v[1:2]
	s_load_b32 s11, s[4:5], 0x0
	v_add_co_u32 v5, vcc_lo, s2, v5
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v6, vcc_lo, s3, v6, vcc_lo
	global_load_b32 v5, v[5:6], off
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_fmac_f32_e32 v3, s11, v5
.LBB1_4:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s10
	s_add_i32 s9, s9, -1
	v_add_nc_u32_e32 v4, -1, v4
	v_add_nc_u32_e32 v1, 1, v1
	s_add_u32 s4, s4, 4
	s_addc_u32 s5, s5, 0
	s_cmp_eq_u32 s9, 0
	s_cbranch_scc0 .LBB1_2
	s_branch .LBB1_6
.LBB1_5:
	v_mov_b32_e32 v3, 0
.LBB1_6:                                ; %Flow48
	v_mad_u64_u32 v[1:2], null, v0, s8, v[0:1]
	v_lshlrev_b32_e32 v4, 2, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	global_load_b32 v2, v4, s[6:7]
	v_add_co_u32 v0, vcc_lo, s2, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v1, vcc_lo
	global_load_b32 v0, v[0:1], off
	s_waitcnt vmcnt(1)
	v_sub_f32_e32 v1, v2, v3
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_scale_f32 v2, null, v0, v0, v1
	v_rcp_f32_e32 v3, v2
	s_waitcnt_depctr 0xfff
	v_fma_f32 v5, -v2, v3, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v3, v5, v3
	v_div_scale_f32 v5, vcc_lo, v1, v0, v1
	v_mul_f32_e32 v6, v5, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v7, -v2, v6, v5
	v_fmac_f32_e32 v6, v7, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v2, -v2, v6, v5
	v_div_fmas_f32 v2, v2, v3, v6
	s_delay_alu instid0(VALU_DEP_1)
	v_div_fixup_f32 v0, v2, v0, v1
	global_store_b32 v4, v0, s[0:1]
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14jacobiOnDevicePfS_S_S_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 40
		.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 8
		.amdhsa_next_free_sgpr 12
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z14jacobiOnDevicePfS_S_S_ii, .Lfunc_end1-_Z14jacobiOnDevicePfS_S_S_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 352
; NumSgprs: 14
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 14
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z23jacobiOptimizedOnDevicePfS_S_S_ii ; -- Begin function _Z23jacobiOptimizedOnDevicePfS_S_S_ii
	.globl	_Z23jacobiOptimizedOnDevicePfS_S_S_ii
	.p2align	8
	.type	_Z23jacobiOptimizedOnDevicePfS_S_S_ii,@function
_Z23jacobiOptimizedOnDevicePfS_S_S_ii:  ; @_Z23jacobiOptimizedOnDevicePfS_S_S_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b64 s[8:9], s[0:1], 0x20
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s8, v1
	s_cbranch_execz .LBB2_7
; %bb.1:
	s_load_b256 s[0:7], s[0:1], 0x0
	v_mul_lo_u32 v4, v1, s9
	v_mov_b32_e32 v0, 0
	s_cmp_lt_i32 s9, 1
	s_cbranch_scc1 .LBB2_6
; %bb.2:                                ; %.lr.ph.preheader
	s_delay_alu instid0(VALU_DEP_2)
	v_dual_mov_b32 v2, v4 :: v_dual_mov_b32 v5, v1
.LBB2_3:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_mov_b32 s8, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_ne_u32_e32 0, v5
	s_cbranch_execz .LBB2_5
; %bb.4:                                ;   in Loop: Header=BB2_3 Depth=1
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v3, 31, v2
	s_waitcnt lgkmcnt(0)
	s_load_b32 s10, s[4:5], 0x0
	v_lshlrev_b64 v[6:7], 2, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, s2, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, s3, v7, vcc_lo
	global_load_b32 v3, v[6:7], off
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_fmac_f32_e32 v0, s10, v3
.LBB2_5:                                ;   in Loop: Header=BB2_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s8
	s_add_i32 s9, s9, -1
	v_add_nc_u32_e32 v5, -1, v5
	v_add_nc_u32_e32 v2, 1, v2
	s_waitcnt lgkmcnt(0)
	s_add_u32 s4, s4, 4
	s_addc_u32 s5, s5, 0
	s_cmp_eq_u32 s9, 0
	s_cbranch_scc0 .LBB2_3
.LBB2_6:                                ; %Flow52
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v3, v4, v1
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v5, vcc_lo, s6, v1
	v_add_co_ci_u32_e32 v6, vcc_lo, s7, v2, vcc_lo
	global_load_b32 v5, v[5:6], off
	s_waitcnt vmcnt(0)
	v_sub_f32_e32 v0, v5, v0
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 2, v[3:4]
	v_add_co_u32 v3, vcc_lo, s2, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s3, v4, vcc_lo
	global_load_b32 v3, v[3:4], off
	s_waitcnt vmcnt(0)
	v_div_scale_f32 v4, null, v3, v3, v0
	v_div_scale_f32 v7, vcc_lo, v0, v3, v0
	v_rcp_f32_e32 v5, v4
	s_waitcnt_depctr 0xfff
	v_fma_f32 v6, -v4, v5, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v5, v6, v5
	v_mul_f32_e32 v6, v7, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v8, -v4, v6, v7
	v_fmac_f32_e32 v6, v8, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v4, -v4, v6, v7
	v_div_fmas_f32 v4, v4, v5, v6
	s_delay_alu instid0(VALU_DEP_1)
	v_div_fixup_f32 v3, v4, v3, v0
	v_add_co_u32 v0, vcc_lo, s0, v1
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v2, vcc_lo
	global_store_b32 v[0:1], v3, off
.LBB2_7:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z23jacobiOptimizedOnDevicePfS_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 9
		.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_end2:
	.size	_Z23jacobiOptimizedOnDevicePfS_S_S_ii, .Lfunc_end2-_Z23jacobiOptimizedOnDevicePfS_S_S_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 436
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

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

	.end_amdgpu_metadata
