// CS 87 - Final Project
// Maria-Elena Solano
//
// Radix-2 Cooley-Tukey Fourier Transform on C^n - parallel 'pi' CUDA version
//

#include <stdio.h>                     // C's standard I/O library
#include <stdlib.h>                    // C's standard library
#include <stdint.h>                    // C's exact width int types
#include <string.h>                    // C's standard string library
#include <time.h>                      // C's time types (for random init)
#include <unistd.h>                    // C's POSIX API
#include <cuda.h>                      // CUDA runtime API


// macro/constant definitions
#define perror_out(X)                  perror(X), fflush(stderr)
#define stderr_out(...)                fprintf(stderr, __VA_ARGS__), \
                                        fflush(stderr)
#define print_out(...)                 printf(__VA_ARGS__), fflush(stdout)
#define cuda_try(X)                    ((X) != cudaSuccess)
#define cuda_malloc(X, Y)              cudaMalloc((void**)(X), (Y))
#define cuda_memcpy_todev(X, Y, Z)     cudaMemcpy((X), (Y), (Z), \
                                        cudaMemcpyHostToDevice)
#define cuda_memcpy_tohost(X, Y, Z)    cudaMemcpy((X), (Y), (Z), \
                                        cudaMemcpyDeviceToHost)
                                        

// data structures
// unit data type
typedef struct complex{                
  float re;                            // real part
  float im;                            // imaginary part
} data_t;

// simple struct to hold transform info
typedef struct tr tr_t;
typedef struct tr{ 
  uint32_t  N;                         // input size
  uint32_t  P;                         // number of processors
  uint32_t  Pi;                        // processor ID
  data_t*   in;                        // input data,
  data_t*   out;                       // output,
  data_t*   tmp_in;                    // input scratchpad,
  data_t*   tmp_out;                   // output scratchpads, and
  uint32_t  test_mode;                 // test mode?
  uint32_t  no_header;                 // no timing headers?
  tr_t*     trs;                       // array of tr_t objects in host,
  tr_t*     trs_dev;                   // and device.
} tr_t;

// simple encapsulating struct for timing
typedef struct timer{
  cudaEvent_t start, stop;             // start and stop events
  float  elapsed;                      // elapsed time (if any), in millisecs
} tmr_t;

// simple helper container (used in how_many_warp_schedulers)
typedef struct sm_to_ws{
  int sm;
  int ws;
} sm_to_ws_t;


// function declarations
// setting up the transform
int  setup_from_args (tr_t* t, int argc, char** argv);
void show_usage      ();

// running the transform
int   run             (tr_t* t);
int   initialize_data (tr_t* t);
void  cleanup_data    (tr_t* t);

__global__ void run_funnel_stage(tr_t* t);
__global__ void run_tube_stage  (tr_t* t);
__device__ void butterfly     (data_t* out, data_t* in, 
                               uint32_t size, uint32_t N);
__device__ void butterfly_half(data_t* out, data_t* in, 
                               uint32_t size, uint32_t N, uint32_t which_half);

// complex arithmetic
__device__ data_t add  (data_t a, data_t b);
__device__ data_t sub  (data_t a, data_t b);
__device__ data_t mul  (data_t a, data_t b);
__device__ data_t omega(uint32_t N, uint32_t k);
__device__ data_t convex_comb(data_t a, data_t b, uint32_t alpha);

// printing and verifying
void print_input     (tr_t* t);
void print_output    (tr_t* t);
void verify_results  (tr_t* t);

// timing
void timer_start(tmr_t* tm);
void timer_stop (tmr_t* tm);

// misc
__device__ __host__ uint32_t ilog2 (uint32_t x);
__device__   void swap_scratchpads (tr_t* t);
int      is_power_of_two           (int x);
uint32_t hash                      (uint32_t x);
uint32_t bit_reverse               (uint32_t x, uint32_t N);
uint32_t how_many_concurrent_blocks();
int      how_many_warp_schedulers  (int arch_major_ver, int arch_minor_ver);


int main(int argc, char** argv){
  tr_t t;                              // main transform object

  // (1) setup the transform from the command line args (or ret -1 if err)
  if(setup_from_args(&t, argc, argv)){
    exit(EXIT_FAILURE);
  }

  // (2) run the transform according to the given args (or ret -1 if err)
  if(run(&t)){
    exit(EXIT_FAILURE);    
  }

  // (3) return
  exit(EXIT_SUCCESS);
}


// This function parses the provided command line args into the given transform
// object, and initializes it accordingly. Returns 0 if success, or -1 if err).
//
//   t:                      (ptr to) tr_t object to update
//   argc:                   number of command line arguments
//   argv:                   array of strings containing the command line args
//
//   returns:                0 if success, or -1 if invalid command line args.
// 
int setup_from_args(tr_t* t, int argc, char** argv){
  int ret;                                  // return value from getopt, and
  int num = 0;                              // number to be retrieved.

  // First, zero all the entries of the tr_t (so we can tell whether or not
  // the entries were filled afterwards simply by checking if they're still 0)
  memset(t, 0, sizeof(tr_t));

  // Then, greedily read all the command line options provided.
  while((ret = getopt(argc, argv, "n:p:to")) != -1){
    switch(ret){
      // If option -n, grab the arg, which should be a nonnegative power of 2
      // (otherwise return -1 err)
      case 'n':{
        if(!(num = atoi(optarg)) || !(num > 1) || !is_power_of_two(num)){
          stderr_out("Invalid input size (should be 2^i for i>0)\n");
          show_usage(); 
          goto err;
        }
        t->N = num;
        break;
      }
      // If option -p, grab the arg, which should be 1 or a nonneg power of 2
      // (otherwise return -1 err)
      case 'p':{
        if(!(num = atoi(optarg)) || !(num > 0) || !is_power_of_two(num)){
          stderr_out("Invalid number of procs (should be 2^i for i>0)\n");
          show_usage();
          goto err;
        }
        t->P = num;
        break;
      }
      // If option -o, set t.no_header to 1.
      case 'o':{
        t->no_header = 1;
        break;
      }
      // If option -t, set t.N to 8 and t.test_mode to 'true', and notify user.
      case 't':{
        print_out("Test mode (ignoring provided input size, if any)...\n");
        t->N = 8;
        t->test_mode = 1;
        break;
      }
      // if unknown or missing arg, show usage and return -1 (error)
      case '?':{
        stderr_out("Unknown or missing arg %c\n", optopt);
        show_usage();
        goto err;
      }
    }
  }

  // Finally, validate the options
  // If the -n option is missing, notify the user, show usage, and return -1.
  if(!t->N){
    stderr_out("Missing option: -n\n");
    show_usage();
    goto err;
  }
  // If the -p option is missing, notify the user, show usage, and return -1.
  if(!t->P){
    stderr_out("Missing option: -p\n");
    show_usage();
    goto err;
  }
  // If more processors than inputs, return -1.
  if(t->P > t->N){
    stderr_out("More processors than inputs!\n");
    show_usage();
    goto err;
  }
  // If more processors than available, return -1.
  if(t->P > how_many_concurrent_blocks()){
    stderr_out("Too many processors! (only %u concurrent blocks available)\n",
               how_many_concurrent_blocks());
    goto err;
  }

  return 0;

err:
  stderr_out("Could not setup the transform from the cmdline args\n");
  return -1;
}

// This function initializes the given transform's data. Returns 0 if success 
// or -1 if err.
//
//   t:                      (ptr to) tr_t object to update
//
//   returns:                0 if success, or -1 if error.
// 
int initialize_data(tr_t* t){
  uint32_t bit;
  cudaError_t ret;                          // return value of CUDA calls

  // We need:
  // - N entries for the input,
  if((t->in = (data_t*)malloc(sizeof(data_t)*t->N)) == NULL){
    perror_out("malloc error");
    goto err;
  }
  // - N entries for the output, and
  if((t->out = (data_t*)malloc(sizeof(data_t)*t->N)) == NULL){
    perror_out("malloc error");
    goto err;
  }
  // - P tr_t objects (one for each block) (on both the host and the device),
  if((t->trs = (tr_t*)malloc(sizeof(tr_t)*t->P)) == NULL){
    perror_out("malloc error");
    goto err;
  }
  if(cuda_try(ret = cuda_malloc(&t->trs_dev, sizeof(tr_t)*t->P))){
    stderr_out("cudaMalloc error: %s\n", cudaGetErrorString(ret));
    goto err;
  }
  // - And, for each processor,
  for(t->Pi = 0; t->Pi < t->P; t->Pi++){
    
    // (Initialize their respective tr_t objects first)
    t->trs[t->Pi] = *t;

    // An input scratchpad of size N, and
    if(cuda_try(ret = cuda_malloc(&t->trs[t->Pi].tmp_in, 
                                  sizeof(data_t)*t->N))){
      stderr_out("cudaMalloc error: %s\n", cudaGetErrorString(ret));
      goto err;
    }

    // An output scratchpad of size N.
    if(cuda_try(ret = cuda_malloc(&t->trs[t->Pi].tmp_out, 
                                  sizeof(data_t)*t->N))){
      stderr_out("cudaMalloc error: %s\n", cudaGetErrorString(ret));
      goto err;
    }

    // (Making sure to copy the updated tr_t to the device's memory too)
    if(cuda_try(ret = cuda_memcpy_todev(t->trs_dev + t->Pi, 
                                        t->trs     + t->Pi,
                                        sizeof(tr_t)))){
      stderr_out("cudaMemcpy error: %s\n", cudaGetErrorString(ret));
      goto err;
    }

  }

  
  // Initialize the input with Bernoulli deviates from the L2 unit circle
  // --i.e. each element drawn from the distribution 1/sqrt{N}*[-1,1].
  if(!t->test_mode){
    for(srand(hash(time(NULL))), bit = 0; bit < t->N; bit++){
      t->in[bit].re = (rand()/(RAND_MAX/2.0)-1.0)/sqrt(t->N);
      t->in[bit].im = (rand()/(RAND_MAX/2.0)-1.0)/sqrt(t->N);
    }
  }
  // (unless in debug mode, in which case the values are always the same
  //  test case: 0,1,0,1,0,1,0,1 (the output should be 4,0,0,0,-4,0,0,0))
  else{
    t->in[0].re = 0; t->in[0].im = 0;
    t->in[1].re = 1; t->in[1].im = 0;
    t->in[2].re = 0; t->in[2].im = 0;
    t->in[3].re = 1; t->in[3].im = 0;
    t->in[4].re = 0; t->in[4].im = 0;
    t->in[5].re = 1; t->in[5].im = 0;
    t->in[6].re = 0; t->in[6].im = 0;
    t->in[7].re = 1; t->in[7].im = 0;
    print_input(t);
  }

  // - And copy the input to the input scratchpad of each block (of size N).
  for(t->Pi = 0; t->Pi < t->P; t->Pi++){
    if(cuda_try(ret = cuda_memcpy_todev(t->trs[t->Pi].tmp_in,
                                        t->in, sizeof(data_t)*t->N))){
      stderr_out("cudaMemcpy error: %s\n", cudaGetErrorString(ret));
      goto err;
    }
  }

  // And return
  return 0;

err:
  stderr_out("Could not initialize the data\n");
  return -1;
}

// This function frees all the data allocated by the given transform. 
//
//   t:                      (ptr to) tr_t object to update
// 
void cleanup_data(tr_t* t){
  cudaError_t ret;                          // return value of CUDA calls

  // Free all the allocated data (if any)
  if(t->in  != NULL){ free(t->in);   t->in  = NULL; }
  if(t->out != NULL){ free(t->out);  t->out = NULL; }
  if(t->trs != NULL){ 
    for(t->Pi = 0; t->Pi < t->P; t->Pi++){
      if(t->trs[t->Pi].tmp_in != NULL && 
         cuda_try(ret = cudaFree(t->trs[t->Pi].tmp_in))){
        stderr_out("cudaFree error: %s\n", cudaGetErrorString(ret)); };
      if(t->trs[t->Pi].tmp_out != NULL && 
         cuda_try(ret = cudaFree(t->trs[t->Pi].tmp_out))){
        stderr_out("cudaFree error: %s\n", cudaGetErrorString(ret)); };
    }  
    free(t->trs);  t->trs = NULL; 
  }
  if(t->trs_dev != NULL && cuda_try(ret = cudaFree(t->trs_dev))){
    stderr_out("cudaFree error: %s\n", cudaGetErrorString(ret)); 
  }

  return;
}

// This function shows the cmdline interface usage.
// 
void show_usage(){
  print_out("\nusage:\n"
            "  fourier-parallel-pi-gpu-cuda { -n <n> -p <p> [-o] | -t }\n"
            "\noptions:\n"
            "  -n <n>     power of two input size\n"
            "  -p <p>     power of two number of processors (less than n)\n"
            "  -o         omit timing headers\n"
            "  -t         compare against precomputed input/output\n"
            "\n");
}


// This function runs the given transform on P separate processors. Returns 0
// if success or -1 if err.
//
//   t:                      (ptr to) tr_t object to update
//
//   returns:                0 if success, or -1 if error.
// 
int run(tr_t* t){
  tmr_t       tm_funnel, tm_tube;           // tmr_t objects (for timing)
  cudaError_t ret;                          // return value of CUDA calls
  uint32_t    bit;

  // Initialize the data (or ret -1 err, cleaning up any malloc'd data first)
  if(initialize_data(t)){
    cleanup_data(t);
    goto err;
  }

  // Run the 1st (aka 'funnel') stage on P blocks, 1 thread per block.
  timer_start(&tm_funnel);
  run_funnel_stage<<<t->P, 1>>>(t->trs_dev);
  timer_stop(&tm_funnel);

  // Run the 2nd (aka 'tube') stage on P blocks, 1 thread per block.
  timer_start(&tm_tube);
  run_tube_stage<<<t->P, 1>>>(t->trs_dev);
  timer_stop(&tm_tube);

  // If not in test mode, show elapsed times (total, tree and cylinder stages)
  if(!t->test_mode){
    if(!t->no_header){ 
      print_out("n\tp\ttime (total)\t"
                "time (stage 1)\ttime (stage 2)\n"); };
    print_out("%u\t%u\t%f\t%f\t%f\n", 
              t->N, t->P, tm_funnel.elapsed + tm_tube.elapsed, 
              tm_funnel.elapsed, tm_tube.elapsed);
  }
  // Otherwise, copy the result from the _assigned segment_ (of size N/P) of
  // the input scratchpad of each processor (which will contain the new results
  // at this point) of each processor to the output, in bit-reversed order.
  //
  // Then print the output, and verify the results.
  else{
    // Update the host's tr_t array first
    if(cuda_try(ret = cuda_memcpy_tohost(
        t->trs, t->trs_dev, sizeof(tr_t)*t->P))){
      stderr_out("cudaMemcpy error: %s\n", cudaGetErrorString(ret));
    }
    for(t->Pi = 0; t->Pi < t->P; t->Pi++){
      for(bit = (t->N/t->P)*t->Pi; bit < (t->N/t->P)*t->Pi+t->N/t->P; bit++){
        if(cuda_try(ret = cuda_memcpy_tohost(
            t->out + bit_reverse(bit, ilog2(t->N)),   // position in output,
            t->trs[t->Pi].tmp_in + bit,               // Pi-th scratchpad.
            sizeof(data_t)))){
          stderr_out("cudaMemcpy error: %s\n", cudaGetErrorString(ret));
        }
      }
    }
    print_output(t);
    verify_results(t);
  }

  // Cleanup the data, and return
  cleanup_data(t);
  return 0;

err:
  stderr_out("Could not run the transform\n");
  return -1;
}

// This function runs the first stage of the transform in the GPU.
//
//   t_ptr:                  (ptr to) tr_t object to use
//
//   returns:                NULL always.
// 
__global__ void run_funnel_stage(tr_t* trs){
  uint32_t size, iter, offset;              // butterfly size, offset and iter,
  uint32_t which_butterfly, which_half;     // which butterfly, and which half,
  tr_t* t = trs + blockIdx.x;               // local, unpacked tr_t object

  // For the first log P iters
  // (i.e. butterfly sizes N,     N/2,       ..., 2(N/P),
  //       iteration stage log P, log P - 1, ..., 1),
  for(size = t->N, iter = ilog2(t->P); size > t->N/t->P; size /= 2, iter--){

  	// Determine _which_ butterfly to compute, depending on (Pi >> iter)
  	which_butterfly = (t->Pi >> iter);

    // Determine _which_ segment_ of size 'size' to compute the butterfly upon
    offset = which_butterfly * size;

    // Determine _which half_, depending on the parity of the 1st, 2nd, ...
    // most significant bit of Pi.
    which_half = ((t->Pi >> (iter - 1)) % 2 == 0);

    // And compute the butterfly accordingly
    butterfly_half(
      t->tmp_out + offset,        // output to the _1st_ half of the scratchpad
      t->tmp_in  + offset,        // and reading from the input scratchpad.
      size, t->N, which_half);

    // And swap scratchpads, so that the new results become the input for
    // the next iteration.
    swap_scratchpads(t);
  }

}

// This function runs the second stage of the transform in the GPU.
//
//   t_ptr:                  (ptr to) tr_t object to use
//
//   returns:                NULL always.
// 
__global__ void run_tube_stage(tr_t* trs){
  uint32_t size, offset;                    // butterfly size and offset
  tr_t* t = trs + blockIdx.x;               // local tr_t object

  // For the last log N/P iters
  // (i.e. butterfly sizes N/P, (N/P)/2, ..., 2), 
  // we work only on the portion of the output assigned to this processor
  for(size = t->N/t->P; size > 1; size /= 2){

    // Compute 1, 2, ..., (N/P)/2 butterflies of size N/P, (N/P)/2, ..., 2 
    // over _consecutive_ intervals across the assigned segment (of size N/P),
    // (which recall starts from (t.N/t.P)).
    for(offset = (t->N/t->P)*t->Pi; 
        offset < (t->N/t->P)*t->Pi + t->N/t->P; 
        offset += size){
      
      butterfly(
        t->tmp_out + offset,       // output to the _assigned_ segment,
        t->tmp_in  + offset,       // and reading from the _assigned_ segment.
        size, t->N);
    }

    // And swap scratchpads, so that the new results become the input for
    // the next iteration.
    swap_scratchpads(t);
  }
}


// This function computes an n-point butterfly over the given input array,
// placing the results on the given output array.
//
//   out,in:                 output and input arrays
//   size:                   size of the butterfly
//   N:                      input size of the broader FFT
//
__device__ void butterfly(data_t* out, data_t* in, uint32_t size, uint32_t N){

  // Compute the left butterfly (note it only writes on the _1st_ half of out)
  butterfly_half(out, in, size, N, 1);

  // And the right butterfly (note it only writes on the _2nd_ half of out)
  butterfly_half(out, in, size, N, 0);

  return;
}

// This function computes either half of an n-point butterfly. Note it only
// writes to either the _first_ half of the output (if left butterfly), or the
// _second_ half of the output (if right butterfly).
//
//   out,in:                 output and input arrays
//   size:                   size of the butterfly
//   N:                      input size of the broader FFT
//   which_half:             which half to compute?
//
__device__ void butterfly_half(data_t* out, data_t* in, 
                               uint32_t size, uint32_t N, uint32_t which_half){
  uint32_t bit;
      
  // For each bit in the segment
  for(out += !which_half*(size/2), bit = 0; bit < size/2; bit++){
    out[bit] =                              //  set the current (output) bit to
      convex_comb(                          //   either:
        add(                                //    the sum of
          in[bit],                          //     the current (input) bit, and
          in[bit+size/2]),                  //     the (size/2)-next one,
        mul(                                //    or the multiplication of
          sub(                              //     the sum of the
            in[bit],                        //      the (stride)-prev bit, and
            in[bit+size/2]),                //      the next one
          omega(N,                          //     times the Nth root of unity,
                bit*(N/size))),             //      to the power of 0,1,2 first
        which_half);                        //     0,2,4 second, etc.
  }

  return;
}

// This function returns (by value) the sum of the two given complex numbers.
//
//   a,b:                    operands (x+yi,z+wi) (of type data_t)
//
//   returns:                the sum a+b = (x+z)+(y+w)i
// 
__device__ data_t add(data_t a, data_t b){
  data_t c;

  c.re = a.re + b.re;
  c.im = a.im + b.im;

  return c;
}

// This function returns (by value) the sum a+(-b) of the given complex nums.
//
// (Note: this can be overriden to provide support for more general transforms
//        on arbitrary fields)
//
//   a,b:                    operands (x+yi,z+wi) (of type data_t)
//
//   returns:                the sum a+(-b) = (x-z)+(y-w)i
// 
__device__ data_t sub(data_t a, data_t b){
  data_t c;

  c.re = a.re - b.re;
  c.im = a.im - b.im;

  return c;
}

// This function returns (by value) the mult a*b of the given complex numbers.
//
// (Note: this can be overriden to provide support for more general transforms
//        on arbitrary fields)
//
//   a,b:                    operands (x+yi,z+wi) (of type data_t)
//
//   returns:                their mult a*b = (xz-yw) + (xw-yz)i
// 
__device__ data_t mul(data_t a, data_t b){
  data_t c;

  c.re = a.re*b.re - a.im*b.im;
  c.im = a.re*b.im + a.im*b.re;

  return c;
}

// This function returns (by value) the primitive N-th root of unity of the
// complex field \mathbb{C} the power of k, which is given by
//
//   e^{-2\pi k/N} = (cos 2\pi/N - i sin 2\pi/N)^k   (by Euler's formula)
//                 = cos 2\pi/N*k - i sin 2\pi/N*k   (by De Moivre's formula)
//
// (Note: this can be overriden to provide support for more general transforms
//        on arbitrary fields)
//
//   N:                      Order of the cyclic group.
//   k:                      Power to raise the root of unity to.
//
//   returns:                N-th primitive root of unity of \mathbb{C}, raised
//                           to the power of k.
// 
__device__ data_t omega(uint32_t N, uint32_t k){
  data_t o;

  o.re =  __cosf(2.0f*3.141592f/N*k);
  o.im = -__sinf(2.0f*3.141592f/N*k);

  return o;
}

// This function returns (by value) the 'convex combination' of a and b, para-
// meterized by the scalar alpha.
//
// (Note: this can be overriden to provide support for more general transforms
//        on arbitrary fields)
//
//   a,b:                    Operands
//   alpha:                  Alpha (between 0 and 1)
//
//   returns:                alpha*a + (1-alpha)*b
// 
__device__ data_t convex_comb(data_t a, data_t b, uint32_t alpha){
  data_t o;

  o.re = alpha*a.re + (1U-alpha)*b.re;
  o.im = alpha*a.im + (1U-alpha)*b.im;

  return o;
}



// This function prints out the input of the transform.
//
//   t:                      (ptr to) tr_t object to use.
//
void print_input(tr_t* t){
  uint32_t bit;                             // entry to print out

  for(print_out("Input:\n"), bit = 0; bit < t->N; bit++){
    print_out("%.1f+%.1fi, ", t->in[bit].re, t->in[bit].im);
  }
  print_out("\n");

  return;
}

// This function prints out the output of the transform.
//
//   t:                      (ptr to) tr_t object to use.
//
void print_output(tr_t* t){
  uint32_t bit;                             // entry to print out

  for(print_out("Output:\n"), bit = 0; bit < t->N; bit++){
    print_out("%.1f+%.1fi, ", t->out[bit].re, t->out[bit].im);
  }
  print_out("\n");

  return;
}

// This function verifies that the output of the transform is correct.
//
//   t:                      (ptr to) tr_t object to use.
//
void verify_results(tr_t* t){

  // since the input is 0,1,0,1,0,1,0,1; the output should be 4,0,0,0,-4,0,0,0.
  print_out(
    (t->out[0].re == 4 && t->out[0].im == 0 &&
     t->out[1].re == 0 && t->out[1].im == 0 &&
     t->out[2].re == 0 && t->out[2].im == 0 &&
     t->out[3].re == 0 && t->out[3].im == 0 &&
     t->out[4].re ==-4 && t->out[4].im == 0 &&
     t->out[5].re == 0 && t->out[5].im == 0 &&
     t->out[6].re == 0 && t->out[6].im == 0 &&
     t->out[7].re == 0 && t->out[7].im == 0)
    ? "Output is correct. Test passed.\n\n" 
    : "Output is incorrect! Test failed.\n\n");

  return;
}


// This function swaps the input and output scratchpads of the given tr_t obj.
//
//   t:                      (ptr to) tr_t object to use.
//
__device__ void swap_scratchpads(tr_t* t){
  data_t* temp;

  temp       = t->tmp_in;  
  t->tmp_in  = t->tmp_out;  
  t->tmp_out = temp;

  return;
}

// This function determines whether or not the given number is a non-negative
// power of two.
//
// From: www.graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
//
//   x:                      value to query.
//
//   returns:                0 if _not_ a non-negative power of 2, 1 otherwise.
// 
int is_power_of_two(int x){
  return x && !(x & (x - 1));
}

// This function computes a hash of the given uint32 number.
// (From http://www.concentric.net/~ttwang/tech/inthash.htm)
//
//   x:                      number to hash.
//
//   returns:                uint32 hash of the given number.
// 
uint32_t hash(uint32_t x){
  x = (x + 0x7ed55d16U) + (x << 12);  x = (x ^ 0xc761c23cU) ^ (x >> 19);
  x = (x + 0x165667b1U) + (x << 5);   x = (x + 0xd3a2646cU) ^ (x << 9);
  x = (x + 0xfd7046c5U) + (x << 3);   x = (x ^ 0xb55a4f09U) ^ (x >> 16);
  return x;
}

// This function computes the log2 of the given uint32_t number.
//
// From: graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn
//
//   x:                      value to compute.
//
//   returns:                log2(x)
// 
__host__ __device__ uint32_t ilog2(uint32_t x){  
  int lookup_table[32] = {
     0,  1, 28,  2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17,  4, 8, 
    31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18,  6, 11,  5, 10, 9 };

  return lookup_table[(uint32_t)(x*0x077CB531U) >> 27];
}


// This function bit-reverses the given index (represented as a m-bit binary 
// number), and returns the resulting value as an integer.
// 
// This is used in the final step of the FFT: due to the recursive nature of
// the factorization, the butterfly's outputs are always in bit-reversed order
// (when represented as log(N)-bit numbers, where N is the input size). So for
// instance for a butterfly of size 8, the 1st output of the butterfly actually
// maps to the 1 -> 001 -> 100 -> 4th output of the array; while the 3rd output
// of the butterfly maps to the 3 -> 011 -> 110 -> 6th output of the array; and
// so forth.
//
// The algorithm below comes from:
//
//  Dietz, H. (2002) The Aggregate Magic Algorithms. University of Kentucky.
//   http://aggregate.org/MAGIC/#Bit%20Reversal
//
// which decomposes the (m m-1 ... 1) permutation into log m cycles: first swap
// all adjacent bits, then swap every two bits, and so forth.
// 
// Note, however, Dietz' particular algorithm is hard-wired to m=32-bits only:
// so in the example above, 3 is not mapped to 110 but to 1100 0000 0000 0000 
// 0000 0000 0000 0000; so, at the end, I just right-shift the result by 32-m 
// bits to obtain the desired value (in this case, 110 -> 6).
// 
//   x:                      Index to bit-reverse.
//   m:                      How many bits to use when representing the index.
//
//   returns:                Bit-reversed integer value of x, when represented
//                           as a m-bit binary number.
// 
uint32_t bit_reverse(uint32_t x, uint32_t m){
  x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
  x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
  x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
  x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));

  return ((x >> 16) | (x << 16)) >> (32-m);
}

// This function starts the given tmr_t object.
//
//   timer:                  (pointer to) tmr_t object to start.
//
//  (From: http://stackoverflow.com/questions/7876624/timing-cuda-operations)
//
void timer_start(tmr_t* tm){
  cudaError_t ret;                          // return value of CUDA calls

  if(cuda_try(ret = cudaEventCreate(&tm->start))  ||
     cuda_try(ret = cudaEventCreate(&tm->stop))   ||
     cuda_try(ret = cudaEventRecord( tm->start, 0))){
    stderr_out("cudaEventCreate|Record error: %s\n", cudaGetErrorString(ret));
  }
}

// This function stops the given tmr_t object, annd calculates the elapsed
// time since the call last to start_timer.
//
//   timer:                  (pointer to) tmr_t object to stop.
//
//  (From: http://stackoverflow.com/questions/7876624/timing-cuda-operations)
//
void timer_stop(tmr_t* tm){
  cudaError_t ret;                          // return value of CUDA calls

  if(cuda_try(ret = cudaEventRecord     ( tm->stop, 0))  ||
     cuda_try(ret = cudaEventSynchronize( tm->stop))     ||
     cuda_try(ret = cudaEventElapsedTime(&tm->elapsed, tm->start, tm->stop))){
    stderr_out("cudaEventRecord|Synchronize|ElapsedTime error: %s\n", 
      cudaGetErrorString(ret));
  }
}

// This function returns the number of concurrent blocks in the GPU.
//
//   returns:                Number of concurrent blocks in the GPU (if any)
//
uint32_t how_many_concurrent_blocks(){
  cudaError_t ret;                     // return value of CUDA calls
  int dev, devs;                       // number of devices
  cudaDeviceProp pr;                   // device properties
  uint32_t p;                          // number of concurrent blocks

  // Count how many devices are there. If err or no devices, set p=0 and print.
  if(cuda_try(ret = cudaGetDeviceCount(&devs)) || devs == 0){
    stderr_out("cudaGetDeviceCount error: %s\n", cudaGetErrorString(ret));
    return 0;
  }

  // Get the device properties of the last device
  dev = devs - 1;
  cudaSetDevice(dev);
  cudaGetDeviceProperties(&pr, dev);

  // Compute the number of concurrent blocks according to the formula 
  //
  //   # of SMs x # of warp schedulers per SM
  //
  p = pr.multiProcessorCount * how_many_warp_schedulers(pr.major,pr.minor);

  return p;
}

// This function determines how many warp schedulers per SM are there in the
// GPU given ts major and minor architectural version.
// 
// Adapted from helper_cuda.h in the CUDA SDK:
//   (/usr/local/cuda/samples/common/inc/helper_cuda.h).
//
//   major, minor:                     major and minor architecture version
//
//   returns:                          number of warp schedulers per SM
//
int how_many_warp_schedulers(int major, int minor){
  int i;
  sm_to_ws_t t[13];                   // Lookup table

  // Tesla architecture (1 warp scheduler per SM)
  t[0] .sm = 0x10;  t[0] .ws = 1;     // Tesla   (SM 1.0) G80 class
  t[1] .sm = 0x11;  t[1] .ws = 1;     // Tesla   (SM 1.1) G8X class
  t[2] .sm = 0x12;  t[2] .ws = 1;     // Tesla   (SM 1.2) G9X class
  t[3] .sm = 0x13;  t[3] .ws = 1;     // Tesla   (SM 1.3) GT200 class

  // Fermi architecture (2 warp schedulers per SM)
  t[4] .sm = 0x20;  t[4] .ws = 2;     // Fermi   (SM 2.0) GF100 class
  t[5] .sm = 0x21;  t[5] .ws = 2;     // Fermi   (SM 2.1) GF10x class

  // Kepler architecture (4 warp schedulers per SM)
  t[6] .sm = 0x30;  t[6] .ws = 4;     // Kepler  (SM 3.0) GK10x class
  t[7] .sm = 0x32;  t[7] .ws = 4;     // Kepler  (SM 3.2) GK10x class
  t[8] .sm = 0x35;  t[8] .ws = 4;     // Kepler  (SM 3.5) GK11x class
  t[9] .sm = 0x37;  t[9] .ws = 4;     // Kepler  (SM 3.7) GK21x class

  // Maxwell architecture (4 warp schedulers per SM)
  t[10].sm = 0x50;  t[10].ws = 4;     // Maxwell (SM 5.0) GM10x class
  t[11].sm = 0x52;  t[11].ws = 4;     // Maxwell (SM 5.2) GM20x class

  // Unknown architecture
  t[12].sm = -1;    t[12].ws = -1;    // Unknown

  for(i=0; i<13; i++){
    if(t[i].sm == ((major << 4) + minor)){
      return t[i].ws;
    }
  }
  return 0;
}

	.file	"tmpxft_002a9618_00000000-6_fourier-parallel-pi-gpu-cuda.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2067:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2067:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"cudaFree error: %s\n"
	.text
	.globl	_Z12cleanup_dataP2tr
	.type	_Z12cleanup_dataP2tr, @function
_Z12cleanup_dataP2tr:
.LFB2043:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	%rdi, %rbx
	pushq	%r8
	.cfi_def_cfa_offset 32
	movq	16(%rdi), %rdi
	testq	%rdi, %rdi
	je	.L3
	call	free@PLT
	xorl	%edi, %edi
	movq	%rdi, 16(%rbx)
.L3:
	movq	24(%rbx), %rdi
	testq	%rdi, %rdi
	je	.L4
	call	free@PLT
	xorl	%esi, %esi
	movq	%rsi, 24(%rbx)
.L4:
	xorl	%eax, %eax
	cmpq	$0, 56(%rbx)
	leaq	.LC1(%rip), %rbp
	je	.L6
.L5:
	movl	%eax, 8(%rbx)
	movq	56(%rbx), %rdi
	cmpl	4(%rbx), %eax
	jnb	.L36
	imulq	$72, %rax, %rax
	movq	32(%rdi,%rax), %rdi
	testq	%rdi, %rdi
	je	.L8
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L8
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%rbp, %rdx
	movl	$2, %esi
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	call	fflush@PLT
.L8:
	movl	8(%rbx), %eax
	imulq	$72, %rax, %rax
	addq	56(%rbx), %rax
	movq	40(%rax), %rdi
	testq	%rdi, %rdi
	je	.L11
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L11
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%rbp, %rdx
	movl	$2, %esi
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	call	fflush@PLT
.L11:
	movl	8(%rbx), %eax
	incl	%eax
	jmp	.L5
.L36:
	call	free@PLT
	xorl	%ecx, %ecx
	movq	%rcx, 56(%rbx)
