// File: /workspace/github_cpp_makefile_star2_O1/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, %r14
shrq $0x20, %r14
movq %r8, 0x10(%rsp)
movq %r8, %r15
shrq $0x20, %r15
leaq 0x10(%rdi), %rax
movq %rax, 0x48(%rsp)
movq %rax, (%rdi)
leaq 0x3ac8(%rip), %rdx      # 0x1352f
movq %rdi, 0x40(%rsp)
movq %rdx, %rsi
callq 0xe3ee
movl %r15d, %r12d
movq %r14, 0x38(%rsp)
movq %r15, 0x30(%rsp)
cmpq %r15, %r14
movq %rbx, 0x18(%rsp)
ja 0xfafc
xorl %r14d, %r14d
leaq 0xc(%rsp), %r13
movl $0x1, %r15d
movq 0x30(%rsp), %rax
movl %eax, %r12d
movq 0x38(%rsp), %rax
movl %eax, %ebp
cmpl 0x10(%rsp), %ebx
ja 0xfae9
movq 0x28(%rsp), %rdi
movl %ebx, %esi
movl %ebp, %edx
leaq 0xe(%rsp), %rcx
leaq 0xd(%rsp), %r8
movq %r13, %r9
callq 0xe85a
movb 0xd(%rsp), %al
orb 0xe(%rsp), %al
orb 0xc(%rsp), %al
movzbl %r14b, %r14d
cmovel %r15d, %r14d
cmovel %ebp, %r12d
incl %ebx
cmpl 0x10(%rsp), %ebx
jbe 0xfaae
testb $0x1, %r14b
jne 0xfafc
incl %ebp
cmpl 0x30(%rsp), %ebp
movq 0x18(%rsp), %rbx
jbe 0xfaa8
xorl %r14d, %r14d
movl $0x1, %r13d
movq 0x30(%rsp), %rax
movl %eax, %ebp
movq 0x38(%rsp), %rax
movl %eax, %ebx
decl %ebp
cmpl 0x38(%rsp), %ebp
jb 0xfb6e
movq 0x18(%rsp), %rax
cmpl 0x10(%rsp), %eax
ja 0xfb68
movl %eax, %r15d
movq 0x28(%rsp), %rdi
movl %r15d, %esi
movl %ebp, %edx
leaq 0xe(%rsp), %rcx
leaq 0xd(%rsp), %r8
leaq 0xc(%rsp), %r9
callq 0xe85a
movb 0xd(%rsp), %al
orb 0xe(%rsp), %al
orb 0xc(%rsp), %al
movzbl %r14b, %r14d
cmovel %r13d, %r14d
cmovel %ebp, %ebx
incl %r15d
cmpl 0x10(%rsp), %r15d
jbe 0xfb29
testb $0x1, %r14b
je 0xfb13
movl %ebx, %eax
subl %r12d, %eax
cmpl $0x7, %eax
ja 0xfcc0
movq 0x10(%rsp), %rax
movl %eax, %ecx
movq %rcx, 0x20(%rsp)
cmpl %eax, 0x18(%rsp)
ja 0xfc05
xorl %r13d, %r13d
movl $0x1, %r14d
movq 0x10(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x18(%rsp), %rax
movl %eax, %ebp
cmpl %r12d, %ebx
jl 0xfbf7
movl %r12d, %r15d
movq 0x28(%rsp), %rdi
movl %ebp, %esi
movl %r15d, %edx
leaq 0xe(%rsp), %rcx
leaq 0xd(%rsp), %r8
leaq 0xc(%rsp), %r9
callq 0xe85a
movb 0xd(%rsp), %al
orb 0xe(%rsp), %al
orb 0xc(%rsp), %al
movzbl %r13b, %r13d
cmovel %r14d, %r13d
movq 0x20(%rsp), %rax
cmovel %ebp, %eax
movq %rax, 0x20(%rsp)
incl %r15d
cmpl %ebx, %r15d
jle 0xfbb0
testb $0x1, %r13b
jne 0xfc05
incl %ebp
cmpl 0x10(%rsp), %ebp
jbe 0xfba8
xorl %r14d, %r14d
movq 0x10(%rsp), %rax
movl %eax, %r13d
movq 0x18(%rsp), %rax
movl %eax, %ebp
decl %r13d
cmpl 0x18(%rsp), %r13d
jb 0xfc73
cmpl %r12d, %ebx
jl 0xfc6d
movl %r12d, %r15d
movq 0x28(%rsp), %rdi
movl %r13d, %esi
movl %r15d, %edx
leaq 0xe(%rsp), %rcx
leaq 0xd(%rsp), %r8
leaq 0xc(%rsp), %r9
callq 0xe85a
movb 0xd(%rsp), %al
orb 0xe(%rsp), %al
orb 0xc(%rsp), %al
movzbl %r14b, %r14d
movl $0x1, %eax
cmovel %eax, %r14d
cmovel %r13d, %ebp
incl %r15d
cmpl %ebx, %r15d
jle 0xfc29
testb $0x1, %r14b
je 0xfc17
addl $0x6, %ebp
movl %ebp, %edi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x118c4
movl %eax, %ebp
addl $-0x7, %ebx
movl %ebx, %edi
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rdx
callq 0x118c4
movl %eax, %r14d
movq 0x20(%rsp), %rax
leal -0x6(%rax), %edi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0x118c4
movl %eax, 0x10(%rsp)
cmpl %r12d, %r14d
jbe 0xfcd4
movq 0x40(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x58(%rsp), %r15
movl 0x10(%rsp), %eax
cmpl 0x20(%rsp), %eax
ja 0xfd49
movq %r14, %rbx
shlq $0x20, %rbx
movl 0x10(%rsp), %r13d
movl %r13d, %ecx
orq %rbx, %rcx
movq %r15, %rdi
movq 0x50(%rsp), %rsi
movq 0x28(%rsp), %rdx
movl %ebp, %r8d
leaq 0xf(%rsp), %r9
callq 0xfebe
movq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x2230
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0xfd38
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21c0
cmpb $0x0, 0xf(%rsp)
jne 0xfcc0
incl %r13d
cmpl 0x20(%rsp), %r13d
jbe 0xfcef
incl %r14d
cmpl %r12d, %r14d
jbe 0xfcd9
jmp 0xfcc0
jmp 0xfd60
jmp 0xfd60
jmp 0xfd60
jmp 0xfd60
jmp 0xfd60
movq %rax, %rbx
movq 0x40(%rsp), %rax
movq (%rax), %rdi
movq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xfd80
movq (%rax), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2340