#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 */
typedef int uint32_t;
typedef int Priority;

/* Variables and functions */
void NVIC_DecodePriority(uint32_t Priority, uint32_t PriorityGroup,
                         uint32_t *pPreemptPriority, uint32_t *pSubPriority) {
  uint32_t PriorityGroupTmp = (PriorityGroup & 0x07);
  uint32_t PreemptPriorityBits;
  uint32_t SubPriorityBits;
  PreemptPriorityBits = ((7 - PriorityGroupTmp) > 3) ? 3 : 7 - PriorityGroupTmp;
  SubPriorityBits = ((PriorityGroupTmp + 3) < 7) ? 0 : PriorityGroupTmp - 7 + 3;
  *pPreemptPriority =
      (Priority >> SubPriorityBits) & ((1 << (PreemptPriorityBits)) - 1);
  *pSubPriority = (Priority) & ((1 << (SubPriorityBits)) - 1);
}


x86 assembly (clang, -O0):
<NVIC_DecodePriority>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
and    $0x7,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x7,%eax
sub    -0x1c(%rbp),%eax
cmp    $0x3,%eax
jle    1139 <NVIC_DecodePriority+0x39>
mov    $0x3,%eax
mov    %eax,-0x28(%rbp)
jmp    1144 <NVIC_DecodePriority+0x44>
mov    $0x7,%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x3,%eax
cmp    $0x7,%eax
jge    1163 <NVIC_DecodePriority+0x63>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    116f <NVIC_DecodePriority+0x6f>
mov    -0x1c(%rbp),%eax
sub    $0x7,%eax
add    $0x3,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x24(%rbp),%ecx
sar    %cl,%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    -0x34(%rbp),%ecx
sub    $0x1,%eax
and    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    -0x30(%rbp),%ecx
sub    $0x1,%eax
and    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<NVIC_DecodePriority>:
and    $0x7,%esi
mov    %esi,%eax
xor    $0x7,%eax
xor    %r8d,%r8d
sub    $0x4,%esi
cmovae %esi,%r8d
mov    %rcx,%r9
mov    %edi,%r10d
mov    %r8d,%ecx
sar    %cl,%r10d
cmp    $0x3,%eax
mov    $0x3,%ecx
cmovb  %eax,%ecx
mov    $0xffffffff,%eax
mov    $0xffffffff,%esi
shl    %cl,%esi
not    %esi
and    %r10d,%esi
mov    %r8d,%ecx
shl    %cl,%eax
mov    %esi,(%rdx)
not    %eax
and    %edi,%eax
mov    %eax,(%r9)
ret

LLVM IR (-O0):
define void @NVIC_DecodePriority(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%12 = load i32, i32* %6
%13 = and i32 %12, 7
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = sub nsw i32 7, %14
%16 = icmp sgt i32 %15, 3
br i1 %16, label %17, label %18
17: ; preds = %4
br label %21
18: ; preds = %4
%19 = load i32, i32* %9
%20 = sub nsw i32 7, %19
br label %21
21: ; preds = %18, %17
%22 = phi i32 [ 3, %17 ], [ %20, %18 ]
store i32 %22, i32* %10
%23 = load i32, i32* %9
%24 = add nsw i32 %23, 3
%25 = icmp slt i32 %24, 7
br i1 %25, label %26, label %27
26: ; preds = %21
br label %31
27: ; preds = %21
%28 = load i32, i32* %9
%29 = sub nsw i32 %28, 7
%30 = add nsw i32 %29, 3
br label %31
31: ; preds = %27, %26
%32 = phi i32 [ 0, %26 ], [ %30, %27 ]
store i32 %32, i32* %11
%33 = load i32, i32* %5
%34 = load i32, i32* %11
%35 = ashr i32 %33, %34
%36 = load i32, i32* %10
%37 = shl i32 1, %36
%38 = sub nsw i32 %37, 1
%39 = and i32 %35, %38
%40 = load i32*, i32** %7
store i32 %39, i32* %40
%41 = load i32, i32* %5
%42 = load i32, i32* %11
%43 = shl i32 1, %42
%44 = sub nsw i32 %43, 1
%45 = and i32 %41, %44
%46 = load i32*, i32** %8
store i32 %45, i32* %46
ret void
}

LLVM IR (-O2):
define void @NVIC_DecodePriority(i32 %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = and i32 %1, 7
%6 = xor i32 %5, 7
%7 = icmp ult i32 %6, 3
%8 = select i1 %7, i32 %6, i32 3
%9 = tail call i32 @llvm.usub.sat.i32(i32 %5, i32 4)
%10 = ashr i32 %0, %9
%11 = shl nsw i32 -1, %8
%12 = xor i32 %11, -1
%13 = and i32 %10, %12
store i32 %13, i32* %2
%14 = shl nsw i32 -1, %9
%15 = xor i32 %14, -1
%16 = and i32 %15, %0
store i32 %16, i32* %3
ret void
}