#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 */

/* Variables and functions */
int /*<<< orphan*/ BMP_loadBitmap(unsigned char *, unsigned short,
                                  unsigned short, unsigned short,
                                  unsigned short, unsigned short);
int /*<<< orphan*/ VDP_setPalette(unsigned short, unsigned short const *);
void BMP_loadGenBmp16(const unsigned short *genbmp16, unsigned short x,
                      unsigned short y, unsigned short numpal) {
  unsigned short w, h;
  w = ((genbmp16)[0]) >> 1;
  h = ((genbmp16)[1]);
  if (numpal < 4)
    VDP_setPalette(numpal, (&((genbmp16)[2])));
  BMP_loadBitmap((unsigned char *)(&((genbmp16)[18])), x, y, w, h, w);
}


x86 assembly (clang, -O0):
<BMP_loadGenBmp16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cx,%ax
mov    %dx,%cx
mov    %si,%dx
mov    %rdi,-0x8(%rbp)
mov    %dx,-0xa(%rbp)
mov    %cx,-0xc(%rbp)
mov    %ax,-0xe(%rbp)
mov    -0x8(%rbp),%rax
movzwl (%rax),%eax
sar    $0x1,%eax
mov    %ax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2(%rax),%ax
mov    %ax,-0x12(%rbp)
movzwl -0xe(%rbp),%eax
cmp    $0x4,%eax
jge    117c <BMP_loadGenBmp16+0x5c>
mov    -0xe(%rbp),%ax
mov    -0x8(%rbp),%rsi
add    $0x4,%rsi
movzwl %ax,%edi
call   1040 <VDP_setPalette@plt>
mov    -0x8(%rbp),%rdi
add    $0x24,%rdi
mov    -0xa(%rbp),%si
mov    -0xc(%rbp),%dx
mov    -0x10(%rbp),%cx
mov    -0x12(%rbp),%ax
movzwl %si,%esi
movzwl %dx,%edx
movzwl %cx,%ecx
movzwl %ax,%r8d
movzwl -0x10(%rbp),%r9d
call   1030 <BMP_loadBitmap@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BMP_loadGenBmp16>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
movzwl (%rdi),%ebp
movzwl 0x2(%rdi),%r12d
cmp    $0x3,%cx
ja     114b <BMP_loadGenBmp16+0x2b>
lea    0x4(%rbx),%rsi
movzwl %cx,%edi
call   1040 <VDP_setPalette@plt>
movzwl %bp,%ecx
shr    %ecx
add    $0x24,%rbx
movzwl %r15w,%esi
movzwl %r14w,%edx
movzwl %r12w,%r8d
mov    %rbx,%rdi
mov    %ecx,%r9d
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <BMP_loadBitmap@plt>

LLVM IR (-O0):
define void @BMP_loadGenBmp16(i16* %0, i16 zeroext %1, i16 zeroext %2, i16 zeroext %3) {
%5 = alloca i16*
%6 = alloca i16
%7 = alloca i16
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16
store i16* %0, i16** %5
store i16 %1, i16* %6
store i16 %2, i16* %7
store i16 %3, i16* %8
%11 = load i16*, i16** %5
%12 = getelementptr inbounds i16, i16* %11, i64 0
%13 = load i16, i16* %12
%14 = zext i16 %13 to i32
%15 = ashr i32 %14, 1
%16 = trunc i32 %15 to i16
store i16 %16, i16* %9
%17 = load i16*, i16** %5
%18 = getelementptr inbounds i16, i16* %17, i64 1
%19 = load i16, i16* %18
store i16 %19, i16* %10
%20 = load i16, i16* %8
%21 = zext i16 %20 to i32
%22 = icmp slt i32 %21, 4
br i1 %22, label %23, label %28
23: ; preds = %4
%24 = load i16, i16* %8
%25 = load i16*, i16** %5
%26 = getelementptr inbounds i16, i16* %25, i64 2
%27 = call i32 @VDP_setPalette(i16 zeroext %24, i16* %26)
br label %28
28: ; preds = %23, %4
%29 = load i16*, i16** %5
%30 = getelementptr inbounds i16, i16* %29, i64 18
%31 = bitcast i16* %30 to i8*
%32 = load i16, i16* %6
%33 = load i16, i16* %7
%34 = load i16, i16* %9
%35 = load i16, i16* %10
%36 = load i16, i16* %9
%37 = call i32 @BMP_loadBitmap(i8* %31, i16 zeroext %32, i16 zeroext %33, i16 zeroext %34, i16 zeroext %35, i16 zeroext %36)
ret void
}

LLVM IR (-O2):
define void @BMP_loadGenBmp16(i16* %0, i16 zeroext %1, i16 zeroext %2, i16 zeroext %3) {
%5 = load i16, i16* %0
%6 = getelementptr inbounds i16, i16* %0, i64 1
%7 = load i16, i16* %6
%8 = icmp ult i16 %3, 4
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = getelementptr inbounds i16, i16* %0, i64 2
%11 = tail call i32 @VDP_setPalette(i16 zeroext %3, i16* %10)
br label %12
12: ; preds = %9, %4
%13 = lshr i16 %5, 1
%14 = getelementptr inbounds i16, i16* %0, i64 18
%15 = bitcast i16* %14 to i8*
%16 = tail call i32 @BMP_loadBitmap(i8* %15, i16 zeroext %1, i16 zeroext %2, i16 zeroext %13, i16 zeroext %7, i16 zeroext %13)
ret void
}