// File: /workspace/github_c_makefile_star2_O3/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 0x3340
leaq 0xca58(%rip), %rcx      # 0x13408
movq %rax, (%rcx)
movl %r12d, (%rax)
movl %ebx, 0x4(%rax)
leaq 0xc3f8(%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 0x6027(%rip), %rdi      # 0xca18
movl %r14d, %esi
movl %r15d, %edx
movl %r8d, %ebx
movl %r8d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x3170
cmpl %r13d, %ebx
jge 0x6b62
movslq %r14d, %rsi
movslq %ebx, %rax
leaq 0xc9eb(%rip), %rcx      # 0x13408
movq (%rcx), %rdi
movslq %r13d, %rcx
movslq %r15d, %r8
subq %rsi, %r8
leaq 0x3(%r8), %rdx
andq $-0x4, %rdx
decq %r8
movq %r8, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movq %rax, %r8
movq (%rsp), %r9
imulq %r9, %r8
shlq $0x2, %rsi
leaq (%rsi,%r8,4), %rsi
addq %rdi, %rsi
addq $0x14, %rsi
leaq (,%r9,4), %rdi
movdqa 0x5f78(%rip), %xmm1     # 0xc9e0
movdqa 0x5f80(%rip), %xmm2     # 0xc9f0
movdqa 0x5f88(%rip), %xmm3     # 0xca00
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
cmpl %r15d, %r14d
jge 0x6b53
xorl %r8d, %r8d
movq %r8, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
movdqa %xmm5, %xmm6
por %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %r9d
notl %r9d
testb $0x1, %r9b
je 0x6ada
movl $0x1, -0xc(%rsi,%r8,4)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %r9d
testb $0x1, %r9b
je 0x6af3
movl $0x1, -0x8(%rsi,%r8,4)
por %xmm1, %xmm5
pxor %xmm3, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
pxor %xmm4, %xmm5
pextrw $0x0, %xmm5, %r9d
testb $0x1, %r9b
je 0x6b32
movl $0x1, -0x4(%rsi,%r8,4)
pextrw $0x4, %xmm5, %r9d
testb $0x1, %r9b
je 0x6b46
movl $0x1, (%rsi,%r8,4)
addq $0x4, %r8
cmpq %r8, %rdx
jne 0x6a8c
incq %rax
addq %rdi, %rsi
cmpq %rcx, %rax
jne 0x6a80
leaq 0xc24f(%rip), %rdx      # 0x12db8
cmpl $0x0, 0x60(%rdx)
jle 0x6c31
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 0x5e72(%rip), %rdi      # 0xca2a
movl %esi, 0x14(%rsp)
movl %r12d, %edx
movl %r15d, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x3170
cmpl %r14d, %r15d
leaq 0xc832(%rip), %r13      # 0x13408
jge 0x6c1a
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 0x6c01
incq %rbx
leaq 0xc194(%rip), %rdx      # 0x12db8
movslq 0x60(%rdx), %rax
cmpq %rax, %rbx
jl 0x6b81
leaq 0xc7d0(%rip), %rax      # 0x13408
movq (%rax), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6c4b