#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 */

/* Variables and functions */
int getRAM(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ setRAM(int, int);
void int_video() {
  switch (getRAM(0xFFFA)) {
  default:
    break;
  case 0x01:
    for (int i = 0xB000; i < 0xB7D0; i++)
      setRAM(i, 0x00);
    break;
  case 0x02:
    break;
  case 0x03:
    printf("%c", getRAM(0xFFFB));
    break;
  }
}


x86 assembly (clang, -O0):
<int_video>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xfffa,%edi
call   1050 <getRAM@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
sub    $0x1,%eax
je     117c <int_video+0x4c>
jmp    1155 <int_video+0x25>
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
je     11ad <int_video+0x7d>
jmp    1166 <int_video+0x36>
mov    -0x8(%rbp),%eax
sub    $0x3,%eax
je     11b2 <int_video+0x82>
jmp    1177 <int_video+0x47>
jmp    11ca <int_video+0x9a>
movl   $0xb000,-0x4(%rbp)
cmpl   $0xb7d0,-0x4(%rbp)
jge    11a8 <int_video+0x78>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1030 <setRAM@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1183 <int_video+0x53>
jmp    11ca <int_video+0x9a>
jmp    11ca <int_video+0x9a>
mov    $0xfffb,%edi
call   1050 <getRAM@plt>
mov    %eax,%esi
lea    0xe3b(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_video>:
push   %rbx
mov    $0xfffa,%edi
call   1050 <getRAM@plt>
cmp    $0x3,%eax
je     1166 <int_video+0x36>
cmp    $0x1,%eax
jne    1164 <int_video+0x34>
mov    $0xb000,%ebx
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <setRAM@plt>
add    $0x1,%ebx
cmp    $0xb7d0,%ebx
jne    1150 <int_video+0x20>
pop    %rbx
ret
mov    $0xfffb,%edi
call   1050 <getRAM@plt>
lea    0xe89(%rip),%rdi
mov    %eax,%esi
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @int_video() {
%1 = alloca i32
%2 = call i32 @getRAM(i32 65530)
switch i32 %2, label %3 [
i32 1, label %4
i32 2, label %15
i32 3, label %16
]
3: ; preds = %0
br label %19
4: ; preds = %0
store i32 45056, i32* %1
br label %5
5: ; preds = %11, %4
%6 = load i32, i32* %1
%7 = icmp slt i32 %6, 47056
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = load i32, i32* %1
%10 = call i32 @setRAM(i32 %9, i32 0)
br label %11
11: ; preds = %8
%12 = load i32, i32* %1
%13 = add nsw i32 %12, 1
store i32 %13, i32* %1
br label %5
14: ; preds = %5
br label %19
15: ; preds = %0
br label %19
16: ; preds = %0
%17 = call i32 @getRAM(i32 65531)
%18 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %16, %15, %14, %3
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define void @int_video() {
%1 = tail call i32 @getRAM(i32 65530)
switch i32 %1, label %10 [
i32 1, label %2
i32 3, label %7
]
2: ; preds = %0, %2
%3 = phi i32 [ %5, %2 ], [ 45056, %0 ]
%4 = tail call i32 @setRAM(i32 %3, i32 0)
%5 = add nuw nsw i32 %3, 1
%6 = icmp eq i32 %5, 47056
br i1 %6, label %10, label %2
7: ; preds = %0
%8 = tail call i32 @getRAM(i32 65531)
%9 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %2, %0, %7
ret void
}