#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*/ eeprom_delay(int);
int eeprom_get_word(unsigned long, int /*<<< orphan*/);
int eeprom_send_addr(unsigned long, int);
int eeprom_send_start(unsigned long, int);
int eeprom_read(unsigned long pci_base, int eeprom_addr, unsigned short *p_data,
                int nwords) {
  int status;
  int i;
  if ((eeprom_addr + nwords) > 64)
    return (3);
  for (i = 0; i < nwords; i++, eeprom_addr++) {
    (*(unsigned char *)(pci_base + 0x0e) |= (1 << 1));
    eeprom_delay(50);
    if (((status = eeprom_send_start(pci_base, 2)) != 0) ||
        ((status = eeprom_send_addr(pci_base, eeprom_addr)) != 0))
      return (status);
    if ((status = eeprom_get_word(pci_base, p_data++)) != 0)
      return (status);
    (*(unsigned char *)(pci_base + 0x0e) &= ~(1 << 1));
    eeprom_delay(100);
  }
  return (0);
}


x86 assembly (clang, -O0):
<eeprom_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x14(%rbp),%eax
add    -0x24(%rbp),%eax
cmp    $0x40,%eax
jle    1171 <eeprom_read+0x31>
movl   $0x3,-0x4(%rbp)
jmp    1240 <eeprom_read+0x100>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1239 <eeprom_read+0xf9>
mov    -0x10(%rbp),%rax
movzbl 0xe(%rax),%ecx
or     $0x2,%ecx
mov    %cl,0xe(%rax)
mov    $0x32,%edi
call   1060 <eeprom_delay@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1050 <eeprom_send_start@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jne    11ce <eeprom_read+0x8e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <eeprom_send_addr@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     11d9 <eeprom_read+0x99>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <eeprom_read+0x100>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x2,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%esi
call   1030 <eeprom_get_word@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     120a <eeprom_read+0xca>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1240 <eeprom_read+0x100>
mov    -0x10(%rbp),%rax
movzbl 0xe(%rax),%ecx
and    $0xfffffffd,%ecx
mov    %cl,0xe(%rax)
mov    $0x64,%edi
call   1060 <eeprom_delay@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1178 <eeprom_read+0x38>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eeprom_read>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %esi,%ebx
lea    (%r15,%rbx,1),%eax
mov    $0x3,%r14d
cmp    $0x40,%eax
jg     11ce <eeprom_read+0x8e>
xor    %r14d,%r14d
test   %r15d,%r15d
jle    11ce <eeprom_read+0x8e>
mov    %rdx,%rbp
mov    %rdi,%r12
nopw   0x0(%rax,%rax,1)
orb    $0x2,0xe(%r12)
mov    $0x32,%edi
call   1060 <eeprom_delay@plt>
mov    %r12,%rdi
mov    $0x2,%esi
call   1050 <eeprom_send_start@plt>
test   %eax,%eax
jne    11cb <eeprom_read+0x8b>
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <eeprom_send_addr@plt>
test   %eax,%eax
jne    11cb <eeprom_read+0x8b>
mov    %r12,%rdi
mov    %ebp,%esi
call   1030 <eeprom_get_word@plt>
test   %eax,%eax
jne    11cb <eeprom_read+0x8b>
andb   $0xfd,0xe(%r12)
mov    $0x64,%edi
call   1060 <eeprom_delay@plt>
add    $0x1,%ebx
add    $0x2,%ebp
add    $0xffffffff,%r15d
jne    1170 <eeprom_read+0x30>
jmp    11ce <eeprom_read+0x8e>
mov    %eax,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @eeprom_read(i64 %0, i32 %1, i16* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i16*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i64 %0, i64* %6
store i32 %1, i32* %7
store i16* %2, i16** %8
store i32 %3, i32* %9
%12 = load i32, i32* %7
%13 = load i32, i32* %9
%14 = add nsw i32 %12, %13
%15 = icmp sgt i32 %14, 64
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 3, i32* %5
br label %65
17: ; preds = %4
store i32 0, i32* %11
br label %18
18: ; preds = %59, %17
%19 = load i32, i32* %11
%20 = load i32, i32* %9
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %64
22: ; preds = %18
%23 = load i64, i64* %6
%24 = add i64 %23, 14
%25 = inttoptr i64 %24 to i8*
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = or i32 %27, 2
%29 = trunc i32 %28 to i8
store i8 %29, i8* %25
%30 = call i32 @eeprom_delay(i32 50)
%31 = load i64, i64* %6
%32 = call i32 @eeprom_send_start(i64 %31, i32 2)
store i32 %32, i32* %10
%33 = icmp ne i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %22
%35 = load i64, i64* %6
%36 = load i32, i32* %7
%37 = call i32 @eeprom_send_addr(i64 %35, i32 %36)
store i32 %37, i32* %10
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34, %22
%40 = load i32, i32* %10
store i32 %40, i32* %5
br label %65
41: ; preds = %34
%42 = load i64, i64* %6
%43 = load i16*, i16** %8
%44 = getelementptr inbounds i16, i16* %43, i32 1
store i16* %44, i16** %8
%45 = ptrtoint i16* %43 to i32
%46 = call i32 @eeprom_get_word(i64 %42, i32 %45)
store i32 %46, i32* %10
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %41
%49 = load i32, i32* %10
store i32 %49, i32* %5
br label %65
50: ; preds = %41
%51 = load i64, i64* %6
%52 = add i64 %51, 14
%53 = inttoptr i64 %52 to i8*
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
%56 = and i32 %55, -3
%57 = trunc i32 %56 to i8
store i8 %57, i8* %53
%58 = call i32 @eeprom_delay(i32 100)
br label %59
59: ; preds = %50
%60 = load i32, i32* %11
%61 = add nsw i32 %60, 1
store i32 %61, i32* %11
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
br label %18
64: ; preds = %18
store i32 0, i32* %5
br label %65
65: ; preds = %64, %48, %39, %16
%66 = load i32, i32* %5
ret i32 %66
}

