#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_read(struct flashrom_flashctx *, int, unsigned char *);
int edi_write(struct flashrom_flashctx *, int, unsigned char);
int edi_spi_disable(struct flashrom_flashctx *flash) {
  unsigned char buffer;
  int rc;
  rc = edi_read(flash, 0xfead, &buffer);
  if (rc < 0)
    return -1;
  buffer &= ~(1 << 3);
  rc = edi_write(flash, 0xfead, buffer);
  if (rc < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<edi_spi_disable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xfead,%esi
lea    -0x11(%rbp),%rdx
call   1040 <edi_read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1157 <edi_spi_disable+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    1193 <edi_spi_disable+0x73>
movzbl -0x11(%rbp),%eax
and    $0xfffffff7,%eax
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xfead,%esi
movzbl -0x11(%rbp),%edx
call   1030 <edi_write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    118c <edi_spi_disable+0x6c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1193 <edi_spi_disable+0x73>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<edi_spi_disable>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xf(%rsp),%rdx
mov    $0xfead,%esi
call   1040 <edi_read@plt>
test   %eax,%eax
js     1159 <edi_spi_disable+0x39>
movzbl 0xf(%rsp),%edx
and    $0xfffffff7,%edx
mov    %dl,0xf(%rsp)
mov    %rbx,%rdi
mov    $0xfead,%esi
call   1030 <edi_write@plt>
sar    $0x1f,%eax
jmp    115e <edi_spi_disable+0x3e>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.flashrom_flashctx = type { i32 }
define i32 @edi_spi_disable(%struct.flashrom_flashctx* %0) {
%2 = alloca i32
%3 = alloca %struct.flashrom_flashctx*
%4 = alloca i8
%5 = alloca i32
store %struct.flashrom_flashctx* %0, %struct.flashrom_flashctx** %3
%6 = load %struct.flashrom_flashctx*, %struct.flashrom_flashctx** %3
%7 = call i32 @edi_read(%struct.flashrom_flashctx* %6, i32 65197, i8* %4)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %23
11: ; preds = %1
%12 = load i8, i8* %4
%13 = zext i8 %12 to i32
%14 = and i32 %13, -9
%15 = trunc i32 %14 to i8
store i8 %15, i8* %4
%16 = load %struct.flashrom_flashctx*, %struct.flashrom_flashctx** %3
%17 = load i8, i8* %4
%18 = call i32 @edi_write(%struct.flashrom_flashctx* %16, i32 65197, i8 zeroext %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %11
store i32 -1, i32* %2
br label %23
22: ; preds = %11
store i32 0, i32* %2
br label %23
23: ; preds = %22, %21, %10
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
%struct.flashrom_flashctx = type { i32 }
define i32 @edi_spi_disable(%struct.flashrom_flashctx* %0) {
%2 = alloca i8
%3 = call i32 @edi_read(%struct.flashrom_flashctx* %0, i32 65197, i8* %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = load i8, i8* %2
%7 = and i8 %6, -9
store i8 %7, i8* %2
%8 = call i32 @edi_write(%struct.flashrom_flashctx* %0, i32 65197, i8 zeroext %7)
%9 = ashr i32 %8, 31
br label %10
10: ; preds = %5, %1
%11 = phi i32 [ -1, %1 ], [ %9, %5 ]
ret i32 %11
}