#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_write16(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);
      return;
    }
    offset >>= 2;
  }
  shm_control_word(ctx, routing, offset);
  assemble_write_mmio(ctx, 0x164, 2, value);
}


x86 assembly (clang, -O0):
<shm_write16>:
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    118b <shm_write16+0x6b>
mov    -0x10(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
je     1182 <shm_write16+0x62>
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
mov    $0x166,%esi
mov    $0x2,%edx
call   1040 <assemble_write_mmio@plt>
jmp    11b0 <shm_write16+0x90>
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    $0x2,%edx
call   1040 <assemble_write_mmio@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shm_write16>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %edx,%eax
mov    %rdi,%rbx
cmp    $0x1,%sil
jne    1142 <shm_write16+0x22>
mov    %eax,%edx
shr    $0x2,%edx
mov    $0x166,%ebp
test   $0x3,%al
jne    1149 <shm_write16+0x29>
jmp    1144 <shm_write16+0x24>
mov    %eax,%edx
mov    $0x164,%ebp
mov    %rbx,%rdi
call   1030 <shm_control_word@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x2,%edx
mov    %r14d,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <assemble_write_mmio@plt>

LLVM IR (-O0):
%struct.ivals_context = type { i32 }
define void @shm_write16(%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 %28
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 %25
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 = call i32 @assemble_write_mmio(%struct.ivals_context* %22, i32 358, i32 2, i32 %23)
br label %36
25: ; preds = %12
%26 = load i32, i32* %7
%27 = lshr i32 %26, 2
store i32 %27, i32* %7
br label %28
28: ; preds = %25, %4
%29 = load %struct.ivals_context*, %struct.ivals_context** %5
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = call i32 @shm_control_word(%struct.ivals_context* %29, i32 %30, i32 %31)
%33 = load %struct.ivals_context*, %struct.ivals_context** %5
%34 = load i32, i32* %8
%35 = call i32 @assemble_write_mmio(%struct.ivals_context* %33, i32 356, i32 2, i32 %34)
br label %36
36: ; preds = %28, %16
ret void
}

LLVM IR (-O2):
%struct.ivals_context = type { i32 }
define void @shm_write16(%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 %11
7: ; preds = %4
%8 = and i32 %2, 3
%9 = icmp eq i32 %8, 0
%10 = lshr i32 %2, 2
br i1 %9, label %11, label %13
11: ; preds = %7, %4
%12 = phi i32 [ %2, %4 ], [ %10, %7 ]
br label %13
13: ; preds = %7, %11
%14 = phi i32 [ %12, %11 ], [ %10, %7 ]
%15 = phi i32 [ 356, %11 ], [ 358, %7 ]
%16 = tail call i32 @shm_control_word(%struct.ivals_context* %0, i32 %1, i32 %14)
%17 = tail call i32 @assemble_write_mmio(%struct.ivals_context* %0, i32 %15, i32 2, i32 %3)
ret void
}