#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ shm_write16(struct ivals_context *, unsigned int,
                               unsigned int, unsigned int);
int /*<<< orphan*/ shm_write32(struct ivals_context *, unsigned int,
                               unsigned int, unsigned int);
int /*<<< orphan*/ stderr;
void assemble_write_shm(struct ivals_context *ctx, unsigned int routing,
                        unsigned int offset, unsigned int value,
                        unsigned int size) {
  switch (routing & 0xFF) {
  case 0:
  case 1:
  case 2:
  case 3:
  case 4:
    break;
  default:
    break;
  }
  switch (size) {
  case 2:
    shm_write16(ctx, routing, offset, value);
    break;
  case 4:
    shm_write32(ctx, routing, offset, value);
    break;
  default:
    fprintf(stderr, "Internal assembler BUG. SHMwrite invalid size\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<assemble_write_shm>:
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    %r8d,-0x18(%rbp)
movzbl -0xc(%rbp),%eax
sub    $0x4,%eax
ja     1170 <assemble_write_shm+0x30>
jmp    116b <assemble_write_shm+0x2b>
jmp    1175 <assemble_write_shm+0x35>
jmp    1175 <assemble_write_shm+0x35>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x2,%eax
je     119a <assemble_write_shm+0x5a>
jmp    1189 <assemble_write_shm+0x49>
mov    -0x1c(%rbp),%eax
sub    $0x4,%eax
je     11b1 <assemble_write_shm+0x71>
jmp    11c8 <assemble_write_shm+0x88>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1040 <shm_write16@plt>
jmp    11e7 <assemble_write_shm+0xa7>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1050 <shm_write32@plt>
jmp    11e7 <assemble_write_shm+0xa7>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assemble_write_shm>:
cmp    $0x4,%r8d
je     1151 <assemble_write_shm+0x11>
cmp    $0x2,%r8d
jne    1156 <assemble_write_shm+0x16>
jmp    1040 <shm_write16@plt>
jmp    1050 <shm_write32@plt>
push   %rax
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
lea    0xe99(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.ivals_context = type { i32 }
@stderr = global i32 0
@.str = [47 x i8] c"Internal assembler BUG. SHMwrite invalid size\0A\00"
define void @assemble_write_shm(%struct.ivals_context* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.ivals_context*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store %struct.ivals_context* %0, %struct.ivals_context** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%11 = load i32, i32* %7
%12 = and i32 %11, 255
switch i32 %12, label %14 [
i32 0, label %13
i32 1, label %13
i32 2, label %13
i32 3, label %13
i32 4, label %13
]
13: ; preds = %5, %5, %5, %5, %5
br label %15
14: ; preds = %5
br label %15
15: ; preds = %14, %13
%16 = load i32, i32* %10
switch i32 %16, label %29 [
i32 2, label %17
i32 4, label %23
]
17: ; preds = %15
%18 = load %struct.ivals_context*, %struct.ivals_context** %6
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = load i32, i32* %9
%22 = call i32 @shm_write16(%struct.ivals_context* %18, i32 %19, i32 %20, i32 %21)
br label %33
23: ; preds = %15
%24 = load %struct.ivals_context*, %struct.ivals_context** %6
%25 = load i32, i32* %7
%26 = load i32, i32* %8
%27 = load i32, i32* %9
%28 = call i32 @shm_write32(%struct.ivals_context* %24, i32 %25, i32 %26, i32 %27)
br label %33
29: ; preds = %15
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %23, %17
ret void
}

LLVM IR (-O2):
%struct.ivals_context = type { i32 }
@stderr = global i32 0
@.str = [47 x i8] c"Internal assembler BUG. SHMwrite invalid size\0A\00"
define void @assemble_write_shm(%struct.ivals_context* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
switch i32 %4, label %10 [
i32 2, label %6
i32 4, label %8
]
6: ; preds = %5
%7 = tail call i32 @shm_write16(%struct.ivals_context* %0, i32 %1, i32 %2, i32 %3)
br label %14
8: ; preds = %5
%9 = tail call i32 @shm_write32(%struct.ivals_context* %0, i32 %1, i32 %2, i32 %3)
br label %14
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8, %6
ret void
}