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


x86 assembly (clang, -O0):
<argb32p_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
mov    (%rax),%eax
shr    $0x18,%eax
mov    %al,-0x12(%rbp)
movzbl -0x12(%rbp),%eax
cmp    $0x0,%eax
jne    1153 <argb32p_rgb32_opacity_inplace+0x33>
jmp    11db <argb32p_rgb32_opacity_inplace+0xbb>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
movzbl -0x11(%rbp),%esi
call   1030 <premul@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
shr    $0x18,%eax
mov    %al,-0x12(%rbp)
movzbl -0x12(%rbp),%eax
cmp    $0x0,%eax
jne    1180 <argb32p_rgb32_opacity_inplace+0x60>
jmp    11d6 <argb32p_rgb32_opacity_inplace+0xb6>
movzbl -0x12(%rbp),%eax
cmp    $0xff,%eax
jne    119d <argb32p_rgb32_opacity_inplace+0x7d>
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    11d1 <argb32p_rgb32_opacity_inplace+0xb1>
movzbl -0x12(%rbp),%ecx
mov    $0xff,%eax
sub    %ecx,%eax
mov    %al,-0x12(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
movzbl -0x12(%rbp),%esi
call   1040 <premul_nozero@plt>
mov    %eax,%ecx
and    $0xffffff,%ecx
add    -0x18(%rbp),%ecx
or     $0xff000000,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    11d6 <argb32p_rgb32_opacity_inplace+0xb6>
jmp    11db <argb32p_rgb32_opacity_inplace+0xbb>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argb32p_rgb32_opacity_inplace>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rsi),%edi
cmp    $0x1000000,%edi
jb     1162 <argb32p_rgb32_opacity_inplace+0x42>
movzbl %dl,%esi
call   1030 <premul@plt>
cmp    $0x1000000,%eax
jb     1162 <argb32p_rgb32_opacity_inplace+0x42>
mov    %eax,%ebp
shr    $0x18,%eax
cmp    $0xff,%eax
je     1160 <argb32p_rgb32_opacity_inplace+0x40>
not    %al
mov    (%rbx),%edi
movzbl %al,%esi
call   1040 <premul_nozero@plt>
add    %ebp,%eax
or     $0xff000000,%eax
mov    %eax,%ebp
mov    %ebp,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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