#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 */
typedef unsigned int uint32_t;
typedef unsigned int uint16_t;

/* Variables and functions */
void transfer_RGBA16161616_to_RGB888(unsigned char *(*output),
                                     uint16_t *input) {
  uint32_t r, g, b, a;
  a = input[3];
  r = (unsigned int)(input)[0] * a;
  g = (unsigned int)(input)[1] * a;
  b = (unsigned int)(input)[2] * a;
  (*output)[0] = (unsigned char)(r / 0xffffff);
  (*output)[1] = (unsigned char)(g / 0xffffff);
  (*output)[2] = (unsigned char)(b / 0xffffff);
  (*output) += 3;
}


x86 assembly (clang, -O0):
<transfer_RGBA16161616_to_RGB888>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
imul   -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xffffff,%ecx
xor    %edx,%edx
div    %ecx
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
mov    $0xffffff,%ecx
xor    %edx,%edx
div    %ecx
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %cl,0x1(%rax)
mov    -0x1c(%rbp),%eax
mov    $0xffffff,%ecx
xor    %edx,%edx
div    %ecx
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %cl,0x2(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x3,%rcx
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<transfer_RGBA16161616_to_RGB888>:
mov    0xc(%rsi),%eax
mov    (%rsi),%edx
imul   %eax,%edx
mov    0x4(%rsi),%ecx
imul   %eax,%ecx
imul   0x8(%rsi),%eax
mov    %rdx,%rsi
shl    $0x8,%rsi
add    %rdx,%rsi
shr    $0x20,%rsi
sub    %esi,%edx
shr    %edx
add    %esi,%edx
shr    $0x17,%edx
mov    (%rdi),%rsi
mov    %dl,(%rsi)
mov    %rcx,%rdx
shl    $0x8,%rdx
add    %rcx,%rdx
shr    $0x20,%rdx
sub    %edx,%ecx
shr    %ecx
add    %edx,%ecx
shr    $0x17,%ecx
mov    (%rdi),%rdx
mov    %cl,0x1(%rdx)
mov    %rax,%rcx
shl    $0x8,%rcx
add    %rax,%rcx
shr    $0x20,%rcx
sub    %ecx,%eax
shr    %eax
add    %ecx,%eax
shr    $0x17,%eax
mov    (%rdi),%rcx
mov    %al,0x2(%rcx)
addq   $0x3,(%rdi)
ret

LLVM IR (-O0):
define void @transfer_RGBA16161616_to_RGB888(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8** %0, i8*** %3
store i32* %1, i32** %4
%9 = load i32*, i32** %4
%10 = getelementptr inbounds i32, i32* %9, i64 3
%11 = load i32, i32* %10
store i32 %11, i32* %8
%12 = load i32*, i32** %4
%13 = getelementptr inbounds i32, i32* %12, i64 0
%14 = load i32, i32* %13
%15 = load i32, i32* %8
%16 = mul i32 %14, %15
store i32 %16, i32* %5
%17 = load i32*, i32** %4
%18 = getelementptr inbounds i32, i32* %17, i64 1
%19 = load i32, i32* %18
%20 = load i32, i32* %8
%21 = mul i32 %19, %20
store i32 %21, i32* %6
%22 = load i32*, i32** %4
%23 = getelementptr inbounds i32, i32* %22, i64 2
%24 = load i32, i32* %23
%25 = load i32, i32* %8
%26 = mul i32 %24, %25
store i32 %26, i32* %7
%27 = load i32, i32* %5
%28 = udiv i32 %27, 16777215
%29 = trunc i32 %28 to i8
%30 = load i8**, i8*** %3
%31 = load i8*, i8** %30
%32 = getelementptr inbounds i8, i8* %31, i64 0
store i8 %29, i8* %32
%33 = load i32, i32* %6
%34 = udiv i32 %33, 16777215
%35 = trunc i32 %34 to i8
%36 = load i8**, i8*** %3
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8, i8* %37, i64 1
store i8 %35, i8* %38
%39 = load i32, i32* %7
%40 = udiv i32 %39, 16777215
%41 = trunc i32 %40 to i8
%42 = load i8**, i8*** %3
%43 = load i8*, i8** %42
%44 = getelementptr inbounds i8, i8* %43, i64 2
store i8 %41, i8* %44
%45 = load i8**, i8*** %3
%46 = load i8*, i8** %45
%47 = getelementptr inbounds i8, i8* %46, i64 3
store i8* %47, i8** %45
ret void
}

LLVM IR (-O2):
define void @transfer_RGBA16161616_to_RGB888(i8** nocapture %0, i32* nocapture %1) {
%3 = getelementptr inbounds i32, i32* %1, i64 3
%4 = load i32, i32* %3
%5 = load i32, i32* %1
%6 = mul i32 %5, %4
%7 = getelementptr inbounds i32, i32* %1, i64 1
%8 = load i32, i32* %7
%9 = mul i32 %8, %4
%10 = getelementptr inbounds i32, i32* %1, i64 2
%11 = load i32, i32* %10
%12 = mul i32 %11, %4
%13 = udiv i32 %6, 16777215
%14 = trunc i32 %13 to i8
%15 = load i8*, i8** %0
store i8 %14, i8* %15
%16 = udiv i32 %9, 16777215
%17 = trunc i32 %16 to i8
%18 = load i8*, i8** %0
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8 %17, i8* %19
%20 = udiv i32 %12, 16777215
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %0
%23 = getelementptr inbounds i8, i8* %22, i64 2
store i8 %21, i8* %23
%24 = load i8*, i8** %0
%25 = getelementptr inbounds i8, i8* %24, i64 3
store i8* %25, i8** %0
ret void
}