#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_getWritePointer(unsigned short, unsigned short);
int /*<<< orphan*/ BMP_scale(unsigned char *, unsigned short, unsigned short,
                             unsigned short, int /*<<< orphan*/, unsigned short,
                             unsigned short, int);
int /*<<< orphan*/ VDP_setPalette(unsigned short, unsigned short const *);
void BMP_loadAndScaleGenBmp16(const unsigned short *genbmp16, unsigned short x,
                              unsigned short y, unsigned short w,
                              unsigned short h, unsigned short numpal) {
  unsigned short bmp_w, bmp_h;
  bmp_w = ((genbmp16)[0]) >> 1;
  bmp_h = ((genbmp16)[1]);
  if (numpal < 4)
    VDP_setPalette(numpal, (&((genbmp16)[2])));
  BMP_scale((unsigned char *)(&((genbmp16)[18])), bmp_w, bmp_h, bmp_w,
            BMP_getWritePointer(x, y), w, h, (1 << (5 + 2)));
}


x86 assembly (clang, -O0):
<BMP_loadAndScaleGenBmp16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %r8d,-0x28(%rbp)
mov    %ecx,%eax
mov    -0x28(%rbp),%ecx
mov    %eax,-0x24(%rbp)
mov    %edx,%eax
mov    -0x24(%rbp),%edx
mov    %eax,-0x20(%rbp)
mov    %esi,%eax
mov    -0x20(%rbp),%esi
mov    %eax,-0x1c(%rbp)
mov    %rdi,%r8
mov    -0x1c(%rbp),%edi
mov    %r9w,%ax
mov    %r8,-0x8(%rbp)
mov    %di,-0xa(%rbp)
mov    %si,-0xc(%rbp)
mov    %dx,-0xe(%rbp)
mov    %cx,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    -0x8(%rbp),%rax
movzwl (%rax),%eax
sar    $0x1,%eax
mov    %ax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    0x2(%rax),%ax
mov    %ax,-0x16(%rbp)
movzwl -0x12(%rbp),%eax
cmp    $0x4,%eax
jge    11b1 <BMP_loadAndScaleGenBmp16+0x81>
mov    -0x12(%rbp),%ax
mov    -0x8(%rbp),%rsi
add    $0x4,%rsi
movzwl %ax,%edi
call   1050 <VDP_setPalette@plt>
mov    -0x8(%rbp),%rax
add    $0x24,%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%ax
mov    %ax,-0x2e(%rbp)
mov    -0x16(%rbp),%ax
mov    %ax,-0x2c(%rbp)
mov    -0x14(%rbp),%ax
mov    %ax,-0x2a(%rbp)
mov    -0xa(%rbp),%ax
movzwl %ax,%edi
movzwl -0xc(%rbp),%esi
call   1040 <BMP_getWritePointer@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2e(%rbp),%si
mov    -0x2c(%rbp),%dx
mov    -0x2a(%rbp),%cx
mov    %eax,%r8d
mov    -0xe(%rbp),%ax
movzwl %si,%esi
movzwl %dx,%edx
movzwl %cx,%ecx
movzwl %ax,%r9d
movzwl -0x10(%rbp),%eax
mov    %eax,(%rsp)
movl   $0x80,0x8(%rsp)
call   1030 <BMP_scale@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BMP_loadAndScaleGenBmp16>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %ecx,0x4(%rsp)
mov    %edx,%r12d
mov    %esi,%r13d
mov    %rdi,%rbx
movzwl (%rdi),%ebp
movzwl 0x2(%rdi),%r14d
cmp    $0x3,%r9w
ja     1167 <BMP_loadAndScaleGenBmp16+0x37>
lea    0x4(%rbx),%rsi
movzwl %r9w,%edi
call   1050 <VDP_setPalette@plt>
movzwl %bp,%ebp
shr    %ebp
add    $0x24,%rbx
movzwl %r13w,%edi
movzwl %r12w,%esi
call   1040 <BMP_getWritePointer@plt>
movzwl %r15w,%r10d
movzwl %r14w,%edx
movzwl 0x4(%rsp),%r9d
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %ebp,%ecx
mov    %eax,%r8d
push   $0x80
push   %r10
call   1030 <BMP_scale@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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