#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;
};
typedef int /*<<< orphan*/ cmd;

/* Variables and functions */
int /*<<< orphan*/ edi_write_cmd(unsigned char *, unsigned short,
                                 unsigned char);
int spi_send_command(struct flashrom_flashctx *, int, int /*<<< orphan*/,
                     unsigned char *, int /*<<< orphan*/ *);
int edi_write(struct flashrom_flashctx *flash, unsigned short address,
              unsigned char data) {
  unsigned char cmd[5];
  int rc;
  edi_write_cmd(cmd, address, data);
  rc = spi_send_command(flash, sizeof(cmd), 0, cmd, NULL);
  if (rc)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<edi_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %si,%cx
mov    %rdi,-0x10(%rbp)
mov    %cx,-0x12(%rbp)
mov    %al,-0x13(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0x12(%rbp),%ax
movzwl %ax,%esi
movzbl -0x13(%rbp),%edx
call   1040 <edi_write_cmd@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rcx
mov    $0x5,%esi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%r8d
call   1030 <spi_send_command@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     117e <edi_write+0x5e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1185 <edi_write+0x65>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<edi_write>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x3(%rsp),%r14
mov    %r14,%rdi
call   1040 <edi_write_cmd@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %edx,%edx
mov    %r14,%rcx
xor    %r8d,%r8d
call   1030 <spi_send_command@plt>
neg    %eax
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.flashrom_flashctx = type { i32 }
define i32 @edi_write(%struct.flashrom_flashctx* %0, i16 zeroext %1, i8 zeroext %2) {
%4 = alloca i32
%5 = alloca %struct.flashrom_flashctx*
%6 = alloca i16
%7 = alloca i8
%8 = alloca [5 x i8]
%9 = alloca i32
store %struct.flashrom_flashctx* %0, %struct.flashrom_flashctx** %5
store i16 %1, i16* %6
store i8 %2, i8* %7
%10 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%11 = load i16, i16* %6
%12 = load i8, i8* %7
%13 = call i32 @edi_write_cmd(i8* %10, i16 zeroext %11, i8 zeroext %12)
%14 = load %struct.flashrom_flashctx*, %struct.flashrom_flashctx** %5
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%16 = call i32 @spi_send_command(%struct.flashrom_flashctx* %14, i32 5, i32 0, i8* %15, i32* null)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %3
store i32 -1, i32* %4
br label %21
20: ; preds = %3
store i32 0, i32* %4
br label %21
21: ; preds = %20, %19
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
%struct.flashrom_flashctx = type { i32 }
define i32 @edi_write(%struct.flashrom_flashctx* %0, i16 zeroext %1, i8 zeroext %2) {
%4 = alloca [5 x i8]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%6 = call i32 @edi_write_cmd(i8* %5, i16 zeroext %1, i8 zeroext %2)
%7 = call i32 @spi_send_command(%struct.flashrom_flashctx* %0, i32 5, i32 0, i8* %5, i32* null)
%8 = icmp ne i32 %7, 0
%9 = sext i1 %8 to i32
ret i32 %9
}