#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 */
struct flashrom_flashctx {
  int dummy;
};

/* Variables and functions */
int edi_write(struct flashrom_flashctx *, int, unsigned int);
int edi_spi_address(struct flashrom_flashctx *flash, unsigned int start,
                    unsigned int address) {
  int rc;
  if ((address == start) || (((address - 1) & 0xff) != (address & 0xff))) {
    rc = edi_write(flash, 0xfea8, ((address & 0xff) >> 0));
    if (rc < 0)
      return -1;
  }
  if ((address == start) || (((address - 1) & 0xff00) != (address & 0xff00))) {
    rc = edi_write(flash, 0xfea9, ((address & 0xff00) >> 8));
    if (rc < 0)
      return -1;
  }
  if ((address == start) ||
      (((address - 1) & 0xff0000) != (address & 0xff0000))) {
    rc = edi_write(flash, 0xfeaa, ((address & 0xff0000) >> 16));
    if (rc < 0)
      return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<edi_spi_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     114a <edi_spi_address+0x3a>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
and    $0xff,%eax
mov    -0x18(%rbp),%ecx
and    $0xff,%ecx
cmp    %ecx,%eax
je     1182 <edi_spi_address+0x72>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
and    $0xff,%edx
shr    $0x0,%edx
mov    $0xfea8,%esi
call   1030 <edi_write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    117d <edi_spi_address+0x6d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <edi_spi_address+0x139>
jmp    1182 <edi_spi_address+0x72>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11aa <edi_spi_address+0x9a>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
and    $0xff00,%eax
mov    -0x18(%rbp),%ecx
and    $0xff00,%ecx
cmp    %ecx,%eax
je     11e2 <edi_spi_address+0xd2>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
and    $0xff00,%edx
shr    $0x8,%edx
mov    $0xfea9,%esi
call   1030 <edi_write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11dd <edi_spi_address+0xcd>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <edi_spi_address+0x139>
jmp    11e2 <edi_spi_address+0xd2>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     120a <edi_spi_address+0xfa>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
and    $0xff0000,%eax
mov    -0x18(%rbp),%ecx
and    $0xff0000,%ecx
cmp    %ecx,%eax
je     1242 <edi_spi_address+0x132>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%edx
and    $0xff0000,%edx
shr    $0x10,%edx
mov    $0xfeaa,%esi
call   1030 <edi_write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    123d <edi_spi_address+0x12d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1249 <edi_spi_address+0x139>
jmp    1242 <edi_spi_address+0x132>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<edi_spi_address>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r15d
mov    %rdi,%r14
cmp    %esi,%edx
jne    1139 <edi_spi_address+0x29>
movzbl %bl,%edx
mov    %r14,%rdi
mov    $0xfea8,%esi
call   1030 <edi_write@plt>
test   %eax,%eax
jns    1160 <edi_spi_address+0x50>
jmp    11a0 <edi_spi_address+0x90>
lea    -0x1(%rbx),%ebp
mov    %ebp,%eax
xor    %bl,%al
je     1156 <edi_spi_address+0x46>
movzbl %bl,%edx
mov    %r14,%rdi
mov    $0xfea8,%esi
call   1030 <edi_write@plt>
test   %eax,%eax
js     11a0 <edi_spi_address+0x90>
xor    %ebx,%ebp
test   $0xff00,%ebp
je     1179 <edi_spi_address+0x69>
movzbl %bh,%edx
mov    %r14,%rdi
mov    $0xfea9,%esi
call   1030 <edi_write@plt>
test   %eax,%eax
js     11a0 <edi_spi_address+0x90>
cmp    %r15d,%ebx
je     1185 <edi_spi_address+0x75>
lea    -0x1(%rbx),%eax
xor    %ebx,%eax
test   $0xff0000,%eax
je     119c <edi_spi_address+0x8c>
shr    $0x10,%ebx
movzbl %bl,%edx
mov    %r14,%rdi
mov    $0xfeaa,%esi
call   1030 <edi_write@plt>
test   %eax,%eax
js     11a0 <edi_spi_address+0x90>
xor    %eax,%eax
jmp    11a5 <edi_spi_address+0x95>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.flashrom_flashctx = type { i32 }
define i32 @edi_spi_address(%struct.flashrom_flashctx* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.flashrom_flashctx*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.flashrom_flashctx* %0, %struct.flashrom_flashctx** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp eq i32 %9, %10
br i1 %11, label %19, label %12
12: ; preds = %3
%13 = load i32, i32* %7
%14 = sub i32 %13, 1
%15 = and i32 %14, 255
%16 = load i32, i32* %7
%17 = and i32 %16, 255
%18 = icmp ne i32 %15, %17
br i1 %18, label %19, label %29
19: ; preds = %12, %3
%20 = load %struct.flashrom_flashctx*, %struct.flashrom_flashctx** %5
%21 = load i32, i32* %7
%22 = and i32 %21, 255
%23 = lshr i32 %22, 0
%24 = call i32 @edi_write(%struct.flashrom_flashctx* %20, i32 65192, i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %19
store i32 -1, i32* %4
br label %72
28: ; preds = %19
br label %29
29: ; preds = %28, %12
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = icmp eq i32 %30, %31
br i1 %32, label %40, label %33
33: ; preds = %29
%34 = load i32, i32* %7
%35 = sub i32 %34, 1
%36 = and i32 %35, 65280
%37 = load i32, i32* %7
%38 = and i32 %37, 65280
%39 = icmp ne i32 %36, %38
br i1 %39, label %40, label %50
40: ; preds = %33, %29
%41 = load %struct.flashrom_flashctx*, %struct.flashrom_flashctx** %5
%42 = load i32, i32* %7
%43 = and i32 %42, 65280
%44 = lshr i32 %43, 8
%45 = call i32 @edi_write(%struct.flashrom_flashctx* %41, i32 65193, i32 %44)
store i32 %45, i32* %8
%46 = load i32, i32* %8
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %40
store i32 -1, i32* %4
br label %72
49: ; preds = %40
br label %50
50: ; preds = %49, %33
%51 = load i32, i32* %7
%52 = load i32, i32* %6
%53 = icmp eq i32 %51, %52
br i1 %53, label %61, label %54
54: ; preds = %50
%55 = load i32, i32* %7
%56 = sub i32 %55, 1
%57 = and i32 %56, 16711680
%58 = load i32, i32* %7
%59 = and i32 %58, 16711680
%60 = icmp ne i32 %57, %59
br i1 %60, label %61, label %71
61: ; preds = %54, %50
%62 = load %struct.flashrom_flashctx*, %struct.flashrom_flashctx** %5
%63 = load i32, i32* %7
%64 = and i32 %63, 16711680
%65 = lshr i32 %64, 16
%66 = call i32 @edi_write(%struct.flashrom_flashctx* %62, i32 65194, i32 %65)
store i32 %66, i32* %8
%67 = load i32, i32* %8
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %61
store i32 -1, i32* %4
br label %72
70: ; preds = %61
br label %71
71: ; preds = %70, %54
store i32 0, i32* %4
br label %72
72: ; preds = %71, %69, %48, %27
%73 = load i32, i32* %4
ret i32 %73
}

LLVM IR (-O2):
%struct.flashrom_flashctx = type { i32 }
define i32 @edi_spi_address(%struct.flashrom_flashctx* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, %1
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = add i32 %2, 255
%7 = xor i32 %6, %2
%8 = and i32 %7, 255
%9 = icmp eq i32 %8, 0
br i1 %9, label %18, label %14
10: ; preds = %3
%11 = and i32 %2, 255
%12 = tail call i32 @edi_write(%struct.flashrom_flashctx* %0, i32 65192, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %40, label %23
14: ; preds = %5
%15 = and i32 %2, 255
%16 = tail call i32 @edi_write(%struct.flashrom_flashctx* %0, i32 65192, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %40, label %18
18: ; preds = %14, %5
%19 = add i32 %2, 65535
%20 = xor i32 %19, %2
%21 = and i32 %20, 65280
%22 = icmp eq i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %10, %18
%24 = lshr i32 %2, 8
%25 = and i32 %24, 255
%26 = tail call i32 @edi_write(%struct.flashrom_flashctx* %0, i32 65193, i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %40, label %28
28: ; preds = %23
br i1 %4, label %34, label %29
29: ; preds = %18, %28
%30 = add i32 %2, 16777215
%31 = xor i32 %30, %2
%32 = and i32 %31, 16711680
%33 = icmp eq i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %29, %28
%35 = lshr i32 %2, 16
%36 = and i32 %35, 255
%37 = tail call i32 @edi_write(%struct.flashrom_flashctx* %0, i32 65194, i32 %36)
%38 = icmp slt i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %34, %29
br label %40
40: ; preds = %14, %34, %23, %10, %39
%41 = phi i32 [ 0, %39 ], [ -1, %10 ], [ -1, %23 ], [ -1, %34 ], [ -1, %14 ]
ret i32 %41
}