#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 int getbits(unsigned int, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
unsigned rightrot(unsigned x, int n) {
  unsigned x_prim = 0;
  unsigned x_sec = 0;
  unsigned x_final = 0;
  int aux = 0, index = 0;
  aux = 1;
  while (aux > 0) {
    aux *= 2;
    index++;
  }
  index++;
  printf("\nthe unsigned is represented in %d bits\n", index);
  x_prim = getbits(x, 0, n);
  x_sec = x >> n;
  x_prim = x_prim << (index - n);
  x_final = x_sec | x_prim;
  return x_final;
}


x86 assembly (clang, -O0):
<rightrot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1179 <rightrot+0x59>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1158 <rightrot+0x38>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%edx
xor    %esi,%esi
call   1040 <getbits@plt>
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
shr    %cl,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    -0x8(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
LLVM IR (-O0):
@.str = [41 x i8] c"\0Athe unsigned is represented in %d bits\0A\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
%9 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 1, i32* %8
br label %10
10: ; preds = %13, %2
%11 = load i32, i32* %8
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i32, i32* %8
%15 = mul nsw i32 %14, 2
store i32 %15, i32* %8
%16 = load i32, i32* %9
%17 = add nsw i32 %16, 1
store i32 %17, i32* %9
br label %10
18: ; preds = %10
%19 = load i32, i32* %9
%20 = add nsw i32 %19, 1
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = call i32 @getbits(i32 %23, i32 0, i32 %24)
store i32 %25, i32* %5
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = lshr i32 %26, %27
store i32 %28, i32* %6
%29 = load i32, i32* %5
%30 = load i32, i32* %9
%31 = load i32, i32* %4
%32 = sub nsw i32 %30, %31
%33 = shl i32 %29, %32
store i32 %33, i32* %5
%34 = load i32, i32* %6
%35 = load i32, i32* %5
%36 = or i32 %34, %35
store i32 %36, i32* %7
%37 = load i32, i32* %7
ret i32 %37
}

LLVM IR (-O2):