#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_mode2(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);
  return low_nib | ((inbyte(ioaddr + 1) << 1) & 0xf0);
}


x86 assembly (clang, -O0):
<read_byte_mode2>:
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>
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_mode2>:
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>
and    $0x78,%eax
lea    0x0(%rbp,%rax,2),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @read_byte_mode2(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 i8, i8* %3
%33 = zext i8 %32 to i32
%34 = load i16, i16* %2
%35 = sext i16 %34 to i32
%36 = add nsw i32 %35, 1
%37 = trunc i32 %36 to i16
%38 = call i32 @inbyte(i16 signext %37)
%39 = shl i32 %38, 1
%40 = and i32 %39, 240
%41 = or i32 %33, %40
%42 = trunc i32 %41 to i8
ret i8 %42
}

LLVM IR (-O2):
define zeroext i8 @read_byte_mode2(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 = shl i32 %11, 1
%13 = and i32 %12, 240
%14 = or i32 %13, %8
%15 = trunc i32 %14 to i8
ret i8 %15
}