// File: /workspace/github_cpp_makefile_star2_O1/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 0xfda79
movl %edi, %r15d
movl $0xfffffff5, %ebx       # imm = 0xFFFFFFF5
cmpl $0x4, %edi
jg 0xfdbea
movl %esi, %r14d
movl %r15d, %edi
callq 0xfd894
movl %r15d, %r12d
imulq $0x194, %r12, %rax      # imm = 0x194
leaq 0x357436(%rip), %rcx    # 0x454e00
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, %r12, %rax      # imm = 0x328
movl $0x1, %edx
xorl %esi, %esi
leaq 0x356587(%rip), %rdi    # 0x453f90
leaq 0x356720(%rip), %r8     # 0x454130
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 0xfda1a
leaq 0x357a55(%rip), %rax    # 0x455490
leaq 0x357a2e(%rip), %rdx    # 0x455470
movq %rcx, (%rax,%r12,8)
leaq 0x357a03(%rip), %rax    # 0x455450
movq %rcx, (%rax,%r12,8)
movabsq $0x45f431e0fae6d721, %rax # imm = 0x45F431E0FAE6D721
movq %rax, (%rdx,%r12,8)
xorl %ebx, %ebx
testl %r14d, %r14d
jle 0xfda83
movl $0x1, %ecx
movl %ecx, %eax
leal (%rax,%rax), %ecx
incl %ebx
cmpl %r14d, %ecx
jle 0xfda6b
jmp 0xfda85
movl $0xfffffff6, %ebx       # imm = 0xFFFFFFF6
jmp 0xfdbea
xorl %eax, %eax
movl %ebx, 0x357a49(%rip)    # 0x4554d4
movl %eax, 0x357a3f(%rip)    # 0x4554d0
movslq %eax, %r14
movl $0x8, %esi
movq %r14, %rdi
callq 0x9230
leaq 0x357328(%rip), %rcx    # 0x454dd0
movq %rax, (%rcx,%r12,8)
testq %rax, %rax
je 0xfdb8f
movl %ebx, %r13d
testl %ebx, %ebx
je 0xfdad4
movl $0x8, %esi
movq %r13, %rdi
callq 0x9230
leaq 0x3579e0(%rip), %rcx    # 0x4554b0
movq %rax, (%rcx,%r12,8)
leaq 0x3579d5(%rip), %rcx    # 0x4554b0
cmpq $0x0, (%rcx,%r12,8)
je 0xfdbb4
testl %ebx, %ebx
je 0xfdbea
movq %r14, -0x38(%rbp)
xorl %r15d, %r15d
movq %rcx, %r14
movq %r13, -0x30(%rbp)
movl $0x10, %esi
movq %r13, %rdi
callq 0x9230
movq (%r14,%r12,8), %rcx
movq %rax, (%rcx,%r15,8)
movq (%r14,%r12,8), %rax
movq (%rax,%r15,8), %r14
testq %r14, %r14
je 0xfdbfb
movl $0x8, %esi
movq -0x38(%rbp), %r13
movq %r13, %rdi
callq 0x9230
movq %rax, (%r14)
leaq 0x357973(%rip), %rax    # 0x4554b0
movq (%rax,%r12,8), %rax
movq (%rax,%r15,8), %r14
cmpq $0x0, (%r14)
je 0xfdc2c
movl $0x8, %esi
movq %r13, %rdi
callq 0x9230
movq %rax, 0x8(%r14)
leaq 0x357949(%rip), %rdx    # 0x4554b0
movq (%rdx,%r12,8), %rax
movq (%rax,%r15,8), %rax
cmpq $0x0, 0x8(%rax)
je 0xfdc52
movq %rdx, %r14
incq %r15
movq -0x30(%rbp), %r13
cmpq %r15, %r13
jne 0xfdafc
jmp 0xfdbea
movups 0x37cfa(%rip), %xmm0    # 0x135890
leaq 0x23e683(%rip), %rax    # 0x33c220
movaps %xmm0, 0x10(%rax)
movups 0x37cd8(%rip), %xmm0    # 0x135880
movaps %xmm0, (%rax)
movl $0x726566, 0x20(%rax)   # imm = 0x726566
jmp 0xfdbd7
movups 0x37cf9(%rip), %xmm0    # 0x1358b4
leaq 0x23e65e(%rip), %rax    # 0x33c220
movaps %xmm0, 0x10(%rax)
movups 0x37cd7(%rip), %xmm0    # 0x1358a4
movaps %xmm0, (%rax)
movl $0x737961, 0x20(%rax)   # imm = 0x737961
xorl %ebx, %ebx
leaq 0x23e640(%rip), %rsi    # 0x33c220
movl $0x32, %edi
callq 0xb425
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movups 0x37cd6(%rip), %xmm0    # 0x1358d8
leaq 0x23e617(%rip), %rax    # 0x33c220
movaps %xmm0, 0x10(%rax)
movups 0x37cb4(%rip), %xmm0    # 0x1358c8
movaps %xmm0, (%rax)
movabsq $0x73796172726120, %rcx # imm = 0x73796172726120
movq %rcx, 0x1d(%rax)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xfdbd9
movups 0x37cd3(%rip), %xmm0    # 0x135906
leaq 0x23e5e6(%rip), %rax    # 0x33c220
movups %xmm0, 0x19(%rax)
movups 0x37cb8(%rip), %xmm0    # 0x1358fd
movaps %xmm0, 0x10(%rax)
movups 0x37c9d(%rip), %xmm0    # 0x1358ed
jmp 0xfdc76
movups 0x37cd6(%rip), %xmm0    # 0x13592f
leaq 0x23e5c0(%rip), %rax    # 0x33c220
movups %xmm0, 0x19(%rax)
movups 0x37cbb(%rip), %xmm0    # 0x135926
movaps %xmm0, 0x10(%rax)
movups 0x37ca0(%rip), %xmm0    # 0x135916
movaps %xmm0, (%rax)
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
jmp 0xfdbd9