#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 | 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
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    121a <smbus_read_byte+0xea>
mov    $0xf00,%edi
call   1040 <inb@plt>
and    $0x1f,%eax
mov    %al,-0x8(%rbp)
movzbl %al,%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1204 <smbus_read_byte+0xd4>
jmp    121a <smbus_read_byte+0xea>
jmp    1209 <smbus_read_byte+0xd9>
mov    -0x6(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x6(%rbp)
jmp    11d1 <smbus_read_byte+0xa1>
movzbl -0x8(%rbp),%eax
and    $0xfffffffc,%eax
cmp    $0x0,%eax
je     123c <smbus_read_byte+0x10c>
movzbl -0x8(%rbp),%edi
call   1050 <smbus_print_error@plt>
movb   $0x0,-0x1(%rbp)
jmp    124f <smbus_read_byte+0x11f>
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,%r14d
mov    %edi,%ebx
mov    $0xff,%edi
mov    $0xf00,%esi
call   1030 <outb@plt>
mov    $0xfffe,%bp
nopl   0x0(%rax)
mov    $0xf00,%edi
call   1040 <inb@plt>
sub    $0x1,%bp
setb   %cl
test   $0x1,%al
je     1169 <smbus_read_byte+0x39>
test   %cl,%cl
je     1150 <smbus_read_byte+0x20>
movzbl %r14b,%edi
mov    $0xf03,%esi
call   1030 <outb@plt>
or     $0x1,%bl
movzbl %bl,%edi
mov    $0xf04,%esi
call   1030 <outb@plt>
mov    $0x48,%edi
mov    $0xf02,%esi
call   1030 <outb@plt>
mov    $0xfffe,%bx
nopw   0x0(%rax,%rax,1)
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 = or i32 %28, 1
%30 = call i32 @outb(i32 %29, i32 3844)
%31 = call i32 @outb(i32 72, i32 3842)
store i16 0, i16* %6
br label %32
32: ; preds = %45, %23
%33 = load i16, i16* %6
%34 = zext i16 %33 to i32
%35 = icmp slt i32 %34, 65535
br i1 %35, label %36, label %48
36: ; preds = %32
%37 = call i32 @inb(i32 3840)
%38 = and i32 %37, 31
%39 = trunc i32 %38 to i8
store i8 %39, i8* %8
%40 = zext i8 %39 to i32
%41 = and i32 %40, 1
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %36
br label %48
44: ; preds = %36
br label %45
45: ; preds = %44
%46 = load i16, i16* %6
%47 = add i16 %46, 1
store i16 %47, i16* %6
br label %32
48: ; preds = %43, %32
%49 = load i8, i8* %8
%50 = zext i8 %49 to i32
%51 = and i32 %50, -4
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = load i8, i8* %8
%55 = call i32 @smbus_print_error(i8 zeroext %54)
store i8 0, i8* %3
br label %60
56: ; preds = %48
%57 = call i32 @inb(i32 3845)
%58 = trunc i32 %57 to i8
store i8 %58, i8* %7
%59 = load i8, i8* %7
store i8 %59, i8* %3
br label %60
60: ; preds = %56, %53
%61 = load i8, i8* %3
ret i8 %61
}

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 = or i8 %0, 1
%16 = zext i8 %15 to i32
%17 = tail call i32 @outb(i32 %16, i32 3844)
%18 = tail call i32 @outb(i32 72, i32 3842)
br label %19
19: ; preds = %19, %12
%20 = phi i16 [ 0, %12 ], [ %24, %19 ]
%21 = tail call i32 @inb(i32 3840)
%22 = and i32 %21, 1
%23 = icmp eq i32 %22, 0
%24 = add nuw i16 %20, 1
%25 = icmp eq i16 %24, -1
%26 = select i1 %23, i1 true, i1 %25
br i1 %26, label %27, label %19
27: ; preds = %19
%28 = trunc i32 %21 to i8
%29 = and i8 %28, 31
%30 = icmp ult i8 %29, 4
br i1 %30, label %33, label %31
31: ; preds = %27
%32 = tail call i32 @smbus_print_error(i8 zeroext %29)
br label %36
33: ; preds = %27
%34 = tail call i32 @inb(i32 3845)
%35 = trunc i32 %34 to i8
br label %36
36: ; preds = %33, %31
%37 = phi i8 [ 0, %31 ], [ %35, %33 ]
ret i8 %37
}