// File: /workspace/github_cpp_makefile_star2_O2/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 %r9d, %r14d
movl %r8d, %r12d
movl %ecx, %ebx
movl %edx, 0xc(%rsp)
movl %esi, 0x8(%rsp)
movq %rdi, 0x38(%rsp)
movq 0xa0(%rsp), %r15
movl 0x98(%rsp), %eax
movl 0x88(%rsp), %ecx
movq %rcx, 0x28(%rsp)
movl 0x80(%rsp), %r10d
leal 0x1(%rbx), %ecx
movq %rcx, 0x30(%rsp)
cmpl %ebx, %eax
jne 0x27f0
movl %r12d, %eax
cltd
pushq $0x2
popq %rcx
idivl %ecx
movl %eax, %r8d
movq %r8, 0x10(%rsp)
movl %r14d, %eax
cltd
idivl %ecx
movl %eax, %r14d
movq 0x38(%rsp), %rbp
movq %rbp, %rdi
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
movl %ebx, %ecx
movl %eax, %r9d
movq 0xb8(%rsp), %rax
pushq %rax
movq 0xb8(%rsp), %rax
pushq %rax
movq 0xb8(%rsp), %rax
pushq %rax
pushq %r15
pushq 0x50(%rsp)
movl 0xb8(%rsp), %eax
pushq %rax
movq 0x58(%rsp), %r13
pushq %r13
pushq %r10
movq %r10, %r12
movq %r10, 0x60(%rsp)
callq 0x267c
addq $0x40, %rsp
movq 0x10(%rsp), %r8
leal (%r12,%r8), %eax
movq %rax, 0x18(%rsp)
movq %rbp, %rdi
movl 0x8(%rsp), %ebp
movl %ebp, %esi
movl 0xc(%rsp), %r12d
movl %r12d, %edx
movl %ebx, %ecx
movl %r14d, %r9d
pushq 0xb8(%rsp)
pushq 0xb8(%rsp)
pushq 0xb8(%rsp)
pushq %r15
pushq %rbx
movl 0xb8(%rsp), %r10d
pushq %r10
pushq %r13
pushq %rax
callq 0x267c
addq $0x40, %rsp
addl %r14d, %r13d
movq 0x38(%rsp), %rdi
movl %ebp, %esi
movl %r12d, %edx
movq 0x10(%rsp), %r12
movl %ebx, %ecx
movl %r12d, %r8d
movl %r14d, %r9d
pushq 0xb8(%rsp)
pushq 0xb8(%rsp)
pushq 0xb8(%rsp)
pushq %r15
pushq %rbx
movl 0xb8(%rsp), %eax
pushq %rax
movq %r13, 0x58(%rsp)
pushq %r13
pushq 0x58(%rsp)
callq 0x267c
addq $0x40, %rsp
movq 0x18(%rsp), %r10
movl %ebx, %eax
jmp 0x26ca
movl 0x8(%rsp), %eax
cltd
pushq $0x2
popq %r8
idivl %r8d
movl %eax, %ecx
movl 0xc(%rsp), %eax
cltd
idivl %r8d
movl %eax, %esi
movl 0x90(%rsp), %edi
movl %edi, %eax
cltd
idivl %r8d
addl %edi, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %r13d, %r13d
testl %r14d, %r14d
cmovlel %r13d, %r14d
movslq %esi, %rax
movq %rax, 0x40(%rsp)
testl %r12d, %r12d
cmovlel %r13d, %r12d
movslq %ecx, %rax
movq %rax, 0x30(%rsp)
movzbl %dil, %eax
movl %eax, 0x28(%rsp)
movq %r12, 0x10(%rsp)
cmpq %r12, %r13
je 0x2a22
movl %r13d, %eax
shll $0x10, %eax
movl %eax, 0x20(%rsp)
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x2a15
movq (%r15,%r13,8), %rax
movzbl (%rax,%r12), %eax
cmpl $0x43, %eax
je 0x2a0d
cmpl $0x54, %eax
je 0x2a0d
subq $0x8, %rsp
movq 0x40(%rsp), %rdi
movl 0x10(%rsp), %esi
movl 0x14(%rsp), %edx
movl %ebx, %ecx
movl 0x30(%rsp), %r8d
movl %r13d, %r9d
pushq %r12
callq 0x24d1
addq $0x10, %rsp
movzbl %al, %eax
addl $-0x4e, %eax
rorl %eax
cmpl $0x6, %eax
ja 0x29c6
leaq 0x273d(%rip), %rcx      # 0x5004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0xb8(%rsp), %rbp
movq %rbp, %rdi
pushq $0x1
popq %rsi
callq 0x44ee
movq %rbp, %rdi
xorl %esi, %esi
jmp 0x2952
movq 0xb8(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
callq 0x44ee
movq %rbp, %rdi
pushq $0x1
popq %rsi
callq 0x44ee
movl 0x8(%rsp), %edi
movl 0xc(%rsp), %esi
movl %ebx, %edx
movl %r13d, %ecx
movl %r12d, %r8d
movq %r15, %r9
callq 0x235c
jmp 0x2a0d
movq 0xb8(%rsp), %rdi
movq %r14, %rbp
movq %r15, %r14
movq %rbx, %r15
pushq $0x1
popq %rbx
movl %ebx, %esi
callq 0x44ee
movq 0xb8(%rsp), %rdi
movl %ebx, %esi
movq %r15, %rbx
movq %r14, %r15
movq %rbp, %r14
callq 0x44ee
movq (%r15,%r13,8), %rax
movb $0x43, (%rax,%r12)
movzwl %r12w, %esi
orl 0x20(%rsp), %esi
movq 0xa8(%rsp), %rdi
callq 0x4526
movq 0xb0(%rsp), %rax
movq (%rax,%r13,8), %rax
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax,%r12,8)
jmp 0x2a0d
movq 0xb8(%rsp), %rdi
xorl %esi, %esi
callq 0x44ee
cmpq 0x30(%rsp), %r13
jg 0x29ac
cmpq 0x40(%rsp), %r12
jle 0x29bb
movq 0xb8(%rsp), %rdi
xorl %esi, %esi
callq 0x44ee
movq (%r15,%r13,8), %rax
movb $0x5a, (%rax,%r12)
jmp 0x2a0d
movq 0x460b(%rip), %rdi      # 0x6fd8
leaq 0x26ec(%rip), %rsi      # 0x50c0
callq 0x2100
movq %rax, %rdi
movl %r13d, %esi
callq 0x21f0
movq %rax, %rdi
leaq 0x26f5(%rip), %rsi      # 0x50e3
callq 0x2100
movq %rax, %rdi
movl %r12d, %esi
callq 0x21f0
movq %rax, %rdi
leaq 0x26dd(%rip), %rsi      # 0x50e5
callq 0x2100
incq %r12
jmp 0x2865
incq %r13
movq 0x10(%rsp), %r12
jmp 0x284f
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq