#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 /*<<< orphan*/ asix88796_eeprom_command(int);
unsigned short asix88796_eeprom_get(int);
int /*<<< orphan*/ asix88796_eeprom_setaddr(int, int /*<<< orphan*/);
int /*<<< orphan*/ delay();
int inb(int);
int /*<<< orphan*/ outb(int, int);
void asix88796_eeprom_read(int ioaddr, unsigned char *buff) {
  int i;
  int addr = 0;
  unsigned short value;
  for (i = 0; i < 3; i++) {
    outb(inb(ioaddr + 0x14) | 0x10, ioaddr + 0x14);
    outb(inb(ioaddr + 0x14) & 0xdf, ioaddr + 0x14);
    delay();
    asix88796_eeprom_command(ioaddr);
    asix88796_eeprom_setaddr(ioaddr, addr++);
    value = asix88796_eeprom_get(ioaddr);
    *buff++ = (unsigned char)(value & 0xff);
    *buff++ = (unsigned char)((value >> 8) & 0xff);
    outb(inb(ioaddr + 0x14) & 0x7f, ioaddr + 0x14);
    outb(inb(ioaddr + 0x14) & 0xdf, ioaddr + 0x14);
    outb(inb(ioaddr + 0x14) & 0xef, ioaddr + 0x14);
  }
}


