#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 */
scalar_t__ lround(unsigned char);
unsigned char calculate_color(unsigned char r1, unsigned char r2,
                              unsigned char a1, unsigned char a2) {
  return (unsigned char)lround(a2 * r2 / 255. +
                               a1 * r1 * (255 - a2) / 255 / 255);
}


x86 assembly (clang, -O0):
<calculate_color>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %cl,%al
mov    %dl,%cl
mov    %sil,%dl
mov    %dil,%sil
mov    %sil,-0x1(%rbp)
mov    %dl,-0x2(%rbp)
mov    %cl,-0x3(%rbp)
mov    %al,-0x4(%rbp)
movzbl -0x4(%rbp),%ecx
movzbl -0x2(%rbp),%edx
mov    %ecx,%eax
imul   %edx,%eax
cvtsi2sd %eax,%xmm0
movsd  0xeb8(%rip),%xmm1
divsd  %xmm1,%xmm0
movzbl -0x3(%rbp),%eax
movzbl -0x1(%rbp),%edx
imul   %edx,%eax
xor    $0xff,%ecx
imul   %ecx,%eax
mov    $0x80808081,%ecx
imul   %rcx,%rax
shr    $0x27,%rax
mov    %eax,%ecx
imul   $0xffffffff80808081,%rax,%rax
shr    $0x20,%rax
add    %ecx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x7,%eax
add    %ecx,%eax
cvtsi2sd %eax,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
movzbl %al,%edi
call   1030 <lround@plt>
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_color>:
push   %rax
imul   %ecx,%esi
cvtsi2sd %esi,%xmm0
divsd  0xee0(%rip),%xmm0
imul   %edx,%edi
xor    $0xff,%ecx
imul   %edi,%ecx
mov    $0x81018203,%eax
imul   %rcx,%rax
shr    $0x2f,%rax
cvtsi2sd %eax,%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
movzbl %al,%edi
call   1030 <lround@plt>
pop    %rcx
ret

LLVM IR (-O0):
define zeroext i8 @calculate_color(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3) {
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
%8 = alloca i8
store i8 %0, i8* %5
store i8 %1, i8* %6
store i8 %2, i8* %7
store i8 %3, i8* %8
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = load i8, i8* %6
%12 = zext i8 %11 to i32
%13 = mul nsw i32 %10, %12
%14 = sitofp i32 %13 to double
%15 = fdiv double %14, 2.550000e+02
%16 = load i8, i8* %7
%17 = zext i8 %16 to i32
%18 = load i8, i8* %5
%19 = zext i8 %18 to i32
%20 = mul nsw i32 %17, %19
%21 = load i8, i8* %8
%22 = zext i8 %21 to i32
%23 = sub nsw i32 255, %22
%24 = mul nsw i32 %20, %23
%25 = sdiv i32 %24, 255
%26 = sdiv i32 %25, 255
%27 = sitofp i32 %26 to double
%28 = fadd double %15, %27
%29 = fptoui double %28 to i8
%30 = call i64 @lround(i8 zeroext %29)
%31 = trunc i64 %30 to i8
ret i8 %31
}

LLVM IR (-O2):
define zeroext i8 @calculate_color(i8 zeroext %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3) {
%5 = zext i8 %3 to i32
%6 = zext i8 %1 to i32
%7 = mul nuw nsw i32 %5, %6
%8 = sitofp i32 %7 to double
%9 = fdiv double %8, 2.550000e+02
%10 = zext i8 %2 to i32
%11 = zext i8 %0 to i32
%12 = mul nuw nsw i32 %10, %11
%13 = xor i32 %5, 255
%14 = mul nuw nsw i32 %12, %13
%15 = udiv i32 %14, 65025
%16 = sitofp i32 %15 to double
%17 = fadd double %9, %16
%18 = fptoui double %17 to i8
%19 = tail call i64 @lround(i8 zeroext %18)
%20 = trunc i64 %19 to i8
ret i8 %20
}