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

/* Variables and functions */
int /*<<< orphan*/ VDP_setAutoInc(int);
void VDP_doDMACopy(unsigned char location, unsigned short from,
                   unsigned short to, unsigned short len) {
  volatile unsigned short *pw;
  volatile unsigned long *pl;
  pw = (unsigned short *)0xC00004;
  *pw = 0x9300 + (len & 0xff);
  len >>= 8;
  *pw = 0x9400 + (len & 0xff);
  *pw = 0x9500 + (from & 0xff);
  *pw = 0x9600 + ((from >> 8) & 0xff);
  *pw = 0x97C0;
  pl = (unsigned long *)0xC00004;
  switch (location) {
  case 0:
    VDP_setAutoInc(1);
    *pl = ((0x4000 + ((to)&0x3FFF)) << 16) + (((to) >> 14) | 0x80);
    break;
  case 1:
    VDP_setAutoInc(2);
    *pl = ((0xC000 + ((to)&0x3FFF)) << 16) + (((to) >> 14) | 0x80);
    break;
  case 2:
    VDP_setAutoInc(2);
    *pl = ((0x4000 + ((to)&0x3FFF)) << 16) + (((to) >> 14) | 0x90);
    break;
  }
}


x86 assembly (clang, -O0):
<VDP_doDMACopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %cx,%ax
mov    %dx,%cx
mov    %si,%dx
mov    %dil,%sil
mov    %sil,-0x1(%rbp)
mov    %dx,-0x4(%rbp)
mov    %cx,-0x6(%rbp)
mov    %ax,-0x8(%rbp)
movq   $0xc00004,-0x10(%rbp)
movzbl -0x8(%rbp),%eax
or     $0x9300,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
movzbl -0x7(%rbp),%eax
mov    %ax,-0x8(%rbp)
movzbl -0x8(%rbp),%eax
or     $0x9400,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
movzbl -0x4(%rbp),%eax
or     $0x9500,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
movzbl -0x3(%rbp),%eax
or     $0x9600,%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
mov    -0x10(%rbp),%rax
movw   $0x97c0,(%rax)
movq   $0xc00004,-0x18(%rbp)
movzbl -0x1(%rbp),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     11d7 <VDP_doDMACopy+0xc7>
jmp    11b5 <VDP_doDMACopy+0xa5>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
je     1210 <VDP_doDMACopy+0x100>
jmp    11c6 <VDP_doDMACopy+0xb6>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1249 <VDP_doDMACopy+0x139>
jmp    127d <VDP_doDMACopy+0x16d>
mov    $0x1,%edi
call   1030 <VDP_setAutoInc@plt>
movzwl -0x6(%rbp),%eax
and    $0x3fff,%eax
add    $0x4000,%eax
shl    $0x10,%eax
movzwl -0x6(%rbp),%ecx
sar    $0xe,%ecx
or     $0x80,%ecx
add    %ecx,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    127d <VDP_doDMACopy+0x16d>
mov    $0x2,%edi
call   1030 <VDP_setAutoInc@plt>
movzwl -0x6(%rbp),%eax
and    $0x3fff,%eax
add    $0xc000,%eax
shl    $0x10,%eax
movzwl -0x6(%rbp),%ecx
sar    $0xe,%ecx
or     $0x80,%ecx
add    %ecx,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    127d <VDP_doDMACopy+0x16d>
mov    $0x2,%edi
call   1030 <VDP_setAutoInc@plt>
movzwl -0x6(%rbp),%eax
and    $0x3fff,%eax
add    $0x4000,%eax
shl    $0x10,%eax
movzwl -0x6(%rbp),%ecx
sar    $0xe,%ecx
or     $0x90,%ecx
add    %ecx,%eax
movslq %eax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VDP_doDMACopy>:
push   %rbx
mov    %edx,%ebx
movzbl %cl,%eax
or     $0x9300,%eax
mov    %ax,0xc00004
shr    $0x8,%ecx
or     $0x9400,%ecx
mov    %cx,0xc00004
movzbl %sil,%eax
or     $0x9500,%eax
mov    %ax,0xc00004
shr    $0x8,%esi
or     $0x9600,%esi
mov    %si,0xc00004
movw   $0x97c0,0xc00004
cmp    $0x2,%dil
je     1195 <VDP_doDMACopy+0x85>
cmp    $0x1,%dil
je     11b9 <VDP_doDMACopy+0xa9>
test   %dil,%dil
jne    11df <VDP_doDMACopy+0xcf>
mov    $0x1,%edi
call   1030 <VDP_setAutoInc@plt>
movzwl %bx,%eax
mov    %eax,%ecx
shl    $0x10,%ecx
and    $0x3fff0000,%ecx
shr    $0xe,%eax
add    %ecx,%eax
add    $0x40000080,%eax
jmp    11d7 <VDP_doDMACopy+0xc7>
mov    $0x2,%edi
call   1030 <VDP_setAutoInc@plt>
movzwl %bx,%eax
mov    %eax,%ecx
shl    $0x10,%ecx
and    $0x3fff0000,%ecx
shr    $0xe,%eax
add    %ecx,%eax
add    $0x40000090,%eax
jmp    11d7 <VDP_doDMACopy+0xc7>
mov    $0x2,%edi
call   1030 <VDP_setAutoInc@plt>
movzwl %bx,%eax
mov    %eax,%ecx
shl    $0x10,%ecx
shr    $0xe,%eax
or     %ecx,%eax
or     $0xc0000080,%eax
cltq
mov    %rax,0xc00004
pop    %rbx
ret

