// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movq %r8, 0x8(%rsp)
movsd %xmm1, 0x38(%rsp)
movsd %xmm0, 0x50(%rsp)
movl %ecx, 0x20(%rsp)
movl %edx, %ebp
movl %esi, %r13d
movq %rdi, 0x48(%rsp)
pushq $0x18
popq %rdi
callq 0x2110
movl %ebp, %esi
imull %r13d, %esi
movq %rax, 0x30(%rsp)
movq %rax, %rdi
callq 0x457e
movl %ebp, %ebx
shlq $0x3, %rbx
xorl %r14d, %r14d
testl %ebp, %ebp
pushq $-0x1
popq %r15
cmovsq %r15, %rbx
movl $0x0, %eax
movl %ebp, 0x24(%rsp)
cmovgl %ebp, %eax
movq %rax, 0x40(%rsp)
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
callq 0x2030
movq %rax, %rbx
pushq $0x10
popq %rdi
callq 0x2110
movq %rbx, %rdx
movl %r13d, %esi
movq 0x8(%rsp), %rcx
movq %rcx, (%rax)
movb $0x0, 0x8(%rax)
movslq %r13d, %rcx
andl $0x0, 0xc(%rax)
leaq (,%rcx,8), %rbp
movq %rcx, %r12
testl %ecx, %ecx
cmovsq %r15, %rbp
movl $0x0, %ebx
cmovgl %r13d, %ebx
movl %r13d, 0x8(%rsp)
movq %rax, 0x28(%rsp)
movq %rdx, 0x10(%rsp)
cmpq 0x40(%rsp), %r14
je 0x2bf7
movq %r12, %rdi
callq 0x2030
movq %rax, %r13
movq 0x18(%rsp), %rax
movq %r13, (%rax,%r14,8)
movq %rbp, %rdi
callq 0x2030
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %rdx
movq %rax, (%rdx,%r14,8)
xorl %ecx, %ecx
cmpq %rcx, %rbx
je 0x2bf2
movb $0x55, (%r13,%rcx)
incq %rcx
jmp 0x2be2
incq %r14
jmp 0x2bb0
cvttsd2si 0x38(%rsp), %r14d
movq 0x48(%rsp), %r15
movq 0x28(%rsp), %r13
movq 0x10(%rsp), %rbp
movq 0x30(%rsp), %r12
movq %r15, %rdi
movl 0x24(%rsp), %edx
movl 0x20(%rsp), %ecx
movl 0x8(%rsp), %r8d
movl %edx, %r9d
pushq %r13
pushq %rbp
pushq %r12
pushq 0x30(%rsp)
pushq $0x0
pushq %r14
pushq $0x0
pushq $0x0
callq 0x267c
addq $0x40, %rsp
movq %r15, %rdi
movl %r14d, %esi
movq %r12, %rdx
movq %rbp, %rcx
movq %r13, %r8
callq 0x2a31
movl 0x8(%rsp), %esi
movl %r14d, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl %eax, %r14d
cvtsi2sd %eax, %xmm0
ucomisd 0x50(%rsp), %xmm0
ja 0x2c12
xorl %r13d, %r13d
pushq $0x1
popq %r12
pushq $0x8
popq %r14
movq 0x18(%rsp), %rbp
cmpq %r13, %rbx
je 0x2ca7
movq (%rbp,%r13,8), %rdi
movq %r12, %rsi
callq 0x2120
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rdi
movq %r14, %rsi
callq 0x2120
incq %r13
jmp 0x2c7f
pushq $0x8
popq %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x2120
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x2120
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x45aa
pushq $0x18
popq %rsi
movq %rbx, %rdi
callq 0x2120
pushq $0x10
popq %rsi
movq 0x28(%rsp), %rdi
callq 0x2120