#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 uint8_t;

/* Variables and functions */
void RGBR_to_RGB3(uint8_t *out, const uint8_t *in, int in_size) {
  int x;
  for (x = 0; x < in_size / 2; x++, in += 2, out += 3) {
    out[0] = (in[0] & 248);
    out[1] = (((in[0] & 7) << 5) + ((in[1] >> 3) & 28));
    out[2] = (in[1] << 3);
  }
}


x86 assembly (clang, -O0):
<RGBR_to_RGB3>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    119f <RGBR_to_RGB3+0x9f>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
and    $0xf8,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
and    $0x7,%ecx
shl    $0x5,%ecx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
sar    $0x3,%eax
and    $0x1c,%eax
add    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
shl    $0x3,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc,%rax
mov    %rax,-0x8(%rbp)
jmp    1116 <RGBR_to_RGB3+0x16>
pop    %rbp
ret

x86 assembly (clang, -O2):
<RGBR_to_RGB3>:
cmp    $0x2,%edx
jl     1157 <RGBR_to_RGB3+0x57>
mov    %edx,%eax
shr    $0x1f,%eax
add    %edx,%eax
sar    %eax
mov    %eax,%r9d
xor    %ecx,%ecx
mov    $0xf8,%r8d
nopl   0x0(%rax)
mov    (%rsi,%rcx,8),%edx
and    %r8d,%edx
mov    %edx,(%rdi)
mov    (%rsi,%rcx,8),%edx
mov    0x4(%rsi,%rcx,8),%eax
shl    $0x5,%edx
movzbl %dl,%edx
shr    $0x3,%eax
and    $0x1c,%eax
or     %edx,%eax
mov    %eax,0x4(%rdi)
mov    0x4(%rsi,%rcx,8),%eax
shl    $0x3,%eax
mov    %eax,0x8(%rdi)
add    $0x1,%rcx
add    $0xc,%rdi
cmp    %ecx,%r9d
jne    1120 <RGBR_to_RGB3+0x20>
ret

LLVM IR (-O0):
define void @RGBR_to_RGB3(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %39, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = sdiv i32 %10, 2
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %46
13: ; preds = %8
%14 = load i32*, i32** %5
%15 = getelementptr inbounds i32, i32* %14, i64 0
%16 = load i32, i32* %15
%17 = and i32 %16, 248
%18 = load i32*, i32** %4
%19 = getelementptr inbounds i32, i32* %18, i64 0
store i32 %17, i32* %19
%20 = load i32*, i32** %5
%21 = getelementptr inbounds i32, i32* %20, i64 0
%22 = load i32, i32* %21
%23 = and i32 %22, 7
%24 = shl i32 %23, 5
%25 = load i32*, i32** %5
%26 = getelementptr inbounds i32, i32* %25, i64 1
%27 = load i32, i32* %26
%28 = ashr i32 %27, 3
%29 = and i32 %28, 28
%30 = add nsw i32 %24, %29
%31 = load i32*, i32** %4
%32 = getelementptr inbounds i32, i32* %31, i64 1
store i32 %30, i32* %32
%33 = load i32*, i32** %5
%34 = getelementptr inbounds i32, i32* %33, i64 1
%35 = load i32, i32* %34
%36 = shl i32 %35, 3
%37 = load i32*, i32** %4
%38 = getelementptr inbounds i32, i32* %37, i64 2
store i32 %36, i32* %38
br label %39
39: ; preds = %13
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
%42 = load i32*, i32** %5
%43 = getelementptr inbounds i32, i32* %42, i64 2
store i32* %43, i32** %5
%44 = load i32*, i32** %4
%45 = getelementptr inbounds i32, i32* %44, i64 3
store i32* %45, i32** %4
br label %8
46: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @RGBR_to_RGB3(i32* nocapture writeonly %0, i32* nocapture %1, i32 %2) {
%4 = sdiv i32 %2, 2
%5 = icmp sgt i32 %2, 1
br i1 %5, label %6, label %28
6: ; preds = %3, %6
%7 = phi i32 [ %24, %6 ], [ 0, %3 ]
%8 = phi i32* [ %26, %6 ], [ %0, %3 ]
%9 = phi i32* [ %25, %6 ], [ %1, %3 ]
%10 = load i32, i32* %9
%11 = and i32 %10, 248
store i32 %11, i32* %8
%12 = load i32, i32* %9
%13 = shl i32 %12, 5
%14 = and i32 %13, 224
%15 = getelementptr inbounds i32, i32* %9, i64 1
%16 = load i32, i32* %15
%17 = lshr i32 %16, 3
%18 = and i32 %17, 28
%19 = or i32 %18, %14
%20 = getelementptr inbounds i32, i32* %8, i64 1
store i32 %19, i32* %20
%21 = load i32, i32* %15
%22 = shl i32 %21, 3
%23 = getelementptr inbounds i32, i32* %8, i64 2
store i32 %22, i32* %23
%24 = add nuw nsw i32 %7, 1
%25 = getelementptr inbounds i32, i32* %9, i64 2
%26 = getelementptr inbounds i32, i32* %8, i64 3
%27 = icmp eq i32 %24, %4
br i1 %27, label %28, label %6
28: ; preds = %6, %3
ret void
}