#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 */
unsigned long BSP_ReadIfr();
int /*<<< orphan*/ BSP_WriteIcr(unsigned long);
int /*<<< orphan*/ printf(char *, unsigned int);
int BSP_AckDspInterrupt(unsigned int dspInt) {
  unsigned long tmp;
  if (dspInt > 15 || dspInt < 4) {
    printf("bad dsp_int%d\n", dspInt);
    return -1;
  }
  tmp = BSP_ReadIfr();
  if (tmp & (1 << dspInt)) {
    tmp = 0;
    tmp |= (1 << dspInt);
    BSP_WriteIcr(tmp);
  } else {
    printf("dsp_int%d is not exist\n", dspInt);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<BSP_AckDspInterrupt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0xf,-0x8(%rbp)
ja     114f <BSP_AckDspInterrupt+0x1f>
cmpl   $0x4,-0x8(%rbp)
jae    116a <BSP_AckDspInterrupt+0x3a>
mov    -0x8(%rbp),%esi
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <BSP_AckDspInterrupt+0xb1>
mov    $0x0,%al
call   1040 <BSP_ReadIfr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     11bf <BSP_AckDspInterrupt+0x8f>
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <BSP_WriteIcr@plt>
jmp    11da <BSP_AckDspInterrupt+0xaa>
mov    -0x8(%rbp),%esi
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <BSP_AckDspInterrupt+0xb1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BSP_AckDspInterrupt>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
lea    -0x10(%rbx),%eax
cmp    $0xfffffff3,%eax
ja     1146 <BSP_AckDspInterrupt+0x16>
lea    0xebc(%rip),%rdi
jmp    116c <BSP_AckDspInterrupt+0x3c>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <BSP_ReadIfr@plt>
mov    $0x1,%edi
mov    %ebx,%ecx
shl    %cl,%edi
bt     %rbx,%rax
jae    1165 <BSP_AckDspInterrupt+0x35>
call   1050 <BSP_WriteIcr@plt>
jmp    1178 <BSP_AckDspInterrupt+0x48>
lea    0xea3(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"bad dsp_int%d\0A\00"
@.str.1 = [24 x i8] c"dsp_int%d is not exist\0A\00"
define i32 @BSP_AckDspInterrupt(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp ugt i32 %5, 15
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp ult i32 %8, 4
br i1 %9, label %10, label %13
10: ; preds = %7, %1
%11 = load i32, i32* %3
%12 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 -1, i32* %2
br label %33
13: ; preds = %7
%14 = call i64 (...) @BSP_ReadIfr()
store i64 %14, i64* %4
%15 = load i64, i64* %4
%16 = load i32, i32* %3
%17 = shl i32 1, %16
%18 = sext i32 %17 to i64
%19 = and i64 %15, %18
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %13
store i64 0, i64* %4
%22 = load i32, i32* %3
%23 = shl i32 1, %22
%24 = sext i32 %23 to i64
%25 = load i64, i64* %4
%26 = or i64 %25, %24
store i64 %26, i64* %4
%27 = load i64, i64* %4
%28 = call i32 @BSP_WriteIcr(i64 %27)
br label %32
29: ; preds = %13
%30 = load i32, i32* %3
%31 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %30)
store i32 -1, i32* %2
br label %33
32: ; preds = %21
store i32 0, i32* %2
br label %33
33: ; preds = %32, %29, %10
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [15 x i8] c"bad dsp_int%d\0A\00"
@.str.1 = [24 x i8] c"dsp_int%d is not exist\0A\00"
define i32 @BSP_AckDspInterrupt(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 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %16
6: ; preds = %1
%7 = tail call i64 (...) @BSP_ReadIfr()
%8 = shl nuw nsw i32 1, %0
%9 = zext i32 %8 to i64
%10 = and i64 %7, %9
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %6
%13 = tail call i32 @BSP_WriteIcr(i64 %9)
br label %16
14: ; preds = %6
%15 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %16
16: ; preds = %12, %14, %4
%17 = phi i32 [ -1, %4 ], [ 0, %12 ], [ -1, %14 ]
ret i32 %17
}