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

/* Variables and functions */
int /*<<< orphan*/ eeprom_read_block(int /*<<< orphan*/ *, void *, size_t);
int /*<<< orphan*/ eeprom_write_block(void const *, void *, size_t);
scalar_t__ memcmp(void const *, int /*<<< orphan*/ *, size_t);
void eeprom_update_block(const void *buf, void *addr, size_t len) {
  uint8_t read_buf[len];
  eeprom_read_block(read_buf, addr, len);
  if (memcmp(buf, read_buf, len) != 0) {
    eeprom_write_block(buf, addr, len);
  }
}


x86 assembly (clang, -O0):
<eeprom_update_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <eeprom_read_block@plt>
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11a5 <eeprom_update_block+0x75>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <eeprom_write_block@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eeprom_update_block>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,%rbx
lea    0xf(,%rdx,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1050 <eeprom_read_block@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <memcmp@plt>
test   %rax,%rax
je     1182 <eeprom_update_block+0x52>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1030 <eeprom_write_block@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @eeprom_update_block(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i64, i64* %6
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %7
%11 = alloca i32, i64 %9
store i64 %9, i64* %8
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = call i32 @eeprom_read_block(i32* %11, i8* %12, i64 %13)
%15 = load i8*, i8** %4
%16 = load i64, i64* %6
%17 = call i64 @memcmp(i8* %15, i32* %11, i64 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %3
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = load i64, i64* %6
%23 = call i32 @eeprom_write_block(i8* %20, i8* %21, i64 %22)
br label %24
24: ; preds = %19, %3
%25 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
define void @eeprom_update_block(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32, i64 %2
%5 = call i32 @eeprom_read_block(i32* %4, i8* %1, i64 %2)
%6 = call i64 @memcmp(i8* %0, i32* %4, i64 %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %3
%9 = call i32 @eeprom_write_block(i8* %0, i8* %1, i64 %2)
br label %10
10: ; preds = %8, %3
ret void
}