// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movslq -0x4(%rbp), %rdi
shlq $0x2, %rdi
movslq -0x8(%rbp), %rax
imulq %rax, %rdi
addq $0x8, %rdi
callq 0x3330
movq %rax, %rcx
leaq 0xdad7(%rip), %rax      # 0x15468
movq %rcx, (%rax)
movl -0x4(%rbp), %ecx
leaq 0xdaca(%rip), %rax      # 0x15468
movq (%rax), %rax
movl %ecx, (%rax)
movl -0x8(%rbp), %ecx
leaq 0xdabb(%rip), %rax      # 0x15468
movq (%rax), %rax
movl %ecx, 0x4(%rax)
leaq 0xdaae(%rip), %rax      # 0x15468
movq (%rax), %rdi
addq $0x8, %rdi
movslq -0x4(%rbp), %rax
imulq $0x0, %rax, %rdx
movslq -0x8(%rbp), %rax
imulq %rax, %rdx
xorl %esi, %esi
callq 0x31b0
leaq 0xd439(%rip), %rax      # 0x14e18
movq (%rax), %rcx
movq %rcx, -0x20(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jle 0x79fc
movl -0x4(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jle 0x7a0a
movl -0x8(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x20(%rbp), %esi
movl -0x1c(%rbp), %edx
movl -0x18(%rbp), %ecx
movl -0x14(%rbp), %r8d
leaq 0x7f7b(%rip), %rdi      # 0xf999
movb $0x0, %al
callq 0x3170
movl -0x18(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x7a8b
leaq 0xda2e(%rip), %rax      # 0x15468
movq (%rax), %rax
addq $0x8, %rax
movl -0xc(%rbp), %ecx
imull -0x4(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x7a7e
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x7a5c
jmp 0x7a80
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x7a2b
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
leaq 0xd37c(%rip), %rcx      # 0x14e18
cmpl 0x60(%rcx), %eax
jge 0x7b5b
movslq -0x10(%rbp), %rcx
leaq 0xd368(%rip), %rax      # 0x14e18
addq $0x10, %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x20(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x4(%rbp), %eax
jle 0x7ad8
movl -0x4(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x8(%rbp), %eax
jle 0x7ae6
movl -0x8(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x20(%rbp), %esi
movl -0x1c(%rbp), %edx
movl -0x18(%rbp), %ecx
movl -0x14(%rbp), %r8d
leaq 0x7eb1(%rip), %rdi      # 0xf9ab
movb $0x0, %al
callq 0x3170
movl -0x18(%rbp), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x7b4b
leaq 0xd952(%rip), %rax      # 0x15468
movq (%rax), %rdi
addq $0x8, %rdi
movl -0xc(%rbp), %eax
imull -0x4(%rbp), %eax
addl -0x20(%rbp), %eax
cltq
shlq $0x2, %rax
addq %rax, %rdi
movl -0x1c(%rbp), %eax
subl -0x20(%rbp), %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x31b0
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x7b07
jmp 0x7b4d
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x7a92
leaq 0xd906(%rip), %rax      # 0x15468
movq (%rax), %rdi
callq 0x7b70
addq $0x30, %rsp
popq %rbp
retq