#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_getPalette(unsigned short num, unsigned short *pal) {
  volatile unsigned short *pw;
  volatile unsigned long *pl;
  unsigned short *dest;
  unsigned short i;
  unsigned short addr;
  VDP_setAutoInc(2);
  pw = (unsigned short *)0xC00000;
  pl = (unsigned long *)0xC00004;
  dest = pal;
  addr = num * 32;
  *pl = ((0x0000 + ((addr)&0x3FFF)) << 16) + (((addr) >> 14) | 0x20);
  i = 16;
  while (i--)
    *dest++ = *pw;
}


x86 assembly (clang, -O0):
<VDP_getPalette>:
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    $0x0,%eax
shl    $0x10,%eax
movzwl -0x2c(%rbp),%ecx
sar    $0xe,%ecx
or     $0x20,%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     11b4 <VDP_getPalette+0xa4>
mov    -0x18(%rbp),%rax
mov    (%rax),%cx
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x2,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cx,(%rax)
jmp    117d <VDP_getPalette+0x6d>
add    $0x30,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define void @VDP_getPalette(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 0, %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, 32
%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** %5
%34 = load volatile i16, i16* %33
%35 = load i16*, i16** %7
%36 = getelementptr inbounds i16, i16* %35, i32 1
store i16* %36, i16** %7
store i16 %34, i16* %35
br label %28
37: ; preds = %28
ret void
}

LLVM IR (-O2):
define void @VDP_getPalette(i16 zeroext %0, i16* nocapture writeonly %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 = and i32 %6, 1071644672
%8 = lshr i32 %5, 14
%9 = or i32 %8, %7
%10 = or i32 %9, 32
%11 = zext i32 %10 to i64
store volatile i64 %11, i64* inttoptr (i64 12582916 to i64*)
%12 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%13 = getelementptr inbounds i16, i16* %1, i64 1
store i16 %12, i16* %1
%14 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%15 = getelementptr inbounds i16, i16* %1, i64 2
store i16 %14, i16* %13
%16 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%17 = getelementptr inbounds i16, i16* %1, i64 3
store i16 %16, i16* %15
%18 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%19 = getelementptr inbounds i16, i16* %1, i64 4
store i16 %18, i16* %17
%20 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%21 = getelementptr inbounds i16, i16* %1, i64 5
store i16 %20, i16* %19
%22 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%23 = getelementptr inbounds i16, i16* %1, i64 6
store i16 %22, i16* %21
%24 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%25 = getelementptr inbounds i16, i16* %1, i64 7
store i16 %24, i16* %23
%26 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%27 = getelementptr inbounds i16, i16* %1, i64 8
store i16 %26, i16* %25
%28 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%29 = getelementptr inbounds i16, i16* %1, i64 9
store i16 %28, i16* %27
%30 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%31 = getelementptr inbounds i16, i16* %1, i64 10
store i16 %30, i16* %29
%32 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%33 = getelementptr inbounds i16, i16* %1, i64 11
store i16 %32, i16* %31
%34 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%35 = getelementptr inbounds i16, i16* %1, i64 12
store i16 %34, i16* %33
%36 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%37 = getelementptr inbounds i16, i16* %1, i64 13
store i16 %36, i16* %35
%38 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%39 = getelementptr inbounds i16, i16* %1, i64 14
store i16 %38, i16* %37
%40 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
%41 = getelementptr inbounds i16, i16* %1, i64 15
store i16 %40, i16* %39
%42 = load volatile i16, i16* inttoptr (i64 12582912 to i16*)
store i16 %42, i16* %41
ret void
}