#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*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
int vt_ar5211_eeprom_read(unsigned char *mem, unsigned long int offset,
                          unsigned short int *data) {
  int timeout = 10000;
  unsigned long int status;
  (*((volatile unsigned long int *)(mem + (0x6010))) = (0)), usleep(5);
  (*((volatile unsigned long int *)(mem + (0x6008))) =
       ((*((volatile unsigned long int *)(mem + (0x6008)))) | 0x0003));
  usleep(5);
  (*((volatile unsigned long int *)(mem + (0x6000))) = ((unsigned char)offset));
  usleep(5);
  (*((volatile unsigned long int *)(mem + (0x6008))) =
       ((*((volatile unsigned long int *)(mem + (0x6008)))) | 0x0001));
  while (timeout > 0) {
    usleep(1);
    status = (*((volatile unsigned long int *)(mem + (0x600C))));
    if (status & 0x0002) {
      if (status & 0x0001) {
        (void)fputs("eeprom read access failed!\n", stderr);
        return 1;
      }
      status = (*((volatile unsigned long int *)(mem + (0x6004))));
      *data = status & 0x0000ffff;
      return 0;
    }
    timeout--;
  }
  (void)fputs("eeprom read timeout!\n", stderr);
  return 1;
}


x86 assembly (clang, -O0):
<vt_ar5211_eeprom_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x2710,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,0x6010(%rax)
mov    $0x5,%edi
call   1040 <usleep@plt>
mov    -0x10(%rbp),%rax
mov    0x6008(%rax),%rcx
or     $0x3,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x6008(%rax)
mov    $0x5,%edi
call   1040 <usleep@plt>
mov    -0x18(%rbp),%rax
movzbl %al,%eax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %rcx,0x6000(%rax)
mov    $0x5,%edi
call   1040 <usleep@plt>
mov    -0x10(%rbp),%rax
mov    0x6008(%rax),%rcx
or     $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x6008(%rax)
cmpl   $0x0,-0x24(%rbp)
jle    1255 <vt_ar5211_eeprom_read+0x135>
mov    $0x1,%edi
call   1040 <usleep@plt>
mov    -0x10(%rbp),%rax
mov    0x600c(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
and    $0x2,%rax
cmp    $0x0,%rax
je     1247 <vt_ar5211_eeprom_read+0x127>
mov    -0x30(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     1218 <vt_ar5211_eeprom_read+0xf8>
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
lea    0xdf9(%rip),%rdi
call   1030 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    1271 <vt_ar5211_eeprom_read+0x151>
mov    -0x10(%rbp),%rax
mov    0x6004(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
and    $0xffff,%rax
mov    %ax,%cx
mov    -0x20(%rbp),%rax
mov    %cx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1271 <vt_ar5211_eeprom_read+0x151>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    11b0 <vt_ar5211_eeprom_read+0x90>
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
lea    0xdb7(%rip),%rdi
call   1030 <fputs@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vt_ar5211_eeprom_read>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movq   $0x0,0x6010(%rdi)
mov    $0x5,%edi
call   1040 <usleep@plt>
orq    $0x3,0x6008(%rbx)
03
mov    $0x5,%edi
call   1040 <usleep@plt>
movzbl %r15b,%eax
mov    %rax,0x6000(%rbx)
mov    $0x5,%edi
call   1040 <usleep@plt>
orq    $0x1,0x6008(%rbx)
01
mov    $0x2711,%ebp
nopl   0x0(%rax)
mov    $0x1,%edi
call   1040 <usleep@plt>
mov    0x600c(%rbx),%rax
test   $0x2,%al
jne    11af <vt_ar5211_eeprom_read+0x8f>
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
jae    1180 <vt_ar5211_eeprom_read+0x60>
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    0xe6f(%rip),%rdi
jmp    11d2 <vt_ar5211_eeprom_read+0xb2>
test   $0x1,%al
jne    11c2 <vt_ar5211_eeprom_read+0xa2>
mov    0x6004(%rbx),%rax
mov    %ax,(%r14)
xor    %eax,%eax
jmp    11dc <vt_ar5211_eeprom_read+0xbc>
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
lea    0xe2e(%rip),%rdi
call   1030 <fputs@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"eeprom read access failed!\0A\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"eeprom read timeout!\0A\00"
define i32 @vt_ar5211_eeprom_read(i8* %0, i64 %1, i16* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i16*
%8 = alloca i32
%9 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i16* %2, i16** %7
store i32 10000, i32* %8
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i64 24592
%12 = bitcast i8* %11 to i64*
store volatile i64 0, i64* %12
%13 = call i32 @usleep(i32 5)
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 24584
%16 = bitcast i8* %15 to i64*
%17 = load volatile i64, i64* %16
%18 = or i64 %17, 3
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 24584
%21 = bitcast i8* %20 to i64*
store volatile i64 %18, i64* %21
%22 = call i32 @usleep(i32 5)
%23 = load i64, i64* %6
%24 = trunc i64 %23 to i8
%25 = zext i8 %24 to i64
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 24576
%28 = bitcast i8* %27 to i64*
store volatile i64 %25, i64* %28
%29 = call i32 @usleep(i32 5)
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 24584
%32 = bitcast i8* %31 to i64*
%33 = load volatile i64, i64* %32
%34 = or i64 %33, 1
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i64 24584
%37 = bitcast i8* %36 to i64*
store volatile i64 %34, i64* %37
br label %38
38: ; preds = %66, %3
%39 = load i32, i32* %8
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %69
41: ; preds = %38
%42 = call i32 @usleep(i32 1)
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i64 24588
%45 = bitcast i8* %44 to i64*
%46 = load volatile i64, i64* %45
store i64 %46, i64* %9
%47 = load i64, i64* %9
%48 = and i64 %47, 2
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %66
50: ; preds = %41
%51 = load i64, i64* %9
%52 = and i64 %51, 1
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = load i32, i32* @stderr
%56 = call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %55)
store i32 1, i32* %4
br label %72
57: ; preds = %50
%58 = load i8*, i8** %5
%59 = getelementptr inbounds i8, i8* %58, i64 24580
%60 = bitcast i8* %59 to i64*
%61 = load volatile i64, i64* %60
store i64 %61, i64* %9
%62 = load i64, i64* %9
%63 = and i64 %62, 65535
%64 = trunc i64 %63 to i16
%65 = load i16*, i16** %7
store i16 %64, i16* %65
store i32 0, i32* %4
br label %72
66: ; preds = %41
%67 = load i32, i32* %8
%68 = add nsw i32 %67, -1
store i32 %68, i32* %8
br label %38
69: ; preds = %38
%70 = load i32, i32* @stderr
%71 = call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %70)
store i32 1, i32* %4
br label %72
72: ; preds = %69, %57, %54
%73 = load i32, i32* %4
ret i32 %73
}

LLVM IR (-O2):
@.str = [28 x i8] c"eeprom read access failed!\0A\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"eeprom read timeout!\0A\00"
define i32 @vt_ar5211_eeprom_read(i8* %0, i64 %1, i16* nocapture writeonly %2) {
%4 = getelementptr inbounds i8, i8* %0, i64 24592
%5 = bitcast i8* %4 to i64*
store volatile i64 0, i64* %5
%6 = tail call i32 @usleep(i32 5)
%7 = getelementptr inbounds i8, i8* %0, i64 24584
%8 = bitcast i8* %7 to i64*
%9 = load volatile i64, i64* %8
%10 = or i64 %9, 3
store volatile i64 %10, i64* %8
%11 = tail call i32 @usleep(i32 5)
%12 = and i64 %1, 255
%13 = getelementptr inbounds i8, i8* %0, i64 24576
%14 = bitcast i8* %13 to i64*
store volatile i64 %12, i64* %14
%15 = tail call i32 @usleep(i32 5)
%16 = load volatile i64, i64* %8
%17 = or i64 %16, 1
store volatile i64 %17, i64* %8
%18 = getelementptr inbounds i8, i8* %0, i64 24588
%19 = bitcast i8* %18 to i64*
br label %23
20: ; preds = %23
%21 = add nsw i32 %24, -1
%22 = icmp ugt i32 %24, 1
br i1 %22, label %23, label %40
23: ; preds = %3, %20
%24 = phi i32 [ 10000, %3 ], [ %21, %20 ]
%25 = tail call i32 @usleep(i32 1)
%26 = load volatile i64, i64* %19
%27 = and i64 %26, 2
%28 = icmp eq i64 %27, 0
br i1 %28, label %20, label %29
29: ; preds = %23
%30 = and i64 %26, 1
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = tail call i32 @fputs(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %43
35: ; preds = %29
%36 = getelementptr inbounds i8, i8* %0, i64 24580
%37 = bitcast i8* %36 to i64*
%38 = load volatile i64, i64* %37
%39 = trunc i64 %38 to i16
store i16 %39, i16* %2
br label %43
40: ; preds = %20
%41 = load i32, i32* @stderr
%42 = tail call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %40, %35, %32
%44 = phi i32 [ 1, %32 ], [ 0, %35 ], [ 1, %40 ]
ret i32 %44
}