#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 */
unsigned char inbyte(short);
int /*<<< orphan*/ outb(int, scalar_t__);
unsigned char read_nibble(short port, unsigned char offset) {
  unsigned char retval;
  outb(0xE0 + offset, port + 0);
  outb(0xC0 + offset, port + 0);
  inbyte(port + 1);
  retval = inbyte(port + 1);
  outb(0xE0 + offset, port + 0);
  return retval;
}


x86 assembly (clang, -O0):
<read_nibble>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %al,-0x3(%rbp)
movzbl -0x3(%rbp),%edi
add    $0xe0,%edi
movswl -0x2(%rbp),%eax
add    $0x0,%eax
movslq %eax,%rsi
call   1030 <outb@plt>
movzbl -0x3(%rbp),%edi
add    $0xc0,%edi
movswl -0x2(%rbp),%eax
add    $0x0,%eax
movslq %eax,%rsi
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>
mov    %al,-0x4(%rbp)
movzbl -0x3(%rbp),%edi
add    $0xe0,%edi
movswl -0x2(%rbp),%eax
add    $0x0,%eax
movslq %eax,%rsi
call   1030 <outb@plt>
movzbl -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_nibble>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
lea    0xe0(%rbx),%r14d
movslq %edi,%rbp
mov    %r14d,%edi
mov    %rbp,%rsi
call   1030 <outb@plt>
add    $0xc0,%ebx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1030 <outb@plt>
lea    0x1(%rbp),%eax
movswl %ax,%ebx
mov    %ebx,%edi
call   1040 <inbyte@plt>
mov    %ebx,%edi
call   1040 <inbyte@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %rbp,%rsi
call   1030 <outb@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define zeroext i8 @read_nibble(i16 signext %0, i8 zeroext %1) {
%3 = zext i8 %1 to i32
%4 = add nuw nsw i32 %3, 224
%5 = sext i16 %0 to i64
%6 = tail call i32 @outb(i32 %4, i64 %5)
%7 = add nuw nsw i32 %3, 192
%8 = tail call i32 @outb(i32 %7, i64 %5)
%9 = add i16 %0, 1
%10 = tail call zeroext i8 @inbyte(i16 signext %9)
%11 = tail call zeroext i8 @inbyte(i16 signext %9)
%12 = tail call i32 @outb(i32 %4, i64 %5)
ret i8 %11
}