#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 wordlenght();
unsigned rightword(unsigned x, int n) {
  int wordlength(void);
  unsigned rbits;
  if ((n = n % wordlenght()) > 0) {
    rbits = ~(~0 << n) & x;
    rbits = rbits << (wordlength() - n);
    x = x >> n;
    x = x | rbits;
  }
  return x;
}


x86 assembly (clang, -O0):
<rightword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <wordlenght@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
cmp    $0x0,%edx
jle    118e <rightword+0x6e>
mov    -0x8(%rbp),%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
and    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
call   1040 <wordlength@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    -0x8(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
shr    %cl,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rightword>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %edi,%r14d
xor    %eax,%eax
call   1030 <wordlenght@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
test   %edx,%edx
jle    115e <rightword+0x3e>
mov    %edx,%ebp
mov    $0xffffffff,%ebx
mov    %ebp,%ecx
shl    %cl,%ebx
not    %ebx
and    %r14d,%ebx
call   1040 <wordlength@plt>
sub    %ebp,%eax
mov    %eax,%ecx
shl    %cl,%ebx
mov    %ebp,%ecx
shr    %cl,%r14d
or     %ebx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rightword(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = call i32 (...) @wordlenght()
%8 = srem i32 %6, %7
store i32 %8, i32* %4
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %27
10: ; preds = %2
%11 = load i32, i32* %4
%12 = shl i32 -1, %11
%13 = xor i32 %12, -1
%14 = load i32, i32* %3
%15 = and i32 %13, %14
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = call i32 @wordlength()
%18 = load i32, i32* %4
%19 = sub nsw i32 %17, %18
%20 = shl i32 %16, %19
store i32 %20, i32* %5
%21 = load i32, i32* %3
%22 = load i32, i32* %4
%23 = lshr i32 %21, %22
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = load i32, i32* %5
%26 = or i32 %24, %25
store i32 %26, i32* %3
br label %27
27: ; preds = %10, %2
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
define i32 @rightword(i32 %0, i32 %1) {
%3 = tail call i32 (...) @wordlenght()
%4 = srem i32 %1, %3
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = shl nsw i32 -1, %4
%8 = xor i32 %7, -1
%9 = and i32 %8, %0
%10 = tail call i32 @wordlength()
%11 = sub nsw i32 %10, %4
%12 = shl i32 %9, %11
%13 = lshr i32 %0, %4
%14 = or i32 %12, %13
br label %15
15: ; preds = %6, %2
%16 = phi i32 [ %14, %6 ], [ %0, %2 ]
ret i32 %16
}