#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ read_pci_config(int);
int /*<<< orphan*/ stderr;
int wait_for_i2c();
int /*<<< orphan*/ wait_for_i2c_init();
int /*<<< orphan*/ write_pci_config(int, int);
uint8_t read_eeprom(int offset) {
  wait_for_i2c_init();
  write_pci_config(0xb1, offset);
  write_pci_config(0xb2, 0x01 | 0xa0);
  if (wait_for_i2c() & 0x02) {
    fprintf(stderr, "serial bus error\n");
    exit(1);
  }
  return read_pci_config(0xb0);
}


x86 assembly (clang, -O0):
<read_eeprom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <wait_for_i2c_init@plt>
mov    -0x4(%rbp),%esi
mov    $0xb1,%edi
call   1070 <write_pci_config@plt>
mov    $0xb2,%edi
mov    $0xa1,%esi
call   1070 <write_pci_config@plt>
mov    $0x0,%al
call   1060 <wait_for_i2c@plt>
and    $0x2,%eax
cmp    $0x0,%eax
je     11c0 <read_eeprom+0x60>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0xb0,%edi
call   1030 <read_pci_config@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_eeprom>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <wait_for_i2c_init@plt>
mov    $0xb1,%edi
mov    %ebx,%esi
call   1070 <write_pci_config@plt>
mov    $0xb2,%edi
mov    $0xa1,%esi
call   1070 <write_pci_config@plt>
xor    %eax,%eax
call   1060 <wait_for_i2c@plt>
test   $0x2,%al
jne    119b <read_eeprom+0x3b>
mov    $0xb0,%edi
pop    %rbx
jmp    1030 <read_pci_config@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"serial bus error\0A\00"
define i32 @read_eeprom(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 (...) @wait_for_i2c_init()
%4 = load i32, i32* %2
%5 = call i32 @write_pci_config(i32 177, i32 %4)
%6 = call i32 @write_pci_config(i32 178, i32 161)
%7 = call i32 (...) @wait_for_i2c()
%8 = and i32 %7, 2
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = call i32 @read_pci_config(i32 176)
ret i32 %15
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"serial bus error\0A\00"
define i32 @read_eeprom(i32 %0) {
%2 = tail call i32 (...) @wait_for_i2c_init()
%3 = tail call i32 @write_pci_config(i32 177, i32 %0)
%4 = tail call i32 @write_pci_config(i32 178, i32 161)
%5 = tail call i32 (...) @wait_for_i2c()
%6 = and i32 %5, 2
%7 = icmp eq i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = tail call i32 @read_pci_config(i32 176)
ret i32 %13
}