#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 */

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int MappedEventGet(int dspInt) {
  int indx;
  int num;
  unsigned long tmp;
  unsigned long last;
  if (dspInt < 4 || dspInt > 15) {
    printf("bad dsp_int\n");
    return -1;
  }
  indx = dspInt % 4;
  num = dspInt / 4 - 1;
  tmp = ({
    unsigned long __v =
        (*(volatile unsigned long *)(((0x01800000 + 0x104) + (num * 4))));
    __v;
  });
  last = ((tmp & (0xff << (indx * 8))) >> (indx * 8));
  return (int)last;
}


x86 assembly (clang, -O0):
<MappedEventGet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     112f <MappedEventGet+0x1f>
cmpl   $0xf,-0x8(%rbp)
jle    1147 <MappedEventGet+0x37>
lea    0xeca(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <MappedEventGet+0xa9>
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x2,%eax
add    $0x1800104,%eax
cltq
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
shl    $0x3,%ecx
mov    $0xff,%edx
shl    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
and    %rcx,%rax
mov    -0xc(%rbp),%ecx
shl    $0x3,%ecx
mov    %ecx,%ecx
shr    %cl,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MappedEventGet>:
push   %rax
mov    %edi,%ecx
lea    -0x10(%rcx),%eax
cmp    $0xfffffff3,%eax
ja     112e <MappedEventGet+0x1e>
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
mov    %ecx,%edx
shl    $0x3,%ecx
mov    $0xff,%eax
shl    %cl,%eax
and    $0xfc,%edx
cltq
and    0x1800100(%rdx),%rax
and    $0x18,%cl
shr    %cl,%rax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"bad dsp_int\0A\00"
define i32 @MappedEventGet(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i32 %0, i32* %3
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 4
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i32, i32* %3
%14 = icmp sgt i32 %13, 15
br i1 %14, label %15, label %17
15: ; preds = %12, %1
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %43
17: ; preds = %12
%18 = load i32, i32* %3
%19 = srem i32 %18, 4
store i32 %19, i32* %4
%20 = load i32, i32* %3
%21 = sdiv i32 %20, 4
%22 = sub nsw i32 %21, 1
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = mul nsw i32 %23, 4
%25 = add nsw i32 25166084, %24
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i64*
%28 = load volatile i64, i64* %27
store i64 %28, i64* %8
%29 = load i64, i64* %8
store i64 %29, i64* %9
%30 = load i64, i64* %9
store i64 %30, i64* %6
%31 = load i64, i64* %6
%32 = load i32, i32* %4
%33 = mul nsw i32 %32, 8
%34 = shl i32 255, %33
%35 = sext i32 %34 to i64
%36 = and i64 %31, %35
%37 = load i32, i32* %4
%38 = mul nsw i32 %37, 8
%39 = zext i32 %38 to i64
%40 = lshr i64 %36, %39
store i64 %40, i64* %7
%41 = load i64, i64* %7
%42 = trunc i64 %41 to i32
store i32 %42, i32* %2
br label %43
43: ; preds = %17, %15
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
@str = [12 x i8] c"bad dsp_int\00"
define i32 @MappedEventGet(i32 %0) {
%2 = add i32 %0, -16
%3 = icmp ult i32 %2, -12
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %20
6: ; preds = %1
%7 = and i32 %0, 252
%8 = or i32 %7, 25166080
%9 = zext i32 %8 to i64
%10 = inttoptr i64 %9 to i64*
%11 = load volatile i64, i64* %10
%12 = shl nuw nsw i32 %0, 3
%13 = and i32 %12, 24
%14 = shl nuw i32 255, %13
%15 = sext i32 %14 to i64
%16 = and i64 %11, %15
%17 = zext i32 %13 to i64
%18 = lshr i64 %16, %17
%19 = trunc i64 %18 to i32
br label %20
20: ; preds = %6, %4
%21 = phi i32 [ -1, %4 ], [ %19, %6 ]
ret i32 %21
}