#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 uint32_t;

/* Variables and functions */
int flash_eeprom_read_uint32(int);
int /*<<< orphan*/ flash_eeprom_write_uint32(int, int);
void write_uint32(uint32_t offset, uint32_t value) {
  uint32_t base_offset = offset & ~3;
  uint32_t byte_offset = offset & 3;
  if (byte_offset == 0) {
    flash_eeprom_write_uint32(offset, value);
  } else {
    uint32_t base_word = flash_eeprom_read_uint32(base_offset);
    base_word &= ~(0xFFFFFFFF << (byte_offset * 8));
    base_word |= (value << (byte_offset * 8));
    flash_eeprom_write_uint32(base_offset, base_word);
    base_word = flash_eeprom_read_uint32(base_offset + 4);
    base_word &= ~(0xFFFFFFFF >> (8 * (4 - byte_offset)));
    base_word |= (value >> (8 * (4 - byte_offset)));
    flash_eeprom_write_uint32(base_offset + 4, base_word);
  }
}


x86 assembly (clang, -O0):
<write_uint32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xfffffffc,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    115a <write_uint32+0x3a>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <flash_eeprom_write_uint32@plt>
jmp    11e4 <write_uint32+0xc4>
mov    -0xc(%rbp),%edi
call   1030 <flash_eeprom_read_uint32@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%ecx
shl    $0x3,%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <flash_eeprom_write_uint32@plt>
mov    -0xc(%rbp),%edi
add    $0x4,%edi
call   1030 <flash_eeprom_read_uint32@plt>
mov    %eax,-0x14(%rbp)
mov    $0x4,%ecx
sub    -0x10(%rbp),%ecx
shl    $0x3,%ecx
mov    $0xffffffff,%eax
shr    %cl,%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
sub    -0x10(%rbp),%ecx
shl    $0x3,%ecx
sar    %cl,%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
add    $0x4,%edi
mov    -0x14(%rbp),%esi
call   1040 <flash_eeprom_write_uint32@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_uint32>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebp
mov    %edi,%ebx
and    $0x3,%ebx
je     1183 <write_uint32+0x63>
and    $0xfffffffc,%ebp
mov    %ebp,%edi
call   1030 <flash_eeprom_read_uint32@plt>
lea    0x0(,%rbx,8),%ecx
mov    $0xffffffff,%edx
shl    %cl,%edx
mov    $0xffffffff,%r15d
not    %edx
and    %eax,%edx
mov    %r14d,%esi
shl    %cl,%esi
or     %edx,%esi
mov    %ebp,%edi
call   1040 <flash_eeprom_write_uint32@plt>
add    $0x4,%ebp
mov    %ebp,%edi
call   1030 <flash_eeprom_read_uint32@plt>
shl    $0x3,%bl
neg    %bl
mov    %ebx,%ecx
shr    %cl,%r15d
not    %r15d
and    %eax,%r15d
sar    %cl,%r14d
or     %r15d,%r14d
mov    %ebp,%edi
mov    %r14d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <flash_eeprom_write_uint32@plt>

LLVM IR (-O0):
define void @write_uint32(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = and i32 %8, -4
store i32 %9, i32* %5
%10 = load i32, i32* %3
%11 = and i32 %10, 3
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* %3
%16 = load i32, i32* %4
%17 = call i32 @flash_eeprom_write_uint32(i32 %15, i32 %16)
br label %57
18: ; preds = %2
%19 = load i32, i32* %5
%20 = call i32 @flash_eeprom_read_uint32(i32 %19)
store i32 %20, i32* %7
%21 = load i32, i32* %6
%22 = mul nsw i32 %21, 8
%23 = shl i32 -1, %22
%24 = xor i32 %23, -1
%25 = load i32, i32* %7
%26 = and i32 %25, %24
store i32 %26, i32* %7
%27 = load i32, i32* %4
%28 = load i32, i32* %6
%29 = mul nsw i32 %28, 8
%30 = shl i32 %27, %29
%31 = load i32, i32* %7
%32 = or i32 %31, %30
store i32 %32, i32* %7
%33 = load i32, i32* %5
%34 = load i32, i32* %7
%35 = call i32 @flash_eeprom_write_uint32(i32 %33, i32 %34)
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 4
%38 = call i32 @flash_eeprom_read_uint32(i32 %37)
store i32 %38, i32* %7
%39 = load i32, i32* %6
%40 = sub nsw i32 4, %39
%41 = mul nsw i32 8, %40
%42 = lshr i32 -1, %41
%43 = xor i32 %42, -1
%44 = load i32, i32* %7
%45 = and i32 %44, %43
store i32 %45, i32* %7
%46 = load i32, i32* %4
%47 = load i32, i32* %6
%48 = sub nsw i32 4, %47
%49 = mul nsw i32 8, %48
%50 = ashr i32 %46, %49
%51 = load i32, i32* %7
%52 = or i32 %51, %50
store i32 %52, i32* %7
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 4
%55 = load i32, i32* %7
%56 = call i32 @flash_eeprom_write_uint32(i32 %54, i32 %55)
br label %57
57: ; preds = %18, %14
ret void
}

LLVM IR (-O2):
define void @write_uint32(i32 %0, i32 %1) {
%3 = and i32 %0, -4
%4 = and i32 %0, 3
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @flash_eeprom_write_uint32(i32 %0, i32 %1)
br label %27
8: ; preds = %2
%9 = tail call i32 @flash_eeprom_read_uint32(i32 %3)
%10 = shl nuw nsw i32 %4, 3
%11 = shl nsw i32 -1, %10
%12 = xor i32 %11, -1
%13 = and i32 %9, %12
%14 = shl i32 %1, %10
%15 = or i32 %13, %14
%16 = tail call i32 @flash_eeprom_write_uint32(i32 %3, i32 %15)
%17 = add nsw i32 %3, 4
%18 = tail call i32 @flash_eeprom_read_uint32(i32 %17)
%19 = mul nsw i32 %4, -8
%20 = add nsw i32 %19, 32
%21 = lshr i32 -1, %20
%22 = xor i32 %21, -1
%23 = and i32 %18, %22
%24 = ashr i32 %1, %20
%25 = or i32 %23, %24
%26 = tail call i32 @flash_eeprom_write_uint32(i32 %17, i32 %25)
br label %27
27: ; preds = %8, %6
ret void
}