#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 */
int premul_nozero(unsigned int, unsigned char);
unsigned int qConvertRgb16To32(unsigned short);
unsigned short qConvertRgb32To16(int);
void argb32p_rgb16_opacity_inplace(unsigned short *dest, unsigned int *src,
                                   unsigned char opacity) {
  unsigned int srcval = *src;
  unsigned char alpha = srcval >> 24;
  if (alpha == 0x00) {
  } else {
    srcval = premul_nozero(srcval, opacity);
    alpha = srcval >> 24;
    if (alpha == 0x00) {
    } else if (alpha == 0xFF) {
      *dest = qConvertRgb32To16(srcval);
    } else {
      alpha = 0xFF - alpha;
      *dest = qConvertRgb32To16(
          (premul_nozero(qConvertRgb16To32(*dest), alpha) & 0xFFFFFF) + srcval);
    }
  }
}


x86 assembly (clang, -O0):
<argb32p_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),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
shr    $0x18,%eax
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jne    1169 <argb32p_rgb16_opacity_inplace+0x39>
jmp    1202 <argb32p_rgb16_opacity_inplace+0xd2>
mov    -0x18(%rbp),%edi
movzbl -0x11(%rbp),%esi
call   1050 <premul_nozero@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
shr    $0x18,%eax
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jne    1193 <argb32p_rgb16_opacity_inplace+0x63>
jmp    11fd <argb32p_rgb16_opacity_inplace+0xcd>
movzbl -0x19(%rbp),%eax
cmp    $0xff,%eax
jne    11b9 <argb32p_rgb16_opacity_inplace+0x89>
mov    -0x18(%rbp),%edi
call   1040 <qConvertRgb32To16@plt>
mov    %ax,%cx
mov    -0x8(%rbp),%rax
mov    %cx,(%rax)
jmp    11f8 <argb32p_rgb16_opacity_inplace+0xc8>
movzbl -0x19(%rbp),%ecx
mov    $0xff,%eax
sub    %ecx,%eax
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rax
movzwl (%rax),%edi
call   1030 <qConvertRgb16To32@plt>
mov    %eax,%edi
movzbl -0x19(%rbp),%esi
call   1050 <premul_nozero@plt>
mov    %eax,%edi
and    $0xffffff,%edi
add    -0x18(%rbp),%edi
call   1040 <qConvertRgb32To16@plt>
mov    %ax,%cx
mov    -0x8(%rbp),%rax
mov    %cx,(%rax)
jmp    11fd <argb32p_rgb16_opacity_inplace+0xcd>
jmp    1202 <argb32p_rgb16_opacity_inplace+0xd2>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argb32p_rgb16_opacity_inplace>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rsi),%edi
cmp    $0x1000000,%edi
jb     1188 <argb32p_rgb16_opacity_inplace+0x58>
movzbl %dl,%esi
call   1050 <premul_nozero@plt>
cmp    $0x1000000,%eax
jb     1188 <argb32p_rgb16_opacity_inplace+0x58>
mov    %eax,%ebx
mov    %eax,%ebp
shr    $0x18,%ebp
cmp    $0xff,%ebp
je     117d <argb32p_rgb16_opacity_inplace+0x4d>
not    %bpl
movzwl (%r14),%edi
call   1030 <qConvertRgb16To32@plt>
movzbl %bpl,%esi
mov    %eax,%edi
call   1050 <premul_nozero@plt>
and    $0xffffff,%eax
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 @argb32p_rgb16_opacity_inplace(i16* %0, i32* %1, i8 zeroext %2) {
%4 = alloca i16*
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i32
%8 = alloca i8
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
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = lshr i32 %11, 24
%13 = trunc i32 %12 to i8
store i8 %13, i8* %8
%14 = load i8, i8* %8
%15 = zext i8 %14 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %3
br label %54
18: ; preds = %3
%19 = load i32, i32* %7
%20 = load i8, i8* %6
%21 = call i32 @premul_nozero(i32 %19, i8 zeroext %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = lshr i32 %22, 24
%24 = trunc i32 %23 to i8
store i8 %24, i8* %8
%25 = load i8, i8* %8
%26 = zext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %18
br label %53
29: ; preds = %18
%30 = load i8, i8* %8
%31 = zext i8 %30 to i32
%32 = icmp eq i32 %31, 255
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* %7
%35 = call zeroext i16 @qConvertRgb32To16(i32 %34)
%36 = load i16*, i16** %4
store i16 %35, i16* %36
br label %52
37: ; preds = %29
%38 = load i8, i8* %8
%39 = zext i8 %38 to i32
%40 = sub nsw i32 255, %39
%41 = trunc i32 %40 to i8
store i8 %41, i8* %8
%42 = load i16*, i16** %4
%43 = load i16, i16* %42
%44 = call i32 @qConvertRgb16To32(i16 zeroext %43)
%45 = load i8, i8* %8
%46 = call i32 @premul_nozero(i32 %44, i8 zeroext %45)
%47 = and i32 %46, 16777215
%48 = load i32, i32* %7
%49 = add i32 %47, %48
%50 = call zeroext i16 @qConvertRgb32To16(i32 %49)
%51 = load i16*, i16** %4
store i16 %50, i16* %51
br label %52
52: ; preds = %37, %33
br label %53
53: ; preds = %52, %28
br label %54
54: ; preds = %53, %17
ret void
}

LLVM IR (-O2):
define void @argb32p_rgb16_opacity_inplace(i16* nocapture %0, i32* nocapture %1, i8 zeroext %2) {
%4 = load i32, i32* %1
%5 = icmp ult i32 %4, 16777216
br i1 %5, label %23, label %6
6: ; preds = %3
%7 = tail call i32 @premul_nozero(i32 %4, i8 zeroext %2)
%8 = lshr i32 %7, 24
%9 = icmp ult i32 %7, 16777216
br i1 %9, label %23, label %10
10: ; preds = %6
%11 = icmp eq i32 %8, 255
br i1 %11, label %20, label %12
12: ; preds = %10
%13 = trunc i32 %8 to i8
%14 = xor i8 %13, -1
%15 = load i16, i16* %0
%16 = tail call i32 @qConvertRgb16To32(i16 zeroext %15)
%17 = tail call i32 @premul_nozero(i32 %16, i8 zeroext %14)
%18 = and i32 %17, 16777215
%19 = add i32 %18, %7
br label %20
20: ; preds = %10, %12
%21 = phi i32 [ %19, %12 ], [ %7, %10 ]
%22 = tail call zeroext i16 @qConvertRgb32To16(i32 %21)
store i16 %22, i16* %0
br label %23
23: ; preds = %20, %6, %3
ret void
}