#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*/ delay10ms();
unsigned int flashrom_chip_read(unsigned long);
int /*<<< orphan*/ flashrom_chip_write(unsigned long, int);
unsigned int flashrom_identify_device(unsigned long base_address) {
  unsigned int flashrom_device_id;
  flashrom_chip_write(base_address | 0x5555, 0xAA);
  flashrom_chip_write(base_address | 0x2AAA, 0x55);
  flashrom_chip_write(base_address | 0x5555, 0x90);
  delay10ms();
  flashrom_device_id = ((unsigned int)flashrom_chip_read(base_address) << 8) |
                       flashrom_chip_read(base_address | 0x0001);
  flashrom_chip_write(base_address | 0x5555, 0xF0);
  delay10ms();
  return flashrom_device_id;
}


x86 assembly (clang, -O0):
<flashrom_identify_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
or     $0x5555,%rdi
mov    $0xaa,%esi
call   1040 <flashrom_chip_write@plt>
mov    -0x8(%rbp),%rdi
or     $0x2aaa,%rdi
mov    $0x55,%esi
call   1040 <flashrom_chip_write@plt>
mov    -0x8(%rbp),%rdi
or     $0x5555,%rdi
mov    $0x90,%esi
call   1040 <flashrom_chip_write@plt>
mov    $0x0,%al
call   1030 <delay10ms@plt>
mov    -0x8(%rbp),%rdi
call   1050 <flashrom_chip_read@plt>
shl    $0x8,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
or     $0x1,%rdi
call   1050 <flashrom_chip_read@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
or     $0x5555,%rdi
mov    $0xf0,%esi
call   1040 <flashrom_chip_write@plt>
mov    $0x0,%al
call   1030 <delay10ms@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flashrom_identify_device>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    %rdi,%r14
or     $0x5555,%r14
mov    %r14,%rdi
mov    $0xaa,%esi
call   1040 <flashrom_chip_write@plt>
mov    %rbx,%rdi
or     $0x2aaa,%rdi
mov    $0x55,%esi
call   1040 <flashrom_chip_write@plt>
mov    %r14,%rdi
mov    $0x90,%esi
call   1040 <flashrom_chip_write@plt>
xor    %eax,%eax
call   1030 <delay10ms@plt>
mov    %rbx,%rdi
call   1050 <flashrom_chip_read@plt>
mov    %eax,%ebp
shl    $0x8,%ebp
or     $0x1,%rbx
mov    %rbx,%rdi
call   1050 <flashrom_chip_read@plt>
mov    %eax,%ebx
or     %ebp,%ebx
mov    %r14,%rdi
mov    $0xf0,%esi
call   1040 <flashrom_chip_write@plt>
xor    %eax,%eax
call   1030 <delay10ms@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @flashrom_identify_device(i64 %0) {
%2 = alloca i64
%3 = alloca i32
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = or i64 %4, 21845
%6 = call i32 @flashrom_chip_write(i64 %5, i32 170)
%7 = load i64, i64* %2
%8 = or i64 %7, 10922
%9 = call i32 @flashrom_chip_write(i64 %8, i32 85)
%10 = load i64, i64* %2
%11 = or i64 %10, 21845
%12 = call i32 @flashrom_chip_write(i64 %11, i32 144)
%13 = call i32 (...) @delay10ms()
%14 = load i64, i64* %2
%15 = call i32 @flashrom_chip_read(i64 %14)
%16 = shl i32 %15, 8
%17 = load i64, i64* %2
%18 = or i64 %17, 1
%19 = call i32 @flashrom_chip_read(i64 %18)
%20 = or i32 %16, %19
store i32 %20, i32* %3
%21 = load i64, i64* %2
%22 = or i64 %21, 21845
%23 = call i32 @flashrom_chip_write(i64 %22, i32 240)
%24 = call i32 (...) @delay10ms()
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
define i32 @flashrom_identify_device(i64 %0) {
%2 = or i64 %0, 21845
%3 = tail call i32 @flashrom_chip_write(i64 %2, i32 170)
%4 = or i64 %0, 10922
%5 = tail call i32 @flashrom_chip_write(i64 %4, i32 85)
%6 = tail call i32 @flashrom_chip_write(i64 %2, i32 144)
%7 = tail call i32 (...) @delay10ms()
%8 = tail call i32 @flashrom_chip_read(i64 %0)
%9 = shl i32 %8, 8
%10 = or i64 %0, 1
%11 = tail call i32 @flashrom_chip_read(i64 %10)
%12 = or i32 %9, %11
%13 = tail call i32 @flashrom_chip_write(i64 %2, i32 240)
%14 = tail call i32 (...) @delay10ms()
ret i32 %12
}