// File: /workspace/github_c_makefile_star2_O1/Matthias-Wandel[P]imgcomp/src/compare_util.c
// Function: FillWeightMap
void FillWeightMap(int width, int height)
{
    int row, r;
    Region_t Reg;

    WeightMap = malloc(offsetof(ImgMap_t, values) + sizeof(WeightMap->values[0])*width*height); // fixme - use init function
    WeightMap->w = width; WeightMap->h = height;

    memset(WeightMap->values, 0,  sizeof(WeightMap->values)*width*height);

    Reg = Regions.DetectReg;
    if (Reg.x2 > width) Reg.x2 = width;
    if (Reg.y2 > height) Reg.y2 = height;
    printf("fill %d-%d,%d-%d\n",Reg.x1, Reg.x2, Reg.y1, Reg.y2);
    for (row=Reg.y1;row<Reg.y2;row++){
		int * rowP = &WeightMap->values[row*width];
		for (int col=Reg.x1;col<Reg.x2;col++){
			rowP[col] = 1;
		}
    }

    for (r=0;r<Regions.NumExcludeReg;r++){
        Reg=Regions.ExcludeReg[r];
        if (Reg.x2 > width) Reg.x2 = width;
        if (Reg.y2 > height) Reg.y2 = height;
        printf("clear %d-%d,%d-%d\n",Reg.x1, Reg.x2, Reg.y1, Reg.y2);
        for (row=Reg.y1;row<Reg.y2;row++){
            memset(&WeightMap->values[row*width+Reg.x1], 0, Reg.x2-Reg.x1);
        }
    }
    
    ShowWeightMap(WeightMap);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebp
movl %edi, %r13d
movslq %edi, %r12
movslq %esi, %rbx
movq %r12, %rax
imulq %rbx, %rax
leaq 0x8(,%rax,4), %rdi
callq 0x3330
leaq 0xcacc(%rip), %rcx      # 0x13408
movq %rax, (%rcx)
movl %r12d, (%rax)
movl %ebx, 0x4(%rax)
leaq 0xc46c(%rip), %rcx      # 0x12db8
movl (%rcx), %r14d
movl 0x4(%rcx), %r15d
movl 0x8(%rcx), %r8d
movq %r12, (%rsp)
cmpl %r12d, %r15d
movl %r13d, 0xc(%rsp)
cmovgel %r13d, %r15d
movl 0xc(%rcx), %r13d
cmpl %ebx, %r13d
movl %ebp, 0x10(%rsp)
cmovgel %ebp, %r13d
leaq 0x6023(%rip), %rdi      # 0xc9a0
movl %r14d, %esi
movl %r15d, %edx
movl %r8d, %ebx
movl %r8d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x3170
cmpl %r13d, %ebx
jge 0x69ec
movslq %r14d, %rax
movslq %ebx, %rcx
leaq 0xca63(%rip), %rdx      # 0x13408
movq (%rdx), %rdi
movslq %r13d, %rdx
movslq %r15d, %rsi
movq %rcx, %r8
movq (%rsp), %r9
imulq %r9, %r8
leaq (%rdi,%r8,4), %rdi
addq $0x8, %rdi
leaq (,%r9,4), %r8
movq %rax, %r9
cmpl %r15d, %r14d
jge 0x69e1
movl $0x1, (%rdi,%r9,4)
incq %r9
cmpq %r9, %rsi
jne 0x69d1
incq %rcx
addq %r8, %rdi
cmpq %rdx, %rcx
jne 0x69c9
leaq 0xc3c5(%rip), %rdx      # 0x12db8
cmpl $0x0, 0x60(%rdx)
jle 0x6abb
movq (%rsp), %rax
leaq (,%rax,4), %rbp
xorl %ebx, %ebx
movq %rbx, %rax
shlq $0x4, %rax
movl 0x10(%rdx,%rax), %esi
movl 0x14(%rdx,%rax), %r12d
movl 0x18(%rdx,%rax), %r15d
movl 0xc(%rsp), %ecx
cmpl %ecx, %r12d
cmovgel %ecx, %r12d
movl 0x1c(%rdx,%rax), %r14d
movl 0x10(%rsp), %eax
cmpl %eax, %r14d
cmovgel %eax, %r14d
leaq 0x5f70(%rip), %rdi      # 0xc9b2
movl %esi, 0x14(%rsp)
movl %r12d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x3170
cmpl %r14d, %r15d
leaq 0xc9a8(%rip), %r13      # 0x13408
jge 0x6aa4
movl 0x14(%rsp), %edx
movslq %edx, %rax
movslq %r15d, %rcx
subl %edx, %r12d
movslq %r12d, %r15
movslq %r14d, %r14
movq (%rsp), %rdx
imulq %rcx, %rdx
addq %rax, %rdx
leaq 0x8(,%rdx,4), %r12
subq %rcx, %r14
movq (%r13), %rdi
addq %r12, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x31b0
addq %rbp, %r12
decq %r14
jne 0x6a8b
incq %rbx
leaq 0xc30a(%rip), %rdx      # 0x12db8
movslq 0x60(%rdx), %rax
cmpq %rax, %rbx
jl 0x6a0b
leaq 0xc946(%rip), %rax      # 0x13408
movq (%rax), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6ad5