void pvr_init_video(int cabletype, int mode, int res) {
  volatile unsigned int *videobase =
      (volatile unsigned int *)(void *)0xa05f8000;
  static int bppshifttab[] = {1, 1, 0, 2};
  int shift, lines, modulo, words_per_line, vpos;
  int laceoffset = 0, voffset = 0;
  unsigned int videoflags, attribs;
  unsigned int hvcounter = (res < 2 ? 0x01060359 : 0x020c0359);
  mode &= 3;
  shift = bppshifttab[mode];
  videobase[8 / 4] = 0;
  videobase[0x40 / 4] = 0;
  mode = (mode << 2) | 1;
  lines = 240;
  if (!(cabletype & 2)) {
    if (res < 2)
      mode |= 2;
    hvcounter = 0x020c0359;
    lines <<= 1;
    mode |= 0x800000;
  }
  videobase[0x44 / 4] = mode;
  videobase[0x50 / 4] = 0;
  videobase[0x54 / 4] = 640 << shift;
  videoflags = 1 << 8;
  if (res == 0)
    words_per_line = (320 / 4) << shift;
  else
    words_per_line = (640 / 4) << shift;
  modulo = 1;
  if (!(cabletype & 2)) {
    if (res == 0)
      modulo += words_per_line;
  } else {
    if (res != 1)
      modulo += words_per_line;
    if (res == 2)
      videoflags |= 1 << 4;
    videoflags |= 1 << 6;
  }
  videobase[0x5c / 4] =
      (((modulo << 10) + lines - 1) << 10) + words_per_line - 1;
  videobase[0xd0 / 4] = videoflags;
  if (!(cabletype & 2))
    voffset += 36;
  else
    voffset += 18;
  vpos = (voffset << 16) | (voffset + laceoffset);
  videobase[0xf0 / 4] = vpos;
  videobase[0xdc / 4] = vpos + lines;
  videobase[0xec / 4] = 0xa4;
  videobase[0xd8 / 4] = hvcounter;
  videobase[0xd4 / 4] = 0x007e0345;
  if (res == 0)
    attribs = ((22 << 8) + 1) << 8;
  else
    attribs = 22 << 16;
  videobase[0xe8 / 4] = attribs;
  vpos = 260;
  if (!(cabletype & 2))
    vpos = 510;
  videobase[0xcc / 4] = (0x21 << 16) | vpos;
  if (cabletype & 1)
    mode = 3;
  else
    mode = 0;
  *(volatile unsigned int *)(void *)0xa0702c00 = mode << 8;
  return;
}


