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

/* Variables and functions */
int /*<<< orphan*/ rgb565_bep(int /*<<< orphan*/ const, int /*<<< orphan*/ *);
int /*<<< orphan*/ rgb565_lep(int /*<<< orphan*/ const, int /*<<< orphan*/ *);
int decode_rgb565(const uint16_t *const data, const long size,
                  const int endian_big, uint8_t *image) {
  const uint16_t *d = data, *d_end = data + size;
  if (endian_big)
    for (; d < d_end; d++, image += 3)
      rgb565_bep(*d, image);
  else
    for (; d < d_end; d++, image += 3)
      rgb565_lep(*d, image);
  return 1;
}


x86 assembly (clang, -O0):
<decode_rgb565>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11a0 <decode_rgb565+0x80>
jmp    1161 <decode_rgb565+0x41>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    119b <decode_rgb565+0x7b>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
call   1030 <rgb565_bep@plt>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0xc,%rax
mov    %rax,-0x20(%rbp)
jmp    1161 <decode_rgb565+0x41>
jmp    11e4 <decode_rgb565+0xc4>
jmp    11a5 <decode_rgb565+0x85>
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    11df <decode_rgb565+0xbf>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rsi
call   1040 <rgb565_lep@plt>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0xc,%rax
mov    %rax,-0x20(%rbp)
jmp    11a5 <decode_rgb565+0x85>
jmp    11e4 <decode_rgb565+0xc4>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_rgb565>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdi,%rbx
lea    (%rdi,%rsi,4),%r15
test   %edx,%edx
je     1159 <decode_rgb565+0x39>
test   %rsi,%rsi
jle    1177 <decode_rgb565+0x57>
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%edi
mov    %r14,%rsi
call   1030 <rgb565_bep@plt>
add    $0x4,%rbx
add    $0xc,%r14
cmp    %r15,%rbx
jb     1140 <decode_rgb565+0x20>
jmp    1177 <decode_rgb565+0x57>
test   %rsi,%rsi
jle    1177 <decode_rgb565+0x57>
xchg   %ax,%ax
mov    (%rbx),%edi
mov    %r14,%rsi
call   1040 <rgb565_lep@plt>
add    $0x4,%rbx
add    $0xc,%r14
cmp    %r15,%rbx
jb     1160 <decode_rgb565+0x40>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @decode_rgb565(i32* %0, i64 %1, i32 %2, i32* %3) {
%5 = getelementptr inbounds i32, i32* %0, i64 %1
%6 = icmp eq i32 %2, 0
%7 = icmp sgt i64 %1, 0
br i1 %6, label %9, label %8
8: ; preds = %4
br i1 %7, label %10, label %26
9: ; preds = %4
br i1 %7, label %18, label %26
10: ; preds = %8, %10
%11 = phi i32* [ %16, %10 ], [ %3, %8 ]
%12 = phi i32* [ %15, %10 ], [ %0, %8 ]
%13 = load i32, i32* %12
%14 = tail call i32 @rgb565_bep(i32 %13, i32* %11)
%15 = getelementptr inbounds i32, i32* %12, i64 1
%16 = getelementptr inbounds i32, i32* %11, i64 3
%17 = icmp ult i32* %15, %5
br i1 %17, label %10, label %26
18: ; preds = %9, %18
%19 = phi i32* [ %24, %18 ], [ %3, %9 ]
%20 = phi i32* [ %23, %18 ], [ %0, %9 ]
%21 = load i32, i32* %20
%22 = tail call i32 @rgb565_lep(i32 %21, i32* %19)
%23 = getelementptr inbounds i32, i32* %20, i64 1
%24 = getelementptr inbounds i32, i32* %19, i64 3
%25 = icmp ult i32* %23, %5
br i1 %25, label %18, label %26
26: ; preds = %10, %18, %8, %9
ret i32 1
}