#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 inb(int);
int /*<<< orphan*/ outb(int, int);
int /*<<< orphan*/ smbus_print_error(unsigned char);
unsigned char smbus_read_byte(unsigned char devAdr, unsigned char bIndex) {
  unsigned short i;
  unsigned char bData;
  unsigned char sts = 0;
  outb(0xff, 0xf00);
  for (i = 0; i < 0xFFFF; i++)
    if ((inb(0xf00) & 0x01) == 0)
      break;
  outb(bIndex, 0xf00 + 3);
  outb((devAdr << 1) | 0x01, 0xf00 + 4);
  outb(0x48, 0xf00 + 2);
  for (i = 0; i < 0xFFFF; i++)
    if (((sts = (inb(0xf00) & 0x1f)) & 0x01) == 0)
      break;
  if ((sts & ~3) != 0) {
    smbus_print_error(sts);
    return 0;
  }
  bData = inb(0xf00 + 5);
  return bData;
}


x86 assembly (clang, -O0):
<smbus_read_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x2(%rbp)
mov    %al,-0x3(%rbp)
movb   $0x0,-0x8(%rbp)
mov    $0xff,%edi
mov    $0xf00,%esi
call   1030 <outb@plt>
movw   $0x0,-0x6(%rbp)
movzwl -0x6(%rbp),%eax
cmp    $0xffff,%eax
jge    119d <smbus_read_byte+0x6d>
mov    $0xf00,%edi
call   1040 <inb@plt>
and    $0x1,%eax
cmp    $0x0,%eax
jne    1187 <smbus_read_byte+0x57>
jmp    119d <smbus_read_byte+0x6d>
jmp    118c <smbus_read_byte+0x5c>
mov    -0x6(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x6(%rbp)
jmp    115d <smbus_read_byte+0x2d>
movzbl -0x3(%rbp),%edi
mov    $0xf03,%esi
call   1030 <outb@plt>
movzbl -0x2(%rbp),%edi
shl    $0x1,%edi
or     $0x1,%edi
mov    $0xf04,%esi
call   1030 <outb@plt>
mov    $0x48,%edi
mov    $0xf02,%esi
call   1030 <outb@plt>
movw   $0x0,-0x6(%rbp)
movzwl -0x6(%rbp),%eax
cmp    $0xffff,%eax
jge    121d <smbus_read_byte+0xed>
mov    $0xf00,%edi
call   1040 <inb@plt>
and    $0x1f,%eax
mov    %al,-0x8(%rbp)
movzbl %al,%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1207 <smbus_read_byte+0xd7>
jmp    121d <smbus_read_byte+0xed>
jmp    120c <smbus_read_byte+0xdc>
mov    -0x6(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x6(%rbp)
jmp    11d4 <smbus_read_byte+0xa4>
movzbl -0x8(%rbp),%eax
and    $0xfffffffc,%eax
cmp    $0x0,%eax
je     123f <smbus_read_byte+0x10f>
movzbl -0x8(%rbp),%edi
call   1050 <smbus_print_error@plt>
movb   $0x0,-0x1(%rbp)
jmp    1252 <smbus_read_byte+0x122>
mov    $0xf05,%edi
call   1040 <inb@plt>
mov    %al,-0x7(%rbp)
mov    -0x7(%rbp),%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smbus_read_byte>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %edi,%r14d
mov    $0xff,%edi
mov    $0xf00,%esi
call   1030 <outb@plt>
mov    $0xfffe,%bx
nopl   0x0(%rax)
mov    $0xf00,%edi
call   1040 <inb@plt>
sub    $0x1,%bx
setb   %cl
test   $0x1,%al
je     1169 <smbus_read_byte+0x39>
test   %cl,%cl
je     1150 <smbus_read_byte+0x20>
movzbl %bpl,%edi
mov    $0xf03,%esi
call   1030 <outb@plt>
movzbl %r14b,%eax
lea    (%rax,%rax,1),%edi
add    $0x1,%edi
mov    $0xf04,%esi
call   1030 <outb@plt>
mov    $0x48,%edi
mov    $0xf02,%esi
call   1030 <outb@plt>
mov    $0xfffe,%bx
xchg   %ax,%ax
mov    $0xf00,%edi
call   1040 <inb@plt>
sub    $0x1,%bx
setb   %cl
test   $0x1,%al
je     11b9 <smbus_read_byte+0x89>
test   %cl,%cl
je     11a0 <smbus_read_byte+0x70>
and    $0x1f,%al
cmp    $0x4,%al
jae    11cb <smbus_read_byte+0x9b>
mov    $0xf05,%edi
call   1040 <inb@plt>
jmp    11d5 <smbus_read_byte+0xa5>
movzbl %al,%edi
call   1050 <smbus_print_error@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @smbus_read_byte(i8 zeroext %0, i8 zeroext %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = alloca i16
%7 = alloca i8
%8 = alloca i8
store i8 %0, i8* %4
store i8 %1, i8* %5
store i8 0, i8* %8
%9 = call i32 @outb(i32 255, i32 3840)
store i16 0, i16* %6
br label %10
10: ; preds = %20, %2
%11 = load i16, i16* %6
%12 = zext i16 %11 to i32
%13 = icmp slt i32 %12, 65535
br i1 %13, label %14, label %23
14: ; preds = %10
%15 = call i32 @inb(i32 3840)
%16 = and i32 %15, 1
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
br label %23
19: ; preds = %14
br label %20
20: ; preds = %19
%21 = load i16, i16* %6
%22 = add i16 %21, 1
store i16 %22, i16* %6
br label %10
23: ; preds = %18, %10
%24 = load i8, i8* %5
%25 = zext i8 %24 to i32
%26 = call i32 @outb(i32 %25, i32 3843)
%27 = load i8, i8* %4
%28 = zext i8 %27 to i32
%29 = shl i32 %28, 1
%30 = or i32 %29, 1
%31 = call i32 @outb(i32 %30, i32 3844)
%32 = call i32 @outb(i32 72, i32 3842)
store i16 0, i16* %6
br label %33
33: ; preds = %46, %23
%34 = load i16, i16* %6
%35 = zext i16 %34 to i32
%36 = icmp slt i32 %35, 65535
br i1 %36, label %37, label %49
37: ; preds = %33
%38 = call i32 @inb(i32 3840)
%39 = and i32 %38, 31
%40 = trunc i32 %39 to i8
store i8 %40, i8* %8
%41 = zext i8 %40 to i32
%42 = and i32 %41, 1
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %37
br label %49
45: ; preds = %37
br label %46
46: ; preds = %45
%47 = load i16, i16* %6
%48 = add i16 %47, 1
store i16 %48, i16* %6
br label %33
49: ; preds = %44, %33
%50 = load i8, i8* %8
%51 = zext i8 %50 to i32
%52 = and i32 %51, -4
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = load i8, i8* %8
%56 = call i32 @smbus_print_error(i8 zeroext %55)
store i8 0, i8* %3
br label %61
57: ; preds = %49
%58 = call i32 @inb(i32 3845)
%59 = trunc i32 %58 to i8
store i8 %59, i8* %7
%60 = load i8, i8* %7
store i8 %60, i8* %3
br label %61
61: ; preds = %57, %54
%62 = load i8, i8* %3
ret i8 %62
}

LLVM IR (-O2):
define zeroext i8 @smbus_read_byte(i8 zeroext %0, i8 zeroext %1) {
%3 = tail call i32 @outb(i32 255, i32 3840)
br label %4
4: ; preds = %4, %2
%5 = phi i16 [ 0, %2 ], [ %9, %4 ]
%6 = tail call i32 @inb(i32 3840)
%7 = and i32 %6, 1
%8 = icmp eq i32 %7, 0
%9 = add nuw i16 %5, 1
%10 = icmp eq i16 %9, -1
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %12, label %4
12: ; preds = %4
%13 = zext i8 %1 to i32
%14 = tail call i32 @outb(i32 %13, i32 3843)
%15 = zext i8 %0 to i32
%16 = shl nuw nsw i32 %15, 1
%17 = or i32 %16, 1
%18 = tail call i32 @outb(i32 %17, i32 3844)
%19 = tail call i32 @outb(i32 72, i32 3842)
br label %20
20: ; preds = %20, %12
%21 = phi i16 [ 0, %12 ], [ %25, %20 ]
%22 = tail call i32 @inb(i32 3840)
%23 = and i32 %22, 1
%24 = icmp eq i32 %23, 0
%25 = add nuw i16 %21, 1
%26 = icmp eq i16 %25, -1
%27 = select i1 %24, i1 true, i1 %26
br i1 %27, label %28, label %20
28: ; preds = %20
%29 = trunc i32 %22 to i8
%30 = and i8 %29, 31
%31 = icmp ult i8 %30, 4
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = tail call i32 @smbus_print_error(i8 zeroext %30)
br label %37
34: ; preds = %28
%35 = tail call i32 @inb(i32 3845)
%36 = trunc i32 %35 to i8
br label %37
37: ; preds = %34, %32
%38 = phi i8 [ 0, %32 ], [ %36, %34 ]
ret i8 %38
}