#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*/ addi_eeprom_clk_93c76(unsigned long, unsigned int);
unsigned int addi_eeprom_cmd_93c76(unsigned long, unsigned int, int);
unsigned int inl(unsigned long);
int /*<<< orphan*/ outl(int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ udelay(int);
unsigned short addi_eeprom_readw_93c76(unsigned long iobase,
                                       unsigned short addr) {
  unsigned short val = 0;
  unsigned int cmd;
  unsigned int tmp;
  int i;
  cmd = (0x0180 << 4) | (addr / 2);
  cmd = addi_eeprom_cmd_93c76(iobase, cmd, 13);
  for (i = 0; i < 16; i++) {
    addi_eeprom_clk_93c76(iobase, cmd);
    tmp = inl(iobase);
    udelay(100);
    val <<= 1;
    if (tmp & (1 << 3))
      val |= 0x1;
  }
  outl(0, iobase);
  udelay(100);
  return val;
}


x86 assembly (clang, -O0):
<addi_eeprom_readw_93c76>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
movw   $0x0,-0xc(%rbp)
movzwl -0xa(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
or     $0x1800,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    $0xd,%edx
call   1040 <addi_eeprom_cmd_93c76@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x10,-0x18(%rbp)
jge    11fc <addi_eeprom_readw_93c76+0xac>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1030 <addi_eeprom_clk_93c76@plt>
mov    -0x8(%rbp),%rdi
call   1060 <inl@plt>
mov    %eax,-0x14(%rbp)
mov    $0x64,%edi
call   1070 <udelay@plt>
movzwl -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %ax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     11e9 <addi_eeprom_readw_93c76+0x99>
movzwl -0xc(%rbp),%eax
or     $0x1,%eax
mov    %ax,-0xc(%rbp)
jmp    11ee <addi_eeprom_readw_93c76+0x9e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1198 <addi_eeprom_readw_93c76+0x48>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1050 <outl@plt>
mov    $0x64,%edi
call   1070 <udelay@plt>
movzwl -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addi_eeprom_readw_93c76>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
shr    %esi
or     $0x1800,%esi
mov    $0xd,%edx
call   1040 <addi_eeprom_cmd_93c76@plt>
mov    %eax,%r15d
mov    $0x10,%ebx
xor    %r12d,%r12d
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15d,%esi
call   1030 <addi_eeprom_clk_93c76@plt>
mov    %r14,%rdi
call   1060 <inl@plt>
mov    %eax,%ebp
mov    $0x64,%edi
call   1070 <udelay@plt>
shr    $0x3,%ebp
and    $0x1,%ebp
lea    0x0(%rbp,%r12,2),%r12d
add    $0xffffffff,%ebx
jne    1180 <addi_eeprom_readw_93c76+0x30>
xor    %edi,%edi
mov    %r14,%rsi
call   1050 <outl@plt>
mov    $0x64,%edi
call   1070 <udelay@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i16 @addi_eeprom_readw_93c76(i64 %0, i16 zeroext %1) {
%3 = alloca i64
%4 = alloca i16
%5 = alloca i16
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i64 %0, i64* %3
store i16 %1, i16* %4
store i16 0, i16* %5
%9 = load i16, i16* %4
%10 = zext i16 %9 to i32
%11 = sdiv i32 %10, 2
%12 = or i32 6144, %11
store i32 %12, i32* %6
%13 = load i64, i64* %3
%14 = load i32, i32* %6
%15 = call i32 @addi_eeprom_cmd_93c76(i64 %13, i32 %14, i32 13)
store i32 %15, i32* %6
store i32 0, i32* %8
br label %16
16: ; preds = %39, %2
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 16
br i1 %18, label %19, label %42
19: ; preds = %16
%20 = load i64, i64* %3
%21 = load i32, i32* %6
%22 = call i32 @addi_eeprom_clk_93c76(i64 %20, i32 %21)
%23 = load i64, i64* %3
%24 = call i32 @inl(i64 %23)
store i32 %24, i32* %7
%25 = call i32 @udelay(i32 100)
%26 = load i16, i16* %5
%27 = zext i16 %26 to i32
%28 = shl i32 %27, 1
%29 = trunc i32 %28 to i16
store i16 %29, i16* %5
%30 = load i32, i32* %7
%31 = and i32 %30, 8
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %19
%34 = load i16, i16* %5
%35 = zext i16 %34 to i32
%36 = or i32 %35, 1
%37 = trunc i32 %36 to i16
store i16 %37, i16* %5
br label %38
38: ; preds = %33, %19
br label %39
39: ; preds = %38
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %16
42: ; preds = %16
%43 = load i64, i64* %3
%44 = call i32 @outl(i32 0, i64 %43)
%45 = call i32 @udelay(i32 100)
%46 = load i16, i16* %5
ret i16 %46
}

LLVM IR (-O2):
define zeroext i16 @addi_eeprom_readw_93c76(i64 %0, i16 zeroext %1) {
%3 = lshr i16 %1, 1
%4 = or i16 %3, 6144
%5 = zext i16 %4 to i32
%6 = tail call i32 @addi_eeprom_cmd_93c76(i64 %0, i32 %5, i32 13)
br label %7
7: ; preds = %2, %7
%8 = phi i32 [ 0, %2 ], [ %18, %7 ]
%9 = phi i16 [ 0, %2 ], [ %17, %7 ]
%10 = tail call i32 @addi_eeprom_clk_93c76(i64 %0, i32 %6)
%11 = tail call i32 @inl(i64 %0)
%12 = tail call i32 @udelay(i32 100)
%13 = shl i16 %9, 1
%14 = trunc i32 %11 to i16
%15 = lshr i16 %14, 3
%16 = and i16 %15, 1
%17 = or i16 %16, %13
%18 = add nuw nsw i32 %8, 1
%19 = icmp eq i32 %18, 16
br i1 %19, label %20, label %7
20: ; preds = %7
%21 = tail call i32 @outl(i32 0, i64 %0)
%22 = tail call i32 @udelay(i32 100)
ret i16 %17
}