// File: 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
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq 0x48(%rbp), %rax
movq 0x40(%rbp), %rax
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x30(%rbp)
movl %esi, -0x34(%rbp)
movl %edx, -0x38(%rbp)
movl %ecx, -0x3c(%rbp)
movl %r8d, -0x40(%rbp)
movl %r9d, -0x44(%rbp)
movl 0x28(%rbp), %eax
cmpl -0x3c(%rbp), %eax
je 0x2c5a
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x2c55
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x2c45
movq 0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x54, %eax
je 0x29f9
movq 0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x43, %eax
jne 0x29fe
jmp 0x2c37
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %edx
movl -0x3c(%rbp), %ecx
movzbl 0x20(%rbp), %r8d
movl -0x48(%rbp), %r9d
movl -0x4c(%rbp), %r10d
movq %rsp, %rax
movl %r10d, (%rax)
callq 0x2660
movb %al, -0x4d(%rbp)
movsbl -0x4d(%rbp), %eax
addl $-0x4e, %eax
movl %eax, %ecx
movq %rcx, -0x58(%rbp)
subl $0xc, %eax
ja 0x2bee
movq -0x58(%rbp), %rax
leaq 0x45bd(%rip), %rcx      # 0x7004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x6580
movq 0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x6580
movq 0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4c(%rbp), %rcx
movb $0x43, (%rax,%rcx)
movq 0x38(%rbp), %rdi
movl -0x48(%rbp), %esi
andl $0xffff, %esi           # imm = 0xFFFF
shll $0x10, %esi
movl -0x4c(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
orl %eax, %esi
callq 0x65f0
movl 0x20(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl 0x20(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x5c(%rbp), %eax
addl %ecx, %eax
cvtsi2sd %eax, %xmm0
movq 0x40(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2c35
movq 0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x6580
movq 0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x6580
movq 0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4c(%rbp), %rcx
movb $0x43, (%rax,%rcx)
movq 0x38(%rbp), %rdi
movl -0x48(%rbp), %esi
andl $0xffff, %esi           # imm = 0xFFFF
shll $0x10, %esi
movl -0x4c(%rbp), %eax
andl $0xffff, %eax           # imm = 0xFFFF
orl %eax, %esi
callq 0x65f0
movl 0x20(%rbp), %eax
movl %eax, -0x60(%rbp)
movl 0x20(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x60(%rbp), %eax
addl %ecx, %eax
cvtsi2sd %eax, %xmm0
movq 0x40(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x2c35
movq 0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x6580
movq 0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x6580
movl -0x34(%rbp), %edi
movl -0x38(%rbp), %esi
movl -0x3c(%rbp), %edx
movl -0x48(%rbp), %ecx
movl -0x4c(%rbp), %r8d
movq 0x30(%rbp), %r9
callq 0x2480
jmp 0x2c35
movq 0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x6580
movl -0x48(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x34(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x64(%rbp), %eax
cmpl %ecx, %eax
jg 0x2bcd
movl -0x4c(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x38(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x68(%rbp), %eax
cmpl %ecx, %eax
jle 0x2bd8
movq 0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x6580
movq 0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4c(%rbp), %rcx
movb $0x5a, (%rax,%rcx)
jmp 0x2c35
movq 0x63e3(%rip), %rdi      # 0x8fd8
leaq 0x44c4(%rip), %rsi      # 0x70c0
callq 0x2170
movq %rax, %rdi
movl -0x48(%rbp), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x44cd(%rip), %rsi      # 0x70e3
callq 0x2170
movq %rax, %rdi
movl -0x4c(%rbp), %esi
callq 0x22d0
movq %rax, %rdi
leaq 0x44b5(%rip), %rsi      # 0x70e5
callq 0x2170
jmp 0x2c37
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x29bb
jmp 0x2c47
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x29a8
jmp 0x2e9a
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x3c(%rbp), %ecx
movl -0x40(%rbp), %eax
movl $0x2, %r8d
cltd
idivl %r8d
movl %eax, %r8d
movl -0x44(%rbp), %eax
movl $0x2, %r9d
cltd
idivl %r9d
movl -0x78(%rbp), %edx
movl %eax, %r9d
movl 0x10(%rbp), %r13d
movl 0x18(%rbp), %r12d
movl 0x20(%rbp), %r15d
movl 0x28(%rbp), %r14d
addl $0x1, %r14d
movq 0x30(%rbp), %rbx
movq 0x38(%rbp), %r11
movq 0x40(%rbp), %r10
movq 0x48(%rbp), %rax
movl %r13d, (%rsp)
movl %r12d, 0x8(%rsp)
movl %r15d, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
callq 0x2950
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x3c(%rbp), %ecx
movl -0x40(%rbp), %eax
movl $0x2, %r8d
cltd
idivl %r8d
movl %eax, %r8d
movl -0x44(%rbp), %eax
movl $0x2, %r9d
cltd
idivl %r9d
movl %eax, %r9d
movl 0x10(%rbp), %r13d
movl -0x40(%rbp), %eax
movl $0x2, %r10d
cltd
idivl %r10d
movl -0x74(%rbp), %edx
addl %eax, %r13d
movl 0x18(%rbp), %r12d
movl 0x20(%rbp), %r15d
movl -0x3c(%rbp), %r14d
movq 0x30(%rbp), %rbx
movq 0x38(%rbp), %r11
movq 0x40(%rbp), %r10
movq 0x48(%rbp), %rax
movl %r13d, (%rsp)
movl %r12d, 0x8(%rsp)
movl %r15d, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
callq 0x2950
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x3c(%rbp), %ecx
movl -0x40(%rbp), %eax
movl $0x2, %r8d
cltd
idivl %r8d
movl %eax, %r8d
movl -0x44(%rbp), %eax
movl $0x2, %r9d
cltd
idivl %r9d
movl %eax, %r9d
movl 0x10(%rbp), %r13d
movl 0x18(%rbp), %r12d
movl -0x44(%rbp), %eax
movl $0x2, %r10d
cltd
idivl %r10d
movl -0x70(%rbp), %edx
addl %eax, %r12d
movl 0x20(%rbp), %r15d
movl -0x3c(%rbp), %r14d
movq 0x30(%rbp), %rbx
movq 0x38(%rbp), %r11
movq 0x40(%rbp), %r10
movq 0x48(%rbp), %rax
movl %r13d, (%rsp)
movl %r12d, 0x8(%rsp)
movl %r15d, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
callq 0x2950
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
movl -0x38(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x3c(%rbp), %ecx
movl -0x40(%rbp), %eax
movl $0x2, %r8d
cltd
idivl %r8d
movl %eax, %r8d
movl -0x44(%rbp), %eax
movl $0x2, %r9d
cltd
idivl %r9d
movl %eax, %r9d
movl 0x10(%rbp), %r13d
movl -0x40(%rbp), %eax
movl $0x2, %r10d
cltd
idivl %r10d
addl %eax, %r13d
movl 0x18(%rbp), %r12d
movl -0x44(%rbp), %eax
movl $0x2, %r10d
cltd
idivl %r10d
movl -0x6c(%rbp), %edx
addl %eax, %r12d
movl 0x20(%rbp), %r15d
movl -0x3c(%rbp), %r14d
movq 0x30(%rbp), %rbx
movq 0x38(%rbp), %r11
movq 0x40(%rbp), %r10
movq 0x48(%rbp), %rax
movl %r13d, (%rsp)
movl %r12d, 0x8(%rsp)
movl %r15d, 0x10(%rsp)
movl %r14d, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
callq 0x2950
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)