.L6:
	movq	64(%rbx), %rdi
	testq	%rdi, %rdi
	je	.L2
	call	cudaFree@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L2
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC1(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	popq	%rdx
	.cfi_remember_state
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	fflush@PLT
.L2:
	.cfi_restore_state
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2043:
	.size	_Z12cleanup_dataP2tr, .-_Z12cleanup_dataP2tr
	.section	.rodata.str1.1
.LC2:
	.ascii	"\nusage:"
	.string	"\n  fourier-parallel-pi-gpu-cuda { -n <n> -p <p> [-o] | -t }\n\noptions:\n  -n <n>     power of two input size\n  -p <p>     power of two number of processors (less than n)\n  -o         omit timing headers\n  -t         compare against precomputed input/output\n\n"
	.text
	.globl	_Z10show_usagev
	.type	_Z10show_usagev, @function
_Z10show_usagev:
.LFB2044:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$2, %edi
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	fflush@PLT
	.cfi_endproc
.LFE2044:
	.size	_Z10show_usagev, .-_Z10show_usagev
	.globl	_Z9butterflyP7complexS0_jj
	.type	_Z9butterflyP7complexS0_jj, @function
_Z9butterflyP7complexS0_jj:
.LFB2046:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2046:
	.size	_Z9butterflyP7complexS0_jj, .-_Z9butterflyP7complexS0_jj
	.globl	_Z14butterfly_halfP7complexS0_jjj
	.type	_Z14butterfly_halfP7complexS0_jjj, @function
_Z14butterfly_halfP7complexS0_jjj:
.LFB2047:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2047:
	.size	_Z14butterfly_halfP7complexS0_jjj, .-_Z14butterfly_halfP7complexS0_jjj
	.globl	_Z3add7complexS_
	.type	_Z3add7complexS_, @function
_Z3add7complexS_:
.LFB2048:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2048:
	.size	_Z3add7complexS_, .-_Z3add7complexS_
	.globl	_Z3sub7complexS_
	.type	_Z3sub7complexS_, @function
_Z3sub7complexS_:
.LFB2212:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	_Z3add7complexS_
	.cfi_endproc
.LFE2212:
	.size	_Z3sub7complexS_, .-_Z3sub7complexS_
	.globl	_Z3mul7complexS_
	.type	_Z3mul7complexS_, @function
_Z3mul7complexS_:
.LFB2214:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	_Z3add7complexS_
	.cfi_endproc
.LFE2214:
	.size	_Z3mul7complexS_, .-_Z3mul7complexS_
	.globl	_Z5omegajj
	.type	_Z5omegajj, @function
_Z5omegajj:
.LFB2051:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2051:
	.size	_Z5omegajj, .-_Z5omegajj
	.globl	_Z11convex_comb7complexS_j
	.type	_Z11convex_comb7complexS_j, @function
_Z11convex_comb7complexS_j:
.LFB2052:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2052:
	.size	_Z11convex_comb7complexS_j, .-_Z11convex_comb7complexS_j
	.section	.rodata.str1.1
.LC3:
	.string	"Input:\n"
.LC4:
	.string	"%.1f+%.1fi, "
.LC5:
	.string	"\n"
	.text
	.globl	_Z11print_inputP2tr
	.type	_Z11print_inputP2tr, @function
_Z11print_inputP2tr:
.LFB2053:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	leaq	.LC4(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
.L54:
	cmpl	(%rbx), %ebp
	jnb	.L57
	movq	16(%rbx), %rax
	movl	%ebp, %edx
	movq	%r12, %rsi
	movl	$2, %edi
	incl	%ebp
	leaq	(%rax,%rdx,8), %rax
	cvtss2sd	(%rax), %xmm0
	cvtss2sd	4(%rax), %xmm1
	movb	$2, %al
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
	jmp	.L54
.L57:
	movl	$2, %edi
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	fflush@PLT
	.cfi_endproc
.LFE2053:
	.size	_Z11print_inputP2tr, .-_Z11print_inputP2tr
	.section	.rodata.str1.1
.LC6:
	.string	"Output:\n"
	.text
	.globl	_Z12print_outputP2tr
	.type	_Z12print_outputP2tr, @function
_Z12print_outputP2tr:
.LFB2054:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	leaq	.LC4(%rip), %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movq	%rdi, %rbx
	movl	$2, %edi
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
.L59:
	cmpl	(%rbx), %ebp
	jnb	.L62
	movq	24(%rbx), %rax
	movl	%ebp, %edx
	movq	%r12, %rsi
	movl	$2, %edi
	incl	%ebp
	leaq	(%rax,%rdx,8), %rax
	cvtss2sd	(%rax), %xmm0
	cvtss2sd	4(%rax), %xmm1
	movb	$2, %al
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
	jmp	.L59
.L62:
	movl	$2, %edi
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	fflush@PLT
	.cfi_endproc
.LFE2054:
	.size	_Z12print_outputP2tr, .-_Z12print_outputP2tr
	.section	.rodata.str1.1
.LC7:
	.string	"Output is correct. Test passed.\n\n"
.LC8:
	.string	"Output is incorrect! Test failed.\n\n"
	.text
	.globl	_Z14verify_resultsP2tr
	.type	_Z14verify_resultsP2tr, @function
_Z14verify_resultsP2tr:
.LFB2055:
	.cfi_startproc
	endbr64
	pushq	%rdx
	.cfi_def_cfa_offset 16
	movq	24(%rdi), %rax
	movss	(%rax), %xmm0
	ucomiss	.LC9(%rip), %xmm0
	jp	.L95
	jne	.L95
	xorps	%xmm0, %xmm0
	ucomiss	4(%rax), %xmm0
	jp	.L95
	jne	.L95
	ucomiss	8(%rax), %xmm0
	jp	.L95
	jne	.L95
	ucomiss	12(%rax), %xmm0
	jp	.L95
	jne	.L95
	ucomiss	16(%rax), %xmm0
	jp	.L95
	jne	.L95
	ucomiss	20(%rax), %xmm0
	jp	.L95
	jne	.L95
	ucomiss	24(%rax), %xmm0
	jp	.L95
	jne	.L95
	ucomiss	28(%rax), %xmm0
	jp	.L95
	jne	.L95
	movss	32(%rax), %xmm1
	ucomiss	.LC11(%rip), %xmm1
	jp	.L95
	jne	.L95
	ucomiss	36(%rax), %xmm0
	jp	.L95
	jne	.L95
	ucomiss	40(%rax), %xmm0
	jp	.L95
	jne	.L95
	ucomiss	44(%rax), %xmm0
	jp	.L95
	jne	.L95
	ucomiss	48(%rax), %xmm0
	jp	.L95
	jne	.L95
	ucomiss	52(%rax), %xmm0
	jp	.L95
	jne	.L95
	ucomiss	56(%rax), %xmm0
	jp	.L95
	jne	.L95
	ucomiss	60(%rax), %xmm0
	jp	.L95
	leaq	.LC7(%rip), %rsi
	je	.L64
.L95:
	leaq	.LC8(%rip), %rsi
.L64:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 8
	jmp	fflush@PLT
	.cfi_endproc
.LFE2055:
	.size	_Z14verify_resultsP2tr, .-_Z14verify_resultsP2tr
	.globl	_Z16swap_scratchpadsP2tr
	.type	_Z16swap_scratchpadsP2tr, @function
_Z16swap_scratchpadsP2tr:
.LFB2056:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2056:
	.size	_Z16swap_scratchpadsP2tr, .-_Z16swap_scratchpadsP2tr
	.globl	_Z15is_power_of_twoi
	.type	_Z15is_power_of_twoi, @function
_Z15is_power_of_twoi:
.LFB2057:
	.cfi_startproc
	endbr64
	xorl	%eax, %eax
	testl	%edi, %edi
	je	.L117
	leal	-1(%rdi), %eax
	testl	%edi, %eax
	sete	%al
.L117:
	movzbl	%al, %eax
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z15is_power_of_twoi, .-_Z15is_power_of_twoi
	.globl	_Z4hashj
	.type	_Z4hashj, @function
_Z4hashj:
.LFB2058:
	.cfi_startproc
	endbr64
	imull	$4097, %edi, %edi
	addl	$2127912214, %edi
	movl	%edi, %eax
	shrl	$19, %eax
	xorl	%edi, %eax
	xorl	$-949894596, %eax
	imull	$33, %eax, %eax
	leal	374761393(%rax), %ecx
	leal	-369570787(%rax), %edx
	sall	$9, %ecx
	xorl	%ecx, %edx
	leal	(%rdx,%rdx,8), %edx
	subl	$42973499, %edx
	movl	%edx, %eax
	shrl	$16, %eax
	xorl	%edx, %eax
	xorl	$-1252372727, %eax
	ret
	.cfi_endproc
.LFE2058:
	.size	_Z4hashj, .-_Z4hashj
	.section	.rodata.str1.1
.LC12:
	.string	"malloc error"
.LC13:
	.string	"cudaMalloc error: %s\n"
.LC14:
	.string	"cudaMemcpy error: %s\n"
.LC17:
	.string	"Could not initialize the data\n"
	.text
	.globl	_Z15initialize_dataP2tr
	.type	_Z15initialize_dataP2tr, @function
_Z15initialize_dataP2tr:
.LFB2042:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	movl	(%rdi), %ebp
	movq	%rdi, %rbx
	salq	$3, %rbp
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rax, 16(%rbx)
	testq	%rax, %rax
	je	.L151
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rax, 24(%rbx)
	testq	%rax, %rax
	je	.L151
	movl	4(%rbx), %ebp
	imulq	$72, %rbp, %rbp
	movq	%rbp, %rdi
	call	malloc@PLT
	movq	%rax, 56(%rbx)
	testq	%rax, %rax
	jne	.L125
.L151:
	leaq	.LC12(%rip), %rdi
	call	perror@PLT
	jmp	.L148
.L125:
	leaq	64(%rbx), %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	xorl	%edi, %edi
	movl	%eax, %ebp
	testl	%ebp, %ebp
	je	.L126
	movl	%ebp, %edi
	jmp	.L150
.L127:
	movl	8(%rbx), %edi
	movl	(%rbx), %esi
	imulq	$72, %rdi, %rdi
	addq	56(%rbx), %rdi
	salq	$3, %rsi
	addq	$40, %rdi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L150
	movl	8(%rbx), %edi
	movq	56(%rbx), %rsi
	movl	$1, %ecx
	movl	$72, %edx
	imulq	$72, %rdi, %rdi
	addq	%rdi, %rsi
	addq	64(%rbx), %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L147
	movl	8(%rbx), %eax
	leal	1(%rax), %edi
.L126:
	movl	%edi, 8(%rbx)
	cmpl	4(%rbx), %edi
	jnb	.L152
	movl	%edi, %eax
	movl	$18, %ecx
	movq	%rbx, %rsi
	imulq	$72, %rax, %rax
	addq	56(%rbx), %rax
	movq	%rax, %rdi
	rep movsl
	movl	8(%rbx), %edi
	movl	(%rbx), %esi
	imulq	$72, %rdi, %rdi
	addq	56(%rbx), %rdi
	salq	$3, %rsi
	addq	$32, %rdi
	call	cudaMalloc@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L127
.L150:
	call	cudaGetErrorString@PLT
	leaq	.LC13(%rip), %rdx
	movq	%rax, %rcx
	jmp	.L149
.L152:
	movl	48(%rbx), %r12d
	testl	%r12d, %r12d
	jne	.L131
	xorl	%edi, %edi
	call	time@PLT
	movl	%eax, %edi
	call	_Z4hashj
	movl	%eax, %edi
	call	srand@PLT
.L132:
	cmpl	(%rbx), %r12d
	jnb	.L139
	call	rand@PLT
	movl	%eax, %r14d
	movl	(%rbx), %eax
	cvtsi2sdq	%rax, %xmm0
	call	sqrt@PLT
	movq	16(%rbx), %rdx
	movl	%r12d, %eax
	incl	%r12d
	movaps	%xmm0, %xmm1
	cvtsi2sdl	%r14d, %xmm0
	divsd	.LC15(%rip), %xmm0
	subsd	.LC16(%rip), %xmm0
	leaq	0(,%rax,8), %r13
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%rdx,%rax,8)
	call	rand@PLT
	movl	%eax, %r14d
	movl	(%rbx), %eax
	cvtsi2sdq	%rax, %xmm0
	call	sqrt@PLT
	movq	16(%rbx), %rax
	movaps	%xmm0, %xmm1
	cvtsi2sdl	%r14d, %xmm0
	divsd	.LC15(%rip), %xmm0
	subsd	.LC16(%rip), %xmm0
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, 4(%rax,%r13)
	jmp	.L132
.L131:
	movq	16(%rbx), %rax
	xorl	%edi, %edi
	xorl	%edx, %edx
	xorl	%ecx, %ecx
	xorl	%esi, %esi
	movq	%rdi, 48(%rax)
	movq	%rbx, %rdi
	movq	%rdx, (%rax)
	movq	$1065353216, 8(%rax)
	movq	%rcx, 16(%rax)
	movq	$1065353216, 24(%rax)
	movq	%rsi, 32(%rax)
	movq	$1065353216, 40(%rax)
	movq	$1065353216, 56(%rax)
	call	_Z11print_inputP2tr
	jmp	.L139
.L147:
	call	cudaGetErrorString@PLT
	leaq	.LC14(%rip), %rdx
	movq	%rax, %rcx
.L149:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
.L148:
.L123:
	movq	stderr(%rip), %rdi
	call	fflush@PLT
	movq	stderr(%rip), %rdi
	leaq	.LC17(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	call	fflush@PLT
	orl	$-1, %eax
	jmp	.L121
.L141:
	movl	(%rbx), %edx
	imulq	$72, %rbp, %rbp
	addq	56(%rbx), %rbp
	movl	$1, %ecx
	movq	32(%rbp), %rdi
	movq	16(%rbx), %rsi
	salq	$3, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L147
	movl	8(%rbx), %eax
	leal	1(%rax), %ebp
.L139:
	movl	%ebp, 8(%rbx)
	cmpl	4(%rbx), %ebp
	jb	.L141
	xorl	%eax, %eax
.L121:
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2042:
	.size	_Z15initialize_dataP2tr, .-_Z15initialize_dataP2tr
	.section	.rodata
	.align 32
.LC0:
	.long	0
	.long	1
	.long	28
	.long	2
	.long	29
	.long	14
	.long	24
	.long	3
	.long	30
	.long	22
	.long	20
	.long	15
	.long	25
	.long	17
	.long	4
	.long	8
	.long	31
	.long	27
	.long	13
	.long	23
	.long	21
	.long	19
	.long	16
	.long	7
	.long	26
	.long	12
	.long	18
	.long	6
	.long	11
	.long	5
	.long	10
	.long	9
	.text
	.globl	_Z5ilog2j
	.type	_Z5ilog2j, @function
_Z5ilog2j:
.LFB2059:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movl	%edi, %eax
	movl	$32, %ecx
	movq	%fs:40, %rdx
	movq	%rdx, 136(%rsp)
	xorl	%edx, %edx
	leaq	8(%rsp), %rdi
	leaq	.LC0(%rip), %rsi
	rep movsl
	imull	$125613361, %eax, %eax
	shrl	$27, %eax
	movl	8(%rsp,%rax,4), %eax
	movq	136(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L154
	call	__stack_chk_fail@PLT
.L154:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2059:
	.size	_Z5ilog2j, .-_Z5ilog2j
	.globl	_Z11bit_reversejj
	.type	_Z11bit_reversejj, @function
_Z11bit_reversejj:
.LFB2060:
	.cfi_startproc
	endbr64
	movl	%edi, %eax
	shrl	%edi
	movl	$32, %ecx
	addl	%eax, %eax
	andl	$1431655765, %edi
	subl	%esi, %ecx
	andl	$-1431655766, %eax
	orl	%eax, %edi
	movl	%edi, %edx
	sall	$2, %edi
	shrl	$2, %edx
	andl	$-858993460, %edi
	andl	$858993459, %edx
	orl	%edi, %edx
	movl	%edx, %eax
	sall	$4, %edx
	shrl	$4, %eax
	andl	$-252645136, %edx
	andl	$252645135, %eax
	orl	%edx, %eax
	bswap	%eax
	shrl	%cl, %eax
	ret
	.cfi_endproc
.LFE2060:
	.size	_Z11bit_reversejj, .-_Z11bit_reversejj
	.section	.rodata.str1.1
.LC18:
	.string	"cudaEventCreate|Record error: %s\n"
	.text
	.globl	_Z11timer_startP5timer
	.type	_Z11timer_startP5timer, @function
_Z11timer_startP5timer:
.LFB2061:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	call	cudaEventCreate@PLT
	testl	%eax, %eax
	jne	.L158
	leaq	8(%rbx), %rdi
	call	cudaEventCreate@PLT
	testl	%eax, %eax
	jne	.L158
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	testl	%eax, %eax
	je	.L157
.L158:
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC18(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	jmp	fflush@PLT
.L157:
	.cfi_restore_state
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2061:
	.size	_Z11timer_startP5timer, .-_Z11timer_startP5timer
	.section	.rodata.str1.1
.LC19:
	.string	"cudaEventRecord|Synchronize|ElapsedTime error: %s\n"
	.text
	.globl	_Z10timer_stopP5timer
	.type	_Z10timer_stopP5timer, @function
_Z10timer_stopP5timer:
.LFB2062:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	movq	8(%rdi), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	testl	%eax, %eax
	jne	.L162
	movq	8(%rbx), %rdi
	call	cudaEventSynchronize@PLT
	testl	%eax, %eax
	jne	.L162
	movq	8(%rbx), %rdx
	movq	(%rbx), %rsi
	leaq	16(%rbx), %rdi
	call	cudaEventElapsedTime@PLT
	testl	%eax, %eax
	je	.L161
.L162:
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC19(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	popq	%rbx
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	jmp	fflush@PLT
.L161:
	.cfi_restore_state
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2062:
	.size	_Z10timer_stopP5timer, .-_Z10timer_stopP5timer
	.globl	_Z24how_many_warp_schedulersii
	.type	_Z24how_many_warp_schedulersii, @function
_Z24how_many_warp_schedulersii:
.LFB2064:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	sall	$4, %edi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	movabsq	$4294967312, %rax
	addl	%esi, %edi
	movq	%rsp, %rdx
	movq	$-1, 96(%rsp)
	movq	%rax, (%rsp)
	incq	%rax
	movq	%rax, 8(%rsp)
	incq	%rax
	movq	%rax, 16(%rsp)
	incq	%rax
	movq	%rax, 24(%rsp)
	movl	$268435457, %eax
	salq	$5, %rax
	movq	%rax, 32(%rsp)
	incq	%rax
	movq	%rax, 40(%rsp)
	movl	$1073741827, %eax
	salq	$4, %rax
	movq	%rax, 48(%rsp)
	addq	$2, %rax
	movq	%rax, 56(%rsp)
	addq	$3, %rax
	movq	%rax, 64(%rsp)
	addq	$2, %rax
	movq	%rax, 72(%rsp)
	addq	$25, %rax
	movq	%rax, 80(%rsp)
	addq	$2, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
.L168:
	cmpl	%edi, (%rdx,%rax,8)
	jne	.L166
	cltq
	movl	4(%rsp,%rax,8), %eax
	jmp	.L165
.L166:
	incq	%rax
	cmpq	$13, %rax
	jne	.L168
	xorl	%eax, %eax
.L165:
	movq	104(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L169
	call	__stack_chk_fail@PLT
.L169:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2064:
	.size	_Z24how_many_warp_schedulersii, .-_Z24how_many_warp_schedulersii
	.section	.rodata.str1.1
.LC20:
	.string	"cudaGetDeviceCount error: %s\n"
	.text
	.globl	_Z26how_many_concurrent_blocksv
	.type	_Z26how_many_concurrent_blocksv, @function
_Z26how_many_concurrent_blocksv:
.LFB2063:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	subq	$1056, %rsp
	.cfi_def_cfa_offset 1072
	movq	%fs:40, %rax
	movq	%rax, 1048(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rdi
	call	cudaGetDeviceCount@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	jne	.L173
	movl	12(%rsp), %ebx
	testl	%ebx, %ebx
	je	.L173
	decl	%ebx
	movl	%ebx, %edi
	call	cudaSetDevice@PLT
	leaq	16(%rsp), %rdi
	movl	%ebx, %esi
	call	cudaGetDeviceProperties_v2@PLT
	movl	380(%rsp), %esi
	movl	376(%rsp), %edi
	call	_Z24how_many_warp_schedulersii
	imull	404(%rsp), %eax
	jmp	.L172
.L173:
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC20(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	call	fflush@PLT
	xorl	%eax, %eax
.L172:
	movq	1048(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L175
	call	__stack_chk_fail@PLT
.L175:
	addq	$1056, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2063:
	.size	_Z26how_many_concurrent_blocksv, .-_Z26how_many_concurrent_blocksv
	.section	.rodata.str1.1
.LC21:
	.string	"Invalid input size (should be 2^i for i>0)\n"
.LC22:
	.string	"Invalid number of procs (should be 2^i for i>0)\n"
.LC23:
	.string	"Test mode (ignoring provided input size, if any)...\n"
.LC24:
	.string	"Unknown or missing arg %c\n"
.LC25:
	.string	"n:p:to"
.LC26:
	.string	"Missing option: -n\n"
.LC27:
	.string	"Missing option: -p\n"
.LC28:
	.string	"More processors than inputs!\n"
.LC29:
	.string	"Too many processors! (only %u concurrent blocks available)\n"
.LC30:
	.string	"Could not setup the transform from the cmdline args\n"
	.text
	.globl	_Z15setup_from_argsP2triPPc
	.type	_Z15setup_from_argsP2triPPc, @function
_Z15setup_from_argsP2triPPc:
.LFB2041:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	xorl	%eax, %eax
	leaq	.LC25(%rip), %r13
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rdi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 48
	movl	$18, %ecx
	rep stosl
.L206:
	movq	%r13, %rdx
	movq	%r12, %rsi
	movl	%ebp, %edi
	call	getopt@PLT
	cmpl	$-1, %eax
	je	.L211
	cmpl	$111, %eax
	je	.L182
	jg	.L183
	cmpl	$63, %eax
	je	.L184
	cmpl	$110, %eax
	je	.L185
	jmp	.L206
.L183:
	cmpl	$112, %eax
	je	.L187
	cmpl	$116, %eax
	jne	.L206
	leaq	.LC23(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
	movl	$8, (%rbx)
	movl	$1, 48(%rbx)
	jmp	.L206
.L185:
	movq	optarg(%rip), %rdi
	call	atoi@PLT
	movl	%eax, %edx
	cmpl	$1, %eax
	jg	.L189
.L191:
	leaq	.LC21(%rip), %rdx
	jmp	.L208
.L189:
	movl	%eax, %edi
	call	_Z15is_power_of_twoi
	testl	%eax, %eax
	je	.L191
	movl	%edx, (%rbx)
	jmp	.L206
.L187:
	movq	optarg(%rip), %rdi
	call	atoi@PLT
	movl	%eax, %edx
	testl	%eax, %eax
	jle	.L193
	movl	%eax, %edi
	call	_Z15is_power_of_twoi
	testl	%eax, %eax
	je	.L193
	movl	%edx, 4(%rbx)
	jmp	.L206
.L193:
	leaq	.LC22(%rip), %rdx
.L208:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
.L209:
	call	__fprintf_chk@PLT
.L210:
	movq	stderr(%rip), %rdi
	call	fflush@PLT
	call	_Z10show_usagev
	jmp	.L190
.L182:
	movl	$1, 52(%rbx)
	jmp	.L206
.L184:
	movl	optopt(%rip), %ecx
	movq	stderr(%rip), %rdi
	leaq	.LC24(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L210
.L211:
	movl	(%rbx), %eax
	testl	%eax, %eax
	jne	.L195
	movq	stderr(%rip), %rdi
	leaq	.LC26(%rip), %rdx
	movl	$2, %esi
	jmp	.L209
.L195:
	movl	4(%rbx), %ebx
	leaq	.LC27(%rip), %rdx
	testl	%ebx, %ebx
	je	.L208
	leaq	.LC28(%rip), %rdx
	cmpl	%ebx, %eax
	jb	.L208
	call	_Z26how_many_concurrent_blocksv
	movl	%eax, %edx
	xorl	%eax, %eax
	cmpl	%ebx, %edx
	jnb	.L180
	call	_Z26how_many_concurrent_blocksv
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC29(%rip), %rdx
	movl	%eax, %ecx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	call	fflush@PLT
.L190:
	movq	stderr(%rip), %rdi
	leaq	.LC30(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	call	fflush@PLT
	orl	$-1, %eax
.L180:
	popq	%rdx
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2041:
	.size	_Z15setup_from_argsP2triPPc, .-_Z15setup_from_argsP2triPPc
	.globl	_Z38__device_stub__Z16run_funnel_stageP2trP2tr
	.type	_Z38__device_stub__Z16run_funnel_stageP2trP2tr, @function
_Z38__device_stub__Z16run_funnel_stageP2trP2tr:
.LFB2089:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L212
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z16run_funnel_stageP2tr(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L212:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L214
	call	__stack_chk_fail@PLT
.L214:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2089:
	.size	_Z38__device_stub__Z16run_funnel_stageP2trP2tr, .-_Z38__device_stub__Z16run_funnel_stageP2trP2tr
	.globl	_Z16run_funnel_stageP2tr
	.type	_Z16run_funnel_stageP2tr, @function
_Z16run_funnel_stageP2tr:
.LFB2090:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z16run_funnel_stageP2trP2tr
	.cfi_endproc
.LFE2090:
	.size	_Z16run_funnel_stageP2tr, .-_Z16run_funnel_stageP2tr
	.globl	_Z36__device_stub__Z14run_tube_stageP2trP2tr
	.type	_Z36__device_stub__Z14run_tube_stageP2trP2tr, @function
_Z36__device_stub__Z14run_tube_stageP2trP2tr:
.LFB2091:
	.cfi_startproc
	endbr64
	subq	$104, %rsp
	.cfi_def_cfa_offset 112
	movq	%rdi, 8(%rsp)
	leaq	24(%rsp), %rcx
	leaq	16(%rsp), %rdx
	leaq	44(%rsp), %rsi
	leaq	32(%rsp), %rdi
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L217
	pushq	24(%rsp)
	.cfi_def_cfa_offset 120
	leaq	_Z14run_tube_stageP2tr(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 128
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 120
	popq	%rdx
	.cfi_def_cfa_offset 112
.L217:
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L219
	call	__stack_chk_fail@PLT
.L219:
	addq	$104, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2091:
	.size	_Z36__device_stub__Z14run_tube_stageP2trP2tr, .-_Z36__device_stub__Z14run_tube_stageP2trP2tr
	.globl	_Z14run_tube_stageP2tr
	.type	_Z14run_tube_stageP2tr, @function
_Z14run_tube_stageP2tr:
.LFB2092:
	.cfi_startproc
	endbr64
	jmp	_Z36__device_stub__Z14run_tube_stageP2trP2tr
	.cfi_endproc
.LFE2092:
	.size	_Z14run_tube_stageP2tr, .-_Z14run_tube_stageP2tr
	.section	.rodata.str1.1
.LC31:
	.string	"Could not run the transform\n"
.LC32:
	.string	"n\tp\ttime (total)\ttime (stage 1)\ttime (stage 2)\n"
.LC33:
	.string	"%u\t%u\t%f\t%f\t%f\n"
	.text
	.globl	_Z3runP2tr
	.type	_Z3runP2tr, @function
_Z3runP2tr:
.LFB2045:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	call	_Z15initialize_dataP2tr
	testl	%eax, %eax
	je	.L223
	movq	%rbx, %rdi
	orl	$-1, %r12d
	call	_Z12cleanup_dataP2tr
	movq	stderr(%rip), %rdi
	leaq	.LC31(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	call	fflush@PLT
	jmp	.L222
.L223:
	leaq	24(%rsp), %rbp
	movl	%eax, %r12d
	movq	%rbp, %rdi
	call	_Z11timer_startP5timer
	movl	4(%rbx), %eax
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rdx
	movl	$1, %ecx
	movl	$1, 56(%rsp)
	movq	%rdx, 16(%rsp)
	movl	20(%rsp), %esi
	movl	%eax, 12(%rsp)
	movq	12(%rsp), %rdi
	movq	%rdx, 48(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L225
	movq	64(%rbx), %rdi
	call	_Z38__device_stub__Z16run_funnel_stageP2trP2tr
.L225:
	movq	%rbp, %rdi
	leaq	48(%rsp), %rbp
	call	_Z10timer_stopP5timer
	movq	%rbp, %rdi
	call	_Z11timer_startP5timer
	movl	4(%rbx), %eax
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rdx
	movl	$1, %ecx
	movl	$1, 20(%rsp)
	movq	%rdx, 4(%rsp)
	movl	8(%rsp), %esi
	movl	%eax, (%rsp)
	movq	(%rsp), %rdi
	movq	%rdx, 12(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L226
	movq	64(%rbx), %rdi
	call	_Z36__device_stub__Z14run_tube_stageP2trP2tr
.L226:
	movq	%rbp, %rdi
	call	_Z10timer_stopP5timer
	cmpl	$0, 48(%rbx)
	jne	.L227
	cmpl	$0, 52(%rbx)
	jne	.L228
	movl	$2, %edi
	leaq	.LC32(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
.L228:
	movss	64(%rsp), %xmm2
	movl	4(%rbx), %ecx
	movl	$2, %edi
	movb	$3, %al
	movss	40(%rsp), %xmm1
	movl	(%rbx), %edx
	leaq	.LC33(%rip), %rsi
	movaps	%xmm2, %xmm0
	cvtss2sd	%xmm2, %xmm2
	addss	%xmm1, %xmm0
	cvtss2sd	%xmm1, %xmm1
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movq	stdout(%rip), %rdi
	call	fflush@PLT
	jmp	.L229
.L227:
	movl	4(%rbx), %edx
	movq	56(%rbx), %rdi
	movl	$2, %ecx
	movq	64(%rbx), %rsi
	imulq	$72, %rdx, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L230
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC14(%rip), %rdx
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	call	fflush@PLT
.L230:
	xorl	%esi, %esi
	leaq	.LC14(%rip), %r13
.L231:
	movl	4(%rbx), %ecx
	movl	%esi, 8(%rbx)
	cmpl	%ecx, %esi
	jnb	.L244
	movl	(%rbx), %eax
	xorl	%edx, %edx
	divl	%ecx
	imull	%esi, %eax
	movl	%eax, %ebp
.L232:
	movl	(%rbx), %edi
	xorl	%edx, %edx
	movl	8(%rbx), %ecx
	movl	%edi, %eax
	leal	1(%rcx), %esi
	divl	4(%rbx)
	imull	%esi, %eax
	cmpl	%eax, %ebp
	jnb	.L231
	imulq	$72, %rcx, %rcx
	addq	56(%rbx), %rcx
	movl	%ebp, %eax
	movq	24(%rbx), %r15
	movq	32(%rcx), %rdx
	leaq	(%rdx,%rax,8), %r14
	call	_Z5ilog2j
	movl	%ebp, %edi
	movl	%eax, %esi
	call	_Z11bit_reversejj
	movl	$2, %ecx
	movl	$8, %edx
	movq	%r14, %rsi
	movl	%eax, %eax
	leaq	(%r15,%rax,8), %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %edi
	testl	%eax, %eax
	je	.L233
	call	cudaGetErrorString@PLT
	movq	stderr(%rip), %rdi
	movq	%r13, %rdx
	movl	$2, %esi
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	call	fflush@PLT
.L233:
	incl	%ebp
	jmp	.L232
.L244:
	movq	%rbx, %rdi
	call	_Z12print_outputP2tr
	movq	%rbx, %rdi
	call	_Z14verify_resultsP2tr
.L229:
	movq	%rbx, %rdi
	call	_Z12cleanup_dataP2tr
.L222:
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L236
	call	__stack_chk_fail@PLT
.L236:
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	movl	%r12d, %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
.LFE2045:
	.size	_Z3runP2tr, .-_Z3runP2tr
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2040:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rsi, %rdx
	movl	%edi, %esi
	subq	$80, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	movq	%rsp, %rbx
	movq	%rbx, %rdi
	call	_Z15setup_from_argsP2triPPc
	testl	%eax, %eax
	je	.L246
.L247:
	movl	$1, %edi
	jmp	.L250
.L246:
	movq	%rbx, %rdi
	call	_Z3runP2tr
	testl	%eax, %eax
	jne	.L247
	xorl	%edi, %edi
.L250:
	call	exit@PLT
	.cfi_endproc
.LFE2040:
	.size	main, .-main
	.section	.rodata.str1.1
.LC34:
	.string	"_Z14run_tube_stageP2tr"
.LC35:
	.string	"_Z16run_funnel_stageP2tr"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2094:
	.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	.LC34(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z14run_tube_stageP2tr(%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	.LC35(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z16run_funnel_stageP2tr(%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
.LFE2094:
	.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.cst4,"aM",@progbits,4
	.align 4
.LC9:
	.long	1082130432
	.align 4
.LC11:
	.long	-1065353216
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC15:
	.long	-4194304
	.long	1104150527
	.align 8
.LC16:
	.long	0
	.long	1072693248
	.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:

// CS 87 - Final Project
// Maria-Elena Solano
//
// Radix-2 Cooley-Tukey Fourier Transform on C^n - parallel 'pi' CUDA version
//

#include <stdio.h>                     // C's standard I/O library
#include <stdlib.h>                    // C's standard library
#include <stdint.h>                    // C's exact width int types
#include <string.h>                    // C's standard string library
#include <time.h>                      // C's time types (for random init)
#include <unistd.h>                    // C's POSIX API
#include <hip/hip_runtime.h>                      // CUDA runtime API


// macro/constant definitions
#define perror_out(X)                  perror(X), fflush(stderr)
#define stderr_out(...)                fprintf(stderr, __VA_ARGS__), \
                                        fflush(stderr)
#define print_out(...)                 printf(__VA_ARGS__), fflush(stdout)
#define cuda_try(X)                    ((X) != hipSuccess)
#define cuda_malloc(X, Y)              hipMalloc((void**)(X), (Y))
#define cuda_memcpy_todev(X, Y, Z)     hipMemcpy((X), (Y), (Z), \
                                        hipMemcpyHostToDevice)
#define cuda_memcpy_tohost(X, Y, Z)    hipMemcpy((X), (Y), (Z), \
                                        hipMemcpyDeviceToHost)
                                        

// data structures
// unit data type
typedef struct complex{                
  float re;                            // real part
  float im;                            // imaginary part
} data_t;

// simple struct to hold transform info
typedef struct tr tr_t;
typedef struct tr{ 
  uint32_t  N;                         // input size
  uint32_t  P;                         // number of processors
  uint32_t  Pi;                        // processor ID
  data_t*   in;                        // input data,
  data_t*   out;                       // output,
  data_t*   tmp_in;                    // input scratchpad,
  data_t*   tmp_out;                   // output scratchpads, and
  uint32_t  test_mode;                 // test mode?
  uint32_t  no_header;                 // no timing headers?
  tr_t*     trs;                       // array of tr_t objects in host,
  tr_t*     trs_dev;                   // and device.
} tr_t;

// simple encapsulating struct for timing
typedef struct timer{
  hipEvent_t start, stop;             // start and stop events
  float  elapsed;                      // elapsed time (if any), in millisecs
} tmr_t;

// simple helper container (used in how_many_warp_schedulers)
typedef struct sm_to_ws{
  int sm;
  int ws;
} sm_to_ws_t;


// function declarations
// setting up the transform
int  setup_from_args (tr_t* t, int argc, char** argv);
void show_usage      ();

// running the transform
int   run             (tr_t* t);
int   initialize_data (tr_t* t);
void  cleanup_data    (tr_t* t);

__global__ void run_funnel_stage(tr_t* t);
__global__ void run_tube_stage  (tr_t* t);
__device__ void butterfly     (data_t* out, data_t* in, 
                               uint32_t size, uint32_t N);
__device__ void butterfly_half(data_t* out, data_t* in, 
                               uint32_t size, uint32_t N, uint32_t which_half);

// complex arithmetic
__device__ data_t add  (data_t a, data_t b);
__device__ data_t sub  (data_t a, data_t b);
__device__ data_t mul  (data_t a, data_t b);
__device__ data_t omega(uint32_t N, uint32_t k);
__device__ data_t convex_comb(data_t a, data_t b, uint32_t alpha);

// printing and verifying
void print_input     (tr_t* t);
void print_output    (tr_t* t);
void verify_results  (tr_t* t);

// timing
void timer_start(tmr_t* tm);
void timer_stop (tmr_t* tm);

// misc
__device__ __host__ uint32_t ilog2 (uint32_t x);
__device__   void swap_scratchpads (tr_t* t);
int      is_power_of_two           (int x);
uint32_t hash                      (uint32_t x);
uint32_t bit_reverse               (uint32_t x, uint32_t N);
uint32_t how_many_concurrent_blocks();
int      how_many_warp_schedulers  (int arch_major_ver, int arch_minor_ver);


int main(int argc, char** argv){
  tr_t t;                              // main transform object

  // (1) setup the transform from the command line args (or ret -1 if err)
  if(setup_from_args(&t, argc, argv)){
    exit(EXIT_FAILURE);
  }

  // (2) run the transform according to the given args (or ret -1 if err)
  if(run(&t)){
    exit(EXIT_FAILURE);    
  }

  // (3) return
  exit(EXIT_SUCCESS);
}


// This function parses the provided command line args into the given transform
// object, and initializes it accordingly. Returns 0 if success, or -1 if err).
//
//   t:                      (ptr to) tr_t object to update
//   argc:                   number of command line arguments
//   argv:                   array of strings containing the command line args
//
//   returns:                0 if success, or -1 if invalid command line args.
// 
int setup_from_args(tr_t* t, int argc, char** argv){
  int ret;                                  // return value from getopt, and
  int num = 0;                              // number to be retrieved.

  // First, zero all the entries of the tr_t (so we can tell whether or not
  // the entries were filled afterwards simply by checking if they're still 0)
  memset(t, 0, sizeof(tr_t));

  // Then, greedily read all the command line options provided.
  while((ret = getopt(argc, argv, "n:p:to")) != -1){
    switch(ret){
      // If option -n, grab the arg, which should be a nonnegative power of 2
      // (otherwise return -1 err)
      case 'n':{
        if(!(num = atoi(optarg)) || !(num > 1) || !is_power_of_two(num)){
          stderr_out("Invalid input size (should be 2^i for i>0)\n");
          show_usage(); 
          goto err;
        }
        t->N = num;
        break;
      }
      // If option -p, grab the arg, which should be 1 or a nonneg power of 2
      // (otherwise return -1 err)
      case 'p':{
        if(!(num = atoi(optarg)) || !(num > 0) || !is_power_of_two(num)){
          stderr_out("Invalid number of procs (should be 2^i for i>0)\n");
          show_usage();
          goto err;
        }
        t->P = num;
        break;
      }
      // If option -o, set t.no_header to 1.
      case 'o':{
        t->no_header = 1;
        break;
      }
      // If option -t, set t.N to 8 and t.test_mode to 'true', and notify user.
      case 't':{
        print_out("Test mode (ignoring provided input size, if any)...\n");
        t->N = 8;
        t->test_mode = 1;
        break;
      }
      // if unknown or missing arg, show usage and return -1 (error)
      case '?':{
        stderr_out("Unknown or missing arg %c\n", optopt);
        show_usage();
        goto err;
      }
    }
  }

  // Finally, validate the options
  // If the -n option is missing, notify the user, show usage, and return -1.
  if(!t->N){
    stderr_out("Missing option: -n\n");
    show_usage();
    goto err;
  }
  // If the -p option is missing, notify the user, show usage, and return -1.
  if(!t->P){
    stderr_out("Missing option: -p\n");
    show_usage();
    goto err;
  }
  // If more processors than inputs, return -1.
  if(t->P > t->N){
    stderr_out("More processors than inputs!\n");
    show_usage();
    goto err;
  }
  // If more processors than available, return -1.
  if(t->P > how_many_concurrent_blocks()){
    stderr_out("Too many processors! (only %u concurrent blocks available)\n",
               how_many_concurrent_blocks());
    goto err;
  }

  return 0;

err:
  stderr_out("Could not setup the transform from the cmdline args\n");
  return -1;
}

// This function initializes the given transform's data. Returns 0 if success 
// or -1 if err.
//
//   t:                      (ptr to) tr_t object to update
//
//   returns:                0 if success, or -1 if error.
// 
int initialize_data(tr_t* t){
  uint32_t bit;
  hipError_t ret;                          // return value of CUDA calls

  // We need:
  // - N entries for the input,
  if((t->in = (data_t*)malloc(sizeof(data_t)*t->N)) == NULL){
    perror_out("malloc error");
    goto err;
  }
  // - N entries for the output, and
  if((t->out = (data_t*)malloc(sizeof(data_t)*t->N)) == NULL){
    perror_out("malloc error");
    goto err;
  }
  // - P tr_t objects (one for each block) (on both the host and the device),
  if((t->trs = (tr_t*)malloc(sizeof(tr_t)*t->P)) == NULL){
    perror_out("malloc error");
    goto err;
  }
  if(cuda_try(ret = cuda_malloc(&t->trs_dev, sizeof(tr_t)*t->P))){
    stderr_out("hipMalloc error: %s\n", hipGetErrorString(ret));
    goto err;
  }
  // - And, for each processor,
  for(t->Pi = 0; t->Pi < t->P; t->Pi++){
    
    // (Initialize their respective tr_t objects first)
    t->trs[t->Pi] = *t;

    // An input scratchpad of size N, and
    if(cuda_try(ret = cuda_malloc(&t->trs[t->Pi].tmp_in, 
                                  sizeof(data_t)*t->N))){
      stderr_out("hipMalloc error: %s\n", hipGetErrorString(ret));
      goto err;
    }

    // An output scratchpad of size N.
    if(cuda_try(ret = cuda_malloc(&t->trs[t->Pi].tmp_out, 
                                  sizeof(data_t)*t->N))){
      stderr_out("hipMalloc error: %s\n", hipGetErrorString(ret));
      goto err;
    }

    // (Making sure to copy the updated tr_t to the device's memory too)
    if(cuda_try(ret = cuda_memcpy_todev(t->trs_dev + t->Pi, 
                                        t->trs     + t->Pi,
                                        sizeof(tr_t)))){
      stderr_out("hipMemcpy error: %s\n", hipGetErrorString(ret));
      goto err;
    }

  }

  
  // Initialize the input with Bernoulli deviates from the L2 unit circle
  // --i.e. each element drawn from the distribution 1/sqrt{N}*[-1,1].
  if(!t->test_mode){
    for(srand(hash(time(NULL))), bit = 0; bit < t->N; bit++){
      t->in[bit].re = (rand()/(RAND_MAX/2.0)-1.0)/sqrt(t->N);
      t->in[bit].im = (rand()/(RAND_MAX/2.0)-1.0)/sqrt(t->N);
    }
  }
  // (unless in debug mode, in which case the values are always the same
  //  test case: 0,1,0,1,0,1,0,1 (the output should be 4,0,0,0,-4,0,0,0))
  else{
    t->in[0].re = 0; t->in[0].im = 0;
    t->in[1].re = 1; t->in[1].im = 0;
    t->in[2].re = 0; t->in[2].im = 0;
    t->in[3].re = 1; t->in[3].im = 0;
    t->in[4].re = 0; t->in[4].im = 0;
    t->in[5].re = 1; t->in[5].im = 0;
    t->in[6].re = 0; t->in[6].im = 0;
    t->in[7].re = 1; t->in[7].im = 0;
    print_input(t);
  }

  // - And copy the input to the input scratchpad of each block (of size N).
  for(t->Pi = 0; t->Pi < t->P; t->Pi++){
    if(cuda_try(ret = cuda_memcpy_todev(t->trs[t->Pi].tmp_in,
                                        t->in, sizeof(data_t)*t->N))){
      stderr_out("hipMemcpy error: %s\n", hipGetErrorString(ret));
      goto err;
    }
  }

  // And return
  return 0;

err:
  stderr_out("Could not initialize the data\n");
  return -1;
}

// This function frees all the data allocated by the given transform. 
//
//   t:                      (ptr to) tr_t object to update
// 
void cleanup_data(tr_t* t){
  hipError_t ret;                          // return value of CUDA calls

  // Free all the allocated data (if any)
  if(t->in  != NULL){ free(t->in);   t->in  = NULL; }
  if(t->out != NULL){ free(t->out);  t->out = NULL; }
  if(t->trs != NULL){ 
    for(t->Pi = 0; t->Pi < t->P; t->Pi++){
      if(t->trs[t->Pi].tmp_in != NULL && 
         cuda_try(ret = hipFree(t->trs[t->Pi].tmp_in))){
        stderr_out("hipFree error: %s\n", hipGetErrorString(ret)); };
      if(t->trs[t->Pi].tmp_out != NULL && 
         cuda_try(ret = hipFree(t->trs[t->Pi].tmp_out))){
        stderr_out("hipFree error: %s\n", hipGetErrorString(ret)); };
    }  
    free(t->trs);  t->trs = NULL; 
  }
  if(t->trs_dev != NULL && cuda_try(ret = hipFree(t->trs_dev))){
    stderr_out("hipFree error: %s\n", hipGetErrorString(ret)); 
  }

  return;
}

// This function shows the cmdline interface usage.
// 
void show_usage(){
  print_out("\nusage:\n"
            "  fourier-parallel-pi-gpu-cuda { -n <n> -p <p> [-o] | -t }\n"
            "\noptions:\n"
            "  -n <n>     power of two input size\n"
            "  -p <p>     power of two number of processors (less than n)\n"
            "  -o         omit timing headers\n"
            "  -t         compare against precomputed input/output\n"
            "\n");
}


// This function runs the given transform on P separate processors. Returns 0
// if success or -1 if err.
//
//   t:                      (ptr to) tr_t object to update
//
//   returns:                0 if success, or -1 if error.
// 
int run(tr_t* t){
  tmr_t       tm_funnel, tm_tube;           // tmr_t objects (for timing)
  hipError_t ret;                          // return value of CUDA calls
  uint32_t    bit;

  // Initialize the data (or ret -1 err, cleaning up any malloc'd data first)
  if(initialize_data(t)){
    cleanup_data(t);
    goto err;
  }

  // Run the 1st (aka 'funnel') stage on P blocks, 1 thread per block.
  timer_start(&tm_funnel);
  run_funnel_stage<<<t->P, 1>>>(t->trs_dev);
  timer_stop(&tm_funnel);

  // Run the 2nd (aka 'tube') stage on P blocks, 1 thread per block.
  timer_start(&tm_tube);
  run_tube_stage<<<t->P, 1>>>(t->trs_dev);
  timer_stop(&tm_tube);

  // If not in test mode, show elapsed times (total, tree and cylinder stages)
  if(!t->test_mode){
    if(!t->no_header){ 
      print_out("n\tp\ttime (total)\t"
                "time (stage 1)\ttime (stage 2)\n"); };
    print_out("%u\t%u\t%f\t%f\t%f\n", 
              t->N, t->P, tm_funnel.elapsed + tm_tube.elapsed, 
              tm_funnel.elapsed, tm_tube.elapsed);
  }
  // Otherwise, copy the result from the _assigned segment_ (of size N/P) of
  // the input scratchpad of each processor (which will contain the new results
  // at this point) of each processor to the output, in bit-reversed order.
  //
  // Then print the output, and verify the results.
  else{
    // Update the host's tr_t array first
    if(cuda_try(ret = cuda_memcpy_tohost(
        t->trs, t->trs_dev, sizeof(tr_t)*t->P))){
      stderr_out("hipMemcpy error: %s\n", hipGetErrorString(ret));
    }
    for(t->Pi = 0; t->Pi < t->P; t->Pi++){
      for(bit = (t->N/t->P)*t->Pi; bit < (t->N/t->P)*t->Pi+t->N/t->P; bit++){
        if(cuda_try(ret = cuda_memcpy_tohost(
            t->out + bit_reverse(bit, ilog2(t->N)),   // position in output,
            t->trs[t->Pi].tmp_in + bit,               // Pi-th scratchpad.
            sizeof(data_t)))){
          stderr_out("hipMemcpy error: %s\n", hipGetErrorString(ret));
        }
      }
    }
    print_output(t);
    verify_results(t);
  }

  // Cleanup the data, and return
  cleanup_data(t);
  return 0;

err:
  stderr_out("Could not run the transform\n");
  return -1;
}

// This function runs the first stage of the transform in the GPU.
//
//   t_ptr:                  (ptr to) tr_t object to use
//
//   returns:                NULL always.
// 
__global__ void run_funnel_stage(tr_t* trs){
  uint32_t size, iter, offset;              // butterfly size, offset and iter,
  uint32_t which_butterfly, which_half;     // which butterfly, and which half,
  tr_t* t = trs + blockIdx.x;               // local, unpacked tr_t object

  // For the first log P iters
  // (i.e. butterfly sizes N,     N/2,       ..., 2(N/P),
  //       iteration stage log P, log P - 1, ..., 1),
  for(size = t->N, iter = ilog2(t->P); size > t->N/t->P; size /= 2, iter--){

  	// Determine _which_ butterfly to compute, depending on (Pi >> iter)
  	which_butterfly = (t->Pi >> iter);

    // Determine _which_ segment_ of size 'size' to compute the butterfly upon
    offset = which_butterfly * size;

    // Determine _which half_, depending on the parity of the 1st, 2nd, ...
    // most significant bit of Pi.
    which_half = ((t->Pi >> (iter - 1)) % 2 == 0);

    // And compute the butterfly accordingly
    butterfly_half(
      t->tmp_out + offset,        // output to the _1st_ half of the scratchpad
      t->tmp_in  + offset,        // and reading from the input scratchpad.
      size, t->N, which_half);

    // And swap scratchpads, so that the new results become the input for
    // the next iteration.
    swap_scratchpads(t);
  }

}

// This function runs the second stage of the transform in the GPU.
//
//   t_ptr:                  (ptr to) tr_t object to use
//
//   returns:                NULL always.
// 
__global__ void run_tube_stage(tr_t* trs){
  uint32_t size, offset;                    // butterfly size and offset
  tr_t* t = trs + blockIdx.x;               // local tr_t object

  // For the last log N/P iters
  // (i.e. butterfly sizes N/P, (N/P)/2, ..., 2), 
  // we work only on the portion of the output assigned to this processor
  for(size = t->N/t->P; size > 1; size /= 2){

    // Compute 1, 2, ..., (N/P)/2 butterflies of size N/P, (N/P)/2, ..., 2 
    // over _consecutive_ intervals across the assigned segment (of size N/P),
    // (which recall starts from (t.N/t.P)).
    for(offset = (t->N/t->P)*t->Pi; 
        offset < (t->N/t->P)*t->Pi + t->N/t->P; 
        offset += size){
      
      butterfly(
        t->tmp_out + offset,       // output to the _assigned_ segment,
        t->tmp_in  + offset,       // and reading from the _assigned_ segment.
        size, t->N);
    }

    // And swap scratchpads, so that the new results become the input for
    // the next iteration.
    swap_scratchpads(t);
  }
}


// This function computes an n-point butterfly over the given input array,
// placing the results on the given output array.
//
//   out,in:                 output and input arrays
//   size:                   size of the butterfly
//   N:                      input size of the broader FFT
//
__device__ void butterfly(data_t* out, data_t* in, uint32_t size, uint32_t N){

  // Compute the left butterfly (note it only writes on the _1st_ half of out)
  butterfly_half(out, in, size, N, 1);

  // And the right butterfly (note it only writes on the _2nd_ half of out)
  butterfly_half(out, in, size, N, 0);

  return;
}

// This function computes either half of an n-point butterfly. Note it only
// writes to either the _first_ half of the output (if left butterfly), or the
// _second_ half of the output (if right butterfly).
//
//   out,in:                 output and input arrays
//   size:                   size of the butterfly
//   N:                      input size of the broader FFT
//   which_half:             which half to compute?
//
__device__ void butterfly_half(data_t* out, data_t* in, 
                               uint32_t size, uint32_t N, uint32_t which_half){
  uint32_t bit;
      
  // For each bit in the segment
  for(out += !which_half*(size/2), bit = 0; bit < size/2; bit++){
    out[bit] =                              //  set the current (output) bit to
      convex_comb(                          //   either:
        add(                                //    the sum of
          in[bit],                          //     the current (input) bit, and
          in[bit+size/2]),                  //     the (size/2)-next one,
        mul(                                //    or the multiplication of
          sub(                              //     the sum of the
            in[bit],                        //      the (stride)-prev bit, and
            in[bit+size/2]),                //      the next one
          omega(N,                          //     times the Nth root of unity,
                bit*(N/size))),             //      to the power of 0,1,2 first
        which_half);                        //     0,2,4 second, etc.
  }

  return;
}

// This function returns (by value) the sum of the two given complex numbers.
//
//   a,b:                    operands (x+yi,z+wi) (of type data_t)
//
//   returns:                the sum a+b = (x+z)+(y+w)i
// 
__device__ data_t add(data_t a, data_t b){
  data_t c;

  c.re = a.re + b.re;
  c.im = a.im + b.im;

  return c;
}

// This function returns (by value) the sum a+(-b) of the given complex nums.
//
// (Note: this can be overriden to provide support for more general transforms
//        on arbitrary fields)
//
//   a,b:                    operands (x+yi,z+wi) (of type data_t)
//
//   returns:                the sum a+(-b) = (x-z)+(y-w)i
// 
__device__ data_t sub(data_t a, data_t b){
  data_t c;

  c.re = a.re - b.re;
  c.im = a.im - b.im;

  return c;
}

// This function returns (by value) the mult a*b of the given complex numbers.
//
// (Note: this can be overriden to provide support for more general transforms
//        on arbitrary fields)
//
//   a,b:                    operands (x+yi,z+wi) (of type data_t)
//
//   returns:                their mult a*b = (xz-yw) + (xw-yz)i
// 
__device__ data_t mul(data_t a, data_t b){
  data_t c;

  c.re = a.re*b.re - a.im*b.im;
  c.im = a.re*b.im + a.im*b.re;

  return c;
}

// This function returns (by value) the primitive N-th root of unity of the
// complex field \mathbb{C} the power of k, which is given by
//
//   e^{-2\pi k/N} = (cos 2\pi/N - i sin 2\pi/N)^k   (by Euler's formula)
//                 = cos 2\pi/N*k - i sin 2\pi/N*k   (by De Moivre's formula)
//
// (Note: this can be overriden to provide support for more general transforms
//        on arbitrary fields)
//
//   N:                      Order of the cyclic group.
//   k:                      Power to raise the root of unity to.
//
//   returns:                N-th primitive root of unity of \mathbb{C}, raised
//                           to the power of k.
// 
__device__ data_t omega(uint32_t N, uint32_t k){
  data_t o;

  o.re =  __cosf(2.0f*3.141592f/N*k);
  o.im = -__sinf(2.0f*3.141592f/N*k);

  return o;
}

// This function returns (by value) the 'convex combination' of a and b, para-
// meterized by the scalar alpha.
//
// (Note: this can be overriden to provide support for more general transforms
//        on arbitrary fields)
//
//   a,b:                    Operands
//   alpha:                  Alpha (between 0 and 1)
//
//   returns:                alpha*a + (1-alpha)*b
// 
__device__ data_t convex_comb(data_t a, data_t b, uint32_t alpha){
  data_t o;

  o.re = alpha*a.re + (1U-alpha)*b.re;
  o.im = alpha*a.im + (1U-alpha)*b.im;

  return o;
}



// This function prints out the input of the transform.
//
//   t:                      (ptr to) tr_t object to use.
//
void print_input(tr_t* t){
  uint32_t bit;                             // entry to print out

  for(print_out("Input:\n"), bit = 0; bit < t->N; bit++){
    print_out("%.1f+%.1fi, ", t->in[bit].re, t->in[bit].im);
  }
  print_out("\n");

  return;
}

// This function prints out the output of the transform.
//
//   t:                      (ptr to) tr_t object to use.
//
void print_output(tr_t* t){
  uint32_t bit;                             // entry to print out

  for(print_out("Output:\n"), bit = 0; bit < t->N; bit++){
    print_out("%.1f+%.1fi, ", t->out[bit].re, t->out[bit].im);
  }
  print_out("\n");

  return;
}

// This function verifies that the output of the transform is correct.
//
//   t:                      (ptr to) tr_t object to use.
//
void verify_results(tr_t* t){

  // since the input is 0,1,0,1,0,1,0,1; the output should be 4,0,0,0,-4,0,0,0.
  print_out(
    (t->out[0].re == 4 && t->out[0].im == 0 &&
     t->out[1].re == 0 && t->out[1].im == 0 &&
     t->out[2].re == 0 && t->out[2].im == 0 &&
     t->out[3].re == 0 && t->out[3].im == 0 &&
     t->out[4].re ==-4 && t->out[4].im == 0 &&
     t->out[5].re == 0 && t->out[5].im == 0 &&
     t->out[6].re == 0 && t->out[6].im == 0 &&
     t->out[7].re == 0 && t->out[7].im == 0)
    ? "Output is correct. Test passed.\n\n" 
    : "Output is incorrect! Test failed.\n\n");

  return;
}


// This function swaps the input and output scratchpads of the given tr_t obj.
//
//   t:                      (ptr to) tr_t object to use.
//
__device__ void swap_scratchpads(tr_t* t){
  data_t* temp;

  temp       = t->tmp_in;  
  t->tmp_in  = t->tmp_out;  
  t->tmp_out = temp;

  return;
}

// This function determines whether or not the given number is a non-negative
// power of two.
//
// From: www.graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
//
//   x:                      value to query.
//
//   returns:                0 if _not_ a non-negative power of 2, 1 otherwise.
// 
int is_power_of_two(int x){
  return x && !(x & (x - 1));
}

// This function computes a hash of the given uint32 number.
// (From http://www.concentric.net/~ttwang/tech/inthash.htm)
//
//   x:                      number to hash.
//
//   returns:                uint32 hash of the given number.
// 
uint32_t hash(uint32_t x){
  x = (x + 0x7ed55d16U) + (x << 12);  x = (x ^ 0xc761c23cU) ^ (x >> 19);
  x = (x + 0x165667b1U) + (x << 5);   x = (x + 0xd3a2646cU) ^ (x << 9);
  x = (x + 0xfd7046c5U) + (x << 3);   x = (x ^ 0xb55a4f09U) ^ (x >> 16);
  return x;
}

// This function computes the log2 of the given uint32_t number.
//
// From: graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn
//
//   x:                      value to compute.
//
//   returns:                log2(x)
// 
__host__ __device__ uint32_t ilog2(uint32_t x){  
  int lookup_table[32] = {
     0,  1, 28,  2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17,  4, 8, 
    31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18,  6, 11,  5, 10, 9 };

  return lookup_table[(uint32_t)(x*0x077CB531U) >> 27];
}


// This function bit-reverses the given index (represented as a m-bit binary 
// number), and returns the resulting value as an integer.
// 
// This is used in the final step of the FFT: due to the recursive nature of
// the factorization, the butterfly's outputs are always in bit-reversed order
// (when represented as log(N)-bit numbers, where N is the input size). So for
// instance for a butterfly of size 8, the 1st output of the butterfly actually
// maps to the 1 -> 001 -> 100 -> 4th output of the array; while the 3rd output
// of the butterfly maps to the 3 -> 011 -> 110 -> 6th output of the array; and
// so forth.
//
// The algorithm below comes from:
//
//  Dietz, H. (2002) The Aggregate Magic Algorithms. University of Kentucky.
//   http://aggregate.org/MAGIC/#Bit%20Reversal
//
// which decomposes the (m m-1 ... 1) permutation into log m cycles: first swap
// all adjacent bits, then swap every two bits, and so forth.
// 
// Note, however, Dietz' particular algorithm is hard-wired to m=32-bits only:
// so in the example above, 3 is not mapped to 110 but to 1100 0000 0000 0000 
// 0000 0000 0000 0000; so, at the end, I just right-shift the result by 32-m 
// bits to obtain the desired value (in this case, 110 -> 6).
// 
//   x:                      Index to bit-reverse.
//   m:                      How many bits to use when representing the index.
//
//   returns:                Bit-reversed integer value of x, when represented
//                           as a m-bit binary number.
// 
uint32_t bit_reverse(uint32_t x, uint32_t m){
  x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
  x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
  x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4));
  x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8));

  return ((x >> 16) | (x << 16)) >> (32-m);
}

// This function starts the given tmr_t object.
//
//   timer:                  (pointer to) tmr_t object to start.
//
//  (From: http://stackoverflow.com/questions/7876624/timing-cuda-operations)
//
void timer_start(tmr_t* tm){
  hipError_t ret;                          // return value of CUDA calls

  if(cuda_try(ret = hipEventCreate(&tm->start))  ||
     cuda_try(ret = hipEventCreate(&tm->stop))   ||
     cuda_try(ret = hipEventRecord( tm->start, 0))){
    stderr_out("cudaEventCreate|Record error: %s\n", hipGetErrorString(ret));
  }
}

// This function stops the given tmr_t object, annd calculates the elapsed
// time since the call last to start_timer.
//
//   timer:                  (pointer to) tmr_t object to stop.
//
//  (From: http://stackoverflow.com/questions/7876624/timing-cuda-operations)
//
void timer_stop(tmr_t* tm){
  hipError_t ret;                          // return value of CUDA calls

  if(cuda_try(ret = hipEventRecord     ( tm->stop, 0))  ||
     cuda_try(ret = hipEventSynchronize( tm->stop))     ||
     cuda_try(ret = hipEventElapsedTime(&tm->elapsed, tm->start, tm->stop))){
    stderr_out("cudaEventRecord|Synchronize|ElapsedTime error: %s\n", 
      hipGetErrorString(ret));
  }
}

// This function returns the number of concurrent blocks in the GPU.
//
//   returns:                Number of concurrent blocks in the GPU (if any)
//
uint32_t how_many_concurrent_blocks(){
  hipError_t ret;                     // return value of CUDA calls
  int dev, devs;                       // number of devices
  hipDeviceProp_t pr;                   // device properties
  uint32_t p;                          // number of concurrent blocks

  // Count how many devices are there. If err or no devices, set p=0 and print.
  if(cuda_try(ret = hipGetDeviceCount(&devs)) || devs == 0){
    stderr_out("hipGetDeviceCount error: %s\n", hipGetErrorString(ret));
    return 0;
  }

  // Get the device properties of the last device
  dev = devs - 1;
  hipSetDevice(dev);
  hipGetDeviceProperties(&pr, dev);

  // Compute the number of concurrent blocks according to the formula 
  //
  //   # of SMs x # of warp schedulers per SM
  //
  p = pr.multiProcessorCount * how_many_warp_schedulers(pr.major,pr.minor);

  return p;
}

// This function determines how many warp schedulers per SM are there in the
// GPU given ts major and minor architectural version.
// 
// Adapted from helper_cuda.h in the CUDA SDK:
//   (/usr/local/cuda/samples/common/inc/helper_cuda.h).
//
//   major, minor:                     major and minor architecture version
//
//   returns:                          number of warp schedulers per SM
//
int how_many_warp_schedulers(int major, int minor){
  int i;
  sm_to_ws_t t[13];                   // Lookup table

  // Tesla architecture (1 warp scheduler per SM)
  t[0] .sm = 0x10;  t[0] .ws = 1;     // Tesla   (SM 1.0) G80 class
  t[1] .sm = 0x11;  t[1] .ws = 1;     // Tesla   (SM 1.1) G8X class
  t[2] .sm = 0x12;  t[2] .ws = 1;     // Tesla   (SM 1.2) G9X class
  t[3] .sm = 0x13;  t[3] .ws = 1;     // Tesla   (SM 1.3) GT200 class

  // Fermi architecture (2 warp schedulers per SM)
  t[4] .sm = 0x20;  t[4] .ws = 2;     // Fermi   (SM 2.0) GF100 class
  t[5] .sm = 0x21;  t[5] .ws = 2;     // Fermi   (SM 2.1) GF10x class

  // Kepler architecture (4 warp schedulers per SM)
  t[6] .sm = 0x30;  t[6] .ws = 4;     // Kepler  (SM 3.0) GK10x class
  t[7] .sm = 0x32;  t[7] .ws = 4;     // Kepler  (SM 3.2) GK10x class
  t[8] .sm = 0x35;  t[8] .ws = 4;     // Kepler  (SM 3.5) GK11x class
  t[9] .sm = 0x37;  t[9] .ws = 4;     // Kepler  (SM 3.7) GK21x class

  // Maxwell architecture (4 warp schedulers per SM)
  t[10].sm = 0x50;  t[10].ws = 4;     // Maxwell (SM 5.0) GM10x class
  t[11].sm = 0x52;  t[11].ws = 4;     // Maxwell (SM 5.2) GM20x class

  // Unknown architecture
  t[12].sm = -1;    t[12].ws = -1;    // Unknown

  for(i=0; i<13; i++){
    if(t[i].sm == ((major << 4) + minor)){
      return t[i].ws;
    }
  }
  return 0;
}

	.text
	.file	"fourier-parallel-pi-gpu-cuda.hip"
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	subq	$72, %rsp
	.cfi_def_cfa_offset 80
	movq	%rsi, %rdx
	movl	%edi, %esi
	movq	%rsp, %rdi
	callq	_Z15setup_from_argsP2triPPc
	testl	%eax, %eax
	jne	.LBB0_3
# %bb.1:
	movq	%rsp, %rdi
	callq	_Z3runP2tr
	testl	%eax, %eax
	jne	.LBB0_3
# %bb.2:
	xorl	%edi, %edi
	callq	exit
.LBB0_3:
	movl	$1, %edi
	callq	exit
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z15setup_from_argsP2triPPc     # -- Begin function _Z15setup_from_argsP2triPPc
	.type	_Z15setup_from_argsP2triPPc,@function
_Z15setup_from_argsP2triPPc:            # @_Z15setup_from_argsP2triPPc
	.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	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdx, %r14
	movl	%esi, %ebp
	movq	%rdi, %rbx
	xorps	%xmm0, %xmm0
	movups	%xmm0, 48(%rdi)
	movups	%xmm0, 32(%rdi)
	movups	%xmm0, 16(%rdi)
	movups	%xmm0, (%rdi)
	movq	$0, 64(%rdi)
	movl	$858993459, %r15d               # imm = 0x33333333
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	movl	$.L.str, %edx
	movl	%ebp, %edi
	movq	%r14, %rsi
	callq	getopt
                                        # kill: def $eax killed $eax def $rax
	leal	-110(%rax), %ecx
	cmpl	$6, %ecx
	ja	.LBB1_2
# %bb.28:                               #   in Loop: Header=BB1_1 Depth=1
	jmpq	*.LJTI1_0(,%rcx,8)
.LBB1_5:                                #   in Loop: Header=BB1_1 Depth=1
	movq	optarg(%rip), %rdi
	callq	atoi
	cmpl	$2, %eax
	jl	.LBB1_7
# %bb.6:                                #   in Loop: Header=BB1_1 Depth=1
	movl	%eax, %ecx
	shrl	%ecx
	andl	$1431655765, %ecx               # imm = 0x55555555
	movl	%eax, %edx
	subl	%ecx, %edx
	movl	%edx, %ecx
	andl	%r15d, %ecx
	shrl	$2, %edx
	andl	%r15d, %edx
	addl	%ecx, %edx
	movl	%edx, %ecx
	shrl	$4, %ecx
	addl	%edx, %ecx
	andl	$252645135, %ecx                # imm = 0xF0F0F0F
	imull	$16843009, %ecx, %ecx           # imm = 0x1010101
	shrl	$24, %ecx
	cmpl	$2, %ecx
	jae	.LBB1_7
# %bb.8:                                #   in Loop: Header=BB1_1 Depth=1
	movl	%eax, (%rbx)
	jmp	.LBB1_1
.LBB1_9:                                #   in Loop: Header=BB1_1 Depth=1
	movq	optarg(%rip), %rdi
	callq	atoi
	testl	%eax, %eax
	jle	.LBB1_11
# %bb.10:                               #   in Loop: Header=BB1_1 Depth=1
	movl	%eax, %ecx
	shrl	%ecx
	andl	$1431655765, %ecx               # imm = 0x55555555
	movl	%eax, %edx
	subl	%ecx, %edx
	movl	%edx, %ecx
	andl	%r15d, %ecx
	shrl	$2, %edx
	andl	%r15d, %edx
	addl	%ecx, %edx
	movl	%edx, %ecx
	shrl	$4, %ecx
	addl	%edx, %ecx
	andl	$252645135, %ecx                # imm = 0xF0F0F0F
	imull	$16843009, %ecx, %ecx           # imm = 0x1010101
	shrl	$24, %ecx
	cmpl	$2, %ecx
	jae	.LBB1_11
# %bb.12:                               #   in Loop: Header=BB1_1 Depth=1
	movl	%eax, 4(%rbx)
	jmp	.LBB1_1
.LBB1_14:                               #   in Loop: Header=BB1_1 Depth=1
	movl	$.Lstr, %edi
	callq	puts@PLT
	movq	stdout(%rip), %rdi
	callq	fflush
	movl	$8, (%rbx)
	movl	$1, 48(%rbx)
	jmp	.LBB1_1
.LBB1_13:                               #   in Loop: Header=BB1_1 Depth=1
	movl	$1, 52(%rbx)
	jmp	.LBB1_1
.LBB1_2:                                #   in Loop: Header=BB1_1 Depth=1
	cmpl	$-1, %eax
	je	.LBB1_15
# %bb.3:                                #   in Loop: Header=BB1_1 Depth=1
	cmpl	$63, %eax
	jne	.LBB1_1
# %bb.4:
	movq	stderr(%rip), %rdi
	movl	optopt(%rip), %edx
	movl	$.L.str.4, %esi
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_19
.LBB1_15:
	movl	(%rbx), %eax
	testl	%eax, %eax
	je	.LBB1_16
# %bb.20:
	movl	4(%rbx), %ebx
	testl	%ebx, %ebx
	je	.LBB1_21
# %bb.22:
	cmpl	%eax, %ebx
	ja	.LBB1_23
# %bb.24:
	callq	_Z26how_many_concurrent_blocksv
	movl	%eax, %ecx
	xorl	%eax, %eax
	cmpl	%ecx, %ebx
	jbe	.LBB1_27
# %bb.25:
	movl	$stderr, %r14d
	movq	stderr(%rip), %rbx
	callq	_Z26how_many_concurrent_blocksv
	movl	$.L.str.8, %esi
	movq	%rbx, %rdi
	movl	%eax, %edx
	xorl	%eax, %eax
	callq	fprintf
	jmp	.LBB1_26
.LBB1_7:
	movq	stderr(%rip), %rcx
	movl	$.L.str.1, %edi
	movl	$43, %esi
	jmp	.LBB1_18
.LBB1_11:
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$48, %esi
	jmp	.LBB1_18
.LBB1_16:
	movq	stderr(%rip), %rcx
	movl	$.L.str.5, %edi
	jmp	.LBB1_17
.LBB1_21:
	movq	stderr(%rip), %rcx
	movl	$.L.str.6, %edi
.LBB1_17:
	movl	$19, %esi
	jmp	.LBB1_18
.LBB1_23:
	movq	stderr(%rip), %rcx
	movl	$.L.str.7, %edi
	movl	$29, %esi
.LBB1_18:
	movl	$1, %edx
	callq	fwrite@PLT
.LBB1_19:
	movq	stderr(%rip), %rdi
	callq	fflush
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$stdout, %r14d
.LBB1_26:
	movq	(%r14), %rdi
	callq	fflush
	movq	stderr(%rip), %rcx
	movl	$.L.str.9, %edi
	movl	$52, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movq	stderr(%rip), %rdi
	callq	fflush
	movl	$-1, %eax
.LBB1_27:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z15setup_from_argsP2triPPc, .Lfunc_end1-_Z15setup_from_argsP2triPPc
	.cfi_endproc
	.section	.rodata,"a",@progbits
	.p2align	3, 0x0
.LJTI1_0:
	.quad	.LBB1_5
	.quad	.LBB1_13
	.quad	.LBB1_9
	.quad	.LBB1_1
	.quad	.LBB1_1
	.quad	.LBB1_1
	.quad	.LBB1_14
                                        # -- End function
	.text
	.globl	_Z3runP2tr                      # -- Begin function _Z3runP2tr
	.type	_Z3runP2tr,@function
_Z3runP2tr:                             # @_Z3runP2tr
	.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	$56, %rsp
	.cfi_def_cfa_offset 112
	.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	%rdi, %rbx
	callq	_Z15initialize_dataP2tr
	testl	%eax, %eax
	jne	.LBB2_1
# %bb.2:
	movabsq	$4294967296, %r14               # imm = 0x100000000
	leaq	32(%rsp), %rdi
	callq	_Z11timer_startP5timer
	movl	4(%rbx), %edi
	btsq	$32, %rdi
	leaq	1(%r14), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_4
# %bb.3:
	movq	64(%rbx), %rdi
	callq	_Z31__device_stub__run_funnel_stageP2tr
.LBB2_4:
	leaq	32(%rsp), %rdi
	callq	_Z10timer_stopP5timer
	leaq	8(%rsp), %rdi
	callq	_Z11timer_startP5timer
	movl	4(%rbx), %edi
	orq	%r14, %rdi
	incq	%r14
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_6
# %bb.5:
	movq	64(%rbx), %rdi
	callq	_Z29__device_stub__run_tube_stageP2tr
.LBB2_6:
	leaq	8(%rsp), %rdi
	callq	_Z10timer_stopP5timer
	cmpl	$0, 48(%rbx)
	je	.LBB2_7
# %bb.10:
	movq	56(%rbx), %rdi
	movq	64(%rbx), %rsi
	movl	4(%rbx), %eax
	shlq	$3, %rax
	leaq	(%rax,%rax,8), %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_11
.LBB2_12:
	movl	$0, 8(%rbx)
	movl	4(%rbx), %edi
	testl	%edi, %edi
	je	.LBB2_20
# %bb.13:                               # %.lr.ph66
	movl	(%rbx), %ecx
	movl	$252645135, %ebp                # imm = 0xF0F0F0F
	movl	$858993459, %r15d               # imm = 0x33333333
	movl	$1431655765, %r12d              # imm = 0x55555555
	xorl	%esi, %esi
.LBB2_15:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_17 Depth 2
	movl	%ecx, %eax
	xorl	%edx, %edx
	divl	%edi
	leal	1(%rsi), %edx
	movl	%edx, %r8d
	imull	%eax, %r8d
	imull	%esi, %eax
	cmpl	%r8d, %eax
	jae	.LBB2_14
# %bb.16:                               # %.lr.ph.preheader
                                        #   in Loop: Header=BB2_15 Depth=1
	movl	%eax, %r13d
.LBB2_17:                               # %.lr.ph
                                        #   Parent Loop BB2_15 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	imull	$125613361, %ecx, %eax          # imm = 0x77CB531
	shrl	$27, %eax
	movl	%r13d, %ecx
	bswapl	%ecx
	movl	%ecx, %edx
	shrl	$4, %edx
	andl	%ebp, %edx
	andl	%ebp, %ecx
	shll	$4, %ecx
	orl	%edx, %ecx
	movl	%ecx, %edx
	andl	%r15d, %edx
	shrl	$2, %ecx
	andl	%r15d, %ecx
	leal	(%rcx,%rdx,4), %ecx
	movl	%ecx, %edx
	andl	%r12d, %edx
	shrl	%ecx
	andl	%r12d, %ecx
	leal	(%rcx,%rdx,2), %edi
	movb	.L__const._Z5ilog2j.lookup_table(,%rax,4), %al
	xorl	%ecx, %ecx
	subb	%al, %cl
                                        # kill: def $cl killed $cl killed $ecx
	shrl	%cl, %edi
	shlq	$3, %rdi
	addq	24(%rbx), %rdi
	movq	56(%rbx), %rax
	movl	%esi, %ecx
	leaq	(%rcx,%rcx,8), %rcx
	leaq	(,%r13,8), %rsi
	addq	32(%rax,%rcx,8), %rsi
	movl	$8, %edx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB2_18
.LBB2_19:                               #   in Loop: Header=BB2_17 Depth=2
	incq	%r13
	movl	(%rbx), %ecx
	movl	4(%rbx), %edi
	movl	%ecx, %eax
	xorl	%edx, %edx
	divl	%edi
                                        # kill: def $eax killed $eax def $rax
	movl	8(%rbx), %esi
	leal	1(%rsi), %edx
	imull	%edx, %eax
	cmpq	%rax, %r13
	jb	.LBB2_17
	jmp	.LBB2_14
.LBB2_18:                               #   in Loop: Header=BB2_17 Depth=2
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movq	%r14, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %rdi
	callq	fflush
	jmp	.LBB2_19
.LBB2_14:                               # %.loopexit
                                        #   in Loop: Header=BB2_15 Depth=1
	movl	%edx, 8(%rbx)
	movl	%edx, %esi
	cmpl	%edi, %edx
	jb	.LBB2_15
.LBB2_20:                               # %._crit_edge
	movq	%rbx, %rdi
	callq	_Z12print_outputP2tr
	movq	%rbx, %rdi
	callq	_Z14verify_resultsP2tr
	jmp	.LBB2_21
.LBB2_7:
	cmpl	$0, 52(%rbx)
	jne	.LBB2_9
# %bb.8:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movq	stdout(%rip), %rdi
	callq	fflush
.LBB2_9:
	movl	(%rbx), %esi
	movl	4(%rbx), %edx
	movss	48(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movss	24(%rsp), %xmm2                 # xmm2 = mem[0],zero,zero,zero
	cvtss2sd	%xmm0, %xmm1
	addss	%xmm2, %xmm0
	cvtss2sd	%xmm0, %xmm0
	cvtss2sd	%xmm2, %xmm2
	movl	$.L.str.17, %edi
	movb	$3, %al
	callq	printf
	movq	stdout(%rip), %rdi
	callq	fflush
.LBB2_21:
	movq	%rbx, %rdi
	callq	_Z12cleanup_dataP2tr
	xorl	%eax, %eax
.LBB2_22:
	addq	$56, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB2_1:
	.cfi_def_cfa_offset 112
	movq	%rbx, %rdi
	callq	_Z12cleanup_dataP2tr
	movq	stderr(%rip), %rcx
	movl	$.L.str.18, %edi
	movl	$28, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movq	stderr(%rip), %rdi
	callq	fflush
	movl	$-1, %eax
	jmp	.LBB2_22
.LBB2_11:
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
	movq	%r14, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %rdi
	callq	fflush
	jmp	.LBB2_12
.Lfunc_end2:
	.size	_Z3runP2tr, .Lfunc_end2-_Z3runP2tr
	.cfi_endproc
                                        # -- End function
	.globl	_Z15is_power_of_twoi            # -- Begin function _Z15is_power_of_twoi
	.type	_Z15is_power_of_twoi,@function
_Z15is_power_of_twoi:                   # @_Z15is_power_of_twoi
	.cfi_startproc
# %bb.0:
                                        # kill: def $edi killed $edi def $rdi
	testl	%edi, %edi
	je	.LBB3_1
# %bb.2:
	leal	-1(%rdi), %ecx
	xorl	%eax, %eax
	testl	%ecx, %edi
	sete	%al
	retq
.LBB3_1:
	xorl	%eax, %eax
	retq
.Lfunc_end3:
	.size	_Z15is_power_of_twoi, .Lfunc_end3-_Z15is_power_of_twoi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10show_usagev                 # -- Begin function _Z10show_usagev
	.type	_Z10show_usagev,@function
_Z10show_usagev:                        # @_Z10show_usagev
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movq	stdout(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 8
	jmp	fflush                          # TAILCALL
.Lfunc_end4:
	.size	_Z10show_usagev, .Lfunc_end4-_Z10show_usagev
	.cfi_endproc
                                        # -- End function
	.globl	_Z26how_many_concurrent_blocksv # -- Begin function _Z26how_many_concurrent_blocksv
	.type	_Z26how_many_concurrent_blocksv,@function
_Z26how_many_concurrent_blocksv:        # @_Z26how_many_concurrent_blocksv
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$1488, %rsp                     # imm = 0x5D0
	.cfi_def_cfa_offset 1520
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	leaq	12(%rsp), %rdi
	callq	hipGetDeviceCount
	testl	%eax, %eax
	jne	.LBB5_2
# %bb.1:
	movl	12(%rsp), %ebx
	testl	%ebx, %ebx
	je	.LBB5_2
# %bb.3:
	decl	%ebx
	movl	%ebx, %edi
	callq	hipSetDevice
	leaq	16(%rsp), %r14
	movq	%r14, %rdi
	movl	%ebx, %esi
	callq	hipGetDevicePropertiesR0600
	movl	388(%r14), %ebp
	movl	360(%r14), %edi
	movl	364(%r14), %esi
	callq	_Z24how_many_warp_schedulersii
	movl	%eax, %ebx
	imull	%ebp, %ebx
.LBB5_4:
	movl	%ebx, %eax
	addq	$1488, %rsp                     # imm = 0x5D0
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB5_2:
	.cfi_def_cfa_offset 1520
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	xorl	%ebx, %ebx
	movl	$.L.str.27, %esi
	movq	%r14, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %rdi
	callq	fflush
	jmp	.LBB5_4
.Lfunc_end5:
	.size	_Z26how_many_concurrent_blocksv, .Lfunc_end5-_Z26how_many_concurrent_blocksv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z15initialize_dataP2tr
.LCPI6_0:
	.long	0x00000000                      # float 0
	.long	0x00000000                      # float 0
	.long	0x3f800000                      # float 1
	.long	0x00000000                      # float 0
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI6_1:
	.quad	0x41cfffffffc00000              # double 1073741823.5
.LCPI6_2:
	.quad	0xbff0000000000000              # double -1
	.text
	.globl	_Z15initialize_dataP2tr
	.type	_Z15initialize_dataP2tr,@function
_Z15initialize_dataP2tr:                # @_Z15initialize_dataP2tr
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %rbx
	movl	(%rdi), %r14d
	shlq	$3, %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, 16(%rbx)
	testq	%rax, %rax
	je	.LBB6_1
# %bb.4:
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, 24(%rbx)
	testq	%rax, %rax
	je	.LBB6_1
# %bb.5:
	movl	4(%rbx), %eax
	shlq	$3, %rax
	leaq	(%rax,%rax,8), %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, 56(%rbx)
	testq	%rax, %rax
	je	.LBB6_1
# %bb.6:
	leaq	64(%rbx), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_7
# %bb.9:
	movl	$0, 8(%rbx)
	cmpl	$0, 4(%rbx)
	je	.LBB6_16
# %bb.10:                               # %.lr.ph.preheader
	xorl	%eax, %eax
.LBB6_11:                               # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%eax, %eax
	leaq	(%rax,%rax,8), %rdi
	shlq	$3, %rdi
	addq	56(%rbx), %rdi
	movl	$9, %ecx
	movq	%rbx, %rsi
	rep;movsq (%rsi), %es:(%rdi)
	movq	56(%rbx), %rax
	movl	(%rbx), %esi
	movl	8(%rbx), %ecx
	leaq	(%rcx,%rcx,8), %rcx
	leaq	(%rax,%rcx,8), %rdi
	addq	$32, %rdi
	shlq	$3, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_7
# %bb.12:                               #   in Loop: Header=BB6_11 Depth=1
	movq	56(%rbx), %rax
	movl	(%rbx), %esi
	movl	8(%rbx), %ecx
	leaq	(%rcx,%rcx,8), %rcx
	leaq	(%rax,%rcx,8), %rdi
	addq	$40, %rdi
	shlq	$3, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_7
# %bb.13:                               #   in Loop: Header=BB6_11 Depth=1
	movl	8(%rbx), %eax
	shlq	$3, %rax
	leaq	(%rax,%rax,8), %rsi
	movq	64(%rbx), %rdi
	addq	%rsi, %rdi
	addq	56(%rbx), %rsi
	movl	$72, %edx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_14
# %bb.15:                               #   in Loop: Header=BB6_11 Depth=1
	movl	8(%rbx), %eax
	incl	%eax
	movl	%eax, 8(%rbx)
	cmpl	4(%rbx), %eax
	jb	.LBB6_11
.LBB6_16:                               # %._crit_edge
	cmpl	$0, 48(%rbx)
	je	.LBB6_17
# %bb.20:
	movq	16(%rbx), %rax
	movaps	.LCPI6_0(%rip), %xmm0           # xmm0 = [0.0E+0,0.0E+0,1.0E+0,0.0E+0]
	movups	%xmm0, (%rax)
	movups	%xmm0, 16(%rax)
	movups	%xmm0, 32(%rax)
	movups	%xmm0, 48(%rax)
	movq	%rbx, %rdi
	callq	_Z11print_inputP2tr
	jmp	.LBB6_21
.LBB6_17:
	xorl	%edi, %edi
	callq	time
	movl	%eax, %ecx
	shll	$12, %ecx
	addl	%ecx, %eax
	addl	$2127912214, %eax               # imm = 0x7ED55D16
	movl	%eax, %ecx
	shrl	$19, %ecx
	xorl	%eax, %ecx
	xorl	$-949894596, %ecx               # imm = 0xC761C23C
	movl	%ecx, %eax
	shll	$5, %eax
	leal	(%rcx,%rax), %edx
	shll	$9, %edx
	addl	%ecx, %eax
	addl	$-369570787, %eax               # imm = 0xE9F8CC1D
	addl	$-1395695104, %edx              # imm = 0xACCF6200
	xorl	%eax, %edx
	leal	(%rdx,%rdx,8), %eax
	addl	$-42973499, %eax                # imm = 0xFD7046C5
	movl	%eax, %edi
	shrl	$16, %edi
	xorl	%eax, %edi
	xorl	$-1252372727, %edi              # imm = 0xB55A4F09
	callq	srand
	cmpl	$0, (%rbx)
	je	.LBB6_21
# %bb.18:                               # %.lr.ph90.preheader
	xorl	%r14d, %r14d
.LBB6_19:                               # %.lr.ph90
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	movsd	.LCPI6_1(%rip), %xmm1           # xmm1 = mem[0],zero
	divsd	%xmm1, %xmm0
	movsd	.LCPI6_2(%rip), %xmm1           # xmm1 = mem[0],zero
	addsd	%xmm1, %xmm0
	movl	(%rbx), %eax
	xorps	%xmm1, %xmm1
	cvtsi2sd	%rax, %xmm1
	sqrtsd	%xmm1, %xmm1
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movq	16(%rbx), %rax
	movss	%xmm0, (%rax,%r14,8)
	callq	rand
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI6_1(%rip), %xmm0
	movl	(%rbx), %eax
	xorps	%xmm1, %xmm1
	cvtsi2sd	%rax, %xmm1
	addsd	.LCPI6_2(%rip), %xmm0
	sqrtsd	%xmm1, %xmm1
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movq	16(%rbx), %rcx
	movss	%xmm0, 4(%rcx,%r14,8)
	incq	%r14
	cmpq	%rax, %r14
	jb	.LBB6_19
.LBB6_21:                               # %.loopexit80
	movl	$0, 8(%rbx)
	cmpl	$0, 4(%rbx)
	je	.LBB6_22
# %bb.23:                               # %.lr.ph93.preheader
	xorl	%eax, %eax
.LBB6_24:                               # %.lr.ph93
                                        # =>This Inner Loop Header: Depth=1
	movq	56(%rbx), %rcx
	movl	%eax, %eax
	leaq	(%rax,%rax,8), %rax
	movq	32(%rcx,%rax,8), %rdi
	movq	16(%rbx), %rsi
	movl	(%rbx), %edx
	shlq	$3, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_14
# %bb.25:                               #   in Loop: Header=BB6_24 Depth=1
	movl	8(%rbx), %eax
	incl	%eax
	movl	%eax, 8(%rbx)
	cmpl	4(%rbx), %eax
	jb	.LBB6_24
.LBB6_22:
	xorl	%eax, %eax
	jmp	.LBB6_3
.LBB6_1:
	movl	$.L.str.10, %edi
	callq	perror
	jmp	.LBB6_2
.LBB6_7:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.11, %esi
	jmp	.LBB6_8
.LBB6_14:
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.12, %esi
.LBB6_8:
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
.LBB6_2:
	movq	stderr(%rip), %rdi
	callq	fflush
	movq	stderr(%rip), %rcx
	movl	$.L.str.13, %edi
	movl	$30, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movq	stderr(%rip), %rdi
	callq	fflush
	movl	$-1, %eax
.LBB6_3:                                # %.loopexit
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end6:
	.size	_Z15initialize_dataP2tr, .Lfunc_end6-_Z15initialize_dataP2tr
	.cfi_endproc
                                        # -- End function
	.globl	_Z4hashj                        # -- Begin function _Z4hashj
	.type	_Z4hashj,@function
_Z4hashj:                               # @_Z4hashj
	.cfi_startproc
# %bb.0:
                                        # kill: def $edi killed $edi def $rdi
	movl	%edi, %eax
	shll	$12, %eax
	addl	%edi, %eax
	addl	$2127912214, %eax               # imm = 0x7ED55D16
	movl	%eax, %ecx
	shrl	$19, %ecx
	xorl	%eax, %ecx
	xorl	$-949894596, %ecx               # imm = 0xC761C23C
	movl	%ecx, %eax
	shll	$5, %eax
	leal	(%rcx,%rax), %edx
	shll	$9, %edx
	addl	%ecx, %eax
	addl	$-369570787, %eax               # imm = 0xE9F8CC1D
	addl	$-1395695104, %edx              # imm = 0xACCF6200
	xorl	%eax, %edx
	leal	(%rdx,%rdx,8), %ecx
	addl	$-42973499, %ecx                # imm = 0xFD7046C5
	movl	%ecx, %eax
	shrl	$16, %eax
	xorl	%ecx, %eax
	xorl	$-1252372727, %eax              # imm = 0xB55A4F09
	retq
.Lfunc_end7:
	.size	_Z4hashj, .Lfunc_end7-_Z4hashj
	.cfi_endproc
                                        # -- End function
	.globl	_Z11print_inputP2tr             # -- Begin function _Z11print_inputP2tr
	.type	_Z11print_inputP2tr,@function
_Z11print_inputP2tr:                    # @_Z11print_inputP2tr
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %rbx
	movl	$.Lstr.3, %edi
	callq	puts@PLT
	movq	stdout(%rip), %rdi
	callq	fflush
	cmpl	$0, (%rbx)
	je	.LBB8_3
# %bb.1:                                # %.lr.ph
	xorl	%r14d, %r14d
.LBB8_2:                                # =>This Inner Loop Header: Depth=1
	movq	16(%rbx), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rax,%r14,8), %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	4(%rax,%r14,8), %xmm1
	movl	$.L.str.20, %edi
	movb	$2, %al
	callq	printf
	movq	stdout(%rip), %rdi
	callq	fflush
	incq	%r14
	movl	(%rbx), %eax
	cmpq	%rax, %r14
	jb	.LBB8_2
.LBB8_3:                                # %._crit_edge
	movl	$10, %edi
	callq	putchar@PLT
	movq	stdout(%rip), %rdi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	fflush                          # TAILCALL
.Lfunc_end8:
	.size	_Z11print_inputP2tr, .Lfunc_end8-_Z11print_inputP2tr
	.cfi_endproc
                                        # -- End function
	.globl	_Z12cleanup_dataP2tr            # -- Begin function _Z12cleanup_dataP2tr
	.type	_Z12cleanup_dataP2tr,@function
_Z12cleanup_dataP2tr:                   # @_Z12cleanup_dataP2tr
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %rbx
	movq	16(%rdi), %rdi
	testq	%rdi, %rdi
	je	.LBB9_2
# %bb.1:
	callq	free
	movq	$0, 16(%rbx)
.LBB9_2:
	movq	24(%rbx), %rdi
	testq	%rdi, %rdi
	je	.LBB9_4
# %bb.3:
	callq	free
	movq	$0, 24(%rbx)
.LBB9_4:
	movq	56(%rbx), %rdi
	testq	%rdi, %rdi
	je	.LBB9_16
# %bb.5:
	movl	$0, 8(%rbx)
	cmpl	$0, 4(%rbx)
	je	.LBB9_15
# %bb.6:                                # %.lr.ph.preheader
	xorl	%eax, %eax
.LBB9_7:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movq	56(%rbx), %rcx
	movl	%eax, %eax
	leaq	(%rax,%rax,8), %rax
	movq	32(%rcx,%rax,8), %rdi
	testq	%rdi, %rdi
	je	.LBB9_10
# %bb.8:                                #   in Loop: Header=BB9_7 Depth=1
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB9_9
.LBB9_10:                               #   in Loop: Header=BB9_7 Depth=1
	movq	56(%rbx), %rax
	movl	8(%rbx), %ecx
	leaq	(%rcx,%rcx,8), %rcx
	movq	40(%rax,%rcx,8), %rdi
	testq	%rdi, %rdi
	je	.LBB9_13
# %bb.11:                               #   in Loop: Header=BB9_7 Depth=1
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB9_12
.LBB9_13:                               #   in Loop: Header=BB9_7 Depth=1
	movl	8(%rbx), %eax
	incl	%eax
	movl	%eax, 8(%rbx)
	cmpl	4(%rbx), %eax
	jb	.LBB9_7
	jmp	.LBB9_14
.LBB9_9:                                #   in Loop: Header=BB9_7 Depth=1
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.14, %esi
	movq	%r14, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %rdi
	callq	fflush
	jmp	.LBB9_10
.LBB9_12:                               #   in Loop: Header=BB9_7 Depth=1
	movq	stderr(%rip), %r14
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.14, %esi
	movq	%r14, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %rdi
	callq	fflush
	jmp	.LBB9_13
.LBB9_14:                               # %._crit_edge.loopexit
	movq	56(%rbx), %rdi
.LBB9_15:                               # %._crit_edge
	callq	free
	movq	$0, 56(%rbx)
.LBB9_16:
	movq	64(%rbx), %rdi
	testq	%rdi, %rdi
	je	.LBB9_18
# %bb.17:
	callq	hipFree
	testl	%eax, %eax
	jne	.LBB9_19
.LBB9_18:
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.LBB9_19:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.14, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %rdi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	fflush                          # TAILCALL
.Lfunc_end9:
	.size	_Z12cleanup_dataP2tr, .Lfunc_end9-_Z12cleanup_dataP2tr
	.cfi_endproc
                                        # -- End function
	.globl	_Z11timer_startP5timer          # -- Begin function _Z11timer_startP5timer
	.type	_Z11timer_startP5timer,@function
_Z11timer_startP5timer:                 # @_Z11timer_startP5timer
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB10_4
# %bb.1:
	leaq	8(%rbx), %rdi
	callq	hipEventCreate
	testl	%eax, %eax
	jne	.LBB10_4
# %bb.2:
	movq	(%rbx), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB10_4
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB10_4:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.25, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	fflush                          # TAILCALL
.Lfunc_end10:
	.size	_Z11timer_startP5timer, .Lfunc_end10-_Z11timer_startP5timer
	.cfi_endproc
                                        # -- End function
	.globl	_Z31__device_stub__run_funnel_stageP2tr # -- Begin function _Z31__device_stub__run_funnel_stageP2tr
	.type	_Z31__device_stub__run_funnel_stageP2tr,@function
_Z31__device_stub__run_funnel_stageP2tr: # @_Z31__device_stub__run_funnel_stageP2tr
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z16run_funnel_stageP2tr, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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_end11:
	.size	_Z31__device_stub__run_funnel_stageP2tr, .Lfunc_end11-_Z31__device_stub__run_funnel_stageP2tr
	.cfi_endproc
                                        # -- End function
	.globl	_Z10timer_stopP5timer           # -- Begin function _Z10timer_stopP5timer
	.type	_Z10timer_stopP5timer,@function
_Z10timer_stopP5timer:                  # @_Z10timer_stopP5timer
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	movq	8(%rdi), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	testl	%eax, %eax
	jne	.LBB12_4
# %bb.1:
	movq	8(%rbx), %rdi
	callq	hipEventSynchronize
	testl	%eax, %eax
	jne	.LBB12_4
# %bb.2:
	leaq	16(%rbx), %rdi
	movq	(%rbx), %rsi
	movq	8(%rbx), %rdx
	callq	hipEventElapsedTime
	testl	%eax, %eax
	jne	.LBB12_4
# %bb.3:
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB12_4:
	.cfi_def_cfa_offset 16
	movq	stderr(%rip), %rbx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.26, %esi
	movq	%rbx, %rdi
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	fprintf
	movq	stderr(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	fflush                          # TAILCALL
.Lfunc_end12:
	.size	_Z10timer_stopP5timer, .Lfunc_end12-_Z10timer_stopP5timer
	.cfi_endproc
                                        # -- End function
	.globl	_Z29__device_stub__run_tube_stageP2tr # -- Begin function _Z29__device_stub__run_tube_stageP2tr
	.type	_Z29__device_stub__run_tube_stageP2tr,@function
_Z29__device_stub__run_tube_stageP2tr:  # @_Z29__device_stub__run_tube_stageP2tr
	.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	$64, %rsp
	.cfi_def_cfa_offset 112
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	movq	%rsp, %rbx
	movq	%rax, (%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z14run_tube_stageP2tr, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$80, %rsp
	.cfi_adjust_cfa_offset -80
	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_end13:
	.size	_Z29__device_stub__run_tube_stageP2tr, .Lfunc_end13-_Z29__device_stub__run_tube_stageP2tr
	.cfi_endproc
                                        # -- End function
	.globl	_Z11bit_reversejj               # -- Begin function _Z11bit_reversejj
	.type	_Z11bit_reversejj,@function
_Z11bit_reversejj:                      # @_Z11bit_reversejj
	.cfi_startproc
# %bb.0:
	movl	%esi, %ecx
                                        # kill: def $edi killed $edi def $rdi
	bswapl	%edi
	movl	%edi, %eax
	shrl	$4, %eax
	movl	$252645135, %edx                # imm = 0xF0F0F0F
	andl	%edx, %eax
	andl	%edx, %edi
	shll	$4, %edi
	orl	%eax, %edi
	movl	$858993459, %eax                # imm = 0x33333333
	movl	%edi, %edx
	andl	%eax, %edx
	shrl	$2, %edi
	andl	%eax, %edi
	leal	(%rdi,%rdx,4), %eax
	movl	$1431655765, %edx               # imm = 0x55555555
	movl	%eax, %esi
	andl	%edx, %esi
	shrl	%eax
	andl	%edx, %eax
	leal	(%rax,%rsi,2), %eax
	negb	%cl
                                        # kill: def $cl killed $cl killed $ecx
	shrl	%cl, %eax
	retq
.Lfunc_end14:
	.size	_Z11bit_reversejj, .Lfunc_end14-_Z11bit_reversejj
	.cfi_endproc
                                        # -- End function
	.globl	_Z5ilog2j                       # -- Begin function _Z5ilog2j
	.type	_Z5ilog2j,@function
_Z5ilog2j:                              # @_Z5ilog2j
	.cfi_startproc
# %bb.0:
	imull	$125613361, %edi, %eax          # imm = 0x77CB531
	shrl	$27, %eax
	movl	.L__const._Z5ilog2j.lookup_table(,%rax,4), %eax
	retq
.Lfunc_end15:
	.size	_Z5ilog2j, .Lfunc_end15-_Z5ilog2j
	.cfi_endproc
                                        # -- End function
	.globl	_Z12print_outputP2tr            # -- Begin function _Z12print_outputP2tr
	.type	_Z12print_outputP2tr,@function
_Z12print_outputP2tr:                   # @_Z12print_outputP2tr
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movq	%rdi, %rbx
	movl	$.Lstr.4, %edi
	callq	puts@PLT
	movq	stdout(%rip), %rdi
	callq	fflush
	cmpl	$0, (%rbx)
	je	.LBB16_3
# %bb.1:                                # %.lr.ph
	xorl	%r14d, %r14d
.LBB16_2:                               # =>This Inner Loop Header: Depth=1
	movq	24(%rbx), %rax
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rax,%r14,8), %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	4(%rax,%r14,8), %xmm1
	movl	$.L.str.20, %edi
	movb	$2, %al
	callq	printf
	movq	stdout(%rip), %rdi
	callq	fflush
	incq	%r14
	movl	(%rbx), %eax
	cmpq	%rax, %r14
	jb	.LBB16_2
.LBB16_3:                               # %._crit_edge
	movl	$10, %edi
	callq	putchar@PLT
	movq	stdout(%rip), %rdi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	fflush                          # TAILCALL
.Lfunc_end16:
	.size	_Z12print_outputP2tr, .Lfunc_end16-_Z12print_outputP2tr
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function _Z14verify_resultsP2tr
.LCPI17_0:
	.long	0x40800000                      # float 4
.LCPI17_1:
	.long	0xc0800000                      # float -4
	.text
	.globl	_Z14verify_resultsP2tr
	.type	_Z14verify_resultsP2tr,@function
_Z14verify_resultsP2tr:                 # @_Z14verify_resultsP2tr
	.cfi_startproc
# %bb.0:
	movq	24(%rdi), %rax
	movss	(%rax), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	movl	$.L.str.24, %edi
	ucomiss	.LCPI17_0(%rip), %xmm0
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.1:
	movss	4(%rax), %xmm1                  # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	ucomiss	%xmm0, %xmm1
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.2:
	movss	8(%rax), %xmm1                  # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.3:
	movss	12(%rax), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.4:
	movss	16(%rax), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.5:
	movss	20(%rax), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.6:
	movss	24(%rax), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.7:
	movss	28(%rax), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	xorps	%xmm1, %xmm1
	ucomiss	%xmm1, %xmm0
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.8:
	movss	32(%rax), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	ucomiss	.LCPI17_1(%rip), %xmm0
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.9:
	movss	36(%rax), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	ucomiss	%xmm0, %xmm1
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.10:
	movss	40(%rax), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.11:
	movss	44(%rax), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.12:
	movss	48(%rax), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.13:
	movss	52(%rax), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.14:
	movss	56(%rax), %xmm1                 # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jne	.LBB17_16
	jp	.LBB17_16
# %bb.15:
	ucomiss	60(%rax), %xmm0
	movl	$.L.str.24, %eax
	movl	$.L.str.23, %edi
	cmovneq	%rax, %rdi
	cmovpq	%rax, %rdi
.LBB17_16:
	pushq	%rax
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	callq	printf
	movq	stdout(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 8
	jmp	fflush                          # TAILCALL
.Lfunc_end17:
	.size	_Z14verify_resultsP2tr, .Lfunc_end17-_Z14verify_resultsP2tr
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z24how_many_warp_schedulersii
.LCPI18_0:
	.long	16                              # 0x10
	.long	1                               # 0x1
	.long	17                              # 0x11
	.long	1                               # 0x1
.LCPI18_1:
	.long	18                              # 0x12
	.long	1                               # 0x1
	.long	19                              # 0x13
	.long	1                               # 0x1
.LCPI18_2:
	.long	32                              # 0x20
	.long	2                               # 0x2
	.long	33                              # 0x21
	.long	2                               # 0x2
.LCPI18_3:
	.long	48                              # 0x30
	.long	4                               # 0x4
	.long	50                              # 0x32
	.long	4                               # 0x4
.LCPI18_4:
	.long	53                              # 0x35
	.long	4                               # 0x4
	.long	55                              # 0x37
	.long	4                               # 0x4
.LCPI18_5:
	.long	80                              # 0x50
	.long	4                               # 0x4
	.long	82                              # 0x52
	.long	4                               # 0x4
	.text
	.globl	_Z24how_many_warp_schedulersii
	.type	_Z24how_many_warp_schedulersii,@function
_Z24how_many_warp_schedulersii:         # @_Z24how_many_warp_schedulersii
	.cfi_startproc
# %bb.0:
	movaps	.LCPI18_0(%rip), %xmm0          # xmm0 = [16,1,17,1]
	movaps	%xmm0, -104(%rsp)
	movaps	.LCPI18_1(%rip), %xmm0          # xmm0 = [18,1,19,1]
	movaps	%xmm0, -88(%rsp)
	movaps	.LCPI18_2(%rip), %xmm0          # xmm0 = [32,2,33,2]
	movaps	%xmm0, -72(%rsp)
	movaps	.LCPI18_3(%rip), %xmm0          # xmm0 = [48,4,50,4]
	movaps	%xmm0, -56(%rsp)
	movaps	.LCPI18_4(%rip), %xmm0          # xmm0 = [53,4,55,4]
	movaps	%xmm0, -40(%rsp)
	movaps	.LCPI18_5(%rip), %xmm0          # xmm0 = [80,4,82,4]
	movaps	%xmm0, -24(%rsp)
	movq	$-1, -8(%rsp)
	shll	$4, %edi
	addl	%esi, %edi
	xorl	%eax, %eax
.LBB18_1:                               # =>This Inner Loop Header: Depth=1
	cmpl	%edi, -104(%rsp,%rax,8)
	je	.LBB18_4
# %bb.2:                                #   in Loop: Header=BB18_1 Depth=1
	incq	%rax
	cmpq	$13, %rax
	jne	.LBB18_1
# %bb.3:
	xorl	%eax, %eax
	retq
.LBB18_4:
	movl	-100(%rsp,%rax,8), %eax
	retq
.Lfunc_end18:
	.size	_Z24how_many_warp_schedulersii, .Lfunc_end18-_Z24how_many_warp_schedulersii
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB19_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB19_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z16run_funnel_stageP2tr, %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	$_Z14run_tube_stageP2tr, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %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_end19:
	.size	__hip_module_ctor, .Lfunc_end19-__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	.LBB20_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
.LBB20_2:
	retq
.Lfunc_end20:
	.size	__hip_module_dtor, .Lfunc_end20-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"n:p:to"
	.size	.L.str, 7

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Invalid input size (should be 2^i for i>0)\n"
	.size	.L.str.1, 44

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Invalid number of procs (should be 2^i for i>0)\n"
	.size	.L.str.2, 49

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Unknown or missing arg %c\n"
	.size	.L.str.4, 27

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Missing option: -n\n"
	.size	.L.str.5, 20

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Missing option: -p\n"
	.size	.L.str.6, 20

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"More processors than inputs!\n"
	.size	.L.str.7, 30

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Too many processors! (only %u concurrent blocks available)\n"
	.size	.L.str.8, 60

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Could not setup the transform from the cmdline args\n"
	.size	.L.str.9, 53

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"malloc error"
	.size	.L.str.10, 13

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"hipMalloc error: %s\n"
	.size	.L.str.11, 21

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"hipMemcpy error: %s\n"
	.size	.L.str.12, 21

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"Could not initialize the data\n"
	.size	.L.str.13, 31

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"hipFree error: %s\n"
	.size	.L.str.14, 19

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

	.type	_Z14run_tube_stageP2tr,@object  # @_Z14run_tube_stageP2tr
	.globl	_Z14run_tube_stageP2tr
	.p2align	3, 0x0
_Z14run_tube_stageP2tr:
	.quad	_Z29__device_stub__run_tube_stageP2tr
	.size	_Z14run_tube_stageP2tr, 8

	.type	.L.str.17,@object               # @.str.17
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.17:
	.asciz	"%u\t%u\t%f\t%f\t%f\n"
	.size	.L.str.17, 16

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"Could not run the transform\n"
	.size	.L.str.18, 29

	.type	.L.str.20,@object               # @.str.20
.L.str.20:
	.asciz	"%.1f+%.1fi, "
	.size	.L.str.20, 13

	.type	.L.str.23,@object               # @.str.23
.L.str.23:
	.asciz	"Output is correct. Test passed.\n\n"
	.size	.L.str.23, 34

	.type	.L.str.24,@object               # @.str.24
.L.str.24:
	.asciz	"Output is incorrect! Test failed.\n\n"
	.size	.L.str.24, 36

	.type	.L__const._Z5ilog2j.lookup_table,@object # @__const._Z5ilog2j.lookup_table
	.section	.rodata,"a",@progbits
	.p2align	4, 0x0
.L__const._Z5ilog2j.lookup_table:
	.long	0                               # 0x0
	.long	1                               # 0x1
	.long	28                              # 0x1c
	.long	2                               # 0x2
	.long	29                              # 0x1d
	.long	14                              # 0xe
	.long	24                              # 0x18
	.long	3                               # 0x3
	.long	30                              # 0x1e
	.long	22                              # 0x16
	.long	20                              # 0x14
	.long	15                              # 0xf
	.long	25                              # 0x19
	.long	17                              # 0x11
	.long	4                               # 0x4
	.long	8                               # 0x8
	.long	31                              # 0x1f
	.long	27                              # 0x1b
	.long	13                              # 0xd
	.long	23                              # 0x17
	.long	21                              # 0x15
	.long	19                              # 0x13
	.long	16                              # 0x10
	.long	7                               # 0x7
	.long	26                              # 0x1a
	.long	12                              # 0xc
	.long	18                              # 0x12
	.long	6                               # 0x6
	.long	11                              # 0xb
	.long	5                               # 0x5
	.long	10                              # 0xa
	.long	9                               # 0x9
	.size	.L__const._Z5ilog2j.lookup_table, 128

	.type	.L.str.25,@object               # @.str.25
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.25:
	.asciz	"cudaEventCreate|Record error: %s\n"
	.size	.L.str.25, 34

	.type	.L.str.26,@object               # @.str.26
.L.str.26:
	.asciz	"cudaEventRecord|Synchronize|ElapsedTime error: %s\n"
	.size	.L.str.26, 51

	.type	.L.str.27,@object               # @.str.27
.L.str.27:
	.asciz	"hipGetDeviceCount error: %s\n"
	.size	.L.str.27, 29

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z16run_funnel_stageP2tr"
	.size	.L__unnamed_1, 25

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z14run_tube_stageP2tr"
	.size	.L__unnamed_2, 23

	.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	"Test mode (ignoring provided input size, if any)..."
	.size	.Lstr, 52

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"n\tp\ttime (total)\ttime (stage 1)\ttime (stage 2)"
	.size	.Lstr.1, 47

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"\nusage:\n  fourier-parallel-pi-gpu-cuda { -n <n> -p <p> [-o] | -t }\n\noptions:\n  -n <n>     power of two input size\n  -p <p>     power of two number of processors (less than n)\n  -o         omit timing headers\n  -t         compare against precomputed input/output\n"
	.size	.Lstr.2, 263

	.type	.Lstr.3,@object                 # @str.3
.Lstr.3:
	.asciz	"Input:"
	.size	.Lstr.3, 7

	.type	.Lstr.4,@object                 # @str.4
.Lstr.4:
	.asciz	"Output:"
	.size	.Lstr.4, 8

	.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 _Z31__device_stub__run_funnel_stageP2tr
	.addrsig_sym _Z29__device_stub__run_tube_stageP2tr
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z16run_funnel_stageP2tr
	.addrsig_sym _Z14run_tube_stageP2tr
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z16run_funnel_stageP2tr ; -- Begin function _Z16run_funnel_stageP2tr
	.globl	_Z16run_funnel_stageP2tr
	.p2align	8
	.type	_Z16run_funnel_stageP2tr,@function
_Z16run_funnel_stageP2tr:               ; @_Z16run_funnel_stageP2tr
; %bb.0:
	s_load_b64 s[2:3], s[0:1], 0x0
	s_mul_i32 s0, s15, 0x48
	s_mul_hi_u32 s1, s15, 0x48
	s_waitcnt lgkmcnt(0)
	s_add_u32 s0, s2, s0
	s_addc_u32 s1, s3, s1
	s_load_b64 s[6:7], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	v_cvt_f32_u32_e32 v0, s7
	s_sub_i32 s5, 0, s7
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v0, v0
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x4f7ffffe, v0
	v_cvt_u32_f32_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_readfirstlane_b32 s4, v0
	s_mul_i32 s5, s5, s4
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s5, s4, s5
	s_add_i32 s4, s4, s5
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s4, s6, s4
	s_mul_i32 s5, s4, s7
	s_add_i32 s8, s4, 1
	s_sub_i32 s5, s6, s5
	s_delay_alu instid0(SALU_CYCLE_1)
	s_sub_i32 s9, s5, s7
	s_cmp_ge_u32 s5, s7
	s_cselect_b32 s4, s8, s4
	s_cselect_b32 s5, s9, s5
	s_add_i32 s8, s4, 1
	s_cmp_ge_u32 s5, s7
	s_cselect_b32 s4, s8, s4
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_le_u32 s6, s4
	s_cbranch_scc1 .LBB0_8
; %bb.1:                                ; %.lr.ph
	s_mul_i32 s8, s7, 0x77cb531
	s_getpc_b64 s[4:5]
	s_add_u32 s4, s4, __const._Z5ilog2j.lookup_table@rel32@lo+4
	s_addc_u32 s5, s5, __const._Z5ilog2j.lookup_table@rel32@hi+12
	s_lshr_b32 s8, s8, 25
	s_mul_i32 s9, s15, 0x48
	s_and_b32 s10, s8, 0x7c
	s_mul_hi_u32 s11, s15, 0x48
	s_add_u32 s8, s2, s9
	s_addc_u32 s9, s3, s11
	s_load_b128 s[12:15], s[8:9], 0x20
	s_load_b32 s11, s[4:5], s10 offset:0x0
	s_add_u32 s2, s8, 8
	v_mov_b32_e32 v5, 0
	s_addc_u32 s3, s9, 0
	s_add_u32 s4, s8, 32
	s_addc_u32 s5, s9, 0
	s_mov_b32 s8, s6
	s_waitcnt lgkmcnt(0)
	v_dual_mov_b32 v0, s12 :: v_dual_mov_b32 v1, s13
	v_dual_mov_b32 v2, s14 :: v_dual_mov_b32 v3, s15
.LBB0_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_4 Depth 2
	s_add_i32 s9, s11, -1
	s_lshr_b32 s10, s8, 1
	s_cmp_lt_u32 s8, 2
	s_cbranch_scc1 .LBB0_6
; %bb.3:                                ; %.lr.ph.i
                                        ;   in Loop: Header=BB0_2 Depth=1
	global_load_b32 v4, v5, s[2:3]
	v_cvt_f32_u32_e32 v7, s6
	v_cvt_f32_u32_e32 v6, s8
	s_sub_i32 s7, 0, s8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_div_scale_f32 v8, null, v7, v7, 0x40c90fd8
	v_rcp_iflag_f32_e32 v6, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f32_e32 v9, v8
	s_waitcnt_depctr 0xfff
	v_fma_f32 v10, -v8, v9, 1.0
	v_dual_mul_f32 v6, 0x4f7ffffe, v6 :: v_dual_fmac_f32 v9, v10, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_u32_f32_e32 v6, v6
	v_readfirstlane_b32 s12, v6
	v_div_scale_f32 v6, vcc_lo, 0x40c90fd8, v7, 0x40c90fd8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_mul_i32 s7, s7, s12
	v_mul_f32_e32 v10, v6, v9
	s_mul_hi_u32 s7, s12, s7
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	s_add_i32 s12, s12, s7
	s_mov_b32 s7, 0
	v_fma_f32 v11, -v8, v10, v6
	s_mul_hi_u32 s12, s6, s12
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_mul_i32 s13, s12, s8
	v_fmac_f32_e32 v10, v11, v9
	s_sub_i32 s6, s6, s13
	s_add_i32 s13, s12, 1
	s_sub_i32 s14, s6, s8
	s_cmp_ge_u32 s6, s8
	v_fma_f32 v6, -v8, v10, v6
	s_cselect_b32 s12, s13, s12
	s_cselect_b32 s6, s14, s6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f32 v6, v6, v9, v10
	v_div_fixup_f32 v6, v6, v7, 0x40c90fd8
	s_waitcnt vmcnt(0)
	v_not_b32_e32 v12, v4
	v_lshrrev_b32_e32 v11, s11, v4
	s_add_i32 s11, s12, 1
	s_cmp_ge_u32 s6, s8
	s_cselect_b32 s6, s11, s12
	v_lshrrev_b32_e32 v8, s9, v12
	v_mul_lo_u32 v4, v11, s8
	s_lshl_b64 s[12:13], s[8:9], 2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	s_and_b32 s8, s13, 3
	v_and_b32_e32 v10, 1, v8
	s_and_b32 s11, s12, -8
	s_mov_b32 s12, s10
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[8:9], 3, v[4:5]
	v_cmp_eq_u32_e32 vcc_lo, 0, v10
	v_cvt_f32_ubyte0_e32 v7, v10
	v_xor_b32_e32 v10, 1, v10
	v_cndmask_b32_e64 v4, 0, s10, vcc_lo
	v_add_co_u32 v11, vcc_lo, v2, v8
	v_add_co_ci_u32_e32 v12, vcc_lo, v3, v9, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_3) | instid1(VALU_DEP_4)
	v_lshlrev_b64 v[2:3], 3, v[4:5]
	v_add_co_u32 v0, vcc_lo, v0, v8
	v_add_co_ci_u32_e32 v1, vcc_lo, v1, v9, vcc_lo
	v_cvt_f32_ubyte0_e32 v4, v10
	v_add_co_u32 v2, vcc_lo, v11, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, v12, v3, vcc_lo
.LBB0_4:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_co_u32 v8, vcc_lo, v0, s11
	v_add_co_ci_u32_e32 v9, vcc_lo, s8, v1, vcc_lo
	v_cvt_f32_u32_e32 v12, s7
	s_add_i32 s12, s12, -1
	s_clause 0x1
	flat_load_b64 v[10:11], v[0:1]
	flat_load_b64 v[8:9], v[8:9]
	v_add_co_u32 v0, vcc_lo, v0, 8
	v_mul_f32_e32 v12, v6, v12
	v_add_co_ci_u32_e32 v1, vcc_lo, 0, v1, vcc_lo
	s_add_i32 s7, s7, s6
	s_cmp_lg_u32 s12, 0
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_dual_sub_f32 v14, v11, v9 :: v_dual_sub_f32 v15, v10, v8
	v_dual_add_f32 v11, v11, v9 :: v_dual_mul_f32 v12, 0.15915494, v12
	s_delay_alu instid0(VALU_DEP_1)
	v_sin_f32_e32 v13, v12
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v9, v15, v13
	v_cos_f32_e32 v12, v12
	s_waitcnt_depctr 0xfff
	v_fma_f32 v9, v12, v14, -v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v9, v9, v4
	v_add_f32_e32 v10, v10, v8
	v_dual_mul_f32 v8, v13, v14 :: v_dual_fmac_f32 v9, v11, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v8, v15, v12
	v_mul_f32_e32 v8, v8, v4
	s_delay_alu instid0(VALU_DEP_1)
	v_fmac_f32_e32 v8, v10, v7
	flat_store_b64 v[2:3], v[8:9]
	v_add_co_u32 v2, vcc_lo, v2, 8
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	s_cbranch_scc1 .LBB0_4
; %bb.5:                                ; %_Z14butterfly_halfP7complexS0_jjj.exit.loopexit
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_clause 0x1
	global_load_b64 v[0:1], v5, s[0:1]
	global_load_b128 v[6:9], v5, s[4:5]
	s_waitcnt vmcnt(1)
	v_readfirstlane_b32 s6, v0
	v_readfirstlane_b32 s7, v1
	s_waitcnt vmcnt(0)
	v_dual_mov_b32 v2, v6 :: v_dual_mov_b32 v3, v7
	v_dual_mov_b32 v0, v8 :: v_dual_mov_b32 v1, v9
	s_branch .LBB0_7
.LBB0_6:                                ;   in Loop: Header=BB0_2 Depth=1
	v_dual_mov_b32 v7, v3 :: v_dual_mov_b32 v6, v2
	v_dual_mov_b32 v3, v1 :: v_dual_mov_b32 v2, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_dual_mov_b32 v0, v6 :: v_dual_mov_b32 v1, v7
.LBB0_7:                                ; %_Z14butterfly_halfP7complexS0_jjj.exit
                                        ;   in Loop: Header=BB0_2 Depth=1
	v_cvt_f32_u32_e32 v4, s7
	s_sub_i32 s11, 0, s7
	s_waitcnt lgkmcnt(0)
	global_store_b128 v5, v[0:3], s[4:5]
	v_rcp_iflag_f32_e32 v4, v4
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v4, 0x4f7ffffe, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_u32_f32_e32 v4, v4
	v_readfirstlane_b32 s8, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s11, s11, s8
	s_mul_hi_u32 s11, s8, s11
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_add_i32 s8, s8, s11
	s_mul_hi_u32 s8, s6, s8
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_mul_i32 s11, s8, s7
	s_add_i32 s12, s8, 1
	s_sub_i32 s11, s6, s11
	s_sub_i32 s13, s11, s7
	s_cmp_ge_u32 s11, s7
	s_cselect_b32 s8, s12, s8
	s_cselect_b32 s11, s13, s11
	s_add_i32 s12, s8, 1
	s_cmp_ge_u32 s11, s7
	s_mov_b32 s11, s9
	s_cselect_b32 s8, s12, s8
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_gt_u32 s10, s8
	s_mov_b32 s8, s10
	s_cbranch_scc1 .LBB0_2
.LBB0_8:                                ; %._crit_edge
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16run_funnel_stageP2tr
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 8
		.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 16
		.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	_Z16run_funnel_stageP2tr, .Lfunc_end0-_Z16run_funnel_stageP2tr
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1060
; NumSgprs: 18
; NumVgprs: 16
; ScratchSize: 0
; MemoryBound: 1
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 16
; 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	_Z14run_tube_stageP2tr  ; -- Begin function _Z14run_tube_stageP2tr
	.globl	_Z14run_tube_stageP2tr
	.p2align	8
	.type	_Z14run_tube_stageP2tr,@function
_Z14run_tube_stageP2tr:                 ; @_Z14run_tube_stageP2tr
; %bb.0:
	s_load_b64 s[6:7], s[0:1], 0x0
	s_mul_i32 s0, s15, 0x48
	s_mul_hi_u32 s1, s15, 0x48
	s_waitcnt lgkmcnt(0)
	s_add_u32 s0, s6, s0
	s_addc_u32 s1, s7, s1
	s_load_b64 s[10:11], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	v_cvt_f32_u32_e32 v0, s11
	s_sub_i32 s3, 0, s11
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v0, v0
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x4f7ffffe, v0
	v_cvt_u32_f32_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_readfirstlane_b32 s2, v0
	s_mul_i32 s3, s3, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s3, s2, s3
	s_add_i32 s2, s2, s3
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s2, s10, s2
	s_mul_i32 s3, s2, s11
	s_add_i32 s4, s2, 1
	s_sub_i32 s3, s10, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_sub_i32 s5, s3, s11
	s_cmp_ge_u32 s3, s11
	s_cselect_b32 s2, s4, s2
	s_cselect_b32 s3, s5, s3
	s_add_i32 s4, s2, 1
	s_cmp_ge_u32 s3, s11
	s_mov_b32 s3, 0
	s_cselect_b32 s4, s4, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_lt_u32 s4, 2
	s_cbranch_scc1 .LBB1_10
; %bb.1:                                ; %.lr.ph
	s_mul_i32 s2, s15, 0x48
	s_mul_hi_u32 s5, s15, 0x48
	s_add_u32 s6, s6, s2
	s_addc_u32 s7, s7, s5
	v_mov_b32_e32 v4, 0
	s_load_b32 s2, s[6:7], 0x8
	s_add_u32 s6, s6, 32
	s_addc_u32 s7, s7, 0
	s_waitcnt lgkmcnt(0)
	v_mov_b32_e32 v2, s2
.LBB1_2:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB1_4 Depth 2
                                        ;       Child Loop BB1_5 Depth 3
                                        ;       Child Loop BB1_7 Depth 3
	v_cvt_f32_u32_e32 v0, s11
	s_sub_i32 s2, 0, s11
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v0, v0
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x4f7ffffe, v0
	v_cvt_u32_f32_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v1, s2, v0
	s_lshr_b32 s2, s4, 1
	v_mul_hi_u32 v1, v0, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v0, v0, v1
	v_mul_hi_u32 v0, s10, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mul_lo_u32 v1, v0, s11
	v_add_nc_u32_e32 v3, 1, v0
	v_sub_nc_u32_e32 v1, s10, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v5, s11, v1
	v_cmp_le_u32_e32 vcc_lo, s11, v1
	v_dual_cndmask_b32 v1, v1, v5 :: v_dual_cndmask_b32 v0, v0, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cmp_le_u32_e32 vcc_lo, s11, v1
	v_add_nc_u32_e32 v3, 1, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v0, v0, v3, vcc_lo
	v_mul_lo_u32 v3, v2, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v0, v3, v0
	v_cmp_ge_u32_e32 vcc_lo, v3, v0
	s_cbranch_vccnz .LBB1_9
; %bb.3:                                ; %.lr.ph.i.i.lr.ph
                                        ;   in Loop: Header=BB1_2 Depth=1
	v_cvt_f32_u32_e32 v0, s4
	s_sub_i32 s5, 0, s4
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_lshl_b64 s[8:9], s[4:5], 2
	v_rcp_iflag_f32_e32 v0, v0
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x4f7ffffe, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_u32_f32_e32 v0, v0
	v_readfirstlane_b32 s11, v0
	s_delay_alu instid0(VALU_DEP_1)
	s_mul_i32 s12, s5, s11
	s_and_b32 s5, s9, 3
	s_mul_hi_u32 s9, s11, s12
	s_and_b32 s12, s8, -8
	s_add_i32 s13, s11, s9
	s_lshl_b64 s[8:9], s[2:3], 3
.LBB1_4:                                ; %.lr.ph.i.i
                                        ;   Parent Loop BB1_2 Depth=1
                                        ; =>  This Loop Header: Depth=2
                                        ;       Child Loop BB1_5 Depth 3
                                        ;       Child Loop BB1_7 Depth 3
	global_load_b128 v[5:8], v4, s[6:7]
	v_cvt_f32_u32_e32 v2, s10
	s_mul_hi_u32 s11, s10, s13
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_mul_i32 s14, s11, s4
	v_div_scale_f32 v0, null, v2, v2, 0x40c90fd8
	v_div_scale_f32 v11, vcc_lo, 0x40c90fd8, v2, 0x40c90fd8
	s_sub_i32 s10, s10, s14
	s_delay_alu instid0(VALU_DEP_2)
	v_rcp_f32_e32 v1, v0
	s_add_i32 s14, s11, 1
	s_sub_i32 s15, s10, s4
	s_cmp_ge_u32 s10, s4
	s_cselect_b32 s11, s14, s11
	s_cselect_b32 s10, s15, s10
	s_add_i32 s14, s11, 1
	s_cmp_ge_u32 s10, s4
	s_waitcnt_depctr 0xfff
	v_fma_f32 v9, -v0, v1, 1.0
	s_cselect_b32 s10, s14, s11
	s_mov_b32 s11, 0
	s_mov_b32 s14, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v1, v9, v1
	v_lshlrev_b64 v[9:10], 3, v[3:4]
	v_mul_f32_e32 v12, v11, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v13, -v0, v12, v11
	v_fmac_f32_e32 v12, v13, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v0, -v0, v12, v11
	v_div_fmas_f32 v11, v0, v1, v12
	s_delay_alu instid0(VALU_DEP_1)
	v_div_fixup_f32 v2, v11, v2, 0x40c90fd8
	s_waitcnt vmcnt(0)
	v_add_co_u32 v0, vcc_lo, v7, v9
	v_add_co_ci_u32_e32 v1, vcc_lo, v8, v10, vcc_lo
	v_add_co_u32 v5, vcc_lo, v5, v9
	v_add_co_ci_u32_e32 v6, vcc_lo, v6, v10, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_dual_mov_b32 v8, v1 :: v_dual_mov_b32 v7, v0
	v_dual_mov_b32 v10, v6 :: v_dual_mov_b32 v9, v5
.LBB1_5:                                ;   Parent Loop BB1_2 Depth=1
                                        ;     Parent Loop BB1_4 Depth=2
                                        ; =>    This Inner Loop Header: Depth=3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v11, vcc_lo, v9, s12
	v_add_co_ci_u32_e32 v12, vcc_lo, s5, v10, vcc_lo
	v_cvt_f32_u32_e32 v15, s11
	s_add_i32 s14, s14, -1
	s_clause 0x1
	flat_load_b64 v[13:14], v[9:10]
	flat_load_b64 v[11:12], v[11:12]
	v_add_co_u32 v9, vcc_lo, v9, 8
	v_add_co_ci_u32_e32 v10, vcc_lo, 0, v10, vcc_lo
	s_add_i32 s11, s11, s10
	s_cmp_lg_u32 s14, 0
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_dual_sub_f32 v17, v14, v12 :: v_dual_sub_f32 v18, v13, v11
	v_dual_add_f32 v11, v13, v11 :: v_dual_add_f32 v12, v14, v12
	v_mul_f32_e32 v15, v2, v15
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v15, 0.15915494, v15
	v_sin_f32_e32 v16, v15
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v14, v18, v16
	v_cos_f32_e32 v15, v15
	v_mul_f32_e32 v13, v16, v17
	s_waitcnt_depctr 0xfff
	v_fmac_f32_e32 v13, v18, v15
	v_fma_f32 v14, v15, v17, -v14
	s_delay_alu instid0(VALU_DEP_1)
	v_dual_fmac_f32 v11, 0, v13 :: v_dual_fmac_f32 v12, 0, v14
	flat_store_b64 v[7:8], v[11:12]
	v_add_co_u32 v7, vcc_lo, v7, 8
	v_add_co_ci_u32_e32 v8, vcc_lo, 0, v8, vcc_lo
	s_cbranch_scc1 .LBB1_5
; %bb.6:                                ; %_Z14butterfly_halfP7complexS0_jjj.exit.i
                                        ;   in Loop: Header=BB1_4 Depth=2
	s_mov_b32 s11, 0
	s_mov_b32 s14, s2
.LBB1_7:                                ;   Parent Loop BB1_2 Depth=1
                                        ;     Parent Loop BB1_4 Depth=2
                                        ; =>    This Inner Loop Header: Depth=3
	v_add_co_u32 v7, vcc_lo, v5, s8
	v_add_co_ci_u32_e32 v8, vcc_lo, s9, v6, vcc_lo
	v_cvt_f32_u32_e32 v11, s11
	s_add_i32 s14, s14, -1
	s_clause 0x1
	flat_load_b64 v[9:10], v[5:6]
	flat_load_b64 v[7:8], v[7:8]
	s_add_i32 s11, s11, s10
	s_cmp_lg_u32 s14, 0
	v_mul_f32_e32 v12, v2, v11
	v_add_co_u32 v11, vcc_lo, v0, s8
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_dual_sub_f32 v16, v10, v8 :: v_dual_sub_f32 v17, v9, v7
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_2) | instid1(VALU_DEP_3)
	v_mul_f32_e32 v13, 0.15915494, v12
	v_add_co_ci_u32_e32 v12, vcc_lo, s9, v1, vcc_lo
	v_add_co_u32 v0, vcc_lo, v0, 8
	v_sin_f32_e32 v14, v13
	v_cos_f32_e32 v15, v13
	v_dual_add_f32 v7, v9, v7 :: v_dual_add_f32 v8, v10, v8
	v_add_co_ci_u32_e32 v1, vcc_lo, 0, v1, vcc_lo
	v_add_co_u32 v5, vcc_lo, v5, 8
	v_add_co_ci_u32_e32 v6, vcc_lo, 0, v6, vcc_lo
	s_waitcnt_depctr 0xfff
	v_dual_mul_f32 v13, v14, v16 :: v_dual_mul_f32 v14, v17, v14
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f32 v14, v15, v16, -v14
	v_dual_fmac_f32 v13, v17, v15 :: v_dual_fmac_f32 v14, 0, v8
	s_delay_alu instid0(VALU_DEP_1)
	v_fmac_f32_e32 v13, 0, v7
	flat_store_b64 v[11:12], v[13:14]
	s_cbranch_scc1 .LBB1_7
; %bb.8:                                ; %_Z9butterflyP7complexS0_jj.exit
                                        ;   in Loop: Header=BB1_4 Depth=2
	global_load_b96 v[0:2], v4, s[0:1]
	v_add_nc_u32_e32 v3, s4, v3
	s_waitcnt vmcnt(0)
	v_readfirstlane_b32 s11, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cvt_f32_u32_e32 v1, s11
	s_sub_i32 s10, 0, s11
	v_rcp_iflag_f32_e32 v1, v1
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v1, 0x4f7ffffe, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_u32_f32_e32 v1, v1
	v_readfirstlane_b32 s14, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(SALU_CYCLE_1)
	s_mul_i32 s15, s10, s14
	v_readfirstlane_b32 s10, v0
	v_add_nc_u32_e32 v0, 1, v2
	s_mul_hi_u32 s15, s14, s15
	s_add_i32 s14, s14, s15
	s_delay_alu instid0(VALU_DEP_2) | instid1(SALU_CYCLE_1)
	s_mul_hi_u32 s14, s10, s14
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	s_mul_i32 s15, s14, s11
	s_add_i32 s16, s14, 1
	s_sub_i32 s15, s10, s15
	s_sub_i32 s17, s15, s11
	s_cmp_ge_u32 s15, s11
	s_cselect_b32 s14, s16, s14
	s_cselect_b32 s15, s17, s15
	s_add_i32 s16, s14, 1
	s_cmp_ge_u32 s15, s11
	s_cselect_b32 s14, s16, s14
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v0, v0, s14
	v_cmp_lt_u32_e32 vcc_lo, v3, v0
	s_cbranch_vccnz .LBB1_4
.LBB1_9:                                ; %._crit_edge
                                        ;   in Loop: Header=BB1_2 Depth=1
	global_load_b128 v[5:8], v4, s[6:7]
	s_cmp_gt_u32 s4, 3
	s_mov_b32 s4, s2
	s_waitcnt vmcnt(0)
	v_dual_mov_b32 v9, v5 :: v_dual_mov_b32 v10, v6
	global_store_b128 v4, v[7:10], s[6:7]
	s_cbranch_scc1 .LBB1_2
.LBB1_10:                               ; %._crit_edge27
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z14run_tube_stageP2tr
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 8
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 19
		.amdhsa_next_free_sgpr 18
		.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	_Z14run_tube_stageP2tr, .Lfunc_end1-_Z14run_tube_stageP2tr
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1236
; NumSgprs: 20
; NumVgprs: 19
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 20
; NumVGPRsForWavesPerEU: 19
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__const._Z5ilog2j.lookup_table,@object ; @__const._Z5ilog2j.lookup_table
	.section	.rodata,"a",@progbits
	.p2align	4, 0x0
__const._Z5ilog2j.lookup_table:
	.long	0                               ; 0x0
	.long	1                               ; 0x1
	.long	28                              ; 0x1c
	.long	2                               ; 0x2
	.long	29                              ; 0x1d
	.long	14                              ; 0xe
	.long	24                              ; 0x18
	.long	3                               ; 0x3
	.long	30                              ; 0x1e
	.long	22                              ; 0x16
	.long	20                              ; 0x14
	.long	15                              ; 0xf
	.long	25                              ; 0x19
	.long	17                              ; 0x11
	.long	4                               ; 0x4
	.long	8                               ; 0x8
	.long	31                              ; 0x1f
	.long	27                              ; 0x1b
	.long	13                              ; 0xd
	.long	23                              ; 0x17
	.long	21                              ; 0x15
	.long	19                              ; 0x13
	.long	16                              ; 0x10
	.long	7                               ; 0x7
	.long	26                              ; 0x1a
	.long	12                              ; 0xc
	.long	18                              ; 0x12
	.long	6                               ; 0x6
	.long	11                              ; 0xb
	.long	5                               ; 0x5
	.long	10                              ; 0xa
	.long	9                               ; 0x9
	.size	__const._Z5ilog2j.lookup_table, 128

	.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
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 8
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z16run_funnel_stageP2tr
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z16run_funnel_stageP2tr.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     16
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 8
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z14run_tube_stageP2tr
    .private_segment_fixed_size: 0
    .sgpr_count:     20
    .sgpr_spill_count: 0
    .symbol:         _Z14run_tube_stageP2tr.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     19
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
