// File: /workspace/github_c_makefile_star2_O1/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 0x448a
movl (%rdi), %r10d
movl 0x40(%rsp), %eax
movl 0x38(%rsp), %ebx
movl 0x14(%rdi), %r11d
testl %r11d, %r11d
jns 0x449f
movl 0x4(%rdi), %r11d
movl 0x8(%rdi), %r13d
movl 0xc(%rdi), %r15d
xorl %esi, %esi
movl %r13d, %r14d
subl %edx, %r14d
cmovlel %esi, %r14d
cmovgl %r13d, %edx
subl %r14d, %ebx
addl %r8d, %r14d
movl %r15d, %r12d
subl %ecx, %r12d
cmovlel %esi, %r12d
cmovgl %r15d, %ecx
subl %r12d, %eax
addl %r9d, %r12d
movl %r14d, %ebp
sarl $0x1f, %ebp
andl %r14d, %ebp
addl %ebp, %ebx
testl %r14d, %r14d
cmovlel %esi, %r14d
movl %edx, %r8d
subl %ebp, %r8d
movl %r12d, %r9d
sarl $0x1f, %r9d
andl %r12d, %r9d
addl %r9d, %eax
testl %r12d, %r12d
cmovlel %esi, %r12d
subl %r9d, %ecx
addl %r13d, %r10d
movl %r10d, %esi
subl %r8d, %esi
addl %ebx, %r8d
cmpl %r10d, %r8d
cmovlel %ebx, %esi
leal (%rcx,%rax), %r8d
addl %r15d, %r11d
movl %r11d, %r9d
subl %ecx, %r9d
cmpl %r11d, %r8d
cmovlel %eax, %r9d
leal (%rsi,%r14), %eax
movq -0x18(%rsp), %r11
movslq (%r11), %r10
movl %r10d, %r13d
subl %r14d, %r13d
cmpl %r10d, %eax
cmovlel %esi, %r13d
leal (%r9,%r12), %eax
movl 0x4(%r11), %esi
movl %esi, %r15d
subl %r12d, %r15d
cmpl %esi, %eax
cmovlel %r9d, %r15d
testl %r13d, %r13d
jle 0x46b7
testl %r15d, %r15d
jle 0x46b7
movq %r10, %r8
movl 0x48(%rsp), %eax
movl %eax, %r9d
shrl $0x8, %r9d
movl %eax, %r10d
shrl $0x10, %r10d
movl %eax, %r11d
shrl $0x18, %r11d
movl $0xff, %esi
movl %eax, %ebx
andl %esi, %ebx
cmpl $0x1, %ebx
sbbl $-0x1, %ebx
andl %esi, %r9d
cmpl $0x1, %r9d
sbbl $-0x1, %r9d
andl %esi, %r10d
cmpl $0x1, %r10d
sbbl $-0x1, %r10d
cmpl $0x1000000, %eax        # imm = 0x1000000
sbbl $-0x1, %r11d
imull %r8d, %r12d
movslq (%rdi), %rax
imull %eax, %ecx
movl %r13d, %r13d
addl %ecx, %edx
subl %ebp, %edx
movslq %edx, %rcx
shlq $0x2, %rcx
addq 0x18(%rdi), %rcx
movl 0x28(%rdi), %edx
shlq $0x2, %rax
movq %rax, -0x10(%rsp)
addl %r12d, %r14d
movslq %r14d, %rdi
shlq $0x2, %rdi
movq -0x18(%rsp), %rax
addq 0x18(%rax), %rdi
shlq $0x2, %r8
movq %r8, -0x8(%rsp)
movl %r15d, -0x18(%rsp)
xorl %esi, %esi
movzbl (%rdi,%rsi,4), %r15d
imull %ebx, %r15d
shrl $0x8, %r15d
movzbl 0x1(%rdi,%rsi,4), %eax
imull %r9d, %eax
shrl $0x8, %eax
movzbl 0x2(%rdi,%rsi,4), %r14d
imull %r10d, %r14d
shrl $0x8, %r14d
movzbl 0x3(%rdi,%rsi,4), %ebp
cmpl $0x1, %ebp
movl %ebp, %r12d
sbbl $-0x1, %r12d
imull %r11d, %r12d
movzbl (%rcx,%rsi,4), %r8d
subl %r8d, %r15d
imull %r12d, %r15d
shrl $0x10, %r15d
addb %r8b, %r15b
movb %r15b, (%rcx,%rsi,4)
movzbl 0x1(%rcx,%rsi,4), %r8d
subl %r8d, %eax
imull %r12d, %eax
shrl $0x10, %eax
addb %r8b, %al
movb %al, 0x1(%rcx,%rsi,4)
movzbl 0x2(%rcx,%rsi,4), %eax
subl %eax, %r14d
imull %r12d, %r14d
shrl $0x10, %r14d
addb %al, %r14b
movb %r14b, 0x2(%rcx,%rsi,4)
movzbl 0x3(%rcx,%rsi,4), %eax
subl %eax, %ebp
imull %r12d, %ebp
shrl $0x10, %ebp
imull %edx, %ebp
addb %al, %bpl
movb %bpl, 0x3(%rcx,%rsi,4)
incq %rsi
cmpq %r13, %rsi
jb 0x45fa
addq -0x10(%rsp), %rcx
addq -0x8(%rsp), %rdi
movl -0x18(%rsp), %r15d
decl %r15d
jne 0x45f3
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq