// File: /workspace/github_cpp_makefile_star2_O2/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 0xe81f4
movl %edi, %ebx
cmpl $0x4, %edi
jbe 0xe81fc
pushq $-0xb
jmp 0xe81f6
pushq $-0xa
popq %rbx
jmp 0xe8479
movl %esi, %r14d
movl %ebx, %edi
callq 0xe8101
movl %ebx, %r15d
imulq $0x194, %r15, %rax      # imm = 0x194
imulq $0x328, %r15, %rcx      # imm = 0x328
pushq $0x1
popq %rdx
xorl %edi, %edi
leaq 0x355c8d(%rip), %r8     # 0x43deb0
leaq 0x356af6(%rip), %r9     # 0x43ed20
leaq 0x355e1f(%rip), %r10    # 0x43e050
movabsq $-0x3a0bce1f051928df, %rsi # imm = 0xC5F431E0FAE6D721
cmpq $0x80, %rdi
je 0xe8261
movl %edx, (%rdi,%r8)
leaq (%rax,%rdi), %r11
andl $0x0, (%r9,%r11)
addl %edx, %edx
leaq (%rcx,%rdi,2), %r11
movq %rsi, (%r10,%r11)
addq $0x4, %rdi
jmp 0xe823b
leaq 0x357148(%rip), %rax    # 0x43f3b0
leaq 0x357121(%rip), %rcx    # 0x43f390
movq %rsi, (%rax,%r15,8)
leaq 0x3570f6(%rip), %rax    # 0x43f370
movq %rsi, (%rax,%r15,8)
movabsq $0x45f431e0fae6d721, %rax # imm = 0x45F431E0FAE6D721
movq %rax, (%rcx,%r15,8)
pushq $0x1
popq %rax
xorl %ebx, %ebx
cmpl %r14d, %eax
jg 0xe829d
addl %eax, %eax
incq %rbx
jmp 0xe8291
movl %ebx, 0x357151(%rip)    # 0x43f3f4
pushq $0x2
popq %rcx
cltd
idivl %ecx
movl %eax, 0x357141(%rip)    # 0x43f3f0
movslq %eax, %r14
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x9220
leaq 0x356a2c(%rip), %rcx    # 0x43ecf0
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0xe82ec
testl %ebx, %ebx
je 0xe8314
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x9220
movq %rax, %r13
leaq 0x3570ea(%rip), %rax    # 0x43f3d0
movq %r13, (%rax,%r15,8)
jmp 0xe831f
movups 0x375ad(%rip), %xmm0    # 0x11f8a0
leaq 0x23df26(%rip), %rax    # 0x326220
movaps %xmm0, 0x10(%rax)
movups 0x3758b(%rip), %xmm0    # 0x11f890
movaps %xmm0, (%rax)
movl $0x726566, 0x20(%rax)   # imm = 0x726566
jmp 0xe840e
leaq 0x3570b5(%rip), %rax    # 0x43f3d0
movq (%rax,%r15,8), %r13
testq %r13, %r13
je 0xe83eb
movq %r14, -0x38(%rbp)
xorl %r12d, %r12d
leaq 0x35709a(%rip), %r14    # 0x43f3d0
movq %rbx, %rax
movq %r15, -0x30(%rbp)
subq $0x1, %rax
jb 0xe8479
movq %rax, -0x40(%rbp)
movq %rbx, %rdi
pushq $0x10
popq %rsi
callq 0x9220
movq %rax, (%r13,%r12)
movq (%r14,%r15,8), %rax
movq (%rax,%r12), %r13
testq %r13, %r13
je 0xe8412
movq -0x38(%rbp), %r15
movq %r15, %rdi
pushq $0x8
popq %rsi
callq 0x9220
movq %rax, (%r13)
movq -0x30(%rbp), %rax
movq (%r14,%rax,8), %rax
movq (%rax,%r12), %r13
cmpq $0x0, (%r13)
je 0xe8440
movq %r15, %rdi
pushq $0x8
popq %rsi
callq 0x9220
movq %rax, 0x8(%r13)
movq -0x30(%rbp), %r15
movq (%r14,%r15,8), %r13
movq (%r13,%r12), %rax
addq $0x8, %r12
cmpq $0x0, 0x8(%rax)
movq -0x40(%rbp), %rax
jne 0xe833d
movups 0x37573(%rip), %xmm0    # 0x11f93f
leaq 0x23de4d(%rip), %rax    # 0x326220
movups %xmm0, 0x19(%rax)
movups 0x37558(%rip), %xmm0    # 0x11f936
movaps %xmm0, 0x10(%rax)
movups 0x3753d(%rip), %xmm0    # 0x11f926
jmp 0xe8464
movups 0x374d2(%rip), %xmm0    # 0x11f8c4
leaq 0x23de27(%rip), %rax    # 0x326220
movaps %xmm0, 0x10(%rax)
movups 0x374b0(%rip), %xmm0    # 0x11f8b4
movaps %xmm0, (%rax)
movl $0x737961, 0x20(%rax)   # imm = 0x737961
xorl %ebx, %ebx
jmp 0xe846a
movups 0x374cf(%rip), %xmm0    # 0x11f8e8
leaq 0x23de00(%rip), %rax    # 0x326220
movaps %xmm0, 0x10(%rax)
movups 0x374ad(%rip), %xmm0    # 0x11f8d8
movaps %xmm0, (%rax)
movabsq $0x73796172726120, %rcx # imm = 0x73796172726120
movq %rcx, 0x1d(%rax)
pushq $-0x1
jmp 0xe8469
movups 0x374cf(%rip), %xmm0    # 0x11f916
leaq 0x23ddd2(%rip), %rax    # 0x326220
movups %xmm0, 0x19(%rax)
movups 0x374b4(%rip), %xmm0    # 0x11f90d
movaps %xmm0, 0x10(%rax)
movups 0x37499(%rip), %xmm0    # 0x11f8fd
movaps %xmm0, (%rax)
pushq $-0x2
popq %rbx
leaq 0x23ddaf(%rip), %rsi    # 0x326220
pushq $0x32
popq %rdi
callq 0xb290
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq