#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;

/* Variables and functions */
int get_magic_number(int, int, int);
uint32_t reduce(uint32_t rn, int rank, int var_p, int value) {
  register uint32_t rn_masked;
  rn_masked = (rn & get_magic_number(rank, var_p, value));
  if (!value)
    return rn_masked | (rn_masked << (1 << var_p));
  return rn_masked | (rn_masked >> (1 << var_p));
}


x86 assembly (clang, -O0):
<reduce>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <get_magic_number@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    116c <reduce+0x5c>
mov    -0x18(%rbp),%eax
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    $0x1,%esi
shl    %cl,%esi
mov    %esi,%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1187 <reduce+0x77>
mov    -0x18(%rbp),%eax
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    $0x1,%esi
shl    %cl,%esi
mov    %esi,%ecx
sar    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reduce>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %edi,%r14d
mov    %esi,%edi
mov    %edx,%esi
mov    %ecx,%edx
call   1030 <get_magic_number@plt>
mov    $0x1,%edx
mov    %ebp,%ecx
shl    %cl,%edx
and    %r14d,%eax
mov    %eax,%esi
mov    %edx,%ecx
sar    %cl,%esi
mov    %eax,%edi
shl    %cl,%edi
test   %ebx,%ebx
cmovne %esi,%edi
or     %edi,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @reduce(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
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = load i32, i32* %9
%15 = call i32 @get_magic_number(i32 %12, i32 %13, i32 %14)
%16 = and i32 %11, %15
store i32 %16, i32* %10
%17 = load i32, i32* %9
%18 = icmp ne i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %4
%20 = load i32, i32* %10
%21 = load i32, i32* %10
%22 = load i32, i32* %8
%23 = shl i32 1, %22
%24 = shl i32 %21, %23
%25 = or i32 %20, %24
store i32 %25, i32* %5
br label %33
26: ; preds = %4
%27 = load i32, i32* %10
%28 = load i32, i32* %10
%29 = load i32, i32* %8
%30 = shl i32 1, %29
%31 = ashr i32 %28, %30
%32 = or i32 %27, %31
store i32 %32, i32* %5
br label %33
33: ; preds = %26, %19
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
define i32 @reduce(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @get_magic_number(i32 %1, i32 %2, i32 %3)
%6 = and i32 %5, %0
%7 = icmp eq i32 %3, 0
%8 = shl nuw i32 1, %2
%9 = ashr i32 %6, %8
%10 = shl i32 %6, %8
%11 = select i1 %7, i32 %10, i32 %9
%12 = or i32 %11, %6
ret i32 %12
}