LLVM IR (-O0):
define void @VDP_doDMACopy(i8 zeroext %0, i16 zeroext %1, i16 zeroext %2, i16 zeroext %3) {
%5 = alloca i8
%6 = alloca i16
%7 = alloca i16
%8 = alloca i16
%9 = alloca i16*
%10 = alloca i64*
store i8 %0, i8* %5
store i16 %1, i16* %6
store i16 %2, i16* %7
store i16 %3, i16* %8
store i16* inttoptr (i64 12582916 to i16*), i16** %9
%11 = load i16, i16* %8
%12 = zext i16 %11 to i32
%13 = and i32 %12, 255
%14 = add nsw i32 37632, %13
%15 = trunc i32 %14 to i16
%16 = load i16*, i16** %9
store volatile i16 %15, i16* %16
%17 = load i16, i16* %8
%18 = zext i16 %17 to i32
%19 = ashr i32 %18, 8
%20 = trunc i32 %19 to i16
store i16 %20, i16* %8
%21 = load i16, i16* %8
%22 = zext i16 %21 to i32
%23 = and i32 %22, 255
%24 = add nsw i32 37888, %23
%25 = trunc i32 %24 to i16
%26 = load i16*, i16** %9
store volatile i16 %25, i16* %26
%27 = load i16, i16* %6
%28 = zext i16 %27 to i32
%29 = and i32 %28, 255
%30 = add nsw i32 38144, %29
%31 = trunc i32 %30 to i16
%32 = load i16*, i16** %9
store volatile i16 %31, i16* %32
%33 = load i16, i16* %6
%34 = zext i16 %33 to i32
%35 = ashr i32 %34, 8
%36 = and i32 %35, 255
%37 = add nsw i32 38400, %36
%38 = trunc i32 %37 to i16
%39 = load i16*, i16** %9
store volatile i16 %38, i16* %39
%40 = load i16*, i16** %9
store volatile i16 -26688, i16* %40
store i64* inttoptr (i64 12582916 to i64*), i64** %10
%41 = load i8, i8* %5
%42 = zext i8 %41 to i32
switch i32 %42, label %85 [
i32 0, label %43
i32 1, label %57
i32 2, label %71
]
43: ; preds = %4
%44 = call i32 @VDP_setAutoInc(i32 1)
%45 = load i16, i16* %7
%46 = zext i16 %45 to i32
%47 = and i32 %46, 16383
%48 = add nsw i32 16384, %47
%49 = shl i32 %48, 16
%50 = load i16, i16* %7
%51 = zext i16 %50 to i32
%52 = ashr i32 %51, 14
%53 = or i32 %52, 128
%54 = add nsw i32 %49, %53
%55 = sext i32 %54 to i64
%56 = load i64*, i64** %10
store volatile i64 %55, i64* %56
br label %85
57: ; preds = %4
%58 = call i32 @VDP_setAutoInc(i32 2)
%59 = load i16, i16* %7
%60 = zext i16 %59 to i32
%61 = and i32 %60, 16383
%62 = add nsw i32 49152, %61
%63 = shl i32 %62, 16
%64 = load i16, i16* %7
%65 = zext i16 %64 to i32
%66 = ashr i32 %65, 14
%67 = or i32 %66, 128
%68 = add nsw i32 %63, %67
%69 = sext i32 %68 to i64
%70 = load i64*, i64** %10
store volatile i64 %69, i64* %70
br label %85
71: ; preds = %4
%72 = call i32 @VDP_setAutoInc(i32 2)
%73 = load i16, i16* %7
%74 = zext i16 %73 to i32
%75 = and i32 %74, 16383
%76 = add nsw i32 16384, %75
%77 = shl i32 %76, 16
%78 = load i16, i16* %7
%79 = zext i16 %78 to i32
%80 = ashr i32 %79, 14
%81 = or i32 %80, 144
%82 = add nsw i32 %77, %81
%83 = sext i32 %82 to i64
%84 = load i64*, i64** %10
store volatile i64 %83, i64* %84
br label %85
85: ; preds = %4, %71, %57, %43
ret void
}

