#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 ivals_context {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assemble_write_mmio(struct ivals_context *, int, int,
                                       unsigned int);
int /*<<< orphan*/ shm_control_word(struct ivals_context *, unsigned int,
                                    unsigned int);
void shm_write32(struct ivals_context *ctx, unsigned int routing,
                 unsigned int offset, unsigned int value) {
  if ((routing & 0xFF) == 0x01) {
    if (offset & 0x0003) {
      shm_control_word(ctx, routing, offset >> 2);
      assemble_write_mmio(ctx, 0x166, 2, (value >> 16) & 0xFFFF);
      shm_control_word(ctx, routing, (offset >> 2) + 1);
      assemble_write_mmio(ctx, 0x164, 2, (value & 0xFFFF));
      return;
    }
    offset >>= 2;
  }
  shm_control_word(ctx, routing, offset);
  assemble_write_mmio(ctx, 0x164, 4, value);
}


x86 assembly (clang, -O0):
<shm_write32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0xc(%rbp),%eax
and    $0xff,%eax
cmp    $0x1,%eax
jne    11c5 <shm_write32+0xa5>
mov    -0x10(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
je     11bc <shm_write32+0x9c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
shr    $0x2,%edx
call   1030 <shm_control_word@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%ecx
shr    $0x10,%ecx
and    $0xffff,%ecx
mov    $0x166,%esi
mov    $0x2,%edx
call   1040 <assemble_write_mmio@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
shr    $0x2,%edx
add    $0x1,%edx
call   1030 <shm_control_word@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%ecx
and    $0xffff,%ecx
mov    $0x164,%esi
mov    $0x2,%edx
call   1040 <assemble_write_mmio@plt>
jmp    11ea <shm_write32+0xca>
mov    -0x10(%rbp),%eax
shr    $0x2,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <shm_control_word@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x164,%esi
mov    $0x4,%edx
call   1040 <assemble_write_mmio@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shm_write32>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,%r15
cmp    $0x1,%bl
jne    1185 <shm_write32+0x65>
mov    %ebp,%eax
shr    $0x2,%ebp
test   $0x3,%al
je     1185 <shm_write32+0x65>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <shm_control_word@plt>
mov    %r14d,%ecx
shr    $0x10,%ecx
mov    %r15,%rdi
mov    $0x166,%esi
mov    $0x2,%edx
call   1040 <assemble_write_mmio@plt>
add    $0x1,%ebp
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <shm_control_word@plt>
movzwl %r14w,%ecx
mov    %r15,%rdi
mov    $0x164,%esi
mov    $0x2,%edx
jmp    11a1 <shm_write32+0x81>
mov    %r15,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <shm_control_word@plt>
mov    %r15,%rdi
mov    $0x164,%esi
mov    $0x4,%edx
mov    %r14d,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <assemble_write_mmio@plt>

LLVM IR (-O0):
%struct.ivals_context = type { i32 }
define void @shm_write32(%struct.ivals_context* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.ivals_context*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.ivals_context* %0, %struct.ivals_context** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%9 = load i32, i32* %6
%10 = and i32 %9, 255
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %40
12: ; preds = %4
%13 = load i32, i32* %7
%14 = and i32 %13, 3
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %37
16: ; preds = %12
%17 = load %struct.ivals_context*, %struct.ivals_context** %5
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = lshr i32 %19, 2
%21 = call i32 @shm_control_word(%struct.ivals_context* %17, i32 %18, i32 %20)
%22 = load %struct.ivals_context*, %struct.ivals_context** %5
%23 = load i32, i32* %8
%24 = lshr i32 %23, 16
%25 = and i32 %24, 65535
%26 = call i32 @assemble_write_mmio(%struct.ivals_context* %22, i32 358, i32 2, i32 %25)
%27 = load %struct.ivals_context*, %struct.ivals_context** %5
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = lshr i32 %29, 2
%31 = add i32 %30, 1
%32 = call i32 @shm_control_word(%struct.ivals_context* %27, i32 %28, i32 %31)
%33 = load %struct.ivals_context*, %struct.ivals_context** %5
%34 = load i32, i32* %8
%35 = and i32 %34, 65535
%36 = call i32 @assemble_write_mmio(%struct.ivals_context* %33, i32 356, i32 2, i32 %35)
br label %48
37: ; preds = %12
%38 = load i32, i32* %7
%39 = lshr i32 %38, 2
store i32 %39, i32* %7
br label %40
40: ; preds = %37, %4
%41 = load %struct.ivals_context*, %struct.ivals_context** %5
%42 = load i32, i32* %6
%43 = load i32, i32* %7
%44 = call i32 @shm_control_word(%struct.ivals_context* %41, i32 %42, i32 %43)
%45 = load %struct.ivals_context*, %struct.ivals_context** %5
%46 = load i32, i32* %8
%47 = call i32 @assemble_write_mmio(%struct.ivals_context* %45, i32 356, i32 4, i32 %46)
br label %48
48: ; preds = %40, %16
ret void
}

LLVM IR (-O2):
%struct.ivals_context = type { i32 }
define void @shm_write32(%struct.ivals_context* %0, i32 %1, i32 %2, i32 %3) {
%5 = and i32 %1, 255
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %19
7: ; preds = %4
%8 = and i32 %2, 3
%9 = icmp eq i32 %8, 0
%10 = lshr i32 %2, 2
br i1 %9, label %19, label %11
11: ; preds = %7
%12 = tail call i32 @shm_control_word(%struct.ivals_context* %0, i32 %1, i32 %10)
%13 = lshr i32 %3, 16
%14 = tail call i32 @assemble_write_mmio(%struct.ivals_context* %0, i32 358, i32 2, i32 %13)
%15 = add nuw nsw i32 %10, 1
%16 = tail call i32 @shm_control_word(%struct.ivals_context* %0, i32 %1, i32 %15)
%17 = and i32 %3, 65535
%18 = tail call i32 @assemble_write_mmio(%struct.ivals_context* %0, i32 356, i32 2, i32 %17)
br label %23
19: ; preds = %7, %4
%20 = phi i32 [ %2, %4 ], [ %10, %7 ]
%21 = tail call i32 @shm_control_word(%struct.ivals_context* %0, i32 %1, i32 %20)
%22 = tail call i32 @assemble_write_mmio(%struct.ivals_context* %0, i32 356, i32 4, i32 %3)
br label %23
23: ; preds = %19, %11
ret void
}