#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 inbyte(short);
int /*<<< orphan*/ outb(int, short);
unsigned char read_byte_mode0(short ioaddr) {
  unsigned char low_nib;
  outb(0x08, ioaddr + 2);
  inbyte(ioaddr + 1);
  low_nib = (inbyte(ioaddr + 1) >> 3) & 0x0f;
  outb(0, ioaddr + 2);
  inbyte(ioaddr + 1);
  inbyte(ioaddr + 1);
  return low_nib | ((inbyte(ioaddr + 1) << 1) & 0xf0);
}


x86 assembly (clang, -O0):
<read_byte_mode0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x2,%eax
mov    $0x8,%edi
movswl %ax,%esi
call   1030 <outb@plt>
movswl -0x2(%rbp),%eax
add    $0x1,%eax
movswl %ax,%edi
call   1040 <inbyte@plt>
movswl -0x2(%rbp),%eax
add    $0x1,%eax
movswl %ax,%edi
call   1040 <inbyte@plt>
sar    $0x3,%eax
and    $0xf,%eax
mov    %al,-0x3(%rbp)
movswl -0x2(%rbp),%eax
add    $0x2,%eax
xor    %edi,%edi
movswl %ax,%esi
call   1030 <outb@plt>
movswl -0x2(%rbp),%eax
add    $0x1,%eax
movswl %ax,%edi
call   1040 <inbyte@plt>
movswl -0x2(%rbp),%eax
add    $0x1,%eax
movswl %ax,%edi
call   1040 <inbyte@plt>
movzbl -0x3(%rbp),%eax
mov    %eax,-0x8(%rbp)
movswl -0x2(%rbp),%eax
add    $0x1,%eax
movswl %ax,%edi
call   1040 <inbyte@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
shl    $0x1,%ecx
and    $0xf0,%ecx
or     %ecx,%eax
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_byte_mode0>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
lea    0x2(%rbx),%eax
movswl %ax,%r14d
mov    $0x8,%edi
mov    %r14d,%esi
call   1030 <outb@plt>
add    $0x1,%ebx
movswl %bx,%ebx
mov    %ebx,%edi
call   1040 <inbyte@plt>
mov    %ebx,%edi
call   1040 <inbyte@plt>
mov    %eax,%ebp
shr    $0x3,%ebp
and    $0xf,%ebp
xor    %edi,%edi
mov    %r14d,%esi
call   1030 <outb@plt>
mov    %ebx,%edi
call   1040 <inbyte@plt>
mov    %ebx,%edi
call   1040 <inbyte@plt>
mov    %ebx,%edi
call   1040 <inbyte@plt>
and    $0x78,%eax
lea    0x0(%rbp,%rax,2),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @read_byte_mode0(i16 signext %0) {
%2 = alloca i16
%3 = alloca i8
store i16 %0, i16* %2
%4 = load i16, i16* %2
%5 = sext i16 %4 to i32
%6 = add nsw i32 %5, 2
%7 = trunc i32 %6 to i16
%8 = call i32 @outb(i32 8, i16 signext %7)
%9 = load i16, i16* %2
%10 = sext i16 %9 to i32
%11 = add nsw i32 %10, 1
%12 = trunc i32 %11 to i16
%13 = call i32 @inbyte(i16 signext %12)
%14 = load i16, i16* %2
%15 = sext i16 %14 to i32
%16 = add nsw i32 %15, 1
%17 = trunc i32 %16 to i16
%18 = call i32 @inbyte(i16 signext %17)
%19 = ashr i32 %18, 3
%20 = and i32 %19, 15
%21 = trunc i32 %20 to i8
store i8 %21, i8* %3
%22 = load i16, i16* %2
%23 = sext i16 %22 to i32
%24 = add nsw i32 %23, 2
%25 = trunc i32 %24 to i16
%26 = call i32 @outb(i32 0, i16 signext %25)
%27 = load i16, i16* %2
%28 = sext i16 %27 to i32
%29 = add nsw i32 %28, 1
%30 = trunc i32 %29 to i16
%31 = call i32 @inbyte(i16 signext %30)
%32 = load i16, i16* %2
%33 = sext i16 %32 to i32
%34 = add nsw i32 %33, 1
%35 = trunc i32 %34 to i16
%36 = call i32 @inbyte(i16 signext %35)
%37 = load i8, i8* %3
%38 = zext i8 %37 to i32
%39 = load i16, i16* %2
%40 = sext i16 %39 to i32
%41 = add nsw i32 %40, 1
%42 = trunc i32 %41 to i16
%43 = call i32 @inbyte(i16 signext %42)
%44 = shl i32 %43, 1
%45 = and i32 %44, 240
%46 = or i32 %38, %45
%47 = trunc i32 %46 to i8
ret i8 %47
}

LLVM IR (-O2):
define zeroext i8 @read_byte_mode0(i16 signext %0) {
%2 = add i16 %0, 2
%3 = tail call i32 @outb(i32 8, i16 signext %2)
%4 = add i16 %0, 1
%5 = tail call i32 @inbyte(i16 signext %4)
%6 = tail call i32 @inbyte(i16 signext %4)
%7 = lshr i32 %6, 3
%8 = and i32 %7, 15
%9 = tail call i32 @outb(i32 0, i16 signext %2)
%10 = tail call i32 @inbyte(i16 signext %4)
%11 = tail call i32 @inbyte(i16 signext %4)
%12 = tail call i32 @inbyte(i16 signext %4)
%13 = shl i32 %12, 1
%14 = and i32 %13, 240
%15 = or i32 %14, %8
%16 = trunc i32 %15 to i8
ret i8 %16
}