// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movq %r8, %r12
movq %xmm1, 0x28(%rsp)
movq %xmm0, 0x48(%rsp)
movl %ecx, 0x1c(%rsp)
movl %edx, %r13d
movl %esi, %ebp
movq %rdi, 0x30(%rsp)
movl $0x18, %edi
callq 0x2130
movq %rax, %rbx
movl %r13d, %r15d
imull %ebp, %r15d
movl $0x4, %esi
movq %r15, %rdi
callq 0x20b0
movq %rax, 0x10(%rbx)
movl %r15d, (%rbx)
movq $0x0, 0x4(%rbx)
xorl %r14d, %r14d
movq %rbx, 0x40(%rsp)
movl %r14d, 0xc(%rbx)
movl %r13d, %eax
movq %rax, 0x8(%rsp)
leaq (,%rax,8), %r15
testl %r13d, %r13d
movq $-0x1, %rbx
cmovsq %rbx, %r15
movq %r15, %rdi
callq 0x2030
movq %rax, 0x10(%rsp)
movq %r15, %rdi
callq 0x2030
movq %rax, %r15
movl $0x10, %edi
callq 0x2130
movq %r12, (%rax)
movb $0x0, 0x8(%rax)
movq %rax, 0x38(%rsp)
movl %r14d, 0xc(%rax)
movl %ebp, 0x4(%rsp)
movl %ebp, %eax
movq %rax, 0x20(%rsp)
movl %r13d, 0x18(%rsp)
testl %r13d, %r13d
jle 0x3266
movslq 0x4(%rsp), %r14
leaq (,%r14,8), %r12
testl %r14d, %r14d
cmovsq %rbx, %r12
leal 0xf(%r14), %ebp
andl $-0x10, %ebp
movq 0x20(%rsp), %rax
decq %rax
movq %rax, %xmm0
pshufd $0x44, %xmm0, %xmm14    # xmm14 = xmm0[0,1,0,1]
xorl %ebx, %ebx
movdqa %xmm14, 0x50(%rsp)
movq %r14, %rdi
callq 0x2030
movq %rax, %r13
movq 0x10(%rsp), %rax
movq %r13, (%rax,%rbx,8)
movq %r12, %rdi
callq 0x2030
movdqa 0x33d0(%rip), %xmm15    # 0x60a0
movdqa 0x50(%rsp), %xmm14
movq %rax, (%r15,%rbx,8)
testl %r14d, %r14d
jle 0x3258
xorl %eax, %eax
movdqa 0x33a2(%rip), %xmm0     # 0x6090
movdqa 0x338a(%rip), %xmm1     # 0x6080
movdqa 0x3372(%rip), %xmm2     # 0x6070
movdqa 0x335a(%rip), %xmm3     # 0x6060
movdqa 0x3342(%rip), %xmm4     # 0x6050
movdqa 0x332a(%rip), %xmm5     # 0x6040
movdqa 0x3312(%rip), %xmm6     # 0x6030
movdqa 0x32fa(%rip), %xmm7     # 0x6020
movdqa %xmm14, %xmm8
pxor %xmm15, %xmm8
movdqa %xmm0, %xmm9
pxor %xmm15, %xmm9
movdqa %xmm9, %xmm11
pcmpgtd %xmm8, %xmm11
pshufd $0xa0, %xmm11, %xmm10   # xmm10 = xmm11[0,0,2,2]
pshuflw $0xe8, %xmm10, %xmm12   # xmm12 = xmm10[0,2,2,3,4,5,6,7]
pcmpeqd %xmm8, %xmm9
pshufd $0xf5, %xmm9, %xmm9     # xmm9 = xmm9[1,1,3,3]
pshuflw $0xe8, %xmm9, %xmm13    # xmm13 = xmm9[0,2,2,3,4,5,6,7]
pand %xmm12, %xmm13
pshufd $0xf5, %xmm11, %xmm11   # xmm11 = xmm11[1,1,3,3]
pshuflw $0xe8, %xmm11, %xmm12   # xmm12 = xmm11[0,2,2,3,4,5,6,7]
por %xmm13, %xmm12
pcmpeqd %xmm13, %xmm13
pxor %xmm13, %xmm12
packssdw %xmm12, %xmm12
movd %xmm12, %ecx
testb $0x1, %cl
je 0x2d96
movb $0x55, (%r13,%rax)
pand %xmm10, %xmm9
por %xmm11, %xmm9
packssdw %xmm9, %xmm9
pxor %xmm13, %xmm9
packssdw %xmm9, %xmm9
packsswb %xmm9, %xmm9
movd %xmm9, %ecx
shrl $0x8, %ecx
testb $0x1, %cl
je 0x2dc7
movb $0x55, 0x1(%r13,%rax)
movdqa %xmm1, %xmm10
pxor %xmm15, %xmm10
movdqa %xmm10, %xmm11
pcmpgtd %xmm8, %xmm11
pshufd $0xa0, %xmm11, %xmm9    # xmm9 = xmm11[0,0,2,2]
pcmpeqd %xmm8, %xmm10
pshufd $0xf5, %xmm10, %xmm10   # xmm10 = xmm10[1,1,3,3]
movdqa %xmm10, %xmm12
pand %xmm9, %xmm12
pshufd $0xf5, %xmm11, %xmm11   # xmm11 = xmm11[1,1,3,3]
por %xmm11, %xmm12
packssdw %xmm12, %xmm12
pxor %xmm13, %xmm12
packssdw %xmm12, %xmm12
packsswb %xmm12, %xmm12
movd %xmm12, %ecx
shrl $0x10, %ecx
testb $0x1, %cl
je 0x2e28
movb $0x55, 0x2(%r13,%rax)
pshufhw $0x84, %xmm9, %xmm9     # xmm9 = xmm9[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm10, %xmm10   # xmm10 = xmm10[0,1,2,3,4,5,4,6]
pand %xmm9, %xmm10
pshufhw $0x84, %xmm11, %xmm9    # xmm9 = xmm11[0,1,2,3,4,5,4,6]
por %xmm10, %xmm9
pxor %xmm13, %xmm9
packssdw %xmm9, %xmm9
packsswb %xmm9, %xmm9
movd %xmm9, %ecx
shrl $0x18, %ecx
testb $0x1, %cl
je 0x2e66
movb $0x55, 0x3(%r13,%rax)
movdqa %xmm2, %xmm9
pxor %xmm15, %xmm9
movdqa %xmm9, %xmm11
pcmpgtd %xmm8, %xmm11
pshufd $0xa0, %xmm11, %xmm10   # xmm10 = xmm11[0,0,2,2]
pshuflw $0xe8, %xmm10, %xmm12   # xmm12 = xmm10[0,2,2,3,4,5,6,7]
pcmpeqd %xmm8, %xmm9
pshufd $0xf5, %xmm9, %xmm9     # xmm9 = xmm9[1,1,3,3]
pshuflw $0xe8, %xmm9, %xmm13    # xmm13 = xmm9[0,2,2,3,4,5,6,7]
pand %xmm12, %xmm13
pshufd $0xf5, %xmm11, %xmm11   # xmm11 = xmm11[1,1,3,3]
pshuflw $0xe8, %xmm11, %xmm12   # xmm12 = xmm11[0,2,2,3,4,5,6,7]
por %xmm13, %xmm12
pcmpeqd %xmm13, %xmm13
pxor %xmm13, %xmm12
packssdw %xmm12, %xmm12
packsswb %xmm12, %xmm12
pextrw $0x2, %xmm12, %ecx
testb $0x1, %cl
je 0x2ed2
movb $0x55, 0x4(%r13,%rax)
pand %xmm10, %xmm9
por %xmm11, %xmm9
packssdw %xmm9, %xmm9
pxor %xmm13, %xmm9
packssdw %xmm9, %xmm9
packsswb %xmm9, %xmm9
pextrw $0x2, %xmm9, %ecx
shrl $0x8, %ecx
testb $0x1, %cl
je 0x2f04
movb $0x55, 0x5(%r13,%rax)
movdqa %xmm3, %xmm10
pxor %xmm15, %xmm10
movdqa %xmm10, %xmm11
pcmpgtd %xmm8, %xmm11
pshufd $0xa0, %xmm11, %xmm9    # xmm9 = xmm11[0,0,2,2]
pcmpeqd %xmm8, %xmm10
pshufd $0xf5, %xmm10, %xmm10   # xmm10 = xmm10[1,1,3,3]
movdqa %xmm10, %xmm12
pand %xmm9, %xmm12
pshufd $0xf5, %xmm11, %xmm11   # xmm11 = xmm11[1,1,3,3]
por %xmm11, %xmm12
packssdw %xmm12, %xmm12
pxor %xmm13, %xmm12
packssdw %xmm12, %xmm12
packsswb %xmm12, %xmm12
pextrw $0x3, %xmm12, %ecx
testb $0x1, %cl
je 0x2f63
movb $0x55, 0x6(%r13,%rax)
pshufhw $0x84, %xmm9, %xmm9     # xmm9 = xmm9[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm10, %xmm10   # xmm10 = xmm10[0,1,2,3,4,5,4,6]
pand %xmm9, %xmm10
pshufhw $0x84, %xmm11, %xmm9    # xmm9 = xmm11[0,1,2,3,4,5,4,6]
por %xmm10, %xmm9
pxor %xmm13, %xmm9
packssdw %xmm9, %xmm9
packsswb %xmm9, %xmm9
pextrw $0x3, %xmm9, %ecx
shrl $0x8, %ecx
testb $0x1, %cl
je 0x2fa2
movb $0x55, 0x7(%r13,%rax)
movdqa %xmm4, %xmm9
pxor %xmm15, %xmm9
movdqa %xmm9, %xmm11
pcmpgtd %xmm8, %xmm11
pshufd $0xa0, %xmm11, %xmm10   # xmm10 = xmm11[0,0,2,2]
pshuflw $0xe8, %xmm10, %xmm12   # xmm12 = xmm10[0,2,2,3,4,5,6,7]
pcmpeqd %xmm8, %xmm9
pshufd $0xf5, %xmm9, %xmm9     # xmm9 = xmm9[1,1,3,3]
pshuflw $0xe8, %xmm9, %xmm13    # xmm13 = xmm9[0,2,2,3,4,5,6,7]
pand %xmm12, %xmm13
pshufd $0xf5, %xmm11, %xmm11   # xmm11 = xmm11[1,1,3,3]
pshuflw $0xe8, %xmm11, %xmm12   # xmm12 = xmm11[0,2,2,3,4,5,6,7]
por %xmm13, %xmm12
pcmpeqd %xmm13, %xmm13
pxor %xmm13, %xmm12
packssdw %xmm12, %xmm12
packsswb %xmm12, %xmm12
pextrw $0x4, %xmm12, %ecx
testb $0x1, %cl
je 0x300e
movb $0x55, 0x8(%r13,%rax)
pand %xmm10, %xmm9
por %xmm11, %xmm9
packssdw %xmm9, %xmm9
pxor %xmm13, %xmm9
packssdw %xmm9, %xmm9
packsswb %xmm9, %xmm9
pextrw $0x4, %xmm9, %ecx
shrl $0x8, %ecx
testb $0x1, %cl
je 0x3040
movb $0x55, 0x9(%r13,%rax)
movdqa %xmm5, %xmm10
pxor %xmm15, %xmm10
movdqa %xmm10, %xmm11
pcmpgtd %xmm8, %xmm11
pshufd $0xa0, %xmm11, %xmm9    # xmm9 = xmm11[0,0,2,2]
pcmpeqd %xmm8, %xmm10
pshufd $0xf5, %xmm10, %xmm10   # xmm10 = xmm10[1,1,3,3]
movdqa %xmm10, %xmm12
pand %xmm9, %xmm12
pshufd $0xf5, %xmm11, %xmm11   # xmm11 = xmm11[1,1,3,3]
por %xmm11, %xmm12
packssdw %xmm12, %xmm12
pxor %xmm13, %xmm12
packssdw %xmm12, %xmm12
packsswb %xmm12, %xmm12
pextrw $0x5, %xmm12, %ecx
testb $0x1, %cl
je 0x309f
movb $0x55, 0xa(%r13,%rax)
pshufhw $0x84, %xmm9, %xmm9     # xmm9 = xmm9[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm10, %xmm10   # xmm10 = xmm10[0,1,2,3,4,5,4,6]
pand %xmm9, %xmm10
pshufhw $0x84, %xmm11, %xmm9    # xmm9 = xmm11[0,1,2,3,4,5,4,6]
por %xmm10, %xmm9
pxor %xmm13, %xmm9
packssdw %xmm9, %xmm9
packsswb %xmm9, %xmm9
pextrw $0x5, %xmm9, %ecx
shrl $0x8, %ecx
testb $0x1, %cl
je 0x30de
movb $0x55, 0xb(%r13,%rax)
movdqa %xmm6, %xmm9
pxor %xmm15, %xmm9
movdqa %xmm9, %xmm11
pcmpgtd %xmm8, %xmm11
pshufd $0xa0, %xmm11, %xmm10   # xmm10 = xmm11[0,0,2,2]
pshuflw $0xe8, %xmm10, %xmm12   # xmm12 = xmm10[0,2,2,3,4,5,6,7]
pcmpeqd %xmm8, %xmm9
pshufd $0xf5, %xmm9, %xmm9     # xmm9 = xmm9[1,1,3,3]
pshuflw $0xe8, %xmm9, %xmm13    # xmm13 = xmm9[0,2,2,3,4,5,6,7]
pand %xmm12, %xmm13
pshufd $0xf5, %xmm11, %xmm11   # xmm11 = xmm11[1,1,3,3]
pshuflw $0xe8, %xmm11, %xmm12   # xmm12 = xmm11[0,2,2,3,4,5,6,7]
por %xmm13, %xmm12
pcmpeqd %xmm13, %xmm13
pxor %xmm13, %xmm12
packssdw %xmm12, %xmm12
packsswb %xmm12, %xmm12
pextrw $0x6, %xmm12, %ecx
testb $0x1, %cl
je 0x314a
movb $0x55, 0xc(%r13,%rax)
pand %xmm10, %xmm9
por %xmm11, %xmm9
packssdw %xmm9, %xmm9
pxor %xmm13, %xmm9
packssdw %xmm9, %xmm9
packsswb %xmm9, %xmm9
pextrw $0x6, %xmm9, %ecx
shrl $0x8, %ecx
testb $0x1, %cl
je 0x317c
movb $0x55, 0xd(%r13,%rax)
movdqa %xmm7, %xmm10
pxor %xmm15, %xmm10
movdqa %xmm10, %xmm11
pcmpgtd %xmm8, %xmm11
pshufd $0xa0, %xmm11, %xmm9    # xmm9 = xmm11[0,0,2,2]
pcmpeqd %xmm8, %xmm10
pshufd $0xf5, %xmm10, %xmm8    # xmm8 = xmm10[1,1,3,3]
movdqa %xmm8, %xmm12
pand %xmm9, %xmm12
pshufd $0xf5, %xmm11, %xmm10   # xmm10 = xmm11[1,1,3,3]
por %xmm10, %xmm12
packssdw %xmm12, %xmm11
pxor %xmm13, %xmm11
packssdw %xmm11, %xmm11
packsswb %xmm11, %xmm11
pextrw $0x7, %xmm11, %ecx
testb $0x1, %cl
je 0x31db
movb $0x55, 0xe(%r13,%rax)
pshufhw $0x84, %xmm9, %xmm9     # xmm9 = xmm9[0,1,2,3,4,5,4,6]
pshufhw $0x84, %xmm8, %xmm8     # xmm8 = xmm8[0,1,2,3,4,5,4,6]
pand %xmm9, %xmm8
pshufhw $0x84, %xmm10, %xmm9    # xmm9 = xmm10[0,1,2,3,4,5,4,6]
por %xmm8, %xmm9
pxor %xmm13, %xmm9
packssdw %xmm9, %xmm8
packsswb %xmm8, %xmm8
pextrw $0x7, %xmm8, %ecx
shrl $0x8, %ecx
testb $0x1, %cl
je 0x321a
movb $0x55, 0xf(%r13,%rax)
addq $0x10, %rax
movdqa 0x2e89(%rip), %xmm8     # 0x60b0
paddq %xmm8, %xmm0
paddq %xmm8, %xmm1
paddq %xmm8, %xmm2
paddq %xmm8, %xmm3
paddq %xmm8, %xmm4
paddq %xmm8, %xmm5
paddq %xmm8, %xmm6
paddq %xmm8, %xmm7
cmpq %rax, %rbp
jne 0x2d26
incq %rbx
cmpq 0x8(%rsp), %rbx
jne 0x2cab
cvttsd2si 0x28(%rsp), %r14d
movq 0x40(%rsp), %r10
movq 0x38(%rsp), %rax
movq %r15, 0x8(%rsp)
movl 0x18(%rsp), %ebx
movq 0x30(%rsp), %rbp
movq 0x8(%rsp), %r12
movq %rbp, %rdi
movl 0x4(%rsp), %esi
movl %ebx, %edx
movl 0x1c(%rsp), %ecx
movl %esi, %r8d
movl %ebx, %r9d
pushq %rax
pushq %r12
pushq %r10
pushq 0x28(%rsp)
movl $0x0, %r11d
pushq %r11
pushq %r14
pushq %r11
pushq %r11
movq %rax, %r13
movq %r10, %r15
callq 0x268f
addq $0x40, %rsp
movq %rbp, %rdi
movl %r14d, %esi
movq %r15, %rdx
movq %r12, %rcx
movq %r13, %r8
callq 0x2ad3
movq %r15, %r10
movl %r14d, %eax
shrl $0x1f, %eax
addl %r14d, %eax
sarl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
ucomisd 0x48(%rsp), %xmm0
movl %eax, %r14d
movq %r13, %rax
ja 0x328a
cmpl $0x0, 0x4(%rsp)
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rbp
movq 0x20(%rsp), %r12
jle 0x3337
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
movl $0x1, %esi
callq 0x2140
movq (%rbp,%rbx,8), %rdi
movl $0x8, %esi
callq 0x2140
incq %rbx
cmpq %rbx, %r12
jne 0x3312
movl $0x8, %esi
movq %r14, %rdi
callq 0x2140
movl $0x8, %esi
movq %rbp, %rdi
callq 0x2140
movq %r15, %rdi
callq 0x4fbe
movl $0x18, %esi
movq %r15, %rdi
callq 0x2140
movl $0x10, %esi
movq %r13, %rdi
callq 0x2140