x86 assembly (clang, -O0):
<pvr_init_video>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    $0xa05f8000,%eax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0xc(%rbp),%edx
mov    $0x20c0359,%eax
mov    $0x1060359,%ecx
cmp    $0x2,%edx
cmovl  %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rcx
lea    0x2ee2(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,0x8(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,0x40(%rax)
mov    -0x8(%rbp),%eax
shl    $0x2,%eax
or     $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0xf0,-0x20(%rbp)
mov    -0x4(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    11ba <pvr_init_video+0xba>
cmpl   $0x2,-0xc(%rbp)
jge    119f <pvr_init_video+0x9f>
mov    -0x8(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0x8(%rbp)
movl   $0x20c0359,-0x40(%rbp)
mov    -0x20(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
or     $0x800000,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x44(%rax)
mov    -0x18(%rbp),%rax
movl   $0x0,0x50(%rax)
mov    -0x1c(%rbp),%ecx
mov    $0x280,%eax
shl    %cl,%eax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x54(%rax)
movl   $0x100,-0x38(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1205 <pvr_init_video+0x105>
mov    -0x1c(%rbp),%ecx
mov    $0x50,%eax
shl    %cl,%eax
mov    %eax,-0x28(%rbp)
jmp    1212 <pvr_init_video+0x112>
mov    -0x1c(%rbp),%ecx
mov    $0xa0,%eax
shl    %cl,%eax
mov    %eax,-0x28(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x4(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    1240 <pvr_init_video+0x140>
cmpl   $0x0,-0xc(%rbp)
jne    123b <pvr_init_video+0x13b>
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    126f <pvr_init_video+0x16f>
cmpl   $0x1,-0xc(%rbp)
je     1253 <pvr_init_video+0x153>
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x2,-0xc(%rbp)
jne    1266 <pvr_init_video+0x166>
mov    -0x38(%rbp),%eax
or     $0x10,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
or     $0x40,%eax
mov    %eax,-0x38(%rbp)
mov    -0x24(%rbp),%ecx
shl    $0xa,%ecx
add    -0x20(%rbp),%ecx
sub    $0x1,%ecx
shl    $0xa,%ecx
add    -0x28(%rbp),%ecx
sub    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x5c(%rax)
mov    -0x38(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xd0(%rax)
mov    -0x4(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    12b5 <pvr_init_video+0x1b5>
mov    -0x34(%rbp),%eax
add    $0x24,%eax
mov    %eax,-0x34(%rbp)
jmp    12be <pvr_init_video+0x1be>
mov    -0x34(%rbp),%eax
add    $0x12,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
shl    $0x10,%eax
mov    -0x34(%rbp),%ecx
add    -0x30(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xf0(%rax)
mov    -0x2c(%rbp),%ecx
add    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xdc(%rax)
mov    -0x18(%rbp),%rax
movl   $0xa4,0xec(%rax)
mov    -0x40(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xd8(%rax)
mov    -0x18(%rbp),%rax
movl   $0x7e0345,0xd4(%rax)
cmpl   $0x0,-0xc(%rbp)
jne    132b <pvr_init_video+0x22b>
movl   $0x160100,-0x3c(%rbp)
jmp    1332 <pvr_init_video+0x232>
movl   $0x160000,-0x3c(%rbp)
mov    -0x3c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xe8(%rax)
movl   $0x104,-0x2c(%rbp)
mov    -0x4(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    135c <pvr_init_video+0x25c>
movl   $0x1fe,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
or     $0x210000,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0xcc(%rax)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     138a <pvr_init_video+0x28a>
movl   $0x3,-0x8(%rbp)
jmp    1391 <pvr_init_video+0x291>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
shl    $0x8,%ecx
mov    $0xa0702c00,%eax
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<pvr_init_video>:
push   %rbp
push   %rbx
and    $0x3,%esi
cmp    $0x2,%edx
lea    0xef1(%rip),%rax
mov    (%rax,%rsi,4),%cl
lea    0x1(,%rsi,4),%r9d
lea    0x3(,%rsi,4),%ebx
cmovge %r9d,%ebx
or     $0x800000,%ebx
mov    $0x280,%eax
shl    %cl,%eax
test   %edx,%edx
mov    $0x50,%r8d
mov    $0xa0,%esi
cmove  %r8d,%esi
mov    $0xa05f8008,%r10d
shl    %cl,%esi
movl   $0x0,(%r10)
mov    $0x1e0,%ecx
mov    $0xf0,%r8d
test   $0x2,%dil
cmove  %ecx,%r8d
cmovne %r9d,%ebx
movl   $0x0,0x38(%r10)
mov    %ebx,0x3c(%r10)
movl   $0x0,0x48(%r10)
mov    %eax,0x4c(%r10)
jne    11a8 <pvr_init_video+0xa8>
lea    0x1(%rsi),%eax
test   %edx,%edx
mov    $0x1,%ecx
cmove  %eax,%ecx
mov    $0x100,%eax
mov    $0x20c0359,%r9d
mov    $0x240024,%ebx
mov    $0x2101fe,%r11d
jmp    11d9 <pvr_init_video+0xd9>
lea    0x1(%rsi),%ecx
cmp    $0x1,%edx
cmove  %edx,%ecx
xor    %eax,%eax
cmp    $0x2,%edx
mov    $0x1060359,%ebx
mov    $0x20c0359,%r9d
cmovl  %ebx,%r9d
sete   %al
or     $0x14,%eax
shl    $0x4,%eax
mov    $0x120012,%ebx
mov    $0x210104,%r11d
xor    %ebp,%ebp
test   %edx,%edx
sete   %bpl
shl    $0x14,%ecx
mov    %r8d,%edx
shl    $0xa,%edx
add    %esi,%edx
add    %edx,%ecx
add    $0xfffffbff,%ecx
mov    %ecx,0x54(%r10)
mov    %eax,0xc8(%r10)
mov    %ebx,0xe8(%r10)
add    %r8d,%ebx
mov    %ebx,0xd4(%r10)
movl   $0xa4,0xe4(%r10)
mov    %r9d,0xd0(%r10)
movl   $0x7e0345,0xcc(%r10)
shl    $0x8,%ebp
or     $0x160000,%ebp
mov    %ebp,0xe0(%r10)
mov    %r11d,0xc4(%r10)
and    $0x1,%edi
neg    %edi
and    $0x300,%edi
mov    %edi,0x10abf8(%r10)
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@pvr_init_video.bppshifttab = internal global [4 x i32] [i32 1, i32 1, i32 0, i32 2]
define void @pvr_init_video(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32* inttoptr (i64 2690613248 to i32*), i32** %7
store i32 0, i32* %13
store i32 0, i32* %14
%18 = load i32, i32* %6
%19 = icmp slt i32 %18, 2
%20 = zext i1 %19 to i64
%21 = select i1 %19, i32 17171289, i32 34341721
store i32 %21, i32* %17
%22 = load i32, i32* %5
%23 = and i32 %22, 3
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [4 x i32], [4 x i32]* @pvr_init_video.bppshifttab, i64 0, i64 %25
%27 = load i32, i32* %26
store i32 %27, i32* %8
%28 = load i32*, i32** %7
%29 = getelementptr inbounds i32, i32* %28, i64 2
store volatile i32 0, i32* %29
%30 = load i32*, i32** %7
%31 = getelementptr inbounds i32, i32* %30, i64 16
store volatile i32 0, i32* %31
%32 = load i32, i32* %5
%33 = shl i32 %32, 2
%34 = or i32 %33, 1
store i32 %34, i32* %5
store i32 240, i32* %9
%35 = load i32, i32* %4
%36 = and i32 %35, 2
%37 = icmp ne i32 %36, 0
br i1 %37, label %49, label %38
38: ; preds = %3
%39 = load i32, i32* %6
%40 = icmp slt i32 %39, 2
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* %5
%43 = or i32 %42, 2
store i32 %43, i32* %5
br label %44
44: ; preds = %41, %38
store i32 34341721, i32* %17
%45 = load i32, i32* %9
%46 = shl i32 %45, 1
store i32 %46, i32* %9
%47 = load i32, i32* %5
%48 = or i32 %47, 8388608
store i32 %48, i32* %5
br label %49
49: ; preds = %44, %3
%50 = load i32, i32* %5
%51 = load i32*, i32** %7
%52 = getelementptr inbounds i32, i32* %51, i64 17
store volatile i32 %50, i32* %52
%53 = load i32*, i32** %7
%54 = getelementptr inbounds i32, i32* %53, i64 20
store volatile i32 0, i32* %54
%55 = load i32, i32* %8
%56 = shl i32 640, %55
%57 = load i32*, i32** %7
%58 = getelementptr inbounds i32, i32* %57, i64 21
store volatile i32 %56, i32* %58
store i32 256, i32* %15
%59 = load i32, i32* %6
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %49
%62 = load i32, i32* %8
%63 = shl i32 80, %62
store i32 %63, i32* %11
br label %67
64: ; preds = %49
%65 = load i32, i32* %8
%66 = shl i32 160, %65
store i32 %66, i32* %11
br label %67
67: ; preds = %64, %61
store i32 1, i32* %10
%68 = load i32, i32* %4
%69 = and i32 %68, 2
%70 = icmp ne i32 %69, 0
br i1 %70, label %79, label %71
71: ; preds = %67
%72 = load i32, i32* %6
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %71
%75 = load i32, i32* %11
%76 = load i32, i32* %10
%77 = add nsw i32 %76, %75
store i32 %77, i32* %10
br label %78
78: ; preds = %74, %71
br label %95
79: ; preds = %67
%80 = load i32, i32* %6
%81 = icmp ne i32 %80, 1
br i1 %81, label %82, label %86
82: ; preds = %79
%83 = load i32, i32* %11
%84 = load i32, i32* %10
%85 = add nsw i32 %84, %83
store i32 %85, i32* %10
br label %86
86: ; preds = %82, %79
%87 = load i32, i32* %6
%88 = icmp eq i32 %87, 2
br i1 %88, label %89, label %92
89: ; preds = %86
%90 = load i32, i32* %15
%91 = or i32 %90, 16
store i32 %91, i32* %15
br label %92
92: ; preds = %89, %86
%93 = load i32, i32* %15
%94 = or i32 %93, 64
store i32 %94, i32* %15
br label %95
95: ; preds = %92, %78
%96 = load i32, i32* %10
%97 = shl i32 %96, 10
%98 = load i32, i32* %9
%99 = add nsw i32 %97, %98
%100 = sub nsw i32 %99, 1
%101 = shl i32 %100, 10
%102 = load i32, i32* %11
%103 = add nsw i32 %101, %102
%104 = sub nsw i32 %103, 1
%105 = load i32*, i32** %7
%106 = getelementptr inbounds i32, i32* %105, i64 23
store volatile i32 %104, i32* %106
%107 = load i32, i32* %15
%108 = load i32*, i32** %7
%109 = getelementptr inbounds i32, i32* %108, i64 52
store volatile i32 %107, i32* %109
%110 = load i32, i32* %4
%111 = and i32 %110, 2
%112 = icmp ne i32 %111, 0
br i1 %112, label %116, label %113
113: ; preds = %95
%114 = load i32, i32* %14
%115 = add nsw i32 %114, 36
store i32 %115, i32* %14
br label %119
116: ; preds = %95
%117 = load i32, i32* %14
%118 = add nsw i32 %117, 18
store i32 %118, i32* %14
br label %119
119: ; preds = %116, %113
%120 = load i32, i32* %14
%121 = shl i32 %120, 16
%122 = load i32, i32* %14
%123 = load i32, i32* %13
%124 = add nsw i32 %122, %123
%125 = or i32 %121, %124
store i32 %125, i32* %12
%126 = load i32, i32* %12
%127 = load i32*, i32** %7
%128 = getelementptr inbounds i32, i32* %127, i64 60
store volatile i32 %126, i32* %128
%129 = load i32, i32* %12
%130 = load i32, i32* %9
%131 = add nsw i32 %129, %130
%132 = load i32*, i32** %7
%133 = getelementptr inbounds i32, i32* %132, i64 55
store volatile i32 %131, i32* %133
%134 = load i32*, i32** %7
%135 = getelementptr inbounds i32, i32* %134, i64 59
store volatile i32 164, i32* %135
%136 = load i32, i32* %17
%137 = load i32*, i32** %7
%138 = getelementptr inbounds i32, i32* %137, i64 54
store volatile i32 %136, i32* %138
%139 = load i32*, i32** %7
%140 = getelementptr inbounds i32, i32* %139, i64 53
store volatile i32 8258373, i32* %140
%141 = load i32, i32* %6
%142 = icmp eq i32 %141, 0
br i1 %142, label %143, label %144
143: ; preds = %119
store i32 1442048, i32* %16
br label %145
144: ; preds = %119
store i32 1441792, i32* %16
br label %145
145: ; preds = %144, %143
%146 = load i32, i32* %16
%147 = load i32*, i32** %7
%148 = getelementptr inbounds i32, i32* %147, i64 58
store volatile i32 %146, i32* %148
store i32 260, i32* %12
%149 = load i32, i32* %4
%150 = and i32 %149, 2
%151 = icmp ne i32 %150, 0
br i1 %151, label %153, label %152
152: ; preds = %145
store i32 510, i32* %12
br label %153
153: ; preds = %152, %145
%154 = load i32, i32* %12
%155 = or i32 2162688, %154
%156 = load i32*, i32** %7
%157 = getelementptr inbounds i32, i32* %156, i64 51
store volatile i32 %155, i32* %157
%158 = load i32, i32* %4
%159 = and i32 %158, 1
%160 = icmp ne i32 %159, 0
br i1 %160, label %161, label %162
161: ; preds = %153
store i32 3, i32* %5
br label %163
162: ; preds = %153
store i32 0, i32* %5
br label %163
163: ; preds = %162, %161
%164 = load i32, i32* %5
%165 = shl i32 %164, 8
store volatile i32 %165, i32* inttoptr (i64 2691705856 to i32*)
ret void
}

LLVM IR (-O2):
@pvr_init_video.bppshifttab = internal unnamed_addr constant [4 x i32] [i32 1, i32 1, i32 0, i32 2]
define void @pvr_init_video(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %2, 2
%5 = and i32 %1, 3
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds [4 x i32], [4 x i32]* @pvr_init_video.bppshifttab, i64 0, i64 %6
%8 = load i32, i32* %7
store volatile i32 0, i32* inttoptr (i64 2690613256 to i32*)
store volatile i32 0, i32* inttoptr (i64 2690613312 to i32*)
%9 = shl nuw nsw i32 %5, 2
%10 = or i32 %9, 1
%11 = and i32 %0, 2
%12 = icmp eq i32 %11, 0
%13 = or i32 %9, 3
%14 = select i1 %4, i32 %13, i32 %10
%15 = or i32 %14, 8388608
%16 = select i1 %12, i32 480, i32 240
%17 = select i1 %12, i32 %15, i32 %10
store volatile i32 %17, i32* inttoptr (i64 2690613316 to i32*)
store volatile i32 0, i32* inttoptr (i64 2690613328 to i32*)
%18 = shl i32 640, %8
store volatile i32 %18, i32* inttoptr (i64 2690613332 to i32*)
%19 = icmp eq i32 %2, 0
%20 = select i1 %19, i32 80, i32 160
%21 = shl i32 %20, %8
br i1 %12, label %22, label %25
22: ; preds = %3
%23 = add nsw i32 %21, 1
%24 = select i1 %19, i32 %23, i32 1
br label %32
25: ; preds = %3
%26 = select i1 %4, i32 17171289, i32 34341721
%27 = icmp eq i32 %2, 1
%28 = add nsw i32 %21, 1
%29 = select i1 %27, i32 1, i32 %28
%30 = icmp eq i32 %2, 2
%31 = select i1 %30, i32 336, i32 320
br label %32
32: ; preds = %22, %25
%33 = phi i32 [ 2163198, %22 ], [ 2162948, %25 ]
%34 = phi i32 [ 2359332, %22 ], [ 1179666, %25 ]
%35 = phi i32 [ 34341721, %22 ], [ %26, %25 ]
%36 = phi i32 [ %24, %22 ], [ %29, %25 ]
%37 = phi i32 [ 256, %22 ], [ %31, %25 ]
%38 = shl i32 %36, 20
%39 = shl nuw nsw i32 %16, 10
%40 = add nsw i32 %39, -1025
%41 = add i32 %40, %21
%42 = add i32 %41, %38
store volatile i32 %42, i32* inttoptr (i64 2690613340 to i32*)
store volatile i32 %37, i32* inttoptr (i64 2690613456 to i32*)
store volatile i32 %34, i32* inttoptr (i64 2690613488 to i32*)
%43 = add nuw nsw i32 %34, %16
store volatile i32 %43, i32* inttoptr (i64 2690613468 to i32*)
store volatile i32 164, i32* inttoptr (i64 2690613484 to i32*)
store volatile i32 %35, i32* inttoptr (i64 2690613464 to i32*)
store volatile i32 8258373, i32* inttoptr (i64 2690613460 to i32*)
%44 = select i1 %19, i32 1442048, i32 1441792
store volatile i32 %44, i32* inttoptr (i64 2690613480 to i32*)
store volatile i32 %33, i32* inttoptr (i64 2690613452 to i32*)
%45 = and i32 %0, 1
%46 = icmp eq i32 %45, 0
%47 = select i1 %46, i32 0, i32 768
store volatile i32 %47, i32* inttoptr (i64 2691705856 to i32*)
ret void
}