// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movq %rcx, %rbx
movq %rdx, 0x28(%rsp)
movq %rsi, 0x50(%rsp)
movq %rcx, %r15
shrq $0x20, %r15
movq %r8, 0x10(%rsp)
movq %r8, %r12
shrq $0x20, %r12
leaq 0x10(%rdi), %rax
movq %rax, 0x48(%rsp)
movq %rax, (%rdi)
leaq 0x3e96(%rip), %rdx      # 0x135ff
movq %rdi, 0x40(%rsp)
movq %rdx, %rsi
callq 0xe0ea
movl %r12d, %r14d
movq %r15, 0x38(%rsp)
movq %r12, 0x30(%rsp)
cmpq %r12, %r15
movq %rbx, 0x18(%rsp)
ja 0xf7ff
leaq 0xd(%rsp), %r15
leaq 0xc(%rsp), %r12
movq 0x30(%rsp), %rax
movl %eax, %r14d
movq 0x38(%rsp), %rax
movl %eax, %ebp
cmpl 0x10(%rsp), %ebx
ja 0xf7f7
movq %rbx, %rax
xorl %ebx, %ebx
movl %eax, %r13d
movq 0x28(%rsp), %rdi
movl %r13d, %esi
movl %ebp, %edx
leaq 0xe(%rsp), %rcx
movq %r15, %r8
movq %r12, %r9
callq 0xe564
movb 0xd(%rsp), %al
orb 0xe(%rsp), %al
orb 0xc(%rsp), %al
cmovel %ebp, %r14d
sete %al
orb %al, %bl
incl %r13d
cmpl 0x10(%rsp), %r13d
jbe 0xf7b4
testb $0x1, %bl
movq 0x18(%rsp), %rbx
jne 0xf7ff
incl %ebp
cmpl 0x30(%rsp), %ebp
jbe 0xf7a6
leaq 0xc(%rsp), %r13
movq 0x30(%rsp), %rax
movl %eax, %r12d
movq 0x38(%rsp), %rax
movl %eax, %ebx
decl %r12d
cmpl 0x38(%rsp), %r12d
jb 0xf874
movq 0x18(%rsp), %rax
cmpl 0x10(%rsp), %eax
jbe 0xf82c
xorl %ebp, %ebp
jmp 0xf86e
xorl %ebp, %ebp
movl %eax, %r15d
movq 0x28(%rsp), %rdi
movl %r15d, %esi
movl %r12d, %edx
leaq 0xe(%rsp), %rcx
leaq 0xd(%rsp), %r8
movq %r13, %r9
callq 0xe564
movb 0xd(%rsp), %al
orb 0xe(%rsp), %al
orb 0xc(%rsp), %al
cmovel %r12d, %ebx
sete %al
orb %al, %bpl
incl %r15d
cmpl 0x10(%rsp), %r15d
jbe 0xf831
testb $0x1, %bpl
je 0xf813
movl %ebx, %eax
subl %r14d, %eax
cmpl $0x7, %eax
ja 0xf9bc
movq 0x10(%rsp), %rax
movl %eax, %ecx
movq %rcx, 0x20(%rsp)
cmpl %eax, 0x18(%rsp)
ja 0xf906
leaq 0xc(%rsp), %r12
movq 0x10(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x18(%rsp), %rax
movl %eax, %ebp
cmpl %r14d, %ebx
jl 0xf8fe
xorl %r13d, %r13d
movl %r14d, %r15d
movq 0x28(%rsp), %rdi
movl %ebp, %esi
movl %r15d, %edx
leaq 0xe(%rsp), %rcx
leaq 0xd(%rsp), %r8
movq %r12, %r9
callq 0xe564
movb 0xd(%rsp), %al
orb 0xe(%rsp), %al
orb 0xc(%rsp), %al
movq 0x20(%rsp), %rax
cmovel %ebp, %eax
movq %rax, 0x20(%rsp)
sete %al
orb %al, %r13b
incl %r15d
cmpl %ebx, %r15d
jle 0xf8b5
testb $0x1, %r13b
jne 0xf906
incl %ebp
cmpl 0x10(%rsp), %ebp
jbe 0xf8aa
movq 0x10(%rsp), %rax
movl %eax, %r12d
movq 0x18(%rsp), %rax
movl %eax, %r15d
decl %r12d
cmpl 0x18(%rsp), %r12d
jb 0xf96d
xorl %ebp, %ebp
cmpl %r14d, %ebx
jl 0xf967
movl %r14d, %r13d
movq 0x28(%rsp), %rdi
movl %r12d, %esi
movl %r13d, %edx
leaq 0xe(%rsp), %rcx
leaq 0xd(%rsp), %r8
leaq 0xc(%rsp), %r9
callq 0xe564
movb 0xd(%rsp), %al
orb 0xe(%rsp), %al
orb 0xc(%rsp), %al
cmovel %r12d, %r15d
sete %al
orb %al, %bpl
incl %r13d
cmpl %ebx, %r13d
jle 0xf92a
testb $0x1, %bpl
je 0xf916
addl $0x6, %r15d
movl %r15d, %edi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x11538
movl %eax, %r15d
addl $-0x7, %ebx
movl %ebx, %edi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x11538
movl %eax, %ebp
movq 0x20(%rsp), %rax
leal -0x6(%rax), %edi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x11538
movl %eax, 0x10(%rsp)
cmpl %r14d, %ebp
jbe 0xf9d0
movq 0x40(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x58(%rsp), %r12
movl 0x10(%rsp), %eax
cmpl 0x20(%rsp), %eax
ja 0xfa45
movq %rbp, %rbx
shlq $0x20, %rbx
movl 0x10(%rsp), %r13d
movl %r13d, %ecx
orq %rbx, %rcx
movq %r12, %rdi
movq 0x50(%rsp), %rsi
movq 0x28(%rsp), %rdx
movl %r15d, %r8d
leaq 0xf(%rsp), %r9
callq 0xfbb6
movq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x2230
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xfa34
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21c0
cmpb $0x0, 0xf(%rsp)
jne 0xf9bc
incl %r13d
cmpl 0x20(%rsp), %r13d
jbe 0xf9eb
incl %ebp
cmpl %r14d, %ebp
jbe 0xf9d5
jmp 0xf9bc
jmp 0xfa5b
jmp 0xfa5b
jmp 0xfa5b
jmp 0xfa5b
jmp 0xfa5b
movq %rax, %rbx
movq 0x40(%rsp), %rax
movq (%rax), %rdi
movq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xfa7b
movq (%rax), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2340
nop