#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*/ flashrom_chip_write(int, int);
int /*<<< orphan*/ flashrom_wait_toggle_bit(unsigned long);
void flashrom_sector_program(unsigned long address, const unsigned char *buffer,
                             unsigned int count) {
  unsigned long prog_address;
  prog_address = address;
  flashrom_chip_write(0x5555, 0xAA);
  flashrom_chip_write(0x2AAA, 0x55);
  flashrom_chip_write(0x5555, 0xA0);
  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),%rax
mov    %rax,-0x20(%rbp)
mov    $0x5555,%edi
mov    $0xaa,%esi
call   1030 <flashrom_chip_write@plt>
mov    $0x2aaa,%edi
mov    $0x55,%esi
call   1030 <flashrom_chip_write@plt>
mov    $0x5555,%edi
mov    $0xa0,%esi
call   1030 <flashrom_chip_write@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     11a9 <flashrom_sector_program+0x89>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    %eax,%edi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movzbl (%rax),%esi
call   1030 <flashrom_chip_write@plt>
jmp    1168 <flashrom_sector_program+0x48>
mov    -0x8(%rbp),%rdi
call   1040 <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   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x5555,%edi
mov    $0xaa,%esi
call   1030 <flashrom_chip_write@plt>
mov    $0x2aaa,%edi
mov    $0x55,%esi
call   1030 <flashrom_chip_write@plt>
mov    $0x5555,%edi
mov    $0xa0,%esi
call   1030 <flashrom_chip_write@plt>
test   %ebp,%ebp
je     1186 <flashrom_sector_program+0x66>
mov    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%r15,%rbx,1),%edi
movzbl (%r14,%rbx,1),%esi
call   1030 <flashrom_chip_write@plt>
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1170 <flashrom_sector_program+0x50>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <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
store i64 %8, i64* %7
%9 = call i32 @flashrom_chip_write(i32 21845, i32 170)
%10 = call i32 @flashrom_chip_write(i32 10922, i32 85)
%11 = call i32 @flashrom_chip_write(i32 21845, i32 160)
br label %12
12: ; preds = %16, %3
%13 = load i32, i32* %6
%14 = add i32 %13, -1
store i32 %14, i32* %6
%15 = icmp ne i32 %13, 0
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i64, i64* %7
%18 = add i64 %17, 1
store i64 %18, i64* %7
%19 = trunc i64 %17 to i32
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
%22 = load i8, i8* %20
%23 = zext i8 %22 to i32
%24 = call i32 @flashrom_chip_write(i32 %19, i32 %23)
br label %12
25: ; preds = %12
%26 = load i64, i64* %4
%27 = call i32 @flashrom_wait_toggle_bit(i64 %26)
ret void
}

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