LLVM IR (-O2):
define i32 @eeprom_read(i64 %0, i32 %1, i16* %2, i32 %3) {
%5 = add nsw i32 %3, %1
%6 = icmp sgt i32 %5, 64
br i1 %6, label %36, label %7
7: ; preds = %4
%8 = add i64 %0, 14
%9 = inttoptr i64 %8 to i8*
%10 = icmp sgt i32 %3, 0
br i1 %10, label %11, label %36
11: ; preds = %7, %28
%12 = phi i32 [ %33, %28 ], [ 0, %7 ]
%13 = phi i16* [ %29, %28 ], [ %2, %7 ]
%14 = phi i32 [ %34, %28 ], [ %1, %7 ]
%15 = load i8, i8* %9
%16 = or i8 %15, 2
store i8 %16, i8* %9
%17 = tail call i32 @eeprom_delay(i32 50)
%18 = tail call i32 @eeprom_send_start(i64 %0, i32 2)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %36
20: ; preds = %11
%21 = tail call i32 @eeprom_send_addr(i64 %0, i32 %14)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %36
23: ; preds = %20
%24 = ptrtoint i16* %13 to i64
%25 = trunc i64 %24 to i32
%26 = tail call i32 @eeprom_get_word(i64 %0, i32 %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %23
%29 = getelementptr inbounds i16, i16* %13, i64 1
%30 = load i8, i8* %9
%31 = and i8 %30, -3
store i8 %31, i8* %9
%32 = tail call i32 @eeprom_delay(i32 100)
%33 = add nuw nsw i32 %12, 1
%34 = add nsw i32 %14, 1
%35 = icmp eq i32 %33, %3
br i1 %35, label %36, label %11
36: ; preds = %20, %11, %23, %28, %7, %4
%37 = phi i32 [ 3, %4 ], [ 0, %7 ], [ %21, %20 ], [ %18, %11 ], [ %26, %23 ], [ 0, %28 ]
ret i32 %37
}