// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathmsc.cpp
// Function: alloc_mtie_data(int, int)
int alloc_mtie_data(int id, int mtie_size)
{
int tau;
int i;

   // alloc mtie tau array, initialize it, and return number of bins
   if(id < 0) return (-10);
   if(id > MAX_MTIE_CHANS) return (-11);

   free_mtie_data(id); // free old info

   tau = 1;
   for(i=0; i<32; i++) {    // calculate powers of 2 table
      pow2[i] = tau;
      tau *= 2;
      mtie_intervals[id][i] = 0;   // init MTIE results table
      mtie[id][i] = (-BIG_NUM);  // init MTIE results table
      mtie0[id] = (-BIG_NUM);
      mtie_max[id] = (-BIG_NUM);
      mtie_min[id] = (BIG_NUM);
   }

   tau = 1;
   mtie_kmax = 0;
   while(1) { // calculate mtie bin count
      if(tau > mtie_size) break;
if(0 && debug_file) fprintf(debug_file, "MTIE_TAU %d: %d\n", mtie_kmax, tau);
      tau *= 2;
      ++mtie_kmax;
   }
   max_mtie_samples = tau/2;
if(0 && debug_file) fprintf(debug_file, "MAX_MTIE_SAMPLES: %d\n", max_mtie_samples);

   mtie_buf[id] = (double *) calloc(max_mtie_samples, sizeof(double));
   if(mtie_buf[id] == 0) {
      sprintf(out, "Could not allocate MTIE data buffer");
      error_exit(50, out);
      return 0;
   }

   if(mtie_kmax) {  // allocate mtie bins
      mtie_taus[id] = (struct MTIE_TAU *) calloc(mtie_kmax, sizeof(struct MTIE_TAU));
   }
   if(mtie_taus[id] == 0) {
      sprintf(out, "Could not allocate MTIE data arrays");
      error_exit(50, out);
      return 0;
   }

   tau = 1;
   i = 0;
   while(i < mtie_kmax) { // allocate and initialize mtie bins
//    mtie_taus[id][i].tau = tau;
if(0 && debug_file) fprintf(debug_file, "MTIE_TAU[%d] %d\n", i, tau);
//    mtie_taus[id][i].val = 0.0;
      mtie_taus[id][i].vals = (struct MTIE_VALS *) calloc(mtie_kmax, sizeof(struct MTIE_VALS));
      if(mtie_taus[id][i].vals == 0) {
         sprintf(out, "Could not allocate MTIE value arrays");
         error_exit(50, out);
         return -1;
      }

      mtie_taus[id][i].vals->min_vals = (double *) calloc(max_mtie_samples, sizeof(double));
      if(mtie_taus[id][i].vals->min_vals == 0) {
         sprintf(out, "Could not allocate MTIE min value arrays");
         error_exit(50, out);
         return (-2);
      }

      mtie_taus[id][i].vals->max_vals = (double *) calloc(max_mtie_samples, sizeof(double));
      if(mtie_taus[id][i].vals->max_vals == 0) {
         sprintf(out, "Could not allocate MTIE max value arrays");
         error_exit(50, out);
         return (-2);
      }

      tau *= 2;
      ++i;
   }

   return mtie_kmax;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testl %edi, %edi
js 0xfe155
movl %edi, %r15d
movl $0xfffffff5, %ebx       # imm = 0xFFFFFFF5
cmpl $0x4, %edi
ja 0xfe2cf
movl %esi, %r14d
movl %r15d, %edi
callq 0xfdf73
movl %r15d, %r13d
imulq $0x194, %r13, %rax      # imm = 0x194
leaq 0x356c7a(%rip), %rcx    # 0x454d20
xorps %xmm0, %xmm0
movups %xmm0, 0x70(%rax,%rcx)
movups %xmm0, 0x60(%rax,%rcx)
movups %xmm0, 0x50(%rax,%rcx)
movups %xmm0, 0x40(%rax,%rcx)
movups %xmm0, 0x30(%rax,%rcx)
movups %xmm0, 0x20(%rax,%rcx)
movups %xmm0, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
imulq $0x328, %r13, %rax      # imm = 0x328
movl $0x1, %edx
xorl %esi, %esi
leaq 0x355dcb(%rip), %rdi    # 0x453eb0
leaq 0x355f64(%rip), %r8     # 0x454050
movabsq $-0x3a0bce1f051928df, %rcx # imm = 0xC5F431E0FAE6D721
movl %edx, (%rsi,%rdi)
addl %edx, %edx
leaq (%rax,%rsi,2), %r9
movq %rcx, (%r8,%r9)
addq $0x4, %rsi
cmpq $0x80, %rsi
jne 0xfe0f6
leaq 0x357299(%rip), %rax    # 0x4553b0
leaq 0x357272(%rip), %rdx    # 0x455390
movq %rcx, (%rax,%r13,8)
leaq 0x357247(%rip), %rax    # 0x455370
movq %rcx, (%rax,%r13,8)
movabsq $0x45f431e0fae6d721, %rax # imm = 0x45F431E0FAE6D721
movq %rax, (%rdx,%r13,8)
xorl %ebx, %ebx
testl %r14d, %r14d
jle 0xfe15f
movl $0x1, %ecx
movl %ecx, %eax
leal (%rax,%rax), %ecx
incl %ebx
cmpl %r14d, %ecx
jle 0xfe147
jmp 0xfe161
movl $0xfffffff6, %ebx       # imm = 0xFFFFFFF6
jmp 0xfe2cf
xorl %eax, %eax
movl %ebx, 0x35728d(%rip)    # 0x4553f4
movl %eax, 0x357283(%rip)    # 0x4553f0
movslq %eax, %r14
movl $0x8, %esi
movq %r14, %rdi
callq 0x9230
leaq 0x356b6c(%rip), %rcx    # 0x454cf0
movq %rax, (%rcx,%r13,8)
testq %rax, %rax
je 0xfe264
testl %ebx, %ebx
je 0xfe289
movl %ebx, %edi
movl $0x8, %esi
movq %rdi, -0x30(%rbp)
callq 0x9230
movq %rax, %r12
leaq 0x35721d(%rip), %rax    # 0x4553d0
movq %r12, (%rax,%r13,8)
testq %r12, %r12
je 0xfe299
movq %r14, -0x38(%rbp)
xorl %r15d, %r15d
movq -0x30(%rbp), %rdi
movl $0x10, %esi
callq 0x9230
movq %rax, (%r12,%r15,8)
leaq 0x3571f0(%rip), %rax    # 0x4553d0
movq (%rax,%r13,8), %rax
movq (%rax,%r15,8), %r12
testq %r12, %r12
je 0xfe2e0
movl $0x8, %esi
movq %r13, %r14
movq -0x38(%rbp), %r13
movq %r13, %rdi
callq 0x9230
movq %rax, (%r12)
leaq 0x3571c0(%rip), %rax    # 0x4553d0
movq (%rax,%r14,8), %rax
movq (%rax,%r15,8), %r12
cmpq $0x0, (%r12)
je 0xfe311
movl $0x8, %esi
movq %r13, %rdi
callq 0x9230
leaq 0x357199(%rip), %rcx    # 0x4553d0
movq %rax, 0x8(%r12)
movq (%rcx,%r14,8), %r12
movq (%r12,%r15,8), %rax
cmpq $0x0, 0x8(%rax)
je 0xfe337
movq %r14, %r13
incq %r15
movq -0x30(%rbp), %rdi
cmpq %r15, %rdi
jne 0xfe1cb
jmp 0xfe2cf
movups 0x37715(%rip), %xmm0    # 0x135980
leaq 0x23dfae(%rip), %rax    # 0x33c220
movaps %xmm0, 0x10(%rax)
movups 0x376f3(%rip), %xmm0    # 0x135970
movaps %xmm0, (%rax)
movl $0x726566, 0x20(%rax)   # imm = 0x726566
jmp 0xfe2bc
leaq 0x357140(%rip), %rax    # 0x4553d0
xorl %ebx, %ebx
cmpq $0x0, (%rax,%r13,8)
jne 0xfe2cf
movups 0x37704(%rip), %xmm0    # 0x1359a4
leaq 0x23df79(%rip), %rax    # 0x33c220
movaps %xmm0, 0x10(%rax)
movups 0x376e2(%rip), %xmm0    # 0x135994
movaps %xmm0, (%rax)
movl $0x737961, 0x20(%rax)   # imm = 0x737961
xorl %ebx, %ebx
leaq 0x23df5b(%rip), %rsi    # 0x33c220
movl $0x32, %edi
callq 0xb424
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movups 0x376e1(%rip), %xmm0    # 0x1359c8
leaq 0x23df32(%rip), %rax    # 0x33c220
movaps %xmm0, 0x10(%rax)
movups 0x376bf(%rip), %xmm0    # 0x1359b8
movaps %xmm0, (%rax)
movabsq $0x73796172726120, %rcx # imm = 0x73796172726120
movq %rcx, 0x1d(%rax)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xfe2be
movups 0x376de(%rip), %xmm0    # 0x1359f6
leaq 0x23df01(%rip), %rax    # 0x33c220
movups %xmm0, 0x19(%rax)
movups 0x376c3(%rip), %xmm0    # 0x1359ed
movaps %xmm0, 0x10(%rax)
movups 0x376a8(%rip), %xmm0    # 0x1359dd
jmp 0xfe35b
movups 0x376e1(%rip), %xmm0    # 0x135a1f
leaq 0x23dedb(%rip), %rax    # 0x33c220
movups %xmm0, 0x19(%rax)
movups 0x376c6(%rip), %xmm0    # 0x135a16
movaps %xmm0, 0x10(%rax)
movups 0x376ab(%rip), %xmm0    # 0x135a06
movaps %xmm0, (%rax)
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
jmp 0xfe2be