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

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int vdp_control_port_read();
int vdp_data_port_read();
int vdp_h_counter_read();
int vdp_v_counter_read();
uint8_t io_port_read(uint8_t port) {
  switch (port) {
  case 0xBE:
    return vdp_data_port_read();
    break;
  case 0xBF:
    return vdp_control_port_read();
    break;
  case 0x7E:
    return vdp_v_counter_read();
    break;
  case 0x7F:
    return vdp_h_counter_read();
    break;
  default:
    fprintf(stderr, "Attempted to read from unknown port 0x%hhX\n", port);
    abort();
  }
  return 0xFF;
}


x86 assembly (clang, -O0):
<io_port_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0x7e,%eax
je     11d4 <io_port_read+0x74>
jmp    117f <io_port_read+0x1f>
mov    -0xc(%rbp),%eax
sub    $0x7f,%eax
je     11e3 <io_port_read+0x83>
jmp    1190 <io_port_read+0x30>
mov    -0xc(%rbp),%eax
sub    $0xbe,%eax
je     11b6 <io_port_read+0x56>
jmp    11a3 <io_port_read+0x43>
mov    -0xc(%rbp),%eax
sub    $0xbf,%eax
je     11c5 <io_port_read+0x65>
jmp    11f2 <io_port_read+0x92>
mov    $0x0,%al
call   1080 <vdp_data_port_read@plt>
mov    %eax,-0x4(%rbp)
jmp    1211 <io_port_read+0xb1>
mov    $0x0,%al
call   1060 <vdp_control_port_read@plt>
mov    %eax,-0x4(%rbp)
jmp    1211 <io_port_read+0xb1>
mov    $0x0,%al
call   1070 <vdp_v_counter_read@plt>
mov    %eax,-0x4(%rbp)
jmp    1211 <io_port_read+0xb1>
mov    $0x0,%al
call   1050 <vdp_h_counter_read@plt>
mov    %eax,-0x4(%rbp)
jmp    1211 <io_port_read+0xb1>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xdfb(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<io_port_read>:
mov    %edi,%edx
cmp    $0xbd,%edi
jg     117b <io_port_read+0x1b>
cmp    $0x7e,%edx
je     1192 <io_port_read+0x32>
cmp    $0x7f,%edx
jne    11a0 <io_port_read+0x40>
xor    %eax,%eax
jmp    1050 <vdp_h_counter_read@plt>
cmp    $0xbf,%edx
je     1199 <io_port_read+0x39>
cmp    $0xbe,%edx
jne    11a0 <io_port_read+0x40>
xor    %eax,%eax
jmp    1080 <vdp_data_port_read@plt>
xor    %eax,%eax
jmp    1070 <vdp_v_counter_read@plt>
xor    %eax,%eax
jmp    1060 <vdp_control_port_read@plt>
push   %rax
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"Attempted to read from unknown port 0x%hhX\0A\00"
define i32 @io_port_read(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %13 [
i32 190, label %5
i32 191, label %7
i32 126, label %9
i32 127, label %11
]
5: ; preds = %1
%6 = call i32 (...) @vdp_data_port_read()
store i32 %6, i32* %2
br label %18
7: ; preds = %1
%8 = call i32 (...) @vdp_control_port_read()
store i32 %8, i32* %2
br label %18
9: ; preds = %1
%10 = call i32 (...) @vdp_v_counter_read()
store i32 %10, i32* %2
br label %18
11: ; preds = %1
%12 = call i32 (...) @vdp_h_counter_read()
store i32 %12, i32* %2
br label %18
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i32, i32* %3
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %11, %9, %7, %5
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"Attempted to read from unknown port 0x%hhX\0A\00"
define i32 @io_port_read(i32 %0) {
switch i32 %0, label %10 [
i32 190, label %2
i32 191, label %4
i32 126, label %6
i32 127, label %8
]
2: ; preds = %1
%3 = tail call i32 (...) @vdp_data_port_read()
br label %14
4: ; preds = %1
%5 = tail call i32 (...) @vdp_control_port_read()
br label %14
6: ; preds = %1
%7 = tail call i32 (...) @vdp_v_counter_read()
br label %14
8: ; preds = %1
%9 = tail call i32 (...) @vdp_h_counter_read()
br label %14
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %0)
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %8, %6, %4, %2
%15 = phi i32 [ %9, %8 ], [ %7, %6 ], [ %5, %4 ], [ %3, %2 ]
ret i32 %15
}