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

/* Variables and functions */
int /*<<< orphan*/ VDP_setAutoInc(int);
void VDP_setPalette(unsigned short num, const unsigned short *pal) {
  volatile unsigned short *pw;
  volatile unsigned long *pl;
  const unsigned short *src;
  unsigned short i;
  unsigned short addr;
  VDP_setAutoInc(2);
  pw = (unsigned short *)0xC00000;
  pl = (unsigned long *)0xC00004;
  src = pal;
  addr = num * 32;
  *pl = ((0xC000 + ((addr)&0x3FFF)) << 16) + (((addr) >> 14) | 0x00);
  i = 16;
  while (i--)
    *pw = *src++;
}


x86 assembly (clang, -O0):
<VDP_setPalette>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x2,%edi
call   1030 <VDP_setAutoInc@plt>
mov    $0xc00000,%eax
mov    %rax,-0x18(%rbp)
mov    $0xc00004,%eax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movzwl -0x2(%rbp),%eax
shl    $0x5,%eax
mov    %ax,-0x2c(%rbp)
movzwl -0x2c(%rbp),%eax
and    $0x3fff,%eax
add    $0xc000,%eax
shl    $0x10,%eax
movzwl -0x2c(%rbp),%ecx
sar    $0xe,%ecx
or     $0x0,%ecx
add    %ecx,%eax
movslq %eax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movw   $0x10,-0x2a(%rbp)
mov    -0x2a(%rbp),%ax
mov    %ax,%cx
add    $0xffff,%cx
mov    %cx,-0x2a(%rbp)
cmp    $0x0,%ax
je     11b6 <VDP_setPalette+0xa6>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x2,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
jmp    117f <VDP_setPalette+0x6f>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VDP_setPalette>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x2,%edi
call   1030 <VDP_setAutoInc@plt>
mov    %ebp,%eax
shl    $0x15,%eax
shr    $0x9,%ebp
and    $0x3,%ebp
or     %eax,%ebp
or     $0xc0000000,%ebp
movslq %ebp,%rax
mov    %rax,0xc00004
movzwl (%rbx),%eax
mov    %ax,0xc00000
movzwl 0x2(%rbx),%eax
mov    %ax,0xc00000
movzwl 0x4(%rbx),%eax
mov    %ax,0xc00000
movzwl 0x6(%rbx),%eax
mov    %ax,0xc00000
movzwl 0x8(%rbx),%eax
mov    %ax,0xc00000
movzwl 0xa(%rbx),%eax
mov    %ax,0xc00000
movzwl 0xc(%rbx),%eax
mov    %ax,0xc00000
movzwl 0xe(%rbx),%eax
mov    %ax,0xc00000
movzwl 0x10(%rbx),%eax
mov    %ax,0xc00000
movzwl 0x12(%rbx),%eax
mov    %ax,0xc00000
movzwl 0x14(%rbx),%eax
mov    %ax,0xc00000
movzwl 0x16(%rbx),%eax
mov    %ax,0xc00000
movzwl 0x18(%rbx),%eax
mov    %ax,0xc00000
movzwl 0x1a(%rbx),%eax
mov    %ax,0xc00000
movzwl 0x1c(%rbx),%eax
mov    %ax,0xc00000
movzwl 0x1e(%rbx),%eax
mov    %ax,0xc00000
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @VDP_setPalette(i16 zeroext %0, i16* %1) {
%3 = alloca i16
%4 = alloca i16*
%5 = alloca i16*
%6 = alloca i64*
%7 = alloca i16*
%8 = alloca i16
%9 = alloca i16
store i16 %0, i16* %3
store i16* %1, i16** %4
%10 = call i32 @VDP_setAutoInc(i32 2)
store i16* inttoptr (i64 12582912 to i16*), i16** %5
store i64* inttoptr (i64 12582916 to i64*), i64** %6
%11 = load i16*, i16** %4
store i16* %11, i16** %7
%12 = load i16, i16* %3
%13 = zext i16 %12 to i32
%14 = mul nsw i32 %13, 32
%15 = trunc i32 %14 to i16
store i16 %15, i16* %9
%16 = load i16, i16* %9
%17 = zext i16 %16 to i32
%18 = and i32 %17, 16383
%19 = add nsw i32 49152, %18
%20 = shl i32 %19, 16
%21 = load i16, i16* %9
%22 = zext i16 %21 to i32
%23 = ashr i32 %22, 14
%24 = or i32 %23, 0
%25 = add nsw i32 %20, %24
%26 = sext i32 %25 to i64
%27 = load i64*, i64** %6
store volatile i64 %26, i64* %27
store i16 16, i16* %8
br label %28
28: ; preds = %32, %2
%29 = load i16, i16* %8
%30 = add i16 %29, -1
store i16 %30, i16* %8
%31 = icmp ne i16 %29, 0
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i16*, i16** %7
%34 = getelementptr inbounds i16, i16* %33, i32 1
store i16* %34, i16** %7
%35 = load i16, i16* %33
%36 = load i16*, i16** %5
store volatile i16 %35, i16* %36
br label %28
37: ; preds = %28
ret void
}

