#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_doDMAEx(int, unsigned long, unsigned short,
                               unsigned short, int);
int /*<<< orphan*/ VDP_setAutoInc(int);
void VDP_setVerticalScrollTile(unsigned short plan, unsigned short tile,
                               short *values, unsigned short len,
                               unsigned short use_dma) {
  unsigned short addr;
  addr = (tile & 0x1F) * 4;
  if (plan == 0xC000)
    addr += 2;
  VDP_setAutoInc(4);
  if (use_dma)
    VDP_doDMAEx(2, (unsigned long)values, addr, len, -1);
  else {
    volatile unsigned short *pw;
    volatile unsigned long *pl;
    unsigned short *src;
    unsigned short i;
    pw = (unsigned short *)0xC00000;
    pl = (unsigned long *)0xC00004;
    *pl = ((0x4000 + ((addr)&0x3FFF)) << 16) + (((addr) >> 14) | 0x10);
    src = values;
    i = len;
    while (i--)
      *pw = *src++;
  }
}


x86 assembly (clang, -O0):
<VDP_setVerticalScrollTile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8w,%ax
mov    %di,-0x2(%rbp)
mov    %si,-0x4(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %cx,-0x12(%rbp)
mov    %ax,-0x14(%rbp)
movzwl -0x4(%rbp),%eax
and    $0x1f,%eax
shl    $0x2,%eax
mov    %ax,-0x16(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0xc000,%eax
jne    1168 <VDP_setVerticalScrollTile+0x48>
movzwl -0x16(%rbp),%eax
add    $0x2,%eax
mov    %ax,-0x16(%rbp)
mov    $0x4,%edi
call   1040 <VDP_setAutoInc@plt>
cmpw   $0x0,-0x14(%rbp)
je     11a1 <VDP_setVerticalScrollTile+0x81>
mov    -0x10(%rbp),%rsi
mov    -0x16(%rbp),%ax
mov    $0x2,%edi
mov    $0xffffffff,%r8d
movzwl %ax,%edx
movzwl -0x12(%rbp),%ecx
call   1030 <VDP_doDMAEx@plt>
jmp    1226 <VDP_setVerticalScrollTile+0x106>
mov    $0xc00000,%eax
mov    %rax,-0x20(%rbp)
mov    $0xc00004,%eax
mov    %rax,-0x28(%rbp)
movzwl -0x16(%rbp),%eax
and    $0x3fff,%eax
add    $0x4000,%eax
shl    $0x10,%eax
movzwl -0x16(%rbp),%ecx
sar    $0xe,%ecx
or     $0x10,%ecx
add    %ecx,%eax
movslq %eax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x12(%rbp),%ax
mov    %ax,-0x32(%rbp)
mov    -0x32(%rbp),%ax
mov    %ax,%cx
add    $0xffff,%cx
mov    %cx,-0x32(%rbp)
cmp    $0x0,%ax
je     1221 <VDP_setVerticalScrollTile+0x101>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x2,%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rax),%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
jmp    11ea <VDP_setVerticalScrollTile+0xca>
jmp    1226 <VDP_setVerticalScrollTile+0x106>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VDP_setVerticalScrollTile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %ecx,%r14d
mov    %rdx,%rbx
shl    $0x2,%esi
and    $0x7c,%esi
lea    0x2(%rsi),%ebp
cmp    $0xc000,%edi
cmovne %esi,%ebp
mov    $0x4,%edi
call   1040 <VDP_setAutoInc@plt>
test   %r15d,%r15d
je     1175 <VDP_setVerticalScrollTile+0x55>
movzwl %bp,%edx
movzwl %r14w,%ecx
mov    $0x2,%edi
mov    %rbx,%rsi
mov    $0xffffffff,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <VDP_doDMAEx@plt>
movzwl %bp,%eax
or     $0x4000,%eax
shl    $0x10,%rax
or     $0x10,%rax
mov    %rax,0xc00004
test   %r14w,%r14w
je     1250 <VDP_setVerticalScrollTile+0x130>
lea    -0x1(%r14),%eax
mov    %r14d,%edx
and    $0x7,%dx
je     11ca <VDP_setVerticalScrollTile+0xaa>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
movzwl (%rbx),%esi
add    $0x2,%rbx
mov    %si,0xc00000
add    $0x1,%ecx
cmp    %cx,%dx
jne    11b0 <VDP_setVerticalScrollTile+0x90>
sub    %ecx,%r14d
cmp    $0x7,%ax
jb     1250 <VDP_setVerticalScrollTile+0x130>
movzwl %r14w,%eax
xor    %ecx,%ecx
nopw   0x0(%rax,%rax,1)
movzwl (%rbx,%rcx,2),%edx
mov    %dx,0xc00000
movzwl 0x2(%rbx,%rcx,2),%edx
mov    %dx,0xc00000
movzwl 0x4(%rbx,%rcx,2),%edx
mov    %dx,0xc00000
movzwl 0x6(%rbx,%rcx,2),%edx
mov    %dx,0xc00000
movzwl 0x8(%rbx,%rcx,2),%edx
mov    %dx,0xc00000
movzwl 0xa(%rbx,%rcx,2),%edx
mov    %dx,0xc00000
movzwl 0xc(%rbx,%rcx,2),%edx
mov    %dx,0xc00000
movzwl 0xe(%rbx,%rcx,2),%edx
mov    %dx,0xc00000
add    $0x8,%rcx
cmp    %cx,%ax
jne    11e0 <VDP_setVerticalScrollTile+0xc0>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @VDP_setVerticalScrollTile(i16 zeroext %0, i16 zeroext %1, i16* %2, i16 zeroext %3, i16 zeroext %4) {
%6 = alloca i16
%7 = alloca i16
%8 = alloca i16*
%9 = alloca i16
%10 = alloca i16
%11 = alloca i16
%12 = alloca i16*
%13 = alloca i64*
%14 = alloca i16*
%15 = alloca i16
store i16 %0, i16* %6
store i16 %1, i16* %7
store i16* %2, i16** %8
store i16 %3, i16* %9
store i16 %4, i16* %10
%16 = load i16, i16* %7
%17 = zext i16 %16 to i32
%18 = and i32 %17, 31
%19 = mul nsw i32 %18, 4
%20 = trunc i32 %19 to i16
store i16 %20, i16* %11
%21 = load i16, i16* %6
%22 = zext i16 %21 to i32
%23 = icmp eq i32 %22, 49152
br i1 %23, label %24, label %29
24: ; preds = %5
%25 = load i16, i16* %11
%26 = zext i16 %25 to i32
%27 = add nsw i32 %26, 2
%28 = trunc i32 %27 to i16
store i16 %28, i16* %11
br label %29
29: ; preds = %24, %5
%30 = call i32 @VDP_setAutoInc(i32 4)
%31 = load i16, i16* %10
%32 = icmp ne i16 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i16*, i16** %8
%35 = ptrtoint i16* %34 to i64
%36 = load i16, i16* %11
%37 = load i16, i16* %9
%38 = call i32 @VDP_doDMAEx(i32 2, i64 %35, i16 zeroext %36, i16 zeroext %37, i32 -1)
br label %64
39: ; preds = %29
store i16* inttoptr (i64 12582912 to i16*), i16** %12
store i64* inttoptr (i64 12582916 to i64*), i64** %13
%40 = load i16, i16* %11
%41 = zext i16 %40 to i32
%42 = and i32 %41, 16383
%43 = add nsw i32 16384, %42
%44 = shl i32 %43, 16
%45 = load i16, i16* %11
%46 = zext i16 %45 to i32
%47 = ashr i32 %46, 14
%48 = or i32 %47, 16
%49 = add nsw i32 %44, %48
%50 = sext i32 %49 to i64
%51 = load i64*, i64** %13
store volatile i64 %50, i64* %51
%52 = load i16*, i16** %8
store i16* %52, i16** %14
%53 = load i16, i16* %9
store i16 %53, i16* %15
br label %54
54: ; preds = %58, %39
%55 = load i16, i16* %15
%56 = add i16 %55, -1
store i16 %56, i16* %15
%57 = icmp ne i16 %55, 0
br i1 %57, label %58, label %63
58: ; preds = %54
%59 = load i16*, i16** %14
%60 = getelementptr inbounds i16, i16* %59, i32 1
store i16* %60, i16** %14
%61 = load i16, i16* %59
%62 = load i16*, i16** %12
store volatile i16 %61, i16* %62
br label %54
63: ; preds = %54
br label %64
64: ; preds = %63, %33
ret void
}

LLVM IR (-O2):
define void @VDP_setVerticalScrollTile(i16 zeroext %0, i16 zeroext %1, i16* %2, i16 zeroext %3, i16 zeroext %4) {
%6 = shl i16 %1, 2
%7 = and i16 %6, 124
%8 = icmp eq i16 %0, -16384
%9 = or i16 %7, 2
%10 = select i1 %8, i16 %9, i16 %7
%11 = tail call i32 @VDP_setAutoInc(i32 4)
%12 = icmp eq i16 %4, 0
br i1 %12, label %16, label %13
13: ; preds = %5
%14 = ptrtoint i16* %2 to i64
%15 = tail call i32 @VDP_doDMAEx(i32 2, i64 %14, i16 zeroext %10, i16 zeroext %3, i32 -1)
br label %60
16: ; preds = %5
%17 = or i16 %10, 16384
%18 = zext i16 %17 to i64
%19 = shl nuw nsw i64 %18, 16
%20 = or i64 %19, 16
store volatile i64 %20, i64* inttoptr (i64 12582916 to i64*)
%21 = icmp eq i16 %3, 0
br i1 %21, label %60, label %22
22: ; preds = %16
%23 = add i16 %3, -1
%24 = and i16 %3, 7
%25 = icmp eq i16 %24, 0
br i1 %25, label %35, label %26
26: ; preds = %22, %26
%27 = phi i16 [ %30, %26 ], [ %3, %22 ]
%28 = phi i16* [ %31, %26 ], [ %2, %22 ]
%29 = phi i16 [ %33, %26 ], [ 0, %22 ]
%30 = add i16 %27, -1
%31 = getelementptr inbounds i16, i16* %28, i64 1
%32 = load i16, i16* %28
store volatile i16 %32, i16* inttoptr (i64 12582912 to i16*)
%33 = add i16 %29, 1
%34 = icmp eq i16 %33, %24
br i1 %34, label %35, label %26
35: ; preds = %26, %22
%36 = phi i16 [ %3, %22 ], [ %30, %26 ]
%37 = phi i16* [ %2, %22 ], [ %31, %26 ]
%38 = icmp ult i16 %23, 7
br i1 %38, label %60, label %39
39: ; preds = %35, %39
%40 = phi i16 [ %56, %39 ], [ %36, %35 ]
%41 = phi i16* [ %57, %39 ], [ %37, %35 ]
%42 = getelementptr inbounds i16, i16* %41, i64 1
%43 = load i16, i16* %41
store volatile i16 %43, i16* inttoptr (i64 12582912 to i16*)
%44 = getelementptr inbounds i16, i16* %41, i64 2
%45 = load i16, i16* %42
store volatile i16 %45, i16* inttoptr (i64 12582912 to i16*)
%46 = getelementptr inbounds i16, i16* %41, i64 3
%47 = load i16, i16* %44
store volatile i16 %47, i16* inttoptr (i64 12582912 to i16*)
%48 = getelementptr inbounds i16, i16* %41, i64 4
%49 = load i16, i16* %46
store volatile i16 %49, i16* inttoptr (i64 12582912 to i16*)
%50 = getelementptr inbounds i16, i16* %41, i64 5
%51 = load i16, i16* %48
store volatile i16 %51, i16* inttoptr (i64 12582912 to i16*)
%52 = getelementptr inbounds i16, i16* %41, i64 6
%53 = load i16, i16* %50
store volatile i16 %53, i16* inttoptr (i64 12582912 to i16*)
%54 = getelementptr inbounds i16, i16* %41, i64 7
%55 = load i16, i16* %52
store volatile i16 %55, i16* inttoptr (i64 12582912 to i16*)
%56 = add i16 %40, -8
%57 = getelementptr inbounds i16, i16* %41, i64 8
%58 = load i16, i16* %54
store volatile i16 %58, i16* inttoptr (i64 12582912 to i16*)
%59 = icmp eq i16 %56, 0
br i1 %59, label %60, label %39
60: ; preds = %35, %39, %16, %13
ret void
}