#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 */
void *premul_nozero(int /*<<< orphan*/, int);
int /*<<< orphan*/ qConvertRgb16To32(unsigned int);
void rgb16_rgb32_opacity_inplace(unsigned int *dest, unsigned short *src,
                                 unsigned char opacity) {
  unsigned int srcval = premul_nozero(qConvertRgb16To32(*src), opacity);
  if (srcval & 0xFF000000) {
    int destval = premul_nozero(qConvertRgb16To32(*dest), 0xFF - opacity);
    *dest = 0xFF000000 | (srcval + destval);
  }
}


x86 assembly (clang, -O0):
<rgb16_rgb32_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   1040 <premul_nozero@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff000000,%eax
cmp    $0x0,%eax
je     1192 <rgb16_rgb32_opacity_inplace+0x72>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <qConvertRgb16To32@plt>
mov    %eax,%edi
movzbl -0x11(%rbp),%eax
mov    $0xff,%esi
sub    %eax,%esi
call   1040 <premul_nozero@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%ecx
add    -0x1c(%rbp),%ecx
or     $0xff000000,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rgb16_rgb32_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   1040 <premul_nozero@plt>
mov    %rax,%rbx
cmp    $0x1000000,%ebx
jb     1166 <rgb16_rgb32_opacity_inplace+0x46>
mov    (%r14),%edi
call   1030 <qConvertRgb16To32@plt>
xor    $0xff,%ebp
mov    %eax,%edi
mov    %ebp,%esi
call   1040 <premul_nozero@plt>
add    %ebx,%eax
or     $0xff000000,%eax
mov    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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