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

/* Variables and functions */
int VDP_getScreenHeight();
int VDP_getScreenWidth();
int /*<<< orphan*/ VDP_setAutoInc(int);
void initTilemap(unsigned short num) {
  volatile unsigned long *plctrl;
  volatile unsigned short *pwdata;
  unsigned short tile_ind;
  unsigned long addr_tilemap;
  unsigned short i, j;
  VDP_setAutoInc(2);
  const unsigned long offset =
      ((((1 << 6) * (((VDP_getScreenHeight() >> 3) - 20) / 2)) +
        (((VDP_getScreenWidth() >> 3) - (1 << 5)) / 2)) *
       2);
  if (num == 0) {
    addr_tilemap = 0xC000 + offset;
    tile_ind = (0x0000 + 0x10);
  } else {
    addr_tilemap = (0xC000 + (((1 << 6) * ((1 << 6) / 2)) * 2)) + offset;
    tile_ind = ((0x0000 + 0x10) + ((1 << 5) * 20));
  }
  plctrl = (unsigned long *)0xC00004;
  pwdata = (unsigned short *)0xC00000;
  i = 20;
  while (i--) {
    *plctrl = ((0x4000 + ((addr_tilemap)&0x3FFF)) << 16) +
              (((addr_tilemap) >> 14) | 0x00);
    j = (1 << 5) >> 3;
    while (j--) {
      *pwdata = tile_ind++;
      *pwdata = tile_ind++;
      *pwdata = tile_ind++;
      *pwdata = tile_ind++;
      *pwdata = tile_ind++;
      *pwdata = tile_ind++;
      *pwdata = tile_ind++;
      *pwdata = tile_ind++;
    }
    addr_tilemap += (1 << 6) * 2;
  }
}


