#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 /*<<< orphan*/ uint8_t;
typedef int uint16_t;

/* Variables and functions */
void rgb15tobgr24(const uint8_t *src, uint8_t *dst, unsigned int src_size) {
  const uint16_t *end;
  uint8_t *d = (uint8_t *)dst;
  const uint16_t *s = (uint16_t *)src;
  end = s + src_size / 2;
  while (s < end) {
    register uint16_t bgr;
    bgr = *s++;
    *d++ = (bgr & 0x7C00) >> 7;
    *d++ = (bgr & 0x3E0) >> 2;
    *d++ = (bgr & 0x1F) << 3;
  }
}


x86 assembly (clang, -O0):
<rgb15tobgr24>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%ecx
shr    $0x1,%ecx
mov    %ecx,%ecx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11b1 <rgb15tobgr24+0xb1>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%ecx
and    $0x7c00,%ecx
sar    $0x7,%ecx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x28(%rbp)
mov    %ecx,(%rax)
mov    -0x34(%rbp),%ecx
and    $0x3e0,%ecx
sar    $0x2,%ecx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x28(%rbp)
mov    %ecx,(%rax)
mov    -0x34(%rbp),%ecx
and    $0x1f,%ecx
shl    $0x3,%ecx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x4,%rdx
mov    %rdx,-0x28(%rbp)
mov    %ecx,(%rax)
jmp    1136 <rgb15tobgr24+0x36>
pop    %rbp
ret

x86 assembly (clang, -O2):
<rgb15tobgr24>:
cmp    $0x2,%edx
jb     1143 <rgb15tobgr24+0x43>
shr    %edx
lea    (%rdi,%rdx,4),%rax
nopl   0x0(%rax,%rax,1)
mov    (%rdi),%ecx
add    $0x4,%rdi
mov    %ecx,%edx
shr    $0x7,%edx
and    $0xf8,%edx
mov    %edx,(%rsi)
mov    %ecx,%edx
shr    $0x2,%edx
and    $0xf8,%edx
mov    %edx,0x4(%rsi)
shl    $0x3,%ecx
movzbl %cl,%ecx
mov    %ecx,0x8(%rsi)
add    $0xc,%rsi
cmp    %rax,%rdi
jb     1110 <rgb15tobgr24+0x10>
ret

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

LLVM IR (-O2):
define void @rgb15tobgr24(i32* %0, i32* nocapture writeonly %1, i32 %2) {
%4 = lshr i32 %2, 1
%5 = zext i32 %4 to i64
%6 = getelementptr inbounds i32, i32* %0, i64 %5
%7 = icmp ult i32 %2, 2
br i1 %7, label %23, label %8
8: ; preds = %3, %8
%9 = phi i32* [ %21, %8 ], [ %1, %3 ]
%10 = phi i32* [ %11, %8 ], [ %0, %3 ]
%11 = getelementptr inbounds i32, i32* %10, i64 1
%12 = load i32, i32* %10
%13 = lshr i32 %12, 7
%14 = and i32 %13, 248
%15 = getelementptr inbounds i32, i32* %9, i64 1
store i32 %14, i32* %9
%16 = lshr i32 %12, 2
%17 = and i32 %16, 248
%18 = getelementptr inbounds i32, i32* %9, i64 2
store i32 %17, i32* %15
%19 = shl i32 %12, 3
%20 = and i32 %19, 248
%21 = getelementptr inbounds i32, i32* %9, i64 3
store i32 %20, i32* %18
%22 = icmp ult i32* %11, %6
br i1 %22, label %8, label %23
23: ; preds = %8, %3
ret void
}