// File: /workspace/github_c_makefile_star2_O0/Matthias-Wandel[P]imgcomp/src/compare_util.c
// Function: ProcessDiffMap
void ProcessDiffMap(MemImage_t * MapPic)
{
    int width, height, row, col;
    int firstrow, lastrow;
    int numred, numblue;
    width = MapPic->width;
    height = MapPic->height;

    // Allocate the detection region.
    WeightMap = malloc(offsetof(ImgMap_t, values) 
             + sizeof(WeightMap->values[0])*width*height);
    WeightMap->w = width; 
    WeightMap->h = height;

    numred = numblue = 0;
    firstrow = -1;
    lastrow = 0;

    for (row=0;row<height;row++){
        int * map;
        unsigned char * img;
        map = &WeightMap->values[width*row];
        img = &MapPic->pixels[width*3*row];
        for (col=0;col<width;col++){
            int r,g,b;
            r = img[0];
            g = img[1];
            b = img[2];
            img += 3;

            // If the map is blue, then ignore.
            // If the map is red, then wight 2x.

            if (b > 100 && b > (r+g)*2){
                // Blue.  Ignore.
                *map = 0;
                numblue += 1;
            }else{
                if (firstrow == -1) firstrow = row;
                lastrow = row;
                *map = 1;                
                if (r > 100 && r > (g+b)*2){
                    // Red.  Weigh 2x.
                    *map = 2;
                    numred += 1;
                }
            }
            map += 1;
        }
    }

    Regions.DetectReg.y1 = firstrow;
    Regions.DetectReg.y2 = lastrow;

    ShowWeightMap(WeightMap);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x10(%rbp)
movslq -0xc(%rbp), %rdi
shlq $0x2, %rdi
movslq -0x10(%rbp), %rax
imulq %rax, %rdi
addq $0x8, %rdi
callq 0x3330
movq %rax, %rcx
leaq 0xd766(%rip), %rax      # 0x15468
movq %rcx, (%rax)
movl -0xc(%rbp), %ecx
leaq 0xd759(%rip), %rax      # 0x15468
movq (%rax), %rax
movl %ecx, (%rax)
movl -0x10(%rbp), %ecx
leaq 0xd74a(%rip), %rax      # 0x15468
movq (%rax), %rax
movl %ecx, 0x4(%rax)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x20(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x7e69
leaq 0xd70e(%rip), %rax      # 0x15468
movq (%rax), %rax
addq $0x8, %rax
movl -0xc(%rbp), %ecx
imull -0x14(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
addq $0xc, %rax
imull $0x3, -0xc(%rbp), %ecx
imull -0x14(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x7e59
movq -0x38(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movzbl 0x1(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movzbl 0x2(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x38(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x38(%rbp)
cmpl $0x64, -0x44(%rbp)
jle 0x7df9
movl -0x44(%rbp), %eax
movl -0x3c(%rbp), %ecx
addl -0x40(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jle 0x7df9
movq -0x30(%rbp), %rax
movl $0x0, (%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x7e3f
cmpl $-0x1, -0x1c(%rbp)
jne 0x7e05
movl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x30(%rbp), %rax
movl $0x1, (%rax)
cmpl $0x64, -0x3c(%rbp)
jle 0x7e3d
movl -0x3c(%rbp), %eax
movl -0x40(%rbp), %ecx
addl -0x44(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jle 0x7e3d
movq -0x30(%rbp), %rax
movl $0x2, (%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x7e3f
movq -0x30(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x7d97
jmp 0x7e5b
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x7d47
movl -0x1c(%rbp), %ecx
leaq 0xcfa5(%rip), %rax      # 0x14e18
movl %ecx, 0x8(%rax)
movl -0x20(%rbp), %ecx
leaq 0xcf98(%rip), %rax      # 0x14e18
movl %ecx, 0xc(%rax)
leaq 0xd5de(%rip), %rax      # 0x15468
movq (%rax), %rdi
callq 0x7b70
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)