#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 char flashrom_chip_read_z180dma(unsigned long);
int /*<<< orphan*/ flashrom_chip_write_z180dma(unsigned long, unsigned char);
void flashrom_program_byte_z180dma(unsigned long address, unsigned char value) {
  unsigned char a, b;
  flashrom_chip_write_z180dma(0x5555, 0xAA);
  flashrom_chip_write_z180dma(0x2AAA, 0x55);
  flashrom_chip_write_z180dma(0x5555, 0xA0);
  flashrom_chip_write_z180dma(address, value);
  do {
    a = flashrom_chip_read_z180dma(address);
    b = flashrom_chip_read_z180dma(address);
    if (a == b) {
      a = flashrom_chip_read_z180dma(address);
      b = flashrom_chip_read_z180dma(address);
    }
  } while (a != b);
}


x86 assembly (clang, -O0):
<flashrom_program_byte_z180dma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    $0x5555,%edi
mov    $0xaa,%esi
call   1040 <flashrom_chip_write_z180dma@plt>
mov    $0x2aaa,%edi
mov    $0x55,%esi
call   1040 <flashrom_chip_write_z180dma@plt>
mov    $0x5555,%edi
mov    $0xa0,%esi
call   1040 <flashrom_chip_write_z180dma@plt>
mov    -0x8(%rbp),%rdi
movzbl -0x9(%rbp),%esi
call   1040 <flashrom_chip_write_z180dma@plt>
mov    -0x8(%rbp),%rdi
call   1030 <flashrom_chip_read_z180dma@plt>
mov    %al,-0xa(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <flashrom_chip_read_z180dma@plt>
mov    %al,-0xb(%rbp)
movzbl -0xa(%rbp),%eax
movzbl -0xb(%rbp),%ecx
cmp    %ecx,%eax
jne    11ac <flashrom_program_byte_z180dma+0x8c>
mov    -0x8(%rbp),%rdi
call   1030 <flashrom_chip_read_z180dma@plt>
mov    %al,-0xa(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <flashrom_chip_read_z180dma@plt>
mov    %al,-0xb(%rbp)
jmp    11b1 <flashrom_program_byte_z180dma+0x91>
movzbl -0xa(%rbp),%eax
movzbl -0xb(%rbp),%ecx
cmp    %ecx,%eax
jne    116c <flashrom_program_byte_z180dma+0x4c>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flashrom_program_byte_z180dma>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
mov    $0x5555,%edi
mov    $0xaa,%esi
call   1040 <flashrom_chip_write_z180dma@plt>
mov    $0x2aaa,%edi
mov    $0x55,%esi
call   1040 <flashrom_chip_write_z180dma@plt>
mov    $0x5555,%edi
mov    $0xa0,%esi
call   1040 <flashrom_chip_write_z180dma@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <flashrom_chip_write_z180dma@plt>
jmp    1174 <flashrom_program_byte_z180dma+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    %al,%bl
je     119e <flashrom_program_byte_z180dma+0x7e>
mov    %r14,%rdi
call   1030 <flashrom_chip_read_z180dma@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <flashrom_chip_read_z180dma@plt>
cmp    %al,%bl
jne    1170 <flashrom_program_byte_z180dma+0x50>
mov    %r14,%rdi
call   1030 <flashrom_chip_read_z180dma@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <flashrom_chip_read_z180dma@plt>
jmp    1170 <flashrom_program_byte_z180dma+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @flashrom_program_byte_z180dma(i64 %0, i8 zeroext %1) {
%3 = alloca i64
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
store i64 %0, i64* %3
store i8 %1, i8* %4
%7 = call i32 @flashrom_chip_write_z180dma(i64 21845, i8 zeroext -86)
%8 = call i32 @flashrom_chip_write_z180dma(i64 10922, i8 zeroext 85)
%9 = call i32 @flashrom_chip_write_z180dma(i64 21845, i8 zeroext -96)
%10 = load i64, i64* %3
%11 = load i8, i8* %4
%12 = call i32 @flashrom_chip_write_z180dma(i64 %10, i8 zeroext %11)
br label %13
13: ; preds = %29, %2
%14 = load i64, i64* %3
%15 = call zeroext i8 @flashrom_chip_read_z180dma(i64 %14)
store i8 %15, i8* %5
%16 = load i64, i64* %3
%17 = call zeroext i8 @flashrom_chip_read_z180dma(i64 %16)
store i8 %17, i8* %6
%18 = load i8, i8* %5
%19 = zext i8 %18 to i32
%20 = load i8, i8* %6
%21 = zext i8 %20 to i32
%22 = icmp eq i32 %19, %21
br i1 %22, label %23, label %28
23: ; preds = %13
%24 = load i64, i64* %3
%25 = call zeroext i8 @flashrom_chip_read_z180dma(i64 %24)
store i8 %25, i8* %5
%26 = load i64, i64* %3
%27 = call zeroext i8 @flashrom_chip_read_z180dma(i64 %26)
store i8 %27, i8* %6
br label %28
28: ; preds = %23, %13
br label %29
29: ; preds = %28
%30 = load i8, i8* %5
%31 = zext i8 %30 to i32
%32 = load i8, i8* %6
%33 = zext i8 %32 to i32
%34 = icmp ne i32 %31, %33
br i1 %34, label %13, label %35
35: ; preds = %29
ret void
}

LLVM IR (-O2):
define void @flashrom_program_byte_z180dma(i64 %0, i8 zeroext %1) {
%3 = tail call i32 @flashrom_chip_write_z180dma(i64 21845, i8 zeroext -86)
%4 = tail call i32 @flashrom_chip_write_z180dma(i64 10922, i8 zeroext 85)
%5 = tail call i32 @flashrom_chip_write_z180dma(i64 21845, i8 zeroext -96)
%6 = tail call i32 @flashrom_chip_write_z180dma(i64 %0, i8 zeroext %1)
br label %7
7: ; preds = %14, %2
%8 = tail call zeroext i8 @flashrom_chip_read_z180dma(i64 %0)
%9 = tail call zeroext i8 @flashrom_chip_read_z180dma(i64 %0)
%10 = icmp eq i8 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call zeroext i8 @flashrom_chip_read_z180dma(i64 %0)
%13 = tail call zeroext i8 @flashrom_chip_read_z180dma(i64 %0)
br label %14
14: ; preds = %7, %11
%15 = phi i8 [ %12, %11 ], [ %8, %7 ]
%16 = phi i8 [ %13, %11 ], [ %9, %7 ]
%17 = icmp eq i8 %15, %16
br i1 %17, label %18, label %7
18: ; preds = %14
ret void
}