#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 wd279x_data_register_read();
int wd279x_sector_register_read();
int wd279x_status_read();
int wd279x_track_register_read();
int io_read(int addr) {
  if ((addr & 7) == 0)
    return wd279x_status_read();
  if ((addr & 7) == 1)
    return wd279x_track_register_read();
  if ((addr & 7) == 2)
    return wd279x_sector_register_read();
  if ((addr & 7) == 3)
    return wd279x_data_register_read();
  return 0x7e;
}


x86 assembly (clang, -O0):
<io_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    1169 <io_read+0x29>
mov    $0x0,%al
call   1030 <wd279x_status_read@plt>
mov    %eax,-0x4(%rbp)
jmp    11ca <io_read+0x8a>
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x1,%eax
jne    1187 <io_read+0x47>
mov    $0x0,%al
call   1050 <wd279x_track_register_read@plt>
mov    %eax,-0x4(%rbp)
jmp    11ca <io_read+0x8a>
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x2,%eax
jne    11a5 <io_read+0x65>
mov    $0x0,%al
call   1060 <wd279x_sector_register_read@plt>
mov    %eax,-0x4(%rbp)
jmp    11ca <io_read+0x8a>
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x3,%eax
jne    11c3 <io_read+0x83>
mov    $0x0,%al
call   1040 <wd279x_data_register_read@plt>
mov    %eax,-0x4(%rbp)
jmp    11ca <io_read+0x8a>
movl   $0x7e,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<io_read>:
and    $0x7,%edi
cmp    $0x3,%edi
ja     115f <io_read+0x1f>
lea    0xeb1(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
xor    %eax,%eax
jmp    1030 <wd279x_status_read@plt>
mov    $0x7e,%eax
ret
xor    %eax,%eax
jmp    1050 <wd279x_track_register_read@plt>
xor    %eax,%eax
jmp    1060 <wd279x_sector_register_read@plt>
xor    %eax,%eax
jmp    1040 <wd279x_data_register_read@plt>

LLVM IR (-O0):
define i32 @io_read(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = and i32 %4, 7
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 (...) @wd279x_status_read()
store i32 %8, i32* %2
br label %28
9: ; preds = %1
%10 = load i32, i32* %3
%11 = and i32 %10, 7
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 (...) @wd279x_track_register_read()
store i32 %14, i32* %2
br label %28
15: ; preds = %9
%16 = load i32, i32* %3
%17 = and i32 %16, 7
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (...) @wd279x_sector_register_read()
store i32 %20, i32* %2
br label %28
21: ; preds = %15
%22 = load i32, i32* %3
%23 = and i32 %22, 7
%24 = icmp eq i32 %23, 3
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 (...) @wd279x_data_register_read()
store i32 %26, i32* %2
br label %28
27: ; preds = %21
store i32 126, i32* %2
br label %28
28: ; preds = %27, %25, %19, %13, %7
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
define i32 @io_read(i32 %0) {
%2 = and i32 %0, 7
switch i32 %2, label %11 [
i32 0, label %3
i32 1, label %5
i32 2, label %7
i32 3, label %9
]
3: ; preds = %1
%4 = tail call i32 (...) @wd279x_status_read()
br label %11
5: ; preds = %1
%6 = tail call i32 (...) @wd279x_track_register_read()
br label %11
7: ; preds = %1
%8 = tail call i32 (...) @wd279x_sector_register_read()
br label %11
9: ; preds = %1
%10 = tail call i32 (...) @wd279x_data_register_read()
br label %11
11: ; preds = %1, %9, %7, %5, %3
%12 = phi i32 [ %4, %3 ], [ %6, %5 ], [ %8, %7 ], [ %10, %9 ], [ 126, %1 ]
ret i32 %12
}