// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movl %ecx, %ebx
movl %edx, 0x4(%rsp)
movl %esi, 0x8(%rsp)
movq %rdi, 0x28(%rsp)
movq 0xa0(%rsp), %r13
movl 0x98(%rsp), %eax
movl 0x88(%rsp), %ecx
movq %rcx, 0x20(%rsp)
movl 0x80(%rsp), %r11d
movl 0x8(%rsp), %ebp
cmpl %ebx, %eax
jne 0x27c8
movl %r8d, %r15d
shrl $0x1f, %r15d
addl %r8d, %r15d
sarl %r15d
movl %r9d, %r12d
shrl $0x1f, %r12d
addl %r9d, %r12d
sarl %r12d
incl %eax
movq 0x28(%rsp), %rdi
movl %ebp, %esi
movl 0x4(%rsp), %edx
movl %ebx, %ecx
movl %r15d, %r8d
movl %r12d, %r9d
movq 0xb8(%rsp), %r10
pushq %r10
movq 0xb8(%rsp), %r10
pushq %r10
movq 0xb8(%rsp), %r10
pushq %r10
pushq 0xb8(%rsp)
pushq %rax
movl 0xb8(%rsp), %eax
pushq %rax
movq 0x50(%rsp), %r14
pushq %r14
pushq %r11
movq %r11, %r13
movq %r11, 0x58(%rsp)
callq 0x264f
addq $0x40, %rsp
leal (%r15,%r13), %eax
movq %rax, 0x10(%rsp)
movq 0x28(%rsp), %rdi
movl %ebp, %esi
movl 0x4(%rsp), %r13d
movl %r13d, %edx
movl %ebx, %ecx
movl %r15d, %r8d
movl %r12d, %r9d
pushq 0xb8(%rsp)
pushq 0xb8(%rsp)
pushq 0xb8(%rsp)
pushq 0xb8(%rsp)
pushq %rbx
movl 0xb8(%rsp), %r10d
pushq %r10
pushq %r14
pushq %rax
callq 0x264f
addq $0x40, %rsp
addl %r12d, %r14d
movq 0x28(%rsp), %rdi
movl %ebp, %esi
movl %r13d, %edx
movq 0xa0(%rsp), %r13
movl %ebx, %ecx
movl %r15d, %r8d
movl %r12d, %r9d
pushq 0xb8(%rsp)
pushq 0xb8(%rsp)
pushq 0xb8(%rsp)
pushq %r13
pushq %rbx
movl 0xb8(%rsp), %eax
pushq %rax
movq %r14, 0x50(%rsp)
pushq %r14
pushq 0x50(%rsp)
callq 0x264f
addq $0x40, %rsp
movl %r15d, %r8d
movl %r12d, %r9d
movq 0x10(%rsp), %r11
movl %ebx, %eax
jmp 0x2693
movl %r9d, 0xc(%rsp)
testl %r8d, %r8d
movl 0x8(%rsp), %ebp
jle 0x2a50
movl %ebp, %eax
shrl $0x1f, %eax
addl %ebp, %eax
sarl %eax
movl 0x4(%rsp), %edx
movl %edx, %ecx
shrl $0x1f, %ecx
addl %edx, %ecx
movl 0x90(%rsp), %edx
movq %rdx, %rsi
shrl $0x1f, %edx
addl %esi, %edx
sarl %edx
addl %esi, %edx
cvtsi2sd %edx, %xmm0
movsd %xmm0, 0x18(%rsp)
sarl %ecx
movslq %ecx, %rcx
movq %rcx, 0x38(%rsp)
cltq
movq %rax, 0x40(%rsp)
movl %r8d, %eax
movq %rax, 0x30(%rsp)
movl 0xc(%rsp), %r14d
xorl %r12d, %r12d
movzbl %sil, %eax
movl %eax, 0x20(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x2a42
movl %r12d, %eax
shll $0x10, %eax
movl %eax, 0x10(%rsp)
xorl %r15d, %r15d
movq (%r13,%r12,8), %rax
movzbl (%rax,%r15), %eax
cmpl $0x43, %eax
je 0x2a36
cmpl $0x54, %eax
je 0x2a36
subq $0x8, %rsp
movq 0x30(%rsp), %rdi
movl %ebp, %esi
movl 0xc(%rsp), %edx
movl %ebx, %ecx
movl 0x28(%rsp), %r8d
movl %r12d, %r9d
pushq %r15
callq 0x24af
addq $0x10, %rsp
movzbl %al, %eax
addl $-0x4e, %eax
rorl %eax
cmpl $0x6, %eax
ja 0x29d6
leaq 0x2760(%rip), %rcx      # 0x5004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0xb8(%rsp), %r13
movq %r13, %rdi
movl $0x1, %esi
callq 0x498e
movq %r13, %rdi
movq 0xa0(%rsp), %r13
xorl %esi, %esi
jmp 0x2938
movq 0xb8(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x498e
movq %r13, %rdi
movq 0xa0(%rsp), %r13
movl $0x1, %esi
callq 0x498e
movl %ebp, %edi
movl 0x4(%rsp), %esi
movl %ebx, %edx
movl %r12d, %ecx
movl %r15d, %r8d
movq %r13, %r9
callq 0x236c
jmp 0x2a36
movq 0xb8(%rsp), %r13
movq %r13, %rdi
movl $0x1, %esi
callq 0x498e
movq %r13, %rdi
movq 0xa0(%rsp), %r13
movl $0x1, %esi
callq 0x498e
movq (%r13,%r12,8), %rax
movb $0x43, (%rax,%r15)
movq 0xa8(%rsp), %rcx
movl 0x4(%rcx), %eax
cmpl (%rcx), %eax
je 0x2981
movzwl %r15w, %ecx
orl 0x10(%rsp), %ecx
incl %eax
movq 0xa8(%rsp), %rsi
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 0xb0(%rsp), %rax
movq (%rax,%r12,8), %rax
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax,%r15,8)
jmp 0x2a36
movq 0xb8(%rsp), %rdi
xorl %esi, %esi
callq 0x498e
cmpq 0x40(%rsp), %r12
jg 0x29bb
cmpq 0x38(%rsp), %r15
jle 0x29ca
movq 0xb8(%rsp), %rdi
xorl %esi, %esi
callq 0x498e
movq (%r13,%r12,8), %rax
movb $0x5a, (%rax,%r15)
jmp 0x2a36
movl $0x22, %edx
movq 0x45f6(%rip), %rbp      # 0x6fd8
movq %rbp, %rdi
leaq 0x2654(%rip), %rsi      # 0x5040
callq 0x2160
movq %rbp, %rdi
movl %r12d, %esi
callq 0x2200
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
leaq 0x2655(%rip), %rsi      # 0x5063
callq 0x2160
movq %rbp, %rdi
movl 0x8(%rsp), %ebp
movl %r15d, %esi
callq 0x2200
movl $0x2, %edx
movq %rax, %rdi
leaq 0x2634(%rip), %rsi      # 0x5065
callq 0x2160
incq %r15
cmpq %r15, %r14
jne 0x284c
incq %r12
cmpq 0x30(%rsp), %r12
jne 0x2834
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq