#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
int wait_for_i2c();
int /*<<< orphan*/ wait_for_i2c_init();
int /*<<< orphan*/ write_pci_config(int, int);
void write_eeprom(int offset, uint8_t value) {
  wait_for_i2c_init();
  write_pci_config(0xb0, value);
  write_pci_config(0xb1, offset);
  write_pci_config(0xb2, 0x00 | 0xa0);
  usleep(10000);
  if (wait_for_i2c() & 0x02) {
    fprintf(stderr, "serial bus error\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<write_eeprom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <wait_for_i2c_init@plt>
mov    -0x8(%rbp),%esi
mov    $0xb0,%edi
call   1060 <write_pci_config@plt>
mov    -0x4(%rbp),%esi
mov    $0xb1,%edi
call   1060 <write_pci_config@plt>
mov    $0xb2,%edi
mov    $0xa0,%esi
call   1060 <write_pci_config@plt>
mov    $0x2710,%edi
call   1080 <usleep@plt>
mov    $0x0,%al
call   1050 <wait_for_i2c@plt>
and    $0x2,%eax
cmp    $0x0,%eax
je     11da <write_eeprom+0x7a>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_eeprom>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <wait_for_i2c_init@plt>
mov    $0xb0,%edi
mov    %ebx,%esi
call   1060 <write_pci_config@plt>
mov    $0xb1,%edi
mov    %ebp,%esi
call   1060 <write_pci_config@plt>
mov    $0xb2,%edi
mov    $0xa0,%esi
call   1060 <write_pci_config@plt>
mov    $0x2710,%edi
call   1080 <usleep@plt>
xor    %eax,%eax
call   1050 <wait_for_i2c@plt>
test   $0x2,%al
jne    11b1 <write_eeprom+0x51>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

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