// File: /workspace/github_cpp_makefile_star2_O1/kchan1[P]helloworld_test1/./encoder.hh
// Function: encode(double**, int, int, int, double, double, std::basic_ofstream<char, std::char_traits<char>>*)
int encode(double**image,int width,int height,int depth,double min_threshold,double max,std::ofstream*file_out)
{
  int threshold = max;
  //this holds the coding states of all the coefficients
  unsigned char**coded;
  //this colds all the reconstructed coefficients
  double**recon_coeff;
  //this is used to keep track of which coefficients need a subordinate pass
  IntQueue*sub_list;
  //for writing individual bits
  BitWriter*bitstream;
  int i,j;
  //initialization
  sub_list = new IntQueue(width*height);
  coded = new unsigned char*[height];
  recon_coeff = new double*[height];
  bitstream = new BitWriter(file_out);
  for(i=0;i<height;i++)
  {
    coded[i]=new unsigned char[width];
    recon_coeff[i]= new double[width];
    for(j=0;j<width;j++)
    {
      coded[i][j]='U';
    }
  }
  //do a dom and sub pass
  //we're going to be doing this at least once
  do
  {
    dominant_pass(image,width,height,depth,width,height,0,0,threshold,0,coded,sub_list,recon_coeff,bitstream);
    subordinate_pass(image,threshold,sub_list,recon_coeff,bitstream);
    threshold/=2;
  }
  while(threshold>min_threshold);
  for(i=0;i<width;i++)
  {
    delete coded[i];
    delete recon_coeff[i];
  }
  delete coded;
  delete recon_coeff;
  delete sub_list;
  delete bitstream;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x10(%rsp)
movsd %xmm1, 0x38(%rsp)
movsd %xmm0, 0x40(%rsp)
movl %ecx, 0x24(%rsp)
movl %edx, %r15d
movl %esi, %ebp
movq %rdi, 0x30(%rsp)
movl $0x18, %edi
callq 0x2130
movq %rax, %rbx
movl %r15d, %r14d
imull %ebp, %r14d
movl $0x4, %esi
movq %r14, %rdi
callq 0x20b0
movq %rax, 0x10(%rbx)
movl %r14d, (%rbx)
movq $0x0, 0x4(%rbx)
xorl %eax, %eax
movq %rbx, 0x28(%rsp)
movl %eax, 0xc(%rbx)
movl %r15d, 0xc(%rsp)
movslq %r15d, %r13
leaq (,%r13,8), %r14
testl %r13d, %r13d
movq $-0x1, %rbx
cmovsq %rbx, %r14
movq %r14, %rdi
callq 0x2030
movq %rax, %r12
movq %r14, %rdi
callq 0x2030
movq %rax, 0x18(%rsp)
movl $0x10, %edi
callq 0x2130
movq 0x10(%rsp), %rcx
movq %rcx, (%rax)
movb $0x0, 0x8(%rax)
movq %rax, 0x10(%rsp)
xorl %ecx, %ecx
movl %ecx, 0xc(%rax)
movl %ebp, 0x8(%rsp)
movl %ebp, %ebp
testl %r13d, %r13d
jle 0x2c4f
movslq 0x8(%rsp), %r14
leaq (,%r14,8), %r15
testl %r14d, %r14d
cmovsq %rbx, %r15
movl 0xc(%rsp), %ebx
xorl %r13d, %r13d
movq %r14, %rdi
callq 0x2030
movq %rax, (%r12,%r13,8)
movq %r15, %rdi
callq 0x2030
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
testl %r14d, %r14d
jle 0x2c47
xorl %eax, %eax
movq (%r12,%r13,8), %rcx
movb $0x55, (%rcx,%rax)
incq %rax
cmpq %rax, %rbp
jne 0x2c37
incq %r13
cmpq %rbx, %r13
jne 0x2c13
cvttsd2si 0x38(%rsp), %r14d
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rbx
movq 0x28(%rsp), %r13
movq 0x30(%rsp), %rdi
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
movl 0x24(%rsp), %ecx
movl %esi, %r8d
movl %edx, %r9d
pushq %r15
pushq %rbx
pushq %r13
pushq %r12
xorl %eax, %eax
pushq %rax
pushq %r14
pushq %rax
pushq %rax
callq 0x264f
addq $0x40, %rsp
movq 0x30(%rsp), %rdi
movl %r14d, %esi
movq %r13, %rdx
movq %rbx, %rcx
movq %r15, %r8
callq 0x2a5f
movl %r14d, %eax
shrl $0x1f, %eax
addl %r14d, %eax
sarl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
ucomisd 0x40(%rsp), %xmm0
movl %eax, %r14d
ja 0x2c65
cmpl $0x0, 0x8(%rsp)
movq 0x18(%rsp), %r14
movq 0x28(%rsp), %r15
jle 0x2d07
xorl %ebx, %ebx
movq (%r12,%rbx,8), %rdi
testq %rdi, %rdi
je 0x2cec
movl $0x1, %esi
callq 0x2140
movq (%r14,%rbx,8), %rdi
testq %rdi, %rdi
je 0x2cff
movl $0x8, %esi
callq 0x2140
incq %rbx
cmpq %rbx, %rbp
jne 0x2cd9
movl $0x8, %esi
movq %r12, %rdi
callq 0x2140
movl $0x8, %esi
movq %r14, %rdi
callq 0x2140
movq %r15, %rdi
callq 0x49da
movl $0x18, %esi
movq %r15, %rdi
callq 0x2140
movl $0x10, %esi
movq 0x10(%rsp), %rdi
callq 0x2140