// File: /workspace/github_c_makefile_star2_O2/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, -0x10(%rsp)
movl 0x10(%rdi), %r10d
testl %r10d, %r10d
jns 0x449a
movl (%rdi), %r10d
movl 0x40(%rsp), %eax
movl 0x38(%rsp), %r15d
movl 0x14(%rdi), %r11d
testl %r11d, %r11d
jns 0x44b0
movl 0x4(%rdi), %r11d
movl 0x8(%rdi), %ebp
movl 0xc(%rdi), %esi
xorl %r13d, %r13d
movl %ebp, %ebx
subl %edx, %ebx
cmovlel %r13d, %ebx
cmovgl %ebp, %edx
subl %ebx, %r15d
addl %r8d, %ebx
movl %esi, %r14d
subl %ecx, %r14d
cmovlel %r13d, %r14d
cmovgl %esi, %ecx
subl %r14d, %eax
addl %r9d, %r14d
movl %ebx, %r12d
sarl $0x1f, %r12d
andl %ebx, %r12d
leal (%r12,%r15), %r8d
testl %ebx, %ebx
cmovlel %r13d, %ebx
movl %r14d, %r9d
sarl $0x1f, %r9d
andl %r14d, %r9d
testl %r14d, %r14d
cmovlel %r13d, %r14d
movl %ecx, %r13d
subl %r9d, %r13d
addl %edx, %r15d
addl %ebp, %r10d
movl %r12d, %ebp
subl %edx, %ebp
addl %r10d, %ebp
cmpl %r10d, %r15d
cmovlel %r8d, %ebp
leal (%r9,%rax), %r8d
addl %ecx, %eax
addl %esi, %r11d
movl %r11d, %esi
subl %r13d, %esi
cmpl %r11d, %eax
cmovlel %r8d, %esi
leal (%rbx,%rbp), %eax
movq -0x10(%rsp), %r9
movslq (%r9), %r8
movl %r8d, %r15d
subl %ebx, %r15d
movq %r8, %rcx
cmpl %r8d, %eax
cmovlel %ebp, %r15d
leal (%rsi,%r14), %eax
movl 0x4(%r9), %r8d
movl %r8d, %r9d
subl %r14d, %r9d
cmpl %r8d, %eax
cmovlel %esi, %r9d
movl %r9d, -0x14(%rsp)
testl %r15d, %r15d
jle 0x46cd
cmpl $0x0, -0x14(%rsp)
jle 0x46cd
movl 0x48(%rsp), %eax
movl %eax, %r8d
shrl $0x8, %r8d
movl %eax, %r9d
shrl $0x10, %r9d
movl %eax, %r10d
shrl $0x18, %r10d
movl $0xff, %esi
movl %eax, %r11d
andl %esi, %r11d
cmpl $0x1, %r11d
sbbl $-0x1, %r11d
andl %esi, %r8d
cmpl $0x1, %r8d
sbbl $-0x1, %r8d
andl %esi, %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, %r13d
movl %r15d, %r15d
shlq $0x2, %r15
addl %r13d, %edx
subl %r12d, %edx
movslq %edx, %rdx
shlq $0x2, %rdx
addq 0x18(%rdi), %rdx
shlq $0x2, %rax
movq %rax, -0x8(%rsp)
shlq $0x2, %rbx
movq -0x10(%rsp), %rax
addq 0x18(%rax), %rbx
shlq $0x2, %rcx
movq %rcx, -0x10(%rsp)
xorl %esi, %esi
cmpq %rsi, %r15
je 0x46b9
movzbl (%rbx,%rsi), %r14d
imull %r11d, %r14d
shrl $0x8, %r14d
movzbl 0x1(%rbx,%rsi), %eax
imull %r8d, %eax
shrl $0x8, %eax
movzbl 0x2(%rbx,%rsi), %r12d
imull %r9d, %r12d
shrl $0x8, %r12d
movzbl 0x3(%rbx,%rsi), %ebp
cmpl $0x1, %ebp
movl %ebp, %r13d
sbbl $-0x1, %r13d
imull %r10d, %r13d
movzbl (%rdx,%rsi), %ecx
subl %ecx, %r14d
imull %r13d, %r14d
shrl $0x10, %r14d
addb %cl, %r14b
movb %r14b, (%rdx,%rsi)
movzbl 0x1(%rdx,%rsi), %ecx
subl %ecx, %eax
imull %r13d, %eax
shrl $0x10, %eax
addb %cl, %al
movb %al, 0x1(%rdx,%rsi)
movzbl 0x2(%rdx,%rsi), %eax
subl %eax, %r12d
imull %r13d, %r12d
shrl $0x10, %r12d
addb %al, %r12b
movb %r12b, 0x2(%rdx,%rsi)
movzbl 0x3(%rdx,%rsi), %eax
subl %eax, %ebp
imull %r13d, %ebp
shrl $0x10, %ebp
imull 0x28(%rdi), %ebp
addb %al, %bpl
movb %bpl, 0x3(%rdx,%rsi)
addq $0x4, %rsi
jmp 0x4611
addq -0x8(%rsp), %rdx
addq -0x10(%rsp), %rbx
decl -0x14(%rsp)
jne 0x460f
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq