// File: /workspace/github_c_makefile_star2_O3/nkanaev[P]tipsy/src/tigr.c
// Function: tigrBlitTint
void tigrBlitTint(Tigr* dst, Tigr* src, int dx, int dy, int sx, int sy, int w, int h, TPixel tint) {
    int cw = dst->cw >= 0 ? dst->cw : dst->w;
    int ch = dst->ch >= 0 ? dst->ch : dst->h;

    CLIP();

    int xr = EXPAND(tint.r);
    int xg = EXPAND(tint.g);
    int xb = EXPAND(tint.b);
    int xa = EXPAND(tint.a);

    TPixel* ts = &src->pix[sy * src->w + sx];
    TPixel* td = &dst->pix[dy * dst->w + dx];
    int st = src->w;
    int dt = dst->w;
    do {
        for (int x = 0; x < w; x++) {
            unsigned r = (xr * ts[x].r) >> 8;
            unsigned g = (xg * ts[x].g) >> 8;
            unsigned b = (xb * ts[x].b) >> 8;
            unsigned a = xa * EXPAND(ts[x].a);
            td[x].r += (unsigned char)((r - td[x].r) * a >> 16);
            td[x].g += (unsigned char)((g - td[x].g) * a >> 16);
            td[x].b += (unsigned char)((b - td[x].b) * a >> 16);
            td[x].a += (dst->blitMode) * (unsigned char)((ts[x].a - td[x].a) * a >> 16);
        }
        ts += st;
        td += dt;
    } while (--h);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rsi, -0x18(%rsp)
movl 0x10(%rdi), %r10d
testl %r10d, %r10d
jns 0x4594
movl (%rdi), %r10d
movl 0x40(%rsp), %eax
movl 0x38(%rsp), %r15d
movl 0x14(%rdi), %r11d
testl %r11d, %r11d
jns 0x45aa
movl 0x4(%rdi), %r11d
movl 0x8(%rdi), %r13d
movl 0xc(%rdi), %ebp
xorl %esi, %esi
movl %r13d, %ebx
subl %edx, %ebx
cmovlel %esi, %ebx
cmovgl %r13d, %edx
subl %ebx, %r15d
addl %r8d, %ebx
movl %ebp, %r14d
subl %ecx, %r14d
cmovlel %esi, %r14d
cmovgl %ebp, %ecx
subl %r14d, %eax
addl %r9d, %r14d
movl %ebx, %r12d
sarl $0x1f, %r12d
andl %ebx, %r12d
leal (%r12,%r15), %r8d
testl %ebx, %ebx
cmovlel %esi, %ebx
movl %r14d, %r9d
sarl $0x1f, %r9d
andl %r14d, %r9d
testl %r14d, %r14d
cmovlel %esi, %r14d
movl %ecx, %esi
subl %r9d, %esi
addl %edx, %r15d
addl %r13d, %r10d
movl %r12d, %r13d
subl %edx, %r13d
addl %r10d, %r13d
cmpl %r10d, %r15d
cmovlel %r8d, %r13d
leal (%r9,%rax), %r8d
addl %ecx, %eax
addl %ebp, %r11d
movl %r11d, %r9d
subl %esi, %r9d
cmpl %r11d, %eax
cmovlel %r8d, %r9d
leal (%rbx,%r13), %eax
movq -0x18(%rsp), %r10
movslq (%r10), %r8
movl %r8d, %ebp
subl %ebx, %ebp
movq %r8, %rcx
cmpl %r8d, %eax
cmovlel %r13d, %ebp
leal (%r9,%r14), %eax
movl 0x4(%r10), %r8d
movl %r8d, %r13d
subl %r14d, %r13d
cmpl %r8d, %eax
cmovlel %r9d, %r13d
testl %ebp, %ebp
jle 0x47bf
testl %r13d, %r13d
jle 0x47bf
movl 0x48(%rsp), %eax
movl %eax, %r8d
shrl $0x8, %r8d
movl %eax, %r9d
shrl $0x10, %r9d
movl %eax, %r10d
shrl $0x18, %r10d
movl $0xff, %r15d
movl %eax, %r11d
andl %r15d, %r11d
cmpl $0x1, %r11d
sbbl $-0x1, %r11d
andl %r15d, %r8d
cmpl $0x1, %r8d
sbbl $-0x1, %r8d
andl %r15d, %r9d
cmpl $0x1, %r9d
sbbl $-0x1, %r9d
cmpl $0x1000000, %eax        # imm = 0x1000000
sbbl $-0x1, %r10d
imull %ecx, %r14d
addl %ebx, %r14d
movslq %r14d, %rbx
movslq (%rdi), %rax
imull %eax, %esi
movl %ebp, %r15d
movl 0x28(%rdi), %ebp
addl %esi, %edx
subl %r12d, %edx
movslq %edx, %rdx
shlq $0x2, %rdx
addq 0x18(%rdi), %rdx
shlq $0x2, %rax
movq %rax, -0x10(%rsp)
shlq $0x2, %rbx
movq -0x18(%rsp), %rax
addq 0x18(%rax), %rbx
shlq $0x2, %rcx
movq %rcx, -0x8(%rsp)
movl %r13d, -0x18(%rsp)
xorl %esi, %esi
movzbl (%rbx,%rsi,4), %r14d
imull %r11d, %r14d
shrl $0x8, %r14d
movzbl 0x1(%rbx,%rsi,4), %eax
imull %r8d, %eax
shrl $0x8, %eax
movzbl 0x2(%rbx,%rsi,4), %r12d
imull %r9d, %r12d
shrl $0x8, %r12d
movzbl 0x3(%rbx,%rsi,4), %edi
cmpl $0x1, %edi
movl %edi, %r13d
sbbl $-0x1, %r13d
imull %r10d, %r13d
movzbl (%rdx,%rsi,4), %ecx
subl %ecx, %r14d
imull %r13d, %r14d
shrl $0x10, %r14d
addb %cl, %r14b
movb %r14b, (%rdx,%rsi,4)
movzbl 0x1(%rdx,%rsi,4), %ecx
subl %ecx, %eax
imull %r13d, %eax
shrl $0x10, %eax
addb %cl, %al
movb %al, 0x1(%rdx,%rsi,4)
movzbl 0x2(%rdx,%rsi,4), %eax
subl %eax, %r12d
imull %r13d, %r12d
shrl $0x10, %r12d
addb %al, %r12b
movb %r12b, 0x2(%rdx,%rsi,4)
movzbl 0x3(%rdx,%rsi,4), %eax
subl %eax, %edi
imull %r13d, %edi
shrl $0x10, %edi
imull %ebp, %edi
addb %al, %dil
movb %dil, 0x3(%rdx,%rsi,4)
incq %rsi
cmpq %r15, %rsi
jb 0x4706
addq -0x10(%rsp), %rdx
addq -0x8(%rsp), %rbx
movl -0x18(%rsp), %r13d
decl %r13d
jne 0x46ff
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq