// File: /workspace/github_cpp_makefile_star2_O2/drummyfish[P]flowchart/src/program.cpp
// Function: std::vector<block_directive, std::allocator<block_directive>> program::get_directive_function_blocks<block_directive>(image*)
vector<T> program::get_directive_function_blocks(image *img)
  {
    unsigned int i,j,x,y;
    vector<T> result;
    coord_2d c1, c2;

    bool directive = switch_value<T>::value == 0;  // whether directive or function blocks are being looked for

    for (j = 0; j < img->get_height(); j++)
      for (i = 0; i < img->get_width(); i++)
        {
          if (   // block corner
            !img->pixel_is_black(i - 1,j)     &&
            !img->pixel_is_black(i - 1,j - 1) &&
            !img->pixel_is_black(i,j - 1) &&
            img->pixel_is_black(i,j)     &&
            img->pixel_is_black(i + 1,j) &&
            img->pixel_is_black(i + 2,j) &&
            img->pixel_is_black(i,j + 1)     &&
            directive != img->pixel_is_black(i + 1,j + 1) &&
            directive != img->pixel_is_black(i + 2,j + 1) &&
            img->pixel_is_black(i,j + 2)     &&
            directive != img->pixel_is_black(i + 1,j + 2) &&
            img->pixel_is_black(i + 2,j + 2))
            {
              // try to follow the block border now:

              c1.x = i;
              c1.y = j;

              x = i + 2;
              y = j;

              while (   // upper horizontal border
                img->pixel_is_black(x + 1,y)     &&
                directive != img->pixel_is_black(x + 1,y + 1) &&    // the middle pixel differs for function and directive block
                img->pixel_is_black(x + 1,y + 2))
                {
                  x++;
                }

              i = x + 1;   // i can skip here now
              y += 2;

              if (directive)    // with directive blocks we have to checks corners
                {
                  if (!(
                    !img->pixel_is_black(x + 1,y - 1) &&
                    img->pixel_is_black(x + 2,y - 1) &&
                    img->pixel_is_black(x + 2,y - 2) &&
                    img->pixel_is_black(x + 1,y - 2)))
                    continue;    // corner not valid

                  x += 2;
                }

              if (x - c1.x < FONT_WIDTH + 6)       // the block must be at least one character wide + borders
                continue;

              while (   // right verticel border
                img->pixel_is_black(x,y + 1)     &&
                directive != img->pixel_is_black(x - 1,y + 1) &&
                img->pixel_is_black(x - 2,y + 1))
                {
                  y++;
                }

              if (c2.y - c1.y < FONT_HEIGHT + 6)   // the block must be at least one character high
                continue;

              if (directive)
                {
                  if (!(
                    img->pixel_is_black(x,y + 1) &&
                    img->pixel_is_black(x,y + 2) &&
                    !img->pixel_is_black(x - 1,y + 1) &&
                    img->pixel_is_black(x - 1,y + 2)))
                    continue;    // corner not valid
                  x -= 2;
                  y += 2;
                }

              c2.x = x;
              c2.y = y;

              if (directive)
                c2.x += 2;

              while (   // lower horizontal border
                img->pixel_is_black(x - 1,y)     &&
                directive != img->pixel_is_black(x - 1,y - 1) &&
                img->pixel_is_black(x - 1,y - 2))
                {
                  x--;
                }

              if (directive)
                {
                  if (!(
                    img->pixel_is_black(x - 1,y) &&
                    img->pixel_is_black(x - 2,y) &&
                    !img->pixel_is_black(x - 1,y - 1) &&
                    img->pixel_is_black(x - 2,y - 1)))
                    continue;    // corner not valid

                  x -= 2;
                }

              y -= 2;

              while (   // left vertical border
                img->pixel_is_black(x,y - 1)     &&
                directive != img->pixel_is_black(x + 1,y - 1) &&
                img->pixel_is_black(x + 2,y - 1))
                {
                  y--;
                }

              if (directive)
                y -= 2;

              if (x == c1.x && y == c1.y)          // block detected
                {
                  string block_string;
                  bool error;

                  block_string = this->string_from_image_area(img,make_coord(c1.x + 3,c1.y + 3),make_coord(c2.x - 3,c2.y - 3),error);

                  T b(block_string,c1,c2);

                  result.push_back(b);
                }
            }
        }

    return result;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdx, %r14
movq %rsi, 0x58(%rsp)
xorps %xmm0, %xmm0
andq $0x0, 0x10(%rdi)
movq %rdi, 0x48(%rsp)
movups %xmm0, (%rdi)
xorl %r12d, %r12d
movq %r14, %rdi
callq 0xb47e
movl %eax, %eax
cmpq %rax, %r12
jae 0xcdcb
leal -0x1(%r12), %eax
movl %eax, 0x34(%rsp)
leaq 0x1(%r12), %rax
movq %rax, 0x28(%rsp)
leal 0x2(%r12), %eax
movl %eax, 0x8(%rsp)
leal 0x3(%r12), %eax
movl %eax, 0x54(%rsp)
movq %r12, %rax
shlq $0x20, %rax
movq %rax, 0x60(%rsp)
xorl %ebx, %ebx
movq %r14, %rdi
callq 0xb46e
cmpl %eax, %ebx
jae 0xcdc1
leal -0x1(%rbx), %ebp
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0xb4ce
testb %al, %al
jne 0xcda8
movq %r14, %rdi
movl %ebp, %esi
movl 0x34(%rsp), %edx
callq 0xb4ce
testb %al, %al
jne 0xcda8
movq %r14, %rdi
movl %ebx, %esi
movl 0x34(%rsp), %edx
callq 0xb4ce
testb %al, %al
jne 0xcda8
movq %r14, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0xb4ce
testb %al, %al
je 0xcda8
leal 0x1(%rbx), %ebp
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0xb4ce
testb %al, %al
je 0xcda8
leal 0x2(%rbx), %esi
movq %r14, %rdi
movl %esi, 0x4(%rsp)
movl %r12d, %edx
callq 0xb4ce
testb %al, %al
je 0xcda8
movq %r14, %rdi
movl %ebx, %esi
movq 0x28(%rsp), %rdx
callq 0xb4ce
testb %al, %al
je 0xcda8
movq %r14, %rdi
movl %ebp, %esi
movq 0x28(%rsp), %rdx
callq 0xb4ce
testb %al, %al
jne 0xcda8
movq %r14, %rdi
movl 0x4(%rsp), %esi
movq 0x28(%rsp), %rdx
callq 0xb4ce
testb %al, %al
jne 0xcda8
movq %r14, %rdi
movl %ebx, %esi
movl 0x8(%rsp), %edx
callq 0xb4ce
testb %al, %al
je 0xcda8
movq %r14, %rdi
movl %ebp, %esi
movl 0x8(%rsp), %edx
callq 0xb4ce
testb %al, %al
jne 0xcda8
movq %r14, %rdi
movl 0x4(%rsp), %esi
movl 0x8(%rsp), %edx
callq 0xb4ce
testb %al, %al
je 0xcda8
xorl %ecx, %ecx
pushq $0x1
popq %rdx
pushq $0x4
popq %rsi
movl 0x4(%rsp), %ebp
movl %ebp, %r15d
movl %esi, %eax
movq %rax, 0x10(%rsp)
movl %ecx, %eax
movq %rax, 0x18(%rsp)
movl %edx, %eax
movq %rax, 0x20(%rsp)
leal 0x1(%r15), %ebp
movq %r14, %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0xb4ce
testb %al, %al
je 0xca54
movq %r14, %rdi
movl %ebp, %esi
movq 0x28(%rsp), %rdx
callq 0xb4ce
testb %al, %al
jne 0xca54
movq %r14, %rdi
movl %ebp, %esi
movl 0x8(%rsp), %edx
callq 0xb4ce
movq 0x10(%rsp), %rcx
leal 0x1(%rcx), %esi
movq 0x18(%rsp), %rcx
decl %ecx
movq 0x20(%rsp), %rdx
incl %edx
testb %al, %al
jne 0xc9ec
movq %r15, 0x40(%rsp)
incl %r15d
movq %r14, %rdi
movl %r15d, %esi
movq 0x28(%rsp), %rdx
callq 0xb4ce
testb %al, %al
jne 0xcdbc
movq 0x40(%rsp), %rax
leal 0x2(%rax), %esi
movq %r14, %rdi
movl %esi, (%rsp)
movq 0x28(%rsp), %rdx
callq 0xb4ce
testb %al, %al
je 0xcdbc
movq %r14, %rdi
movl (%rsp), %esi
movl %r12d, %edx
callq 0xb4ce
testb %al, %al
je 0xcdbc
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0xb4ce
cmpl $0xd, 0x10(%rsp)
setae %cl
andb %cl, %al
cmpb $0x1, %al
jne 0xcdbc
movl %r12d, %ecx
movl 0x8(%rsp), %ebp
movl %ebp, %eax
movq %rcx, 0x10(%rsp)
movq %rax, 0x38(%rsp)
leal 0x1(%rax), %ebp
movq %r14, %rdi
movl (%rsp), %esi
movl %ebp, %edx
callq 0xb4ce
testb %al, %al
je 0xcb1c
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0xb4ce
testb %al, %al
jne 0xcb1c
movq %r14, %rdi
movq 0x40(%rsp), %rsi
movl %ebp, %edx
callq 0xb4ce
movq 0x10(%rsp), %rcx
incl %ecx
testb %al, %al
jne 0xcad1
movl %r13d, %eax
subl %r12d, %eax
cmpl $0xe, %eax
jb 0xcdbc
movq 0x38(%rsp), %rax
leal 0x1(%rax), %edx
movq %r14, %rdi
movl (%rsp), %esi
movl %edx, 0xc(%rsp)
callq 0xb4ce
testb %al, %al
je 0xcdbc
movq 0x38(%rsp), %rax
leal 0x2(%rax), %ebp
movq %r14, %rdi
movl (%rsp), %esi
movl %ebp, %edx
callq 0xb4ce
testb %al, %al
je 0xcdbc
movq %r14, %rdi
movl %r15d, %esi
movl 0xc(%rsp), %edx
callq 0xb4ce
testb %al, %al
jne 0xcdbc
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0xb4ce
testb %al, %al
je 0xcdbc
movq 0x18(%rsp), %rdx
movq %rdx, 0x18(%rsp)
movq 0x20(%rsp), %rax
leal (%rbx,%rax), %esi
movq %r14, %rdi
movl %esi, %r13d
movl %ebp, %edx
callq 0xb4ce
testb %al, %al
je 0xcbf1
movq %r14, %rdi
movl %r13d, %esi
movl 0xc(%rsp), %edx
callq 0xb4ce
testb %al, %al
jne 0xcbf1
movq %r14, %rdi
movl %r13d, %esi
movq 0x38(%rsp), %rdx
callq 0xb4ce
movq 0x18(%rsp), %rcx
leal 0x1(%rcx), %edx
movq 0x20(%rsp), %rcx
decl %ecx
movq %rcx, 0x20(%rsp)
testb %al, %al
jne 0xcb98
movq %r14, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0xb4ce
testb %al, %al
je 0xcdae
movl %ebx, %esi
subl 0x18(%rsp), %esi
movq %r14, %rdi
movl %esi, 0x30(%rsp)
movl %ebp, %edx
callq 0xb4ce
testb %al, %al
je 0xcdae
movq %r14, %rdi
movl %r13d, %esi
movl 0xc(%rsp), %edx
callq 0xb4ce
testb %al, %al
jne 0xcdae
movq %r14, %rdi
movl 0x30(%rsp), %esi
movl 0xc(%rsp), %edx
callq 0xb4ce
testb %al, %al
je 0xcdae
movq 0x18(%rsp), %rax
subl %eax, 0x4(%rsp)
movq 0x10(%rsp), %rcx
movq %rcx, 0x20(%rsp)
leal 0x1(%rcx), %edx
movq %r14, %rdi
movl 0x30(%rsp), %esi
movl %edx, 0x10(%rsp)
callq 0xb4ce
testb %al, %al
je 0xcca9
movq %r14, %rdi
movl %r13d, %esi
movl 0x10(%rsp), %edx
callq 0xb4ce
testb %al, %al
jne 0xcca9
movq %r14, %rdi
movl 0x4(%rsp), %esi
movl 0x10(%rsp), %edx
callq 0xb4ce
movq 0x20(%rsp), %rcx
decl %ecx
testb %al, %al
jne 0xcc5f
cmpl $0x0, 0x18(%rsp)
sete %al
movl 0x20(%rsp), %ecx
cmpq %rcx, %r12
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xcdae
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
andq $0x0, 0x70(%rsp)
movb $0x0, 0x78(%rsp)
leal 0x3(%rbx), %edi
movl 0x54(%rsp), %esi
callq 0xdac4
movq %rax, %r13
movq 0x40(%rsp), %rdi
decl %edi
movq 0x38(%rsp), %rsi
decl %esi
callq 0xdac4
leaq 0xa8(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq %r14, %rdx
movq %r13, %rcx
movq %rax, %r8
callq 0xc2a2
leaq 0x68(%rsp), %rdi
leaq 0xa8(%rsp), %r13
movq %r13, %rsi
callq 0x2210
movq %r13, %rdi
callq 0x20d0
leaq 0x88(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x2280
movl %ebx, %edx
orq 0x60(%rsp), %rdx
movq %rbp, %rax
shlq $0x20, %rax
movl (%rsp), %ecx
orq %rax, %rcx
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0xdf16
leaq 0x88(%rsp), %rdi
callq 0x20d0
movq 0x48(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0xd672
leaq 0xa8(%rsp), %rdi
callq 0x20d0
leaq 0x68(%rsp), %rdi
callq 0x20d0
jmp 0xcdae
movl %r13d, %ebp
movl %ebx, %r15d
incl %r15d
movl %ebp, %r13d
movl %r15d, %ebx
jmp 0xc8ba
movl %r13d, %ebp
jmp 0xcdae
movq 0x28(%rsp), %r12
jmp 0xc874
movq 0x48(%rsp), %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0xcdfa
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x20d0
jmp 0xce06
jmp 0xce03
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x20d0
jmp 0xce1f
jmp 0xce1c
jmp 0xce1c
jmp 0xce1c
jmp 0xce1c
jmp 0xce1c
movq %rax, %rbx
movq 0x48(%rsp), %rdi
callq 0xc7d8
movq %rbx, %rdi
callq 0x2330
nop