// File: /workspace/github_cpp_makefile_star2_O2/drummyfish[P]flowchart/src/program.cpp
// Function: program::string_from_image_area[abi:cxx11](image*, coord_2d, coord_2d, bool&)
string program::string_from_image_area(image *img, coord_2d c1, coord_2d c2, bool &error)
  {
    string result = "";

    int max_y, min_y, max_x, min_x;
    unsigned int i,j;
    unsigned char r,g,b;
    bool end_it;

    end_it = false;
    min_y = c2.y;

    for (j = c1.y; j <= c2.y; j++)
      {
        for (i = c1.x; i <= c2.x; i++)
          {
            img->get_pixel(i,j,r,g,b);

            if (is_black(r,g,b))
              {
                end_it = true;
                min_y = j;
              }
          }

        if (end_it)
          break;
      }

    max_y = c1.y;
    end_it = false;

    for (j = c2.y - 1; j >= c1.y; j--)
      {
        for (i = c1.x; i <= c2.x; i++)
          {
            img->get_pixel(i,j,r,g,b);

            if (is_black(r,g,b))
              {
                end_it = true;
                max_y = j;
              }
          }

        if (end_it)
          break;
      }

    if (max_y - min_y > (FONT_HEIGHT - 1) || max_y - min_y < 0)   // in this cases there cannot be a valid text
      {
        // SET ERROR HEREEEEEEEEEEEEEEEEEEE LATER

        return result;
      }

    min_x = c2.x;
    end_it = false;

    for (i = c1.x; i <= c2.x; i++)
      {
        for (j = min_y; ((int) j) <= max_y; j++)
          {
            img->get_pixel(i,j,r,g,b);

            if (is_black(r,g,b))
              {
                end_it = true;
                min_x = i;
              }
          }

        if (end_it)
          break;
      }

    max_x = c1.x;
    end_it = false;

    for (i = c2.x - 1; i >= c1.x; i--)
      {
        for (j = min_y; ((int) j) <= max_y; j++)
          {
            img->get_pixel(i,j,r,g,b);

            if (is_black(r,g,b))
              {
                end_it = true;
                max_x = i;
              }
          }

        if (end_it)
          break;
      }

    // now try to read the string at possitions it could possibly appear:

    coord_2d coord_from, coord_to;   // range of possible top left corner of the string, will be brute force-tested
    coord_2d current_coord;
    int x_limit, y_difference;
    bool success;

    y_difference = max_y - min_y;

    x_limit = saturate(max_x + FONT_WIDTH - 1,c1.x,c2.x);  // to what maximum x the sring should be read

    coord_to.x = min_x;
    coord_to.y = min_y;

    coord_from.y = saturate(coord_to.y - (FONT_HEIGHT - y_difference - 1),c1.y,c2.y);
    coord_from.x = saturate(min_x - FONT_WIDTH + 1,c1.x,c2.x);

    for (j = coord_from.y; j <= coord_to.y; j++)
      for (i = coord_from.x; i <= coord_to.x; i++)
        {
          current_coord.x = i;
          current_coord.y = j;

          result = this->string_from_image_position(img,current_coord,x_limit,success);

          if (success)
            return result;
        }

    return result;
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %r14
movq %rsi, 0x40(%rsp)
movq %rcx, 0x10(%rsp)
movq %rcx, %rbx
shrq $0x20, %rbx
movq %r8, 0x8(%rsp)
movq %r8, %r15
shrq $0x20, %r15
leaq 0x3294(%rip), %rsi      # 0xf56b
leaq 0x48(%rsp), %rdx
movq %rdi, 0x28(%rsp)
callq 0xb110
leaq 0x4(%rsp), %r13
movq %rbx, 0x30(%rsp)
movl %ebx, %ebp
movq %r15, 0x38(%rsp)
movl %r15d, %r12d
cmpl 0x38(%rsp), %ebp
ja 0xc34b
xorl %r15d, %r15d
movq 0x10(%rsp), %rax
movl %eax, %ebx
cmpl 0x8(%rsp), %ebx
ja 0xc343
movq %r14, %rdi
movl %ebx, %esi
movl %ebp, %edx
leaq 0x6(%rsp), %rcx
leaq 0x5(%rsp), %r8
movq %r13, %r9
callq 0xb48e
movb 0x5(%rsp), %al
orb 0x6(%rsp), %al
orb 0x4(%rsp), %al
sete %al
cmovel %ebp, %r12d
orb %al, %r15b
incl %ebx
jmp 0xc30a
incl %ebp
testb $0x1, %r15b
je 0xc2fa
movq 0x38(%rsp), %rax
movl %eax, %ebp
movq 0x30(%rsp), %rax
movl %eax, %ebx
decl %ebp
cmpl 0x30(%rsp), %ebp
jb 0xc3af
xorl %r13d, %r13d
movq 0x10(%rsp), %rax
movl %eax, %r15d
cmpl 0x8(%rsp), %r15d
ja 0xc3a9
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
leaq 0x6(%rsp), %rcx
leaq 0x5(%rsp), %r8
leaq 0x4(%rsp), %r9
callq 0xb48e
movb 0x5(%rsp), %al
orb 0x6(%rsp), %al
orb 0x4(%rsp), %al
sete %al
cmovel %ebp, %ebx
orb %al, %r13b
incl %r15d
jmp 0xc36c
testb $0x1, %r13b
je 0xc359
movl %ebx, %eax
subl %r12d, %eax
cmpl $0x7, %eax
jbe 0xc3cd
movq 0x28(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rax
movl %eax, %ebp
movq 0x8(%rsp), %rax
movq %rax, 0x20(%rsp)
cmpl 0x8(%rsp), %ebp
ja 0xc437
xorl %r13d, %r13d
movl %r12d, %r15d
cmpl %ebx, %r15d
jg 0xc42f
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
leaq 0x6(%rsp), %rcx
leaq 0x5(%rsp), %r8
leaq 0x4(%rsp), %r9
callq 0xb48e
movb 0x5(%rsp), %al
orb 0x6(%rsp), %al
orb 0x4(%rsp), %al
sete %al
movq 0x20(%rsp), %rcx
cmovel %ebp, %ecx
movq %rcx, 0x20(%rsp)
orb %al, %r13b
incl %r15d
jmp 0xc3ea
incl %ebp
testb $0x1, %r13b
je 0xc3de
movq 0x8(%rsp), %rax
movl %eax, %r13d
movq 0x10(%rsp), %rax
movl %eax, %ebp
movl %r12d, 0x1c(%rsp)
decl %r13d
cmpl 0x10(%rsp), %r13d
jb 0xc4a3
movl %r12d, %r15d
xorl %r12d, %r12d
cmpl %ebx, %r15d
jg 0xc498
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %edx
leaq 0x6(%rsp), %rcx
leaq 0x5(%rsp), %r8
leaq 0x4(%rsp), %r9
callq 0xb48e
movb 0x5(%rsp), %al
orb 0x6(%rsp), %al
orb 0x4(%rsp), %al
sete %al
cmovel %r13d, %ebp
orb %al, %r12b
incl %r15d
jmp 0xc45b
testb $0x1, %r12b
movl 0x1c(%rsp), %r12d
je 0xc44b
addl $0x6, %ebp
movl %ebp, %edi
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0xdbef
movl %eax, %ebp
addl $-0x7, %ebx
movl %ebx, %edi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0xdbef
movl %eax, %ebx
movq 0x20(%rsp), %rax
leal -0x6(%rax), %edi
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0xdbef
movl %eax, 0x10(%rsp)
leaq 0x48(%rsp), %r12
leaq 0x7(%rsp), %r13
movq %rbx, 0x8(%rsp)
cmpl 0x1c(%rsp), %ebx
ja 0xc3b9
movq 0x8(%rsp), %rbx
shlq $0x20, %rbx
movl 0x10(%rsp), %r15d
cmpl 0x20(%rsp), %r15d
ja 0xc558
movl %r15d, %ecx
orq %rbx, %rcx
movq %r12, %rdi
movq 0x40(%rsp), %rsi
movq %r14, %rdx
movl %ebp, %r8d
movq %r13, %r9
callq 0xc690
movq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0x2210
movq %r12, %rdi
callq 0x20d0
incl %r15d
cmpb $0x0, 0x7(%rsp)
je 0xc511
jmp 0xc3b9
movq 0x8(%rsp), %rbx
incl %ebx
jmp 0xc4f4
jmp 0xc56b
jmp 0xc56b
jmp 0xc56b
jmp 0xc56b
jmp 0xc56b
movq %rax, %rbx
movq 0x28(%rsp), %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x2330