#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 */
unsigned long chip_base_address(unsigned long);
int /*<<< orphan*/ flashrom_chip_write(unsigned long, int);
int /*<<< orphan*/ flashrom_wait_toggle_bit(unsigned long);
void flashrom_sector_program(unsigned long address, unsigned char *buffer,
                             unsigned int count) {
  unsigned long prog_address;
  prog_address = chip_base_address(address);
  flashrom_chip_write(prog_address | 0x5555, 0xAA);
  flashrom_chip_write(prog_address | 0x2AAA, 0x55);
  flashrom_chip_write(prog_address | 0x5555, 0xA0);
  prog_address = address;
  while (count--) {
    flashrom_chip_write(prog_address++, *(buffer++));
  }
  flashrom_wait_toggle_bit(address);
}


x86 assembly (clang, -O0):
<flashrom_sector_program>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <chip_base_address@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
or     $0x5555,%rdi
mov    $0xaa,%esi
call   1040 <flashrom_chip_write@plt>
mov    -0x20(%rbp),%rdi
or     $0x2aaa,%rdi
mov    $0x55,%esi
call   1040 <flashrom_chip_write@plt>
mov    -0x20(%rbp),%rdi
or     $0x5555,%rdi
mov    $0xa0,%esi
call   1040 <flashrom_chip_write@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     11d6 <flashrom_sector_program+0xa6>
mov    -0x20(%rbp),%rdi
mov    %rdi,%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%esi
call   1040 <flashrom_chip_write@plt>
jmp    1197 <flashrom_sector_program+0x67>
mov    -0x8(%rbp),%rdi
call   1050 <flashrom_wait_toggle_bit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flashrom_sector_program>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%r14
mov    %rdi,%r13
call   1030 <chip_base_address@plt>
mov    %rax,%rbp
mov    %rax,%r12
or     $0x5555,%r12
mov    %r12,%rdi
mov    $0xaa,%esi
call   1040 <flashrom_chip_write@plt>
or     $0x2aaa,%rbp
mov    %rbp,%rdi
mov    $0x55,%esi
call   1040 <flashrom_chip_write@plt>
mov    %r12,%rdi
mov    $0xa0,%esi
call   1040 <flashrom_chip_write@plt>
test   %r15d,%r15d
je     11a6 <flashrom_sector_program+0x76>
mov    %r15d,%ebp
xor    %ebx,%ebx
xchg   %ax,%ax
lea    (%rbx,%r13,1),%rdi
movzbl (%r14,%rbx,1),%esi
call   1040 <flashrom_chip_write@plt>
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1190 <flashrom_sector_program+0x60>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <flashrom_wait_toggle_bit@plt>

LLVM IR (-O0):
define void @flashrom_sector_program(i64 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
store i64 %0, i64* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i64, i64* %4
%9 = call i64 @chip_base_address(i64 %8)
store i64 %9, i64* %7
%10 = load i64, i64* %7
%11 = or i64 %10, 21845
%12 = call i32 @flashrom_chip_write(i64 %11, i32 170)
%13 = load i64, i64* %7
%14 = or i64 %13, 10922
%15 = call i32 @flashrom_chip_write(i64 %14, i32 85)
%16 = load i64, i64* %7
%17 = or i64 %16, 21845
%18 = call i32 @flashrom_chip_write(i64 %17, i32 160)
%19 = load i64, i64* %4
store i64 %19, i64* %7
br label %20
20: ; preds = %24, %3
%21 = load i32, i32* %6
%22 = add i32 %21, -1
store i32 %22, i32* %6
%23 = icmp ne i32 %21, 0
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i64, i64* %7
%26 = add i64 %25, 1
store i64 %26, i64* %7
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
%29 = load i8, i8* %27
%30 = zext i8 %29 to i32
%31 = call i32 @flashrom_chip_write(i64 %25, i32 %30)
br label %20
32: ; preds = %20
%33 = load i64, i64* %4
%34 = call i32 @flashrom_wait_toggle_bit(i64 %33)
ret void
}

LLVM IR (-O2):
define void @flashrom_sector_program(i64 %0, i8* nocapture %1, i32 %2) {
%4 = tail call i64 @chip_base_address(i64 %0)
%5 = or i64 %4, 21845
%6 = tail call i32 @flashrom_chip_write(i64 %5, i32 170)
%7 = or i64 %4, 10922
%8 = tail call i32 @flashrom_chip_write(i64 %7, i32 85)
%9 = tail call i32 @flashrom_chip_write(i64 %5, i32 160)
%10 = icmp eq i32 %2, 0
br i1 %10, label %22, label %11
11: ; preds = %3, %11
%12 = phi i64 [ %16, %11 ], [ %0, %3 ]
%13 = phi i32 [ %15, %11 ], [ %2, %3 ]
%14 = phi i8* [ %17, %11 ], [ %1, %3 ]
%15 = add i32 %13, -1
%16 = add i64 %12, 1
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = load i8, i8* %14
%19 = zext i8 %18 to i32
%20 = tail call i32 @flashrom_chip_write(i64 %12, i32 %19)
%21 = icmp eq i32 %15, 0
br i1 %21, label %22, label %11
22: ; preds = %11, %3
%23 = tail call i32 @flashrom_wait_toggle_bit(i64 %0)
ret void
}