x86 assembly (clang, -O0):
<initTilemap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    $0x2,%edi
call   1040 <VDP_setAutoInc@plt>
mov    $0x0,%al
call   1050 <VDP_getScreenHeight@plt>
sar    $0x3,%eax
sub    $0x14,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
shl    $0x6,%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1030 <VDP_getScreenWidth@plt>
sar    $0x3,%eax
sub    $0x20,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
shl    $0x1,%eax
cltq
mov    %rax,-0x38(%rbp)
movzwl -0x2(%rbp),%eax
cmp    $0x0,%eax
jne    11af <initTilemap+0x7f>
mov    -0x38(%rbp),%rax
add    $0xc000,%rax
mov    %rax,-0x28(%rbp)
movw   $0x10,-0x1a(%rbp)
jmp    11c3 <initTilemap+0x93>
mov    -0x38(%rbp),%rax
add    $0xd000,%rax
mov    %rax,-0x28(%rbp)
movw   $0x290,-0x1a(%rbp)
mov    $0xc00004,%eax
mov    %rax,-0x10(%rbp)
mov    $0xc00000,%eax
mov    %rax,-0x18(%rbp)
movw   $0x14,-0x2a(%rbp)
mov    -0x2a(%rbp),%ax
mov    %ax,%cx
add    $0xffff,%cx
mov    %cx,-0x2a(%rbp)
cmp    $0x0,%ax
je     1307 <initTilemap+0x1d7>
mov    -0x28(%rbp),%rcx
and    $0x3fff,%rcx
add    $0x4000,%rcx
shl    $0x10,%rcx
mov    -0x28(%rbp),%rax
shr    $0xe,%rax
or     $0x0,%rax
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movw   $0x4,-0x2c(%rbp)
mov    -0x2c(%rbp),%ax
mov    %ax,%cx
add    $0xffff,%cx
mov    %cx,-0x2c(%rbp)
cmp    $0x0,%ax
je     12f4 <initTilemap+0x1c4>
mov    -0x1a(%rbp),%cx
mov    %cx,%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x1a(%rbp),%cx
mov    %cx,%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x1a(%rbp),%cx
mov    %cx,%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x1a(%rbp),%cx
mov    %cx,%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x1a(%rbp),%cx
mov    %cx,%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x1a(%rbp),%cx
mov    %cx,%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x1a(%rbp),%cx
mov    %cx,%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x1a(%rbp),%cx
mov    %cx,%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
jmp    1226 <initTilemap+0xf6>
mov    -0x28(%rbp),%rax
add    $0x80,%rax
mov    %rax,-0x28(%rbp)
jmp    11db <initTilemap+0xab>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initTilemap>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
mov    $0x2,%edi
call   1040 <VDP_setAutoInc@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <VDP_getScreenHeight@plt>
sar    $0x3,%eax
mov    %eax,%ecx
add    $0xffffffec,%ecx
shr    $0x1f,%ecx
lea    (%rax,%rcx,1),%ebp
add    $0xffffffec,%ebp
shl    $0x5,%ebp
and    $0x7fffffc0,%ebp
xor    %eax,%eax
call   1030 <VDP_getScreenWidth@plt>
sar    $0x3,%eax
mov    %eax,%ecx
add    $0xffffffe0,%ecx
shr    $0x1f,%ecx
add    %ecx,%eax
add    $0xffffffe0,%eax
shr    %eax
add    %ebp,%eax
add    %eax,%eax
cltq
xor    %ecx,%ecx
test   %r14d,%r14d
setne  %cl
mov    $0x10,%edx
mov    $0x290,%esi
cmove  %edx,%esi
shl    $0xc,%rcx
lea    (%rcx,%rax,1),%rbp
add    $0xc000,%rbp
mov    %rbp,%rcx
shl    $0x10,%rcx
movzwl %si,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%rdx,%rbx,1),%esi
mov    %ecx,%edi
and    $0x3ffe0000,%edi
mov    %rbp,%rax
shr    $0xe,%rax
add    %rdi,%rax
add    $0x40000000,%rax
mov    %rax,0xc00004
mov    %si,0xc00000
lea    0x1(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x2(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x3(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x4(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x5(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x6(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x7(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x8(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x9(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0xa(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0xb(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0xc(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0xd(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0xe(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0xf(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x10(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x11(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x12(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x13(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x14(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x15(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x16(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x17(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x18(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x19(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x1a(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x1b(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x1c(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x1d(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    0x1e(%rdx,%rbx,1),%eax
mov    %ax,0xc00000
lea    (%rdx,%rbx,1),%eax
add    $0x1f,%eax
mov    %ax,0xc00000
sub    $0xffffffffffffff80,%rbp
add    $0x20,%ebx
add    $0x800000,%rcx
movzwl %bx,%eax
cmp    $0x280,%eax
jne    11c0 <initTilemap+0x90>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @initTilemap(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i64*
%4 = alloca i16*
%5 = alloca i16
%6 = alloca i64
%7 = alloca i16
%8 = alloca i16
%9 = alloca i64
store i16 %0, i16* %2
%10 = call i32 @VDP_setAutoInc(i32 2)
%11 = call i32 (...) @VDP_getScreenHeight()
%12 = ashr i32 %11, 3
%13 = sub nsw i32 %12, 20
%14 = sdiv i32 %13, 2
%15 = mul nsw i32 64, %14
%16 = call i32 (...) @VDP_getScreenWidth()
%17 = ashr i32 %16, 3
%18 = sub nsw i32 %17, 32
%19 = sdiv i32 %18, 2
%20 = add nsw i32 %15, %19
%21 = mul nsw i32 %20, 2
%22 = sext i32 %21 to i64
store i64 %22, i64* %9
%23 = load i16, i16* %2
%24 = zext i16 %23 to i32
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %1
%27 = load i64, i64* %9
%28 = add i64 49152, %27
store i64 %28, i64* %6
store i16 16, i16* %5
br label %32
29: ; preds = %1
%30 = load i64, i64* %9
%31 = add i64 53248, %30
store i64 %31, i64* %6
store i16 656, i16* %5
br label %32
32: ; preds = %29, %26
store i64* inttoptr (i64 12582916 to i64*), i64** %3
store i16* inttoptr (i64 12582912 to i16*), i16** %4
store i16 20, i16* %7
br label %33
33: ; preds = %76, %32
%34 = load i16, i16* %7
%35 = add i16 %34, -1
store i16 %35, i16* %7
%36 = icmp ne i16 %34, 0
br i1 %36, label %37, label %79
37: ; preds = %33
%38 = load i64, i64* %6
%39 = and i64 %38, 16383
%40 = add i64 16384, %39
%41 = shl i64 %40, 16
%42 = load i64, i64* %6
%43 = lshr i64 %42, 14
%44 = or i64 %43, 0
%45 = add i64 %41, %44
%46 = load i64*, i64** %3
store volatile i64 %45, i64* %46
store i16 4, i16* %8
br label %47
47: ; preds = %51, %37
%48 = load i16, i16* %8
%49 = add i16 %48, -1
store i16 %49, i16* %8
%50 = icmp ne i16 %48, 0
br i1 %50, label %51, label %76
51: ; preds = %47
%52 = load i16, i16* %5
%53 = add i16 %52, 1
store i16 %53, i16* %5
%54 = load i16*, i16** %4
store volatile i16 %52, i16* %54
%55 = load i16, i16* %5
%56 = add i16 %55, 1
store i16 %56, i16* %5
%57 = load i16*, i16** %4
store volatile i16 %55, i16* %57
%58 = load i16, i16* %5
%59 = add i16 %58, 1
store i16 %59, i16* %5
%60 = load i16*, i16** %4
store volatile i16 %58, i16* %60
%61 = load i16, i16* %5
%62 = add i16 %61, 1
store i16 %62, i16* %5
%63 = load i16*, i16** %4
store volatile i16 %61, i16* %63
%64 = load i16, i16* %5
%65 = add i16 %64, 1
store i16 %65, i16* %5
%66 = load i16*, i16** %4
store volatile i16 %64, i16* %66
%67 = load i16, i16* %5
%68 = add i16 %67, 1
store i16 %68, i16* %5
%69 = load i16*, i16** %4
store volatile i16 %67, i16* %69
%70 = load i16, i16* %5
%71 = add i16 %70, 1
store i16 %71, i16* %5
%72 = load i16*, i16** %4
store volatile i16 %70, i16* %72
%73 = load i16, i16* %5
%74 = add i16 %73, 1
store i16 %74, i16* %5
%75 = load i16*, i16** %4
store volatile i16 %73, i16* %75
br label %47
76: ; preds = %47
%77 = load i64, i64* %6
%78 = add i64 %77, 128
store i64 %78, i64* %6
br label %33
79: ; preds = %33
ret void
}

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