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


x86 assembly (clang, -O0):
<argb32p_rgb16_inplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
shr    $0x18,%eax
mov    %al,-0x11(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    115e <argb32p_rgb16_inplace+0x2e>
jmp    11ce <argb32p_rgb16_inplace+0x9e>
movzbl -0x11(%rbp),%eax
cmp    $0xff,%eax
jne    1187 <argb32p_rgb16_inplace+0x57>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1040 <qConvertRgb32To16@plt>
mov    %ax,%cx
mov    -0x8(%rbp),%rax
mov    %cx,(%rax)
jmp    11c9 <argb32p_rgb16_inplace+0x99>
movzbl -0x11(%rbp),%ecx
mov    $0xff,%eax
sub    %ecx,%eax
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
movzwl (%rax),%edi
call   1030 <qConvertRgb16To32@plt>
mov    %eax,%edi
movzbl -0x11(%rbp),%esi
call   1050 <premul_nozero@plt>
mov    %eax,%edi
and    $0xffffff,%edi
mov    -0x10(%rbp),%rax
add    (%rax),%edi
call   1040 <qConvertRgb32To16@plt>
mov    %ax,%cx
mov    -0x8(%rbp),%rax
mov    %cx,(%rax)
jmp    11ce <argb32p_rgb16_inplace+0x9e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argb32p_rgb16_inplace>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rsi),%edi
cmp    $0x1000000,%edi
jb     117b <argb32p_rgb16_inplace+0x4b>
mov    %edi,%ebp
shr    $0x18,%ebp
cmp    $0xff,%ebp
je     1172 <argb32p_rgb16_inplace+0x42>
mov    %rsi,%rbx
not    %bpl
movzwl (%r14),%edi
call   1030 <qConvertRgb16To32@plt>
movzbl %bpl,%esi
mov    %eax,%edi
call   1050 <premul_nozero@plt>
mov    %eax,%edi
and    $0xffffff,%edi
add    (%rbx),%edi
call   1040 <qConvertRgb32To16@plt>
mov    %ax,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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