#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 MapDspInt(int efnum, int dspInt) {
  int indx;
  int num;
  unsigned long tmp;
  unsigned long last;
  if (dspInt < 4 || dspInt > 15) {
    printf("bad dsp_int\n");
    return -1;
  }
  if (efnum > 128) {
    printf("bad efnum \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));
  tmp &= ~(0xff << (indx * 8));
  tmp |= (efnum << (indx * 8));
  ({
    unsigned long __v = tmp;
    (*(volatile unsigned long *)(((0x01800000 + 0x104) + (num * 4))) = (__v));
    __v;
  });
  printf("map %d to dsp %d, in register 0x%08x\n", efnum, dspInt,
         ((0x01800000 + 0x104) + (num * 4)));
  printf("COREPAC_INT_MUX_REG(%d) is now 0x%08x\n", num, ({
           unsigned long __v = (*(
               volatile unsigned long *)(((0x01800000 + 0x104) + (num * 4))));
           __v;
         }));
  return (int)last;
}


x86 assembly (clang, -O0):
<MapDspInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jl     1132 <MapDspInt+0x22>
cmpl   $0xf,-0xc(%rbp)
jle    114c <MapDspInt+0x3c>
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1289 <MapDspInt+0x179>
cmpl   $0x80,-0x8(%rbp)
jle    1173 <MapDspInt+0x63>
lea    0xead(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1289 <MapDspInt+0x179>
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
add    $0x1800104,%eax
cltq
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%ecx
shl    $0x3,%ecx
mov    $0xff,%edx
shl    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
and    %rcx,%rax
mov    -0x10(%rbp),%ecx
shl    $0x3,%ecx
mov    %ecx,%ecx
shr    %cl,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%ecx
shl    $0x3,%ecx
mov    $0xff,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
cltq
and    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
cltq
or     -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
add    $0x1800104,%eax
cltq
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
add    $0x1800104,%ecx
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
add    $0x1800104,%eax
cltq
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdx
lea    0xdc4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MapDspInt>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%edx
lea    -0x10(%rdx),%eax
cmp    $0xfffffff3,%eax
ja     1137 <MapDspInt+0x17>
lea    0xf23(%rip),%rdi
jmp    1149 <MapDspInt+0x29>
mov    %edi,%r10d
cmp    $0x81,%edi
jl     1158 <MapDspInt+0x38>
lea    0xf04(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    11db <MapDspInt+0xbb>
mov    %edx,%r14d
shr    $0x2,%r14d
add    $0xffffffff,%r14d
lea    0x1800104(,%r14,4),%r8
01
lea    0x0(,%rdx,8),%edi
mov    $0xff,%ebx
mov    %edi,%ecx
shl    %cl,%ebx
mov    0x1800104(,%r14,4),%r9
01
and    $0x18,%cl
movslq %ebx,%rax
mov    %r9,%rbx
and    %rax,%rbx
shr    %cl,%rbx
not    %eax
cltq
mov    %r10d,%esi
mov    %edi,%ecx
shl    %cl,%esi
and    %r9,%rax
movslq %esi,%rcx
or     %rax,%rcx
mov    %rcx,0x1800104(,%r14,4)
01
lea    0xe4b(%rip),%rdi
mov    %r10d,%esi
mov    %r8d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x1800104(,%r14,4),%rdx
01
lea    0xe55(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"bad dsp_int\0A\00"
@.str.1 = [12 x i8] c"bad efnum \0A\00"
@.str.2 = [38 x i8] c"map %d to dsp %d, in register 0x%08x\0A\00"
@.str.3 = [39 x i8] c"COREPAC_INT_MUX_REG(%d) is now 0x%08x\0A\00"
define i32 @MapDspInt(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
store i32 %0, i32* %4
store i32 %1, i32* %5
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 4
br i1 %17, label %21, label %18
18: ; preds = %2
%19 = load i32, i32* %5
%20 = icmp sgt i32 %19, 15
br i1 %20, label %21, label %23
21: ; preds = %18, %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %93
23: ; preds = %18
%24 = load i32, i32* %4
%25 = icmp sgt i32 %24, 128
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %93
28: ; preds = %23
%29 = load i32, i32* %5
%30 = srem i32 %29, 4
store i32 %30, i32* %6
%31 = load i32, i32* %5
%32 = sdiv i32 %31, 4
%33 = sub nsw i32 %32, 1
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = mul nsw i32 %34, 4
%36 = add nsw i32 25166084, %35
%37 = sext i32 %36 to i64
%38 = inttoptr i64 %37 to i64*
%39 = load volatile i64, i64* %38
store i64 %39, i64* %10
%40 = load i64, i64* %10
store i64 %40, i64* %11
%41 = load i64, i64* %11
store i64 %41, i64* %8
%42 = load i64, i64* %8
%43 = load i32, i32* %6
%44 = mul nsw i32 %43, 8
%45 = shl i32 255, %44
%46 = sext i32 %45 to i64
%47 = and i64 %42, %46
%48 = load i32, i32* %6
%49 = mul nsw i32 %48, 8
%50 = zext i32 %49 to i64
%51 = lshr i64 %47, %50
store i64 %51, i64* %9
%52 = load i32, i32* %6
%53 = mul nsw i32 %52, 8
%54 = shl i32 255, %53
%55 = xor i32 %54, -1
%56 = sext i32 %55 to i64
%57 = load i64, i64* %8
%58 = and i64 %57, %56
store i64 %58, i64* %8
%59 = load i32, i32* %4
%60 = load i32, i32* %6
%61 = mul nsw i32 %60, 8
%62 = shl i32 %59, %61
%63 = sext i32 %62 to i64
%64 = load i64, i64* %8
%65 = or i64 %64, %63
store i64 %65, i64* %8
%66 = load i64, i64* %8
store i64 %66, i64* %12
%67 = load i64, i64* %12
%68 = load i32, i32* %7
%69 = mul nsw i32 %68, 4
%70 = add nsw i32 25166084, %69
%71 = sext i32 %70 to i64
%72 = inttoptr i64 %71 to i64*
store volatile i64 %67, i64* %72
%73 = load i64, i64* %12
store i64 %73, i64* %13
%74 = load i64, i64* %13
%75 = load i32, i32* %4
%76 = load i32, i32* %5
%77 = load i32, i32* %7
%78 = mul nsw i32 %77, 4
%79 = add nsw i32 25166084, %78
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %75, i32 %76, i32 %79)
%81 = load i32, i32* %7
%82 = load i32, i32* %7
%83 = mul nsw i32 %82, 4
%84 = add nsw i32 25166084, %83
%85 = sext i32 %84 to i64
%86 = inttoptr i64 %85 to i64*
%87 = load volatile i64, i64* %86
store i64 %87, i64* %14
%88 = load i64, i64* %14
store i64 %88, i64* %15
%89 = load i64, i64* %15
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %81, i64 %89)
%91 = load i64, i64* %9
%92 = trunc i64 %91 to i32
store i32 %92, i32* %3
br label %93
93: ; preds = %28, %26, %21
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@.str.2 = [38 x i8] c"map %d to dsp %d, in register 0x%08x\0A\00"
@.str.3 = [39 x i8] c"COREPAC_INT_MUX_REG(%d) is now 0x%08x\0A\00"
@str = [11 x i8] c"bad efnum \00"
@str.4 = [12 x i8] c"bad dsp_int\00"
define i32 @MapDspInt(i32 %0, i32 %1) {
%3 = add i32 %1, -16
%4 = icmp ult i32 %3, -12
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.4, i64 0, i64 0))
br label %36
7: ; preds = %2
%8 = icmp sgt i32 %0, 128
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %36
11: ; preds = %7
%12 = lshr i32 %1, 2
%13 = add nsw i32 %12, -1
%14 = shl nuw nsw i32 %13, 2
%15 = add nuw nsw i32 %14, 25166084
%16 = zext i32 %15 to i64
%17 = inttoptr i64 %16 to i64*
%18 = load volatile i64, i64* %17
%19 = shl nuw nsw i32 %1, 3
%20 = and i32 %19, 24
%21 = shl nuw i32 255, %20
%22 = sext i32 %21 to i64
%23 = and i64 %18, %22
%24 = zext i32 %20 to i64
%25 = lshr i64 %23, %24
%26 = xor i32 %21, -1
%27 = sext i32 %26 to i64
%28 = and i64 %18, %27
%29 = shl i32 %0, %20
%30 = sext i32 %29 to i64
%31 = or i64 %28, %30
store volatile i64 %31, i64* %17
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %1, i32 %15)
%33 = load volatile i64, i64* %17
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %13, i64 %33)
%35 = trunc i64 %25 to i32
br label %36
36: ; preds = %11, %9, %5
%37 = phi i32 [ -1, %5 ], [ -1, %9 ], [ %35, %11 ]
ret i32 %37
}