int in_gp2x_get_mmsp2_bits(void) {
  extern volatile unsigned short *gp2x_memregs;
  int value;
  value = gp2x_memregs[0x1198 >> 1] & 0xff;
  if (value == 0xFD)
    value = 0xFA;
  if (value == 0xF7)
    value = 0xEB;
  if (value == 0xDF)
    value = 0xAF;
  if (value == 0x7F)
    value = 0xBE;
  value |= gp2x_memregs[0x1184 >> 1] & 0xFF00;
  value |= gp2x_memregs[0x1186 >> 1] << 16;
  value = ~value & 0x08c0ff55;
  return value;
}


x86 assembly (clang, -O0):
<in_gp2x_get_mmsp2_bits>:
push   %rbp
mov    %rsp,%rbp
mov    0x2ed5(%rip),%rax
mov    (%rax),%rax
mov    0x1198(%rax),%ax
movzwl %ax,%eax
and    $0xff,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0xfd,-0x4(%rbp)
jne    1134 <in_gp2x_get_mmsp2_bits+0x34>
movl   $0xfa,-0x4(%rbp)
cmpl   $0xf7,-0x4(%rbp)
jne    1148 <in_gp2x_get_mmsp2_bits+0x48>
movl   $0xeb,-0x4(%rbp)
cmpl   $0xdf,-0x4(%rbp)
jne    115c <in_gp2x_get_mmsp2_bits+0x5c>
movl   $0xaf,-0x4(%rbp)
cmpl   $0x7f,-0x4(%rbp)
jne    116d <in_gp2x_get_mmsp2_bits+0x6d>
movl   $0xbe,-0x4(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%rax
mov    0x1184(%rax),%ax
movzwl %ax,%eax
and    $0xff00,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%rax
mov    0x1186(%rax),%ax
movzwl %ax,%eax
shl    $0x10,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
xor    $0xffffffff,%eax
and    $0x8c0ff55,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<in_gp2x_get_mmsp2_bits>:
mov    0x2ed9(%rip),%rax
mov    (%rax),%rax
movzwl 0x1198(%rax),%ecx
movzbl %cl,%ecx
cmp    $0xfd,%ecx
mov    $0xfa,%edx
cmovne %ecx,%edx
cmp    $0xf7,%edx
mov    $0xeb,%ecx
cmovne %edx,%ecx
cmp    $0xdf,%ecx
mov    $0xaf,%edx
cmovne %ecx,%edx
cmp    $0x7f,%dx
mov    $0x14,%ecx
cmovne %edx,%ecx
movzwl 0x1184(%rax),%edx
and    $0xff00,%edx
or     %ecx,%edx
movzwl 0x1186(%rax),%eax
shl    $0x10,%eax
or     %edx,%eax
not    %eax
and    $0x8c0ff55,%eax
ret

LLVM IR (-O0):
@gp2x_memregs = external global i16*
define i32 @in_gp2x_get_mmsp2_bits() {
%1 = alloca i32
%2 = load i16*, i16** @gp2x_memregs
%3 = getelementptr inbounds i16, i16* %2, i64 2252
%4 = load volatile i16, i16* %3
%5 = zext i16 %4 to i32
%6 = and i32 %5, 255
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 253
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 250, i32* %1
br label %10
10: ; preds = %9, %0
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, 247
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 235, i32* %1
br label %14
14: ; preds = %13, %10
%15 = load i32, i32* %1
%16 = icmp eq i32 %15, 223
br i1 %16, label %17, label %18
17: ; preds = %14
store i32 175, i32* %1
br label %18
18: ; preds = %17, %14
%19 = load i32, i32* %1
%20 = icmp eq i32 %19, 127
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 190, i32* %1
br label %22
22: ; preds = %21, %18
%23 = load i16*, i16** @gp2x_memregs
%24 = getelementptr inbounds i16, i16* %23, i64 2242
%25 = load volatile i16, i16* %24
%26 = zext i16 %25 to i32
%27 = and i32 %26, 65280
%28 = load i32, i32* %1
%29 = or i32 %28, %27
store i32 %29, i32* %1
%30 = load i16*, i16** @gp2x_memregs
%31 = getelementptr inbounds i16, i16* %30, i64 2243
%32 = load volatile i16, i16* %31
%33 = zext i16 %32 to i32
%34 = shl i32 %33, 16
%35 = load i32, i32* %1
%36 = or i32 %35, %34
store i32 %36, i32* %1
%37 = load i32, i32* %1
%38 = xor i32 %37, -1
%39 = and i32 %38, 146866005
store i32 %39, i32* %1
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@gp2x_memregs = external global i16*
define i32 @in_gp2x_get_mmsp2_bits() {
%1 = load i16*, i16** @gp2x_memregs
%2 = getelementptr inbounds i16, i16* %1, i64 2252
%3 = load volatile i16, i16* %2
%4 = and i16 %3, 255
%5 = icmp eq i16 %4, 253
%6 = select i1 %5, i16 250, i16 %4
%7 = icmp eq i16 %6, 247
%8 = select i1 %7, i16 235, i16 %6
%9 = icmp eq i16 %8, 223
%10 = select i1 %9, i16 175, i16 %8
%11 = icmp eq i16 %10, 127
%12 = select i1 %11, i16 20, i16 %10
%13 = getelementptr inbounds i16, i16* %1, i64 2242
%14 = load volatile i16, i16* %13
%15 = and i16 %14, -256
%16 = or i16 %12, %15
%17 = zext i16 %16 to i32
%18 = getelementptr inbounds i16, i16* %1, i64 2243
%19 = load volatile i16, i16* %18
%20 = zext i16 %19 to i32
%21 = shl nuw i32 %20, 16
%22 = or i32 %21, %17
%23 = and i32 %22, 146866005
%24 = xor i32 %23, 146866005
ret i32 %24
}