#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 /*<<< orphan*/, unsigned long,
                               unsigned short, unsigned short, int);
int /*<<< orphan*/ VDP_setAutoInc(int);
void VDP_setHorizontalScrollLine(unsigned short plan, unsigned short line,
                                 short *values, unsigned short len,
                                 unsigned short use_dma) {
  unsigned short addr;
  addr = 0xB800 + ((line & 0xFF) * 4);
  if (plan == 0xC000)
    addr += 2;
  VDP_setAutoInc(4);
  if (use_dma)
    VDP_doDMAEx(0, (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) | 0x00);
    src = values;
    i = len;
    while (i--)
      *pw = *src++;
  }
}


x86 assembly (clang, -O0):
<VDP_setHorizontalScrollLine>:
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    $0xff,%eax
shl    $0x2,%eax
add    $0xb800,%eax
mov    %ax,-0x16(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0xc000,%eax
jne    116f <VDP_setHorizontalScrollLine+0x4f>
movzwl -0x16(%rbp),%eax
add    $0x2,%eax
mov    %ax,-0x16(%rbp)
mov    $0x4,%edi
call   1040 <VDP_setAutoInc@plt>
cmpw   $0x0,-0x14(%rbp)
je     11a5 <VDP_setHorizontalScrollLine+0x85>
mov    -0x10(%rbp),%rsi
mov    -0x16(%rbp),%ax
xor    %edi,%edi
mov    $0xffffffff,%r8d
movzwl %ax,%edx
movzwl -0x12(%rbp),%ecx
call   1030 <VDP_doDMAEx@plt>
jmp    122a <VDP_setHorizontalScrollLine+0x10a>
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     $0x0,%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     1225 <VDP_setHorizontalScrollLine+0x105>
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    11ee <VDP_setHorizontalScrollLine+0xce>
jmp    122a <VDP_setHorizontalScrollLine+0x10a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VDP_setHorizontalScrollLine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %ecx,%r14d
mov    %rdx,%rbx
movzbl %sil,%eax
shl    $0x2,%eax
xor    %ecx,%ecx
cmp    $0xc000,%edi
sete   %cl
lea    (%rax,%rcx,2),%ebp
add    $0xb800,%ebp
mov    $0x4,%edi
call   1040 <VDP_setAutoInc@plt>
test   %r15d,%r15d
je     117b <VDP_setHorizontalScrollLine+0x5b>
movzwl %bp,%edx
movzwl %r14w,%ecx
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0xffffffff,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <VDP_doDMAEx@plt>
and    $0x3bfe,%ebp
or     $0x4000,%ebp
shl    $0x10,%rbp
or     $0x2,%rbp
mov    %rbp,0xc00004
test   %r14w,%r14w
je     1250 <VDP_setHorizontalScrollLine+0x130>
lea    -0x1(%r14),%eax
mov    %r14d,%edx
and    $0x7,%dx
je     11ca <VDP_setHorizontalScrollLine+0xaa>
xor    %ecx,%ecx
movzwl (%rbx),%esi
add    $0x2,%rbx
mov    %si,0xc00000
add    $0x1,%ecx
cmp    %cx,%dx
jne    11b0 <VDP_setHorizontalScrollLine+0x90>
sub    %ecx,%r14d
cmp    $0x7,%ax
jb     1250 <VDP_setHorizontalScrollLine+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_setHorizontalScrollLine+0xc0>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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