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

/* Variables and functions */
int /*<<< orphan*/ VDP_doVRamDMAFill(unsigned short, int, int /*<<< orphan*/);
int VDP_getPlanHeight();
int VDP_getPlanWidth();
int /*<<< orphan*/ VDP_waitDMACompletion();
void VDP_clearPlan(unsigned short plan, unsigned char use_dma) {
  if (use_dma) {
    VDP_waitDMACompletion();
    VDP_doVRamDMAFill(plan, VDP_getPlanWidth() * VDP_getPlanHeight() * 2, 0);
  } else {
    volatile unsigned long *plctrl;
    volatile unsigned long *pldata;
    unsigned short i;
    plctrl = (unsigned long *)0xC00004;
    pldata = (unsigned long *)0xC00000;
    *plctrl = ((0x4000 + ((plan)&0x3FFF)) << 16) + (((plan) >> 14) | 0x00);
    i = VDP_getPlanWidth() * VDP_getPlanHeight() / (2 * 8);
    while (i--) {
      *pldata = 0;
      *pldata = 0;
      *pldata = 0;
      *pldata = 0;
      *pldata = 0;
      *pldata = 0;
      *pldata = 0;
      *pldata = 0;
    }
  }
}


x86 assembly (clang, -O0):
<VDP_clearPlan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %al,-0x3(%rbp)
cmpb   $0x0,-0x3(%rbp)
je     119d <VDP_clearPlan+0x5d>
mov    $0x0,%al
call   1050 <VDP_waitDMACompletion@plt>
mov    -0x2(%rbp),%ax
mov    %ax,-0x1c(%rbp)
mov    $0x0,%al
call   1060 <VDP_getPlanWidth@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <VDP_getPlanHeight@plt>
mov    -0x20(%rbp),%esi
mov    %eax,%ecx
mov    -0x1c(%rbp),%ax
imul   %ecx,%esi
shl    $0x1,%esi
xor    %edx,%edx
movzwl %ax,%edi
call   1040 <VDP_doVRamDMAFill@plt>
jmp    1276 <VDP_clearPlan+0x136>
mov    $0xc00004,%eax
mov    %rax,-0x10(%rbp)
mov    $0xc00000,%eax
mov    %rax,-0x18(%rbp)
movzwl -0x2(%rbp),%eax
and    $0x3fff,%eax
add    $0x4000,%eax
shl    $0x10,%eax
movzwl -0x2(%rbp),%ecx
sar    $0xe,%ecx
or     $0x0,%ecx
add    %ecx,%eax
movslq %eax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    $0x0,%al
call   1060 <VDP_getPlanWidth@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <VDP_getPlanHeight@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
imul   %ecx,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %ax,-0x1a(%rbp)
mov    -0x1a(%rbp),%ax
mov    %ax,%cx
add    $0xffff,%cx
mov    %cx,-0x1a(%rbp)
cmp    $0x0,%ax
je     1271 <VDP_clearPlan+0x131>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
jmp    11fb <VDP_clearPlan+0xbb>
jmp    1276 <VDP_clearPlan+0x136>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<VDP_clearPlan>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
test   %esi,%esi
je     1177 <VDP_clearPlan+0x37>
xor    %eax,%eax
call   1050 <VDP_waitDMACompletion@plt>
xor    %eax,%eax
call   1060 <VDP_getPlanWidth@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <VDP_getPlanHeight@plt>
imul   %eax,%ebp
add    %ebp,%ebp
movzwl %bx,%edi
mov    %ebp,%esi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <VDP_doVRamDMAFill@plt>
movzwl %bx,%eax
mov    %eax,%ecx
shl    $0x10,%ecx
and    $0x3fff0000,%ecx
shr    $0xe,%eax
add    %ecx,%eax
add    $0x40000000,%eax
mov    %rax,0xc00004
xor    %eax,%eax
call   1060 <VDP_getPlanWidth@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <VDP_getPlanHeight@plt>
imul   %ebx,%eax
lea    0xf(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
shr    $0x4,%ecx
test   %cx,%cx
je     130a <VDP_clearPlan+0x1ca>
mov    %ecx,%eax
test   $0x1,%cl
je     1228 <VDP_clearPlan+0xe8>
lea    -0x1(%rcx),%eax
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
cmp    $0x1,%cx
je     130a <VDP_clearPlan+0x1ca>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
movq   $0x0,0xc00000
add    $0xfffe,%ax
jne    1240 <VDP_clearPlan+0x100>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @VDP_clearPlan(i16 zeroext %0, i8 zeroext %1) {
%3 = alloca i16
%4 = alloca i8
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i16
store i16 %0, i16* %3
store i8 %1, i8* %4
%8 = load i8, i8* %4
%9 = icmp ne i8 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = call i32 (...) @VDP_waitDMACompletion()
%12 = load i16, i16* %3
%13 = call i32 (...) @VDP_getPlanWidth()
%14 = call i32 (...) @VDP_getPlanHeight()
%15 = mul nsw i32 %13, %14
%16 = mul nsw i32 %15, 2
%17 = call i32 @VDP_doVRamDMAFill(i16 zeroext %12, i32 %16, i32 0)
br label %50
18: ; preds = %2
store i64* inttoptr (i64 12582916 to i64*), i64** %5
store i64* inttoptr (i64 12582912 to i64*), i64** %6
%19 = load i16, i16* %3
%20 = zext i16 %19 to i32
%21 = and i32 %20, 16383
%22 = add nsw i32 16384, %21
%23 = shl i32 %22, 16
%24 = load i16, i16* %3
%25 = zext i16 %24 to i32
%26 = ashr i32 %25, 14
%27 = or i32 %26, 0
%28 = add nsw i32 %23, %27
%29 = sext i32 %28 to i64
%30 = load i64*, i64** %5
store volatile i64 %29, i64* %30
%31 = call i32 (...) @VDP_getPlanWidth()
%32 = call i32 (...) @VDP_getPlanHeight()
%33 = mul nsw i32 %31, %32
%34 = sdiv i32 %33, 16
%35 = trunc i32 %34 to i16
store i16 %35, i16* %7
br label %36
36: ; preds = %40, %18
%37 = load i16, i16* %7
%38 = add i16 %37, -1
store i16 %38, i16* %7
%39 = icmp ne i16 %37, 0
br i1 %39, label %40, label %49
40: ; preds = %36
%41 = load i64*, i64** %6
store volatile i64 0, i64* %41
%42 = load i64*, i64** %6
store volatile i64 0, i64* %42
%43 = load i64*, i64** %6
store volatile i64 0, i64* %43
%44 = load i64*, i64** %6
store volatile i64 0, i64* %44
%45 = load i64*, i64** %6
store volatile i64 0, i64* %45
%46 = load i64*, i64** %6
store volatile i64 0, i64* %46
%47 = load i64*, i64** %6
store volatile i64 0, i64* %47
%48 = load i64*, i64** %6
store volatile i64 0, i64* %48
br label %36
49: ; preds = %36
br label %50
50: ; preds = %49, %10
ret void
}

LLVM IR (-O2):
define void @VDP_clearPlan(i16 zeroext %0, i8 zeroext %1) {
%3 = icmp eq i8 %1, 0
br i1 %3, label %11, label %4
4: ; preds = %2
%5 = tail call i32 (...) @VDP_waitDMACompletion()
%6 = tail call i32 (...) @VDP_getPlanWidth()
%7 = tail call i32 (...) @VDP_getPlanHeight()
%8 = shl i32 %6, 1
%9 = mul i32 %8, %7
%10 = tail call i32 @VDP_doVRamDMAFill(i16 zeroext %0, i32 %9, i32 0)
br label %37
11: ; preds = %2
%12 = zext i16 %0 to i32
%13 = shl nuw i32 %12, 16
%14 = and i32 %13, 1073676288
%15 = lshr i32 %12, 14
%16 = or i32 %15, %14
%17 = or i32 %16, 1073741824
%18 = zext i32 %17 to i64
store volatile i64 %18, i64* inttoptr (i64 12582916 to i64*)
%19 = tail call i32 (...) @VDP_getPlanWidth()
%20 = tail call i32 (...) @VDP_getPlanHeight()
%21 = mul nsw i32 %20, %19
%22 = sdiv i32 %21, 16
%23 = trunc i32 %22 to i16
%24 = icmp eq i16 %23, 0
br i1 %24, label %37, label %25
25: ; preds = %11
%26 = and i16 %23, 1
%27 = icmp eq i16 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = add i16 %23, -1
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
br label %30
30: ; preds = %28, %25
%31 = phi i16 [ %23, %25 ], [ %29, %28 ]
%32 = icmp eq i16 %23, 1
br i1 %32, label %37, label %33
33: ; preds = %30, %33
%34 = phi i16 [ %35, %33 ], [ %31, %30 ]
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
%35 = add i16 %34, -2
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
store volatile i64 0, i64* inttoptr (i64 12582912 to i64*)
%36 = icmp eq i16 %35, 0
br i1 %36, label %37, label %33
37: ; preds = %30, %33, %11, %4
ret void
}