#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 /*<<< orphan*/ printf(char *, unsigned int);
unsigned rightrot(unsigned x, int n) {
  unsigned t;
  unsigned ui = 1;
  int i;
  t = (x & ~(~0 << n));
  printf("0x%x\n", t);
  for (i = 0; ui; ++i)
    ui = ui * 2;
  return (x >> n) | (t << i - n);
}


x86 assembly (clang, -O0):
<rightrot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    $0xffffffff,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1173 <rightrot+0x63>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1152 <rightrot+0x42>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
shr    %cl,%eax
mov    -0xc(%rbp),%edx
mov    -0x14(%rbp),%ecx
sub    -0x8(%rbp),%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rightrot>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    $0xffffffff,%esi
mov    %ebx,%ecx
shl    %cl,%esi
mov    %edi,%ebp
not    %esi
and    %edi,%esi
lea    0xed5(%rip),%rdi
call   1030 <printf@plt>
mov    %ebx,%ecx
ror    %cl,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"0x%x\0A\00"
define i32 @rightrot(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 1, i32* %6
%8 = load i32, i32* %3
%9 = load i32, i32* %4
%10 = shl i32 -1, %9
%11 = xor i32 %10, -1
%12 = and i32 %8, %11
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 0, i32* %7
br label %15
15: ; preds = %21, %2
%16 = load i32, i32* %6
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i32, i32* %6
%20 = mul i32 %19, 2
store i32 %20, i32* %6
br label %21
21: ; preds = %18
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %15
24: ; preds = %15
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = lshr i32 %25, %26
%28 = load i32, i32* %5
%29 = load i32, i32* %7
%30 = load i32, i32* %4
%31 = sub nsw i32 %29, %30
%32 = shl i32 %28, %31
%33 = or i32 %27, %32
ret i32 %33
}

LLVM IR (-O2):
@.str = [6 x i8] c"0x%x\0A\00"
define i32 @rightrot(i32 %0, i32 %1) {
%3 = shl nsw i32 -1, %1
%4 = xor i32 %3, -1
%5 = and i32 %4, %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = lshr i32 %0, %1
%8 = sub nsw i32 32, %1
%9 = shl i32 %0, %8
%10 = or i32 %9, %7
ret i32 %10
}