#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 int uint16_t;

/* Variables and functions */
void transfer_RGB161616_to_RGBA8888(unsigned char *(*output), uint16_t *input) {
  (*output)[0] = input[0] >> 8;
  (*output)[1] = input[1] >> 8;
  (*output)[2] = input[2] >> 8;
  (*output)[3] = 0xff;
  (*output) += 4;
}


x86 assembly (clang, -O0):
<transfer_RGB161616_to_RGBA8888>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %cl,0x1(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %cl,0x2(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movb   $0xff,0x3(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x4,%rcx
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<transfer_RGB161616_to_RGBA8888>:
mov    0x1(%rsi),%al
mov    (%rdi),%rcx
mov    %al,(%rcx)
mov    0x5(%rsi),%al
mov    (%rdi),%rcx
mov    %al,0x1(%rcx)
mov    0x9(%rsi),%al
mov    (%rdi),%rcx
mov    %al,0x2(%rcx)
mov    (%rdi),%rax
movb   $0xff,0x3(%rax)
addq   $0x4,(%rdi)
ret

LLVM IR (-O0):
define void @transfer_RGB161616_to_RGBA8888(i8** %0, i32* %1) {
%3 = alloca i8**
%4 = alloca i32*
store i8** %0, i8*** %3
store i32* %1, i32** %4
%5 = load i32*, i32** %4
%6 = getelementptr inbounds i32, i32* %5, i64 0
%7 = load i32, i32* %6
%8 = ashr i32 %7, 8
%9 = trunc i32 %8 to i8
%10 = load i8**, i8*** %3
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8, i8* %11, i64 0
store i8 %9, i8* %12
%13 = load i32*, i32** %4
%14 = getelementptr inbounds i32, i32* %13, i64 1
%15 = load i32, i32* %14
%16 = ashr i32 %15, 8
%17 = trunc i32 %16 to i8
%18 = load i8**, i8*** %3
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8, i8* %19, i64 1
store i8 %17, i8* %20
%21 = load i32*, i32** %4
%22 = getelementptr inbounds i32, i32* %21, i64 2
%23 = load i32, i32* %22
%24 = ashr i32 %23, 8
%25 = trunc i32 %24 to i8
%26 = load i8**, i8*** %3
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i64 2
store i8 %25, i8* %28
%29 = load i8**, i8*** %3
%30 = load i8*, i8** %29
%31 = getelementptr inbounds i8, i8* %30, i64 3
store i8 -1, i8* %31
%32 = load i8**, i8*** %3
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i64 4
store i8* %34, i8** %32
ret void
}

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