// File: kchan1[P]helloworld_test1/./encoder.hh
// Function: isPNTZ(double**, int, int, int, unsigned char, int, int)
char isPNTZ(double**image,int width,int height,int depth, unsigned char threshold,int x, int y)
{
  //if the image is below the threshold, it may be a zerotree
  if(image[x][y] < threshold)
  {
    int layer = depth;
    while(x > width>>layer)
      layer++;
    //if this is the deepest level, there are three children to check
    if(x < width>>depth && y < height>>depth)
    {
      if(isPNTZ(image,width,height,depth,threshold, 
        x+(width>>depth),y)=='T' &&
	isPNTZ(image,width,height,depth,threshold, 
        x,y+(height>>depth))=='T' &&
	isPNTZ(image,width,height,depth,threshold, 
        x+(width>>depth),y+(height>>depth))=='T')
	return 'T';
      else
	return 'Z';
    }
    //if this is the lowest level, there are no children to check
    else if(x > width/2 && y > height/2)
    {
      return 'Z';
    }
    //otherwise there are 4 children to check
    else
    {
      if(isPNTZ(image,width,height,depth,threshold, 
	x*2,y*2)=='T' &&
	isPNTZ(image,width,height,depth,threshold, 
	x*2+1,y*2)=='T' &&
	isPNTZ(image,width,height,depth,threshold, 
        x*2,y*2+1)=='T' &&
	isPNTZ(image,width,height,depth,threshold, 
        x*2+1,y*2+1)=='T')
	return 'T';
      else
	return 'Z';
    }
  }
  else if(image[x][y] >= threshold)
    return 'P';
  else if(image[x][y] >= threshold)
    return 'N';
  else
    return '?';
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movb %r8b, %al
movl 0x10(%rbp), %r8d
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movb %al, -0x1d(%rbp)
movl %r9d, -0x24(%rbp)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x10(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movzbl -0x1d(%rbp), %eax
cvtsi2sd %eax, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x28f1
movl -0x1c(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x24(%rbp), %eax
movl -0x14(%rbp), %edx
movl -0x28(%rbp), %ecx
sarl %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jle 0x26cc
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x26b0
movl -0x24(%rbp), %eax
movl -0x14(%rbp), %edx
movl -0x1c(%rbp), %ecx
sarl %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jge 0x27d2
movl 0x10(%rbp), %eax
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %ecx
sarl %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jge 0x27d2
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movb -0x1d(%rbp), %r8b
movl -0x24(%rbp), %r9d
movl -0x14(%rbp), %eax
movl -0x1c(%rbp), %ecx
sarl %cl, %eax
movl -0x2c(%rbp), %ecx
addl %eax, %r9d
movl 0x10(%rbp), %eax
movzbl %r8b, %r8d
movl %eax, (%rsp)
callq 0x2660
movsbl %al, %eax
cmpl $0x54, %eax
jne 0x27c9
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %eax
movl %eax, -0x30(%rbp)
movb -0x1d(%rbp), %r8b
movl -0x24(%rbp), %r9d
movl 0x10(%rbp), %eax
movl -0x18(%rbp), %r10d
movl -0x1c(%rbp), %ecx
sarl %cl, %r10d
movl -0x30(%rbp), %ecx
addl %r10d, %eax
movzbl %r8b, %r8d
movl %eax, (%rsp)
callq 0x2660
movsbl %al, %eax
cmpl $0x54, %eax
jne 0x27c9
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %eax
movl %eax, -0x34(%rbp)
movb -0x1d(%rbp), %r8b
movl -0x24(%rbp), %r9d
movl -0x14(%rbp), %eax
movl -0x1c(%rbp), %ecx
sarl %cl, %eax
addl %eax, %r9d
movl 0x10(%rbp), %eax
movl -0x18(%rbp), %r10d
movl -0x1c(%rbp), %ecx
sarl %cl, %r10d
movl -0x34(%rbp), %ecx
addl %r10d, %eax
movzbl %r8b, %r8d
movl %eax, (%rsp)
callq 0x2660
movsbl %al, %eax
cmpl $0x54, %eax
jne 0x27c9
movb $0x54, -0x1(%rbp)
jmp 0x2947
movb $0x5a, -0x1(%rbp)
jmp 0x2947
movl -0x24(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x14(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x38(%rbp), %eax
cmpl %ecx, %eax
jle 0x280f
movl 0x10(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x18(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x3c(%rbp), %eax
cmpl %ecx, %eax
jle 0x280f
movb $0x5a, -0x1(%rbp)
jmp 0x2947
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %ecx
movb -0x1d(%rbp), %r8b
movl -0x24(%rbp), %r9d
shll %r9d
movl 0x10(%rbp), %eax
shll %eax
movzbl %r8b, %r8d
movl %eax, (%rsp)
callq 0x2660
movsbl %al, %eax
cmpl $0x54, %eax
jne 0x28eb
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %ecx
movb -0x1d(%rbp), %r8b
movl -0x24(%rbp), %r9d
shll %r9d
addl $0x1, %r9d
movl 0x10(%rbp), %eax
shll %eax
movzbl %r8b, %r8d
movl %eax, (%rsp)
callq 0x2660
movsbl %al, %eax
cmpl $0x54, %eax
jne 0x28eb
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %ecx
movb -0x1d(%rbp), %r8b
movl -0x24(%rbp), %r9d
shll %r9d
movl 0x10(%rbp), %eax
shll %eax
addl $0x1, %eax
movzbl %r8b, %r8d
movl %eax, (%rsp)
callq 0x2660
movsbl %al, %eax
cmpl $0x54, %eax
jne 0x28eb
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movl -0x1c(%rbp), %ecx
movb -0x1d(%rbp), %r8b
movl -0x24(%rbp), %r9d
shll %r9d
addl $0x1, %r9d
movl 0x10(%rbp), %eax
shll %eax
addl $0x1, %eax
movzbl %r8b, %r8d
movl %eax, (%rsp)
callq 0x2660
movsbl %al, %eax
cmpl $0x54, %eax
jne 0x28eb
movb $0x54, -0x1(%rbp)
jmp 0x2947
movb $0x5a, -0x1(%rbp)
jmp 0x2947
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x10(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movzbl -0x1d(%rbp), %eax
cvtsi2sd %eax, %xmm1
ucomisd %xmm1, %xmm0
jb 0x291a
movb $0x50, -0x1(%rbp)
jmp 0x2947
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x10(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movzbl -0x1d(%rbp), %eax
cvtsi2sd %eax, %xmm1
ucomisd %xmm1, %xmm0
jb 0x2943
movb $0x4e, -0x1(%rbp)
jmp 0x2947
movb $0x3f, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x50, %rsp
popq %rbp
retq