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


x86 assembly (clang, -O0):
<rgb32_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
mov    (%rax),%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     119e <rgb32_rgb16_opacity_inplace+0x6e>
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):
<rgb32_rgb16_opacity_inplace>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rdi,%r14
mov    (%rsi),%edi
mov    %edx,%esi
call   1050 <premul_nozero@plt>
cmp    $0x1000000,%eax
jb     1170 <rgb32_rgb16_opacity_inplace+0x40>
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 @rgb32_rgb16_opacity_inplace(i16* %0, i32* %1, i8 zeroext %2) {
%4 = alloca i16*
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i16* %0, i16** %4
store i32* %1, i32** %5
store i8 %2, i8* %6
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = load i8, i8* %6
%12 = zext i8 %11 to i32
%13 = call i32 @premul_nozero(i32 %10, i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = and i32 %14, -16777216
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %3
%18 = load i16*, i16** %4
%19 = load i16, i16* %18
%20 = call i32 @qConvertRgb16To32(i16 zeroext %19)
%21 = load i8, i8* %6
%22 = zext i8 %21 to i32
%23 = sub nsw i32 255, %22
%24 = call i32 @premul_nozero(i32 %20, i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = add i32 %25, %26
%28 = call zeroext i16 @qConvertRgb32To16(i32 %27)
%29 = load i16*, i16** %4
store i16 %28, i16* %29
br label %30
30: ; preds = %17, %3
ret void
}

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