LLVM IR (-O2):
define void @VDP_doDMACopy(i8 zeroext %0, i16 zeroext %1, i16 zeroext %2, i16 zeroext %3) {
%5 = and i16 %3, 255
%6 = or i16 %5, -27904
store volatile i16 %6, i16* inttoptr (i64 12582916 to i16*)
%7 = lshr i16 %3, 8
%8 = or i16 %7, -27648
store volatile i16 %8, i16* inttoptr (i64 12582916 to i16*)
%9 = and i16 %1, 255
%10 = or i16 %9, -27392
store volatile i16 %10, i16* inttoptr (i64 12582916 to i16*)
%11 = lshr i16 %1, 8
%12 = or i16 %11, -27136
store volatile i16 %12, i16* inttoptr (i64 12582916 to i16*)
store volatile i16 -26688, i16* inttoptr (i64 12582916 to i16*)
switch i8 %0, label %41 [
i8 0, label %13
i8 1, label %22
i8 2, label %30
]
13: ; preds = %4
%14 = tail call i32 @VDP_setAutoInc(i32 1)
%15 = zext i16 %2 to i32
%16 = shl nuw i32 %15, 16
%17 = and i32 %16, 1073676288
%18 = lshr i32 %15, 14
%19 = or i32 %18, %17
%20 = or i32 %19, 1073741952
%21 = zext i32 %20 to i64
br label %39
22: ; preds = %4
%23 = tail call i32 @VDP_setAutoInc(i32 2)
%24 = zext i16 %2 to i32
%25 = shl nuw i32 %24, 16
%26 = lshr i32 %24, 14
%27 = or i32 %25, %26
%28 = or i32 %27, -1073741696
%29 = sext i32 %28 to i64
br label %39
30: ; preds = %4
%31 = tail call i32 @VDP_setAutoInc(i32 2)
%32 = zext i16 %2 to i32
%33 = shl nuw i32 %32, 16
%34 = and i32 %33, 1073676288
%35 = lshr i32 %32, 14
%36 = or i32 %35, %34
%37 = or i32 %36, 1073741968
%38 = zext i32 %37 to i64
br label %39
39: ; preds = %13, %22, %30
%40 = phi i64 [ %38, %30 ], [ %29, %22 ], [ %21, %13 ]
store volatile i64 %40, i64* inttoptr (i64 12582916 to i64*)
br label %41
41: ; preds = %39, %4
ret void
}