x86 assembly (clang, -O0):
<asix88796_eeprom_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x14(%rbp)
jge    128e <asix88796_eeprom_read+0x12e>
mov    -0x4(%rbp),%edi
add    $0x14,%edi
call   1080 <inb@plt>
mov    %eax,%edi
or     $0x10,%edi
mov    -0x4(%rbp),%esi
add    $0x14,%esi
call   1050 <outb@plt>
mov    -0x4(%rbp),%edi
add    $0x14,%edi
call   1080 <inb@plt>
mov    %eax,%edi
and    $0xdf,%edi
mov    -0x4(%rbp),%esi
add    $0x14,%esi
call   1050 <outb@plt>
mov    $0x0,%al
call   1070 <delay@plt>
mov    -0x4(%rbp),%edi
call   1030 <asix88796_eeprom_command@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
call   1060 <asix88796_eeprom_setaddr@plt>
mov    -0x4(%rbp),%edi
call   1040 <asix88796_eeprom_get@plt>
mov    %ax,-0x1a(%rbp)
movzwl -0x1a(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
movzwl -0x1a(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%edi
add    $0x14,%edi
call   1080 <inb@plt>
mov    %eax,%edi
and    $0x7f,%edi
mov    -0x4(%rbp),%esi
add    $0x14,%esi
call   1050 <outb@plt>
mov    -0x4(%rbp),%edi
add    $0x14,%edi
call   1080 <inb@plt>
mov    %eax,%edi
and    $0xdf,%edi
mov    -0x4(%rbp),%esi
add    $0x14,%esi
call   1050 <outb@plt>
mov    -0x4(%rbp),%edi
add    $0x14,%edi
call   1080 <inb@plt>
mov    %eax,%edi
and    $0xef,%edi
mov    -0x4(%rbp),%esi
add    $0x14,%esi
call   1050 <outb@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <asix88796_eeprom_read+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asix88796_eeprom_read>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%r15d
lea    0x14(%r15),%ebx
mov    %ebx,%edi
call   1080 <inb@plt>
or     $0x10,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
call   1080 <inb@plt>
and    $0xdf,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
xor    %eax,%eax
call   1070 <delay@plt>
mov    %r15d,%edi
call   1030 <asix88796_eeprom_command@plt>
mov    %r15d,%edi
xor    %esi,%esi
call   1060 <asix88796_eeprom_setaddr@plt>
mov    %r15d,%edi
call   1040 <asix88796_eeprom_get@plt>
mov    %ax,(%r14)
mov    %ebx,%edi
call   1080 <inb@plt>
and    $0x7f,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
call   1080 <inb@plt>
and    $0xdf,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
call   1080 <inb@plt>
and    $0xef,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
call   1080 <inb@plt>
or     $0x10,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
call   1080 <inb@plt>
and    $0xdf,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
xor    %eax,%eax
call   1070 <delay@plt>
mov    %r15d,%edi
call   1030 <asix88796_eeprom_command@plt>
mov    %r15d,%edi
mov    $0x1,%esi
call   1060 <asix88796_eeprom_setaddr@plt>
mov    %r15d,%edi
call   1040 <asix88796_eeprom_get@plt>
mov    %ax,0x2(%r14)
mov    %ebx,%edi
call   1080 <inb@plt>
and    $0x7f,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
call   1080 <inb@plt>
and    $0xdf,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
call   1080 <inb@plt>
and    $0xef,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
call   1080 <inb@plt>
or     $0x10,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
call   1080 <inb@plt>
and    $0xdf,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
xor    %eax,%eax
call   1070 <delay@plt>
mov    %r15d,%edi
call   1030 <asix88796_eeprom_command@plt>
mov    %r15d,%edi
mov    $0x2,%esi
call   1060 <asix88796_eeprom_setaddr@plt>
mov    %r15d,%edi
call   1040 <asix88796_eeprom_get@plt>
mov    %ax,0x4(%r14)
mov    %ebx,%edi
call   1080 <inb@plt>
and    $0x7f,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
call   1080 <inb@plt>
and    $0xdf,%eax
mov    %eax,%edi
mov    %ebx,%esi
call   1050 <outb@plt>
mov    %ebx,%edi
call   1080 <inb@plt>
and    $0xef,%eax
mov    %eax,%edi
mov    %ebx,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <outb@plt>

LLVM IR (-O0):
define void @asix88796_eeprom_read(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i16
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %8
8: ; preds = %69, %2
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %72
11: ; preds = %8
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 20
%14 = call i32 @inb(i32 %13)
%15 = or i32 %14, 16
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 20
%18 = call i32 @outb(i32 %15, i32 %17)
%19 = load i32, i32* %3
%20 = add nsw i32 %19, 20
%21 = call i32 @inb(i32 %20)
%22 = and i32 %21, 223
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 20
%25 = call i32 @outb(i32 %22, i32 %24)
%26 = call i32 (...) @delay()
%27 = load i32, i32* %3
%28 = call i32 @asix88796_eeprom_command(i32 %27)
%29 = load i32, i32* %3
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
%32 = call i32 @asix88796_eeprom_setaddr(i32 %29, i32 %30)
%33 = load i32, i32* %3
%34 = call zeroext i16 @asix88796_eeprom_get(i32 %33)
store i16 %34, i16* %7
%35 = load i16, i16* %7
%36 = zext i16 %35 to i32
%37 = and i32 %36, 255
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %4
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %4
store i8 %38, i8* %39
%41 = load i16, i16* %7
%42 = zext i16 %41 to i32
%43 = ashr i32 %42, 8
%44 = and i32 %43, 255
%45 = trunc i32 %44 to i8
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %4
store i8 %45, i8* %46
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 20
%50 = call i32 @inb(i32 %49)
%51 = and i32 %50, 127
%52 = load i32, i32* %3
%53 = add nsw i32 %52, 20
%54 = call i32 @outb(i32 %51, i32 %53)
%55 = load i32, i32* %3
%56 = add nsw i32 %55, 20
%57 = call i32 @inb(i32 %56)
%58 = and i32 %57, 223
%59 = load i32, i32* %3
%60 = add nsw i32 %59, 20
%61 = call i32 @outb(i32 %58, i32 %60)
%62 = load i32, i32* %3
%63 = add nsw i32 %62, 20
%64 = call i32 @inb(i32 %63)
%65 = and i32 %64, 239
%66 = load i32, i32* %3
%67 = add nsw i32 %66, 20
%68 = call i32 @outb(i32 %65, i32 %67)
br label %69
69: ; preds = %11
%70 = load i32, i32* %5
%71 = add nsw i32 %70, 1
store i32 %71, i32* %5
br label %8
72: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @asix88796_eeprom_read(i32 %0, i8* nocapture writeonly %1) {
%3 = add nsw i32 %0, 20
%4 = tail call i32 @inb(i32 %3)
%5 = or i32 %4, 16
%6 = tail call i32 @outb(i32 %5, i32 %3)
%7 = tail call i32 @inb(i32 %3)
%8 = and i32 %7, 223
%9 = tail call i32 @outb(i32 %8, i32 %3)
%10 = tail call i32 (...) @delay()
%11 = tail call i32 @asix88796_eeprom_command(i32 %0)
%12 = tail call i32 @asix88796_eeprom_setaddr(i32 %0, i32 0)
%13 = tail call zeroext i16 @asix88796_eeprom_get(i32 %0)
%14 = trunc i16 %13 to i8
%15 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %14, i8* %1
%16 = lshr i16 %13, 8
%17 = trunc i16 %16 to i8
%18 = getelementptr inbounds i8, i8* %1, i64 2
store i8 %17, i8* %15
%19 = tail call i32 @inb(i32 %3)
%20 = and i32 %19, 127
%21 = tail call i32 @outb(i32 %20, i32 %3)
%22 = tail call i32 @inb(i32 %3)
%23 = and i32 %22, 223
%24 = tail call i32 @outb(i32 %23, i32 %3)
%25 = tail call i32 @inb(i32 %3)
%26 = and i32 %25, 239
%27 = tail call i32 @outb(i32 %26, i32 %3)
%28 = tail call i32 @inb(i32 %3)
%29 = or i32 %28, 16
%30 = tail call i32 @outb(i32 %29, i32 %3)
%31 = tail call i32 @inb(i32 %3)
%32 = and i32 %31, 223
%33 = tail call i32 @outb(i32 %32, i32 %3)
%34 = tail call i32 (...) @delay()
%35 = tail call i32 @asix88796_eeprom_command(i32 %0)
%36 = tail call i32 @asix88796_eeprom_setaddr(i32 %0, i32 1)
%37 = tail call zeroext i16 @asix88796_eeprom_get(i32 %0)
%38 = trunc i16 %37 to i8
%39 = getelementptr inbounds i8, i8* %1, i64 3
store i8 %38, i8* %18
%40 = lshr i16 %37, 8
%41 = trunc i16 %40 to i8
%42 = getelementptr inbounds i8, i8* %1, i64 4
store i8 %41, i8* %39
%43 = tail call i32 @inb(i32 %3)
%44 = and i32 %43, 127
%45 = tail call i32 @outb(i32 %44, i32 %3)
%46 = tail call i32 @inb(i32 %3)
%47 = and i32 %46, 223
%48 = tail call i32 @outb(i32 %47, i32 %3)
%49 = tail call i32 @inb(i32 %3)
%50 = and i32 %49, 239
%51 = tail call i32 @outb(i32 %50, i32 %3)
%52 = tail call i32 @inb(i32 %3)
%53 = or i32 %52, 16
%54 = tail call i32 @outb(i32 %53, i32 %3)
%55 = tail call i32 @inb(i32 %3)
%56 = and i32 %55, 223
%57 = tail call i32 @outb(i32 %56, i32 %3)
%58 = tail call i32 (...) @delay()
%59 = tail call i32 @asix88796_eeprom_command(i32 %0)
%60 = tail call i32 @asix88796_eeprom_setaddr(i32 %0, i32 2)
%61 = tail call zeroext i16 @asix88796_eeprom_get(i32 %0)
%62 = trunc i16 %61 to i8
%63 = getelementptr inbounds i8, i8* %1, i64 5
store i8 %62, i8* %42
%64 = lshr i16 %61, 8
%65 = trunc i16 %64 to i8
store i8 %65, i8* %63
%66 = tail call i32 @inb(i32 %3)
%67 = and i32 %66, 127
%68 = tail call i32 @outb(i32 %67, i32 %3)
%69 = tail call i32 @inb(i32 %3)
%70 = and i32 %69, 223
%71 = tail call i32 @outb(i32 %70, i32 %3)
%72 = tail call i32 @inb(i32 %3)
%73 = and i32 %72, 239
%74 = tail call i32 @outb(i32 %73, i32 %3)
ret void
}