LLVM IR (-O2):
define void @VDP_setPalette(i16 zeroext %0, i16* nocapture %1) {
%3 = tail call i32 @VDP_setAutoInc(i32 2)
%4 = shl i16 %0, 5
%5 = zext i16 %4 to i32
%6 = shl nuw i32 %5, 16
%7 = lshr i32 %5, 14
%8 = or i32 %6, %7
%9 = or i32 %8, -1073741824
%10 = sext i32 %9 to i64
store volatile i64 %10, i64* inttoptr (i64 12582916 to i64*)
%11 = getelementptr inbounds i16, i16* %1, i64 1
%12 = load i16, i16* %1
store volatile i16 %12, i16* inttoptr (i64 12582912 to i16*)
%13 = getelementptr inbounds i16, i16* %1, i64 2
%14 = load i16, i16* %11
store volatile i16 %14, i16* inttoptr (i64 12582912 to i16*)
%15 = getelementptr inbounds i16, i16* %1, i64 3
%16 = load i16, i16* %13
store volatile i16 %16, i16* inttoptr (i64 12582912 to i16*)
%17 = getelementptr inbounds i16, i16* %1, i64 4
%18 = load i16, i16* %15
store volatile i16 %18, i16* inttoptr (i64 12582912 to i16*)
%19 = getelementptr inbounds i16, i16* %1, i64 5
%20 = load i16, i16* %17
store volatile i16 %20, i16* inttoptr (i64 12582912 to i16*)
%21 = getelementptr inbounds i16, i16* %1, i64 6
%22 = load i16, i16* %19
store volatile i16 %22, i16* inttoptr (i64 12582912 to i16*)
%23 = getelementptr inbounds i16, i16* %1, i64 7
%24 = load i16, i16* %21
store volatile i16 %24, i16* inttoptr (i64 12582912 to i16*)
%25 = getelementptr inbounds i16, i16* %1, i64 8
%26 = load i16, i16* %23
store volatile i16 %26, i16* inttoptr (i64 12582912 to i16*)
%27 = getelementptr inbounds i16, i16* %1, i64 9
%28 = load i16, i16* %25
store volatile i16 %28, i16* inttoptr (i64 12582912 to i16*)
%29 = getelementptr inbounds i16, i16* %1, i64 10
%30 = load i16, i16* %27
store volatile i16 %30, i16* inttoptr (i64 12582912 to i16*)
%31 = getelementptr inbounds i16, i16* %1, i64 11
%32 = load i16, i16* %29
store volatile i16 %32, i16* inttoptr (i64 12582912 to i16*)
%33 = getelementptr inbounds i16, i16* %1, i64 12
%34 = load i16, i16* %31
store volatile i16 %34, i16* inttoptr (i64 12582912 to i16*)
%35 = getelementptr inbounds i16, i16* %1, i64 13
%36 = load i16, i16* %33
store volatile i16 %36, i16* inttoptr (i64 12582912 to i16*)
%37 = getelementptr inbounds i16, i16* %1, i64 14
%38 = load i16, i16* %35
store volatile i16 %38, i16* inttoptr (i64 12582912 to i16*)
%39 = getelementptr inbounds i16, i16* %1, i64 15
%40 = load i16, i16* %37
store volatile i16 %40, i16* inttoptr (i64 12582912 to i16*)
%41 = load i16, i16* %39
store volatile i16 %41, i16* inttoptr (i64 12582912 to i16*)
ret void
}