// File: drummyfish[P]flowchart/src/program.cpp
// Function: program::get_command_blocks(image*)
vector<block_command> program::get_command_blocks(image *img)
  {
    unsigned int i, j, x, y;
    coord_2d c1, c2;
    vector<block_command> result;

    for (j = 0; j < img->get_height(); j++)
      for (i = 0; i < img->get_width(); i++)
        {
          if (   // block corner
            img->pixel_is_black(i,j)     &&
            img->pixel_is_black(i + 1,j) &&
            img->pixel_is_black(i,j + 1) &&
            !img->pixel_is_black(i + 1,j + 1))
            {
              c1.x = i;
              c1.y = j;

              x = i + 1;
              y = j;

              // trace the block border:

              while (img->pixel_is_black(x + 1,y))
                x++;

              i = x;    // i can skip here

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

              while (img->pixel_is_black(x,y + 1))
                y++;

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

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

              while (img->pixel_is_black(x - 1,y))
                x--;

              while (img->pixel_is_black(x,y - 1))
                y--;

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

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

                  block_command b(block_string,c1,c2);
                  result.push_back(b);
                }
            }
        }

    return result;
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x120(%rbp)
movq %rdi, %rax
movq %rax, -0x118(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x110(%rbp)
movb $0x0, -0x39(%rbp)
callq 0x18a90
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x128(%rbp)
movq -0x18(%rbp), %rdi
callq 0x15f40
movl %eax, -0x124(%rbp)
jmp 0x17c4d
movl -0x128(%rbp), %eax
movl -0x124(%rbp), %ecx
cmpl %ecx, %eax
jae 0x1801e
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x130(%rbp)
movq -0x18(%rbp), %rdi
callq 0x15f00
movl %eax, -0x12c(%rbp)
jmp 0x17c82
movl -0x130(%rbp), %eax
movl -0x12c(%rbp), %ecx
cmpl %ecx, %eax
jae 0x1800e
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
callq 0x160c0
movb %al, -0x131(%rbp)
jmp 0x17cad
movb -0x131(%rbp), %al
testb $0x1, %al
jne 0x17cbc
jmp 0x17ffe
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
incl %esi
movl -0x20(%rbp), %edx
callq 0x160c0
movb %al, -0x132(%rbp)
jmp 0x17cd5
movb -0x132(%rbp), %al
testb $0x1, %al
jne 0x17ce4
jmp 0x17ffe
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
incl %edx
callq 0x160c0
movb %al, -0x133(%rbp)
jmp 0x17cfd
movb -0x133(%rbp), %al
testb $0x1, %al
jne 0x17d0c
jmp 0x17ffe
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
incl %esi
movl -0x20(%rbp), %edx
incl %edx
callq 0x160c0
movb %al, -0x134(%rbp)
jmp 0x17d27
movb -0x134(%rbp), %al
testb $0x1, %al
jne 0x17ffe
jmp 0x17d37
movl -0x1c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
incl %esi
movl -0x28(%rbp), %edx
callq 0x160c0
movb %al, -0x135(%rbp)
jmp 0x17d6b
movb -0x135(%rbp), %al
testb $0x1, %al
jne 0x17d77
jmp 0x17d93
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x17d52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x18044
movl -0x24(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x24(%rbp), %eax
subl -0x30(%rbp), %eax
cmpl $0x9, %eax
jae 0x17da9
jmp 0x18000
jmp 0x17dab
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
incl %edx
callq 0x160c0
movb %al, -0x136(%rbp)
jmp 0x17dc4
movb -0x136(%rbp), %al
testb $0x1, %al
jne 0x17dd0
jmp 0x17ddb
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x17dab
movl -0x24(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
subl -0x2c(%rbp), %eax
cmpl $0xa, %eax
jae 0x17df7
jmp 0x18000
jmp 0x17df9
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
decl %esi
movl -0x28(%rbp), %edx
callq 0x160c0
movb %al, -0x137(%rbp)
jmp 0x17e12
movb -0x137(%rbp), %al
testb $0x1, %al
jne 0x17e1e
jmp 0x17e29
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x17df9
jmp 0x17e2b
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
decl %edx
callq 0x160c0
movb %al, -0x138(%rbp)
jmp 0x17e44
movb -0x138(%rbp), %al
testb $0x1, %al
jne 0x17e50
jmp 0x17e5b
movl -0x28(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x17e2b
movl -0x24(%rbp), %eax
cmpl -0x30(%rbp), %eax
jne 0x17ffc
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x17ffc
leaq -0x70(%rbp), %rdi
callq 0x3380
movq -0x18(%rbp), %rax
movq %rax, -0x148(%rbp)
movl -0x30(%rbp), %edi
movl -0x2c(%rbp), %esi
incl %edi
incl %esi
callq 0x1c860
movq %rax, -0x140(%rbp)
jmp 0x17e9f
movq -0x140(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl -0x38(%rbp), %edi
movl -0x34(%rbp), %esi
decl %edi
decl %esi
callq 0x1c860
movq %rax, -0x150(%rbp)
jmp 0x17ec5
movq -0x148(%rbp), %rdx
movq -0x110(%rbp), %rsi
movq -0x150(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rcx
movq -0xa8(%rbp), %r8
leaq -0x98(%rbp), %rdi
leaq -0x71(%rbp), %r9
callq 0x18060
jmp 0x17f01
leaq -0x70(%rbp), %rdi
movq %rdi, -0x158(%rbp)
leaq -0x98(%rbp), %rsi
movq %rsi, -0x160(%rbp)
callq 0x32f0
movq -0x160(%rbp), %rdi
callq 0x3160
movq -0x158(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x30f0
jmp 0x17f40
movq -0x30(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x100(%rbp), %rdx
movq -0x108(%rbp), %rcx
leaq -0xd8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x1d710
jmp 0x17f79
leaq -0xf8(%rbp), %rdi
callq 0x3160
movq -0x120(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x18ab0
jmp 0x17f9a
leaq -0xd8(%rbp), %rdi
callq 0x18b20
leaq -0x70(%rbp), %rdi
callq 0x3160
jmp 0x17ffc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x17ff1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x3160
jmp 0x17ff1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x18b20
leaq -0x70(%rbp), %rdi
callq 0x3160
jmp 0x18044
jmp 0x17ffe
jmp 0x18000
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x17c68
jmp 0x18010
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x17c33
movb $0x1, -0x39(%rbp)
testb $0x1, -0x39(%rbp)
jne 0x18034
movq -0x120(%rbp), %rdi
callq 0x18970
movq -0x118(%rbp), %rax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq -0x120(%rbp), %rdi
callq 0x18970
movq -0x48(%rbp), %rdi
callq 0x3460
nopl (%rax)