// File: /workspace/github_cpp_makefile_star2_O3/kchan1[P]helloworld_test1/./encoder.hh
// Function: dominant_pass(double**, int, int, int, int, int, int, int, int, int, unsigned char**, IntQueue*, double**, BitWriter*)
void dominant_pass(double**image,int orgwidth,int orgheight,int depth, int newwidth,int newheight,int origin_x,int origin_y,int threshold,int level, unsigned char**coded,IntQueue*sub_list,double**recon_coeff,BitWriter*bitstream)
{
  int i,j;
  char read;
  //if we are not at the roots of the zerotree forest
  if(level!=depth)
  {
    //actually do the coding
    for(i=0;i<newwidth;i++)
    {
      for(j=0;j<newheight;j++)
      {
	//for coded, T is part of a zerotree, C is coded, U is uncoded
	//if the coefficient is either coded already or is part of a zerotree, skip
	if(coded[i][j]=='T'||coded[i][j]=='C')
	  continue;
	//get the state of this specific coefficient
	read = isPNTZ(image,orgwidth,orgheight,depth,threshold,i,j);
	//11 positive
	//10 negative
	//01 zerotree root
	//00 isolated zero
	//0 level 0 zero
	switch(read)
	{
	case 'P':
	  bitstream->write(1);
	  bitstream->write(1);
	  coded[i][j]='C';
	  sub_list->NQ((i&0xFFFF)<<16 | (j&0xFFFF));
	  recon_coeff[i][j]=threshold+threshold/2;
	  break;
	case 'N':
	  bitstream->write(1);
	  bitstream->write(0);
	  coded[i][j]='C';
	  sub_list->NQ((i&0xFFFF)<<16 | (j&0xFFFF));
	  recon_coeff[i][j]=threshold+threshold/2;
	  break;
	case 'T':
	  bitstream->write(0);
	  bitstream->write(1);
	  markTree(orgwidth,orgheight,depth,i,j,coded);
	  break;
	case 'Z':
	  bitstream->write(0);
	  //only write that second zero if we aren't on the lowest level
	  if(i>orgwidth/2 || j>orgheight/2)
	    bitstream->write(0);
	  coded[i][j] = 'Z';
	  break;
	default:
	  std::cout<<"ERROR! UNKNOWN COEFFICIENT STATE ("<<i<<","<<j<<")\n";
	  break;
	}
      }
    }
  }
  else
  {
    //recurse on the next level
    dominant_pass(image,orgwidth,orgheight,depth,
		  newwidth/2,
		  newheight/2,
		  origin_x,
		  origin_y,
		  threshold,level+1,coded,sub_list,recon_coeff,bitstream);
    //TODO THIS ORDER IS NOT CLEAR?! I just do the +width first
    //recurse also on the LH, HL, and HH but they don't recurse themselves
    //LH?
    dominant_pass(image,orgwidth,orgheight,depth,
		  newwidth/2,
		  newheight/2,
		  origin_x+newwidth/2,
		  origin_y,
		  threshold,depth,coded,sub_list,recon_coeff,bitstream);
    //HL?
    dominant_pass(image,orgwidth,orgheight,depth,
		  newwidth/2,
		  newheight/2,
		  origin_x,
		  origin_y+newheight/2,
		  threshold,depth,coded,sub_list,recon_coeff,bitstream);
    //HH
    dominant_pass(image,orgwidth,orgheight,depth,
		  newwidth/2,
		  newheight/2,
		  origin_x+newwidth/2,
		  origin_y+newheight/2,
		  threshold,depth,coded,sub_list,recon_coeff,bitstream);
  }//end if level
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, %r14d
movq %rdi, %rbp
movq 0xc8(%rsp), %r12
movq 0xb0(%rsp), %rbx
movl 0xa8(%rsp), %ecx
movl 0xa0(%rsp), %r11d
cmpl %r14d, %ecx
jne 0x2832
movl %esi, 0x8(%rsp)
movq %rbp, 0x30(%rsp)
movl 0x98(%rsp), %eax
movq %rax, 0x10(%rsp)
movl %edx, 0xc(%rsp)
movl 0x90(%rsp), %ebx
movl 0xa8(%rsp), %eax
incl %eax
movq %rax, 0x28(%rsp)
movl %r9d, %r13d
movq 0x30(%rsp), %r14
movl 0xc(%rsp), %ebp
movl %r8d, %r12d
shrl $0x1f, %r12d
addl %r8d, %r12d
sarl %r12d
shrl $0x1f, %r13d
addl %r9d, %r13d
sarl %r13d
movq %r14, %rdi
movl 0x8(%rsp), %esi
movl %ebp, %edx
movl 0xa8(%rsp), %r15d
movq %r15, %rcx
movl %r12d, %r8d
movl %r13d, %r9d
movq 0xc8(%rsp), %rax
pushq %rax
movq 0xc8(%rsp), %rax
pushq %rax
movq 0xc8(%rsp), %rax
pushq %rax
movq 0xc8(%rsp), %rax
pushq %rax
pushq 0x48(%rsp)
movl 0xc8(%rsp), %eax
pushq %rax
movq 0x40(%rsp), %r15
pushq %r15
pushq %rbx
callq 0x268f
addq $0x40, %rsp
movq %rbx, 0x38(%rsp)
leal (%rbx,%r12), %r10d
movq %r10, 0x18(%rsp)
movq %r14, %rdi
movl 0x8(%rsp), %ebx
movl %ebx, %esi
movl %ebp, %edx
movl 0xa8(%rsp), %ecx
movl %r12d, %r8d
movl %r13d, %r9d
pushq 0xc8(%rsp)
pushq 0xc8(%rsp)
pushq 0xc8(%rsp)
pushq 0xc8(%rsp)
pushq %rcx
movl 0xc8(%rsp), %eax
pushq %rax
pushq %r15
pushq %r10
callq 0x268f
addq $0x40, %rsp
addl %r13d, %r15d
movq %r14, %rdi
movl %ebx, %esi
movl %ebp, %edx
movl 0xa8(%rsp), %ecx
movl %r12d, %r8d
movl %r13d, %r9d
pushq 0xc8(%rsp)
pushq 0xc8(%rsp)
pushq 0xc8(%rsp)
pushq 0xc8(%rsp)
pushq %rcx
movl 0xc8(%rsp), %eax
pushq %rax
movq %r15, 0x40(%rsp)
pushq %r15
pushq 0x70(%rsp)
callq 0x268f
addq $0x40, %rsp
movq 0x18(%rsp), %r11
movl %r11d, %ebx
movl %r13d, %r9d
movl %r12d, %r8d
jmp 0x2705
testl %r8d, %r8d
jle 0x2ac4
movl %r9d, 0x20(%rsp)
movl %esi, %eax
shrl $0x1f, %eax
addl %esi, %eax
sarl %eax
movl %edx, %ecx
shrl $0x1f, %ecx
addl %edx, %ecx
movl %r11d, %edi
shrl $0x1f, %edi
addl %r11d, %edi
sarl %edi
addl %r11d, %edi
cvtsi2sd %edi, %xmm0
movsd %xmm0, 0x28(%rsp)
sarl %ecx
movslq %ecx, %rcx
movq %rcx, 0x48(%rsp)
cltq
movq %rax, 0x50(%rsp)
movl 0x20(%rsp), %eax
movl %r8d, %ecx
movq %rcx, 0x40(%rsp)
movl %eax, %ecx
xorl %r9d, %r9d
movzbl %r11b, %edi
movl %edi, 0x38(%rsp)
movl %r14d, 0x18(%rsp)
movq %rbp, 0x30(%rsp)
movl %edx, 0xc(%rsp)
movl %esi, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
testl %eax, %eax
jle 0x2ab2
movl %r9d, %eax
shll $0x10, %eax
movl %eax, 0x24(%rsp)
xorl %r15d, %r15d
movq (%rbx,%r9,8), %rax
movzbl (%rax,%r15), %eax
cmpl $0x43, %eax
je 0x2aa6
cmpl $0x54, %eax
je 0x2aa6
subq $0x8, %rsp
movq %rbp, %rdi
movl %r14d, %ecx
movl 0x40(%rsp), %r8d
movq %r9, %r13
pushq %r15
callq 0x24ef
addq $0x10, %rsp
movzbl %al, %eax
addl $-0x4e, %eax
rorl %eax
cmpl $0x6, %eax
ja 0x2a2a
leaq 0x36f6(%rip), %rcx      # 0x6004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r12, %rdi
movl $0x1, %esi
callq 0x4f72
movq %r12, %rdi
xorl %esi, %esi
jmp 0x2997
movq %r12, %rdi
xorl %esi, %esi
callq 0x4f72
movq %r12, %rdi
movl $0x1, %esi
callq 0x4f72
movq %r12, %rbp
movl 0x8(%rsp), %r12d
movl %r12d, %edi
movl 0xc(%rsp), %r14d
movl %r14d, %esi
movl 0x18(%rsp), %edx
movl %r13d, %ecx
movl %r15d, %r8d
movq %rbx, %r9
callq 0x236c
movq %r13, %r9
movl %r12d, %esi
movq %rbp, %r12
movq 0x30(%rsp), %rbp
movl %r14d, %edx
movl 0x18(%rsp), %r14d
jmp 0x2aa1
movq %r12, %rdi
movl $0x1, %esi
callq 0x4f72
movq %r12, %rdi
movl $0x1, %esi
callq 0x4f72
movq %r13, %r9
movq (%rbx,%r13,8), %rax
movb $0x43, (%rax,%r15)
movq 0xb8(%rsp), %rsi
movl 0x4(%rsi), %eax
cmpl (%rsi), %eax
je 0x29da
movzwl %r15w, %ecx
orl 0x24(%rsp), %ecx
incl %eax
movl %eax, 0x4(%rsi)
movq 0x10(%rsi), %rax
movl 0xc(%rsi), %edx
movl %ecx, (%rax,%rdx,4)
movl 0xc(%rsi), %eax
incl %eax
xorl %edx, %edx
divl (%rsi)
movl %edx, 0xc(%rsi)
movq 0xc0(%rsp), %rax
movq (%rax,%r9,8), %rax
movsd 0x28(%rsp), %xmm0
movsd %xmm0, (%rax,%r15,8)
jmp 0x2a99
movq %r12, %rdi
xorl %esi, %esi
callq 0x4f72
cmpq 0x50(%rsp), %r13
jg 0x2a12
movq %r13, %r9
cmpq 0x48(%rsp), %r15
jle 0x2a1f
movq %r12, %rdi
xorl %esi, %esi
callq 0x4f72
movq %r13, %r9
movq (%rbx,%r9,8), %rax
movb $0x5a, (%rax,%r15)
jmp 0x2a99
movl $0x22, %edx
movq 0x55a2(%rip), %r14      # 0x7fd8
movq %r14, %rdi
leaq 0x3728(%rip), %rsi      # 0x6168
callq 0x2160
movq %r14, %rdi
movl %r13d, %esi
callq 0x2200
movq %r12, %rbp
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3726(%rip), %rsi      # 0x618b
callq 0x2160
movq %r12, %rdi
movq %rbp, %r12
movl 0x18(%rsp), %r14d
movq 0x30(%rsp), %rbp
movl %r15d, %esi
callq 0x2200
movl $0x2, %edx
movq %rax, %rdi
leaq 0x36fc(%rip), %rsi      # 0x618d
callq 0x2160
movq %r13, %r9
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %esi
movq 0x10(%rsp), %rcx
incq %r15
cmpq %r15, %rcx
jne 0x28be
incq %r9
cmpq 0x40(%rsp), %r9
movl 0x20(%rsp), %eax
jne 0x28a9
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq