#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 /*<<< orphan*/ x;

/* Variables and functions */
int CHAR_BIT;
int /*<<< orphan*/ printbits(char *, int);
int rightrot(int x, int n) {
  unsigned int ws = sizeof(x) * CHAR_BIT;
  n %= ws;
  unsigned int mh = ~0 << (ws - n);
  if (n == 0)
    mh = 0;
  printbits("mh", mh);
  unsigned int ml = ~(~0 << n);
  printbits("ml", ml);
  unsigned int sb = x & ml;
  printbits("sb", sb);
  sb <<= ws - n;
  printbits("ls", sb);
  x >>= n;
  printbits("rs", x);
  x &= ~mh;
  printbits("nb", x);
  return x | sb;
}


x86 assembly (clang, -O0):
<rightrot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2ebb(%rip),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %edx,-0x8(%rbp)
mov    -0xc(%rbp),%ecx
sub    -0x8(%rbp),%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    115d <rightrot+0x4d>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xe99(%rip),%rdi
call   1030 <printbits@plt>
mov    -0x8(%rbp),%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe7d(%rip),%rdi
call   1030 <printbits@plt>
mov    -0x4(%rbp),%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe68(%rip),%rdi
call   1030 <printbits@plt>
mov    -0xc(%rbp),%ecx
sub    -0x8(%rbp),%ecx
mov    -0x18(%rbp),%eax
shl    %cl,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe4e(%rip),%rdi
call   1030 <printbits@plt>
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
sar    %cl,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe37(%rip),%rdi
call   1030 <printbits@plt>
mov    -0x10(%rbp),%eax
xor    $0xffffffff,%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe1f(%rip),%rdi
call   1030 <printbits@plt>
mov    -0x4(%rbp),%eax
or     -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rightrot>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%eax
mov    %edi,%r14d
mov    0x2ebc(%rip),%rcx
mov    (%rcx),%r12d
shl    $0x2,%r12d
xor    %edx,%edx
div    %r12d
mov    %edx,%r15d
sub    %edx,%r12d
mov    $0xffffffff,%ebp
mov    %r12d,%ecx
shl    %cl,%ebp
mov    $0xffffffff,%ebx
test   %edx,%edx
cmove  %edx,%ebp
lea    0xeaf(%rip),%rdi
mov    %ebp,%esi
call   1030 <printbits@plt>
mov    %r15d,%ecx
shl    %cl,%ebx
not    %ebx
lea    0xe9d(%rip),%rdi
mov    %ebx,%esi
call   1030 <printbits@plt>
and    %r14d,%ebx
lea    0xe8f(%rip),%rdi
mov    %ebx,%esi
call   1030 <printbits@plt>
mov    %r12d,%ecx
shl    %cl,%ebx
lea    0xe7f(%rip),%rdi
mov    %ebx,%esi
call   1030 <printbits@plt>
mov    %r15d,%ecx
sar    %cl,%r14d
lea    0xe6e(%rip),%rdi
mov    %r14d,%esi
call   1030 <printbits@plt>
not    %ebp
and    %r14d,%ebp
lea    0xe5d(%rip),%rdi
mov    %ebp,%esi
call   1030 <printbits@plt>
or     %ebx,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
@.str = [3 x i8] c"mh\00"
@.str.1 = [3 x i8] c"ml\00"
@.str.2 = [3 x i8] c"sb\00"
@.str.3 = [3 x i8] c"ls\00"
@.str.4 = [3 x i8] c"rs\00"
@.str.5 = [3 x i8] c"nb\00"
define i32 @rightrot(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* @CHAR_BIT
%10 = sext i32 %9 to i64
%11 = mul i64 4, %10
%12 = trunc i64 %11 to i32
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = urem i32 %14, %13
store i32 %15, i32* %4
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = sub i32 %16, %17
%19 = shl i32 -1, %18
store i32 %19, i32* %6
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %2
store i32 0, i32* %6
br label %23
23: ; preds = %22, %2
%24 = load i32, i32* %6
%25 = call i32 @printbits(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %4
%27 = shl i32 -1, %26
%28 = xor i32 %27, -1
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = call i32 @printbits(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %3
%32 = load i32, i32* %7
%33 = and i32 %31, %32
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = call i32 @printbits(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %5
%37 = load i32, i32* %4
%38 = sub i32 %36, %37
%39 = load i32, i32* %8
%40 = shl i32 %39, %38
store i32 %40, i32* %8
%41 = load i32, i32* %8
%42 = call i32 @printbits(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %4
%44 = load i32, i32* %3
%45 = ashr i32 %44, %43
store i32 %45, i32* %3
%46 = load i32, i32* %3
%47 = call i32 @printbits(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %6
%49 = xor i32 %48, -1
%50 = load i32, i32* %3
%51 = and i32 %50, %49
store i32 %51, i32* %3
%52 = load i32, i32* %3
%53 = call i32 @printbits(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = load i32, i32* %3
%55 = load i32, i32* %8
%56 = or i32 %54, %55
ret i32 %56
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@.str = [3 x i8] c"mh\00"
@.str.1 = [3 x i8] c"ml\00"
@.str.2 = [3 x i8] c"sb\00"
@.str.3 = [3 x i8] c"ls\00"
@.str.4 = [3 x i8] c"rs\00"
@.str.5 = [3 x i8] c"nb\00"
define i32 @rightrot(i32 %0, i32 %1) {
%3 = load i32, i32* @CHAR_BIT
%4 = shl i32 %3, 2
%5 = urem i32 %1, %4
%6 = sub i32 %4, %5
%7 = shl nsw i32 -1, %6
%8 = icmp eq i32 %5, 0
%9 = select i1 %8, i32 0, i32 %7
%10 = tail call i32 @printbits(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = shl nsw i32 -1, %5
%12 = xor i32 %11, -1
%13 = tail call i32 @printbits(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = and i32 %12, %0
%15 = tail call i32 @printbits(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = shl i32 %14, %6
%17 = tail call i32 @printbits(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = ashr i32 %0, %5
%19 = tail call i32 @printbits(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = xor i32 %9, -1
%21 = and i32 %18, %20
%22 = tail call i32 @printbits(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%23 = or i32 %21, %16
ret i32 %23
}