#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
unsigned int premul_nozero(int /*<<< orphan*/, int);
int /*<<< orphan*/ qConvertRgb16To32(unsigned short);
unsigned short qConvertRgb32To16(unsigned int);
void rgb16_rgb16_opacity_inplace(unsigned short *dest, unsigned short *src,
                                 unsigned char opacity) {
  unsigned int srcval = premul_nozero(qConvertRgb16To32(*src), opacity);
  if (srcval & 0xFF000000) {
    unsigned int destval =
        premul_nozero(qConvertRgb16To32(*dest), 0xFF - opacity);
    *dest = qConvertRgb32To16(srcval + destval);
  }
}


x86 assembly (clang, -O0):
<rgb16_rgb16_opacity_inplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
movzwl (%rax),%edi
call   1030 <qConvertRgb16To32@plt>
mov    %eax,%edi
movzbl -0x11(%rbp),%esi
call   1050 <premul_nozero@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff000000,%eax
cmp    $0x0,%eax
je     11a6 <rgb16_rgb16_opacity_inplace+0x76>
mov    -0x8(%rbp),%rax
movzwl (%rax),%edi
call   1030 <qConvertRgb16To32@plt>
mov    %eax,%edi
movzbl -0x11(%rbp),%eax
mov    $0xff,%esi
sub    %eax,%esi
call   1050 <premul_nozero@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
add    -0x1c(%rbp),%edi
call   1040 <qConvertRgb32To16@plt>
mov    %ax,%cx
mov    -0x8(%rbp),%rax
mov    %cx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rgb16_rgb16_opacity_inplace>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rdi,%r14
movzwl (%rsi),%edi
call   1030 <qConvertRgb16To32@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1050 <premul_nozero@plt>
cmp    $0x1000000,%eax
jb     1178 <rgb16_rgb16_opacity_inplace+0x48>
mov    %eax,%ebx
movzwl (%r14),%edi
call   1030 <qConvertRgb16To32@plt>
xor    $0xff,%ebp
mov    %eax,%edi
mov    %ebp,%esi
call   1050 <premul_nozero@plt>
add    %eax,%ebx
mov    %ebx,%edi
call   1040 <qConvertRgb32To16@plt>
mov    %ax,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @rgb16_rgb16_opacity_inplace(i16* %0, i16* %1, i8 zeroext %2) {
%4 = alloca i16*
%5 = alloca i16*
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i16* %0, i16** %4
store i16* %1, i16** %5
store i8 %2, i8* %6
%9 = load i16*, i16** %5
%10 = load i16, i16* %9
%11 = call i32 @qConvertRgb16To32(i16 zeroext %10)
%12 = load i8, i8* %6
%13 = zext i8 %12 to i32
%14 = call i32 @premul_nozero(i32 %11, i32 %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = and i32 %15, -16777216
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %3
%19 = load i16*, i16** %4
%20 = load i16, i16* %19
%21 = call i32 @qConvertRgb16To32(i16 zeroext %20)
%22 = load i8, i8* %6
%23 = zext i8 %22 to i32
%24 = sub nsw i32 255, %23
%25 = call i32 @premul_nozero(i32 %21, i32 %24)
store i32 %25, i32* %8
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = add i32 %26, %27
%29 = call zeroext i16 @qConvertRgb32To16(i32 %28)
%30 = load i16*, i16** %4
store i16 %29, i16* %30
br label %31
31: ; preds = %18, %3
ret void
}

LLVM IR (-O2):
define void @rgb16_rgb16_opacity_inplace(i16* nocapture %0, i16* nocapture %1, i8 zeroext %2) {
%4 = load i16, i16* %1
%5 = tail call i32 @qConvertRgb16To32(i16 zeroext %4)
%6 = zext i8 %2 to i32
%7 = tail call i32 @premul_nozero(i32 %5, i32 %6)
%8 = icmp ult i32 %7, 16777216
br i1 %8, label %16, label %9
9: ; preds = %3
%10 = load i16, i16* %0
%11 = tail call i32 @qConvertRgb16To32(i16 zeroext %10)
%12 = xor i32 %6, 255
%13 = tail call i32 @premul_nozero(i32 %11, i32 %12)
%14 = add i32 %13, %7
%15 = tail call zeroext i16 @qConvertRgb32To16(i32 %14)
store i16 %15, i16* %0
br label %16
16: ; preds = %9, %3
ret void
}