#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 dec_bin(unsigned short);
int /*<<< orphan*/ printf(char *, int);
unsigned short int rightrot(unsigned short int x, unsigned short int n) {
  unsigned short int first = 0;
  unsigned short int second = 0;
  unsigned short int third = 0;
  unsigned short int fourth = 0;
  first = x & (~(~0 << n));
  printf("first = %52d;\n", dec_bin(first));
  second = x >> n;
  printf("second = %51d;\n", dec_bin(second));
  third = first << (16 - n);
  printf("third = %52lu;\n", dec_bin(third));
  fourth = (second | third);
  printf("fourth = %51lu;\n\n", dec_bin(fourth));
  return fourth;
}


x86 assembly (clang, -O0):
<rightrot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %si,%ax
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %ax,-0x4(%rbp)
movw   $0x0,-0x6(%rbp)
movw   $0x0,-0x8(%rbp)
movw   $0x0,-0xa(%rbp)
movw   $0x0,-0xc(%rbp)
movzwl -0x2(%rbp),%eax
movzwl -0x4(%rbp),%ecx
mov    $0xffffffff,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %ax,-0x6(%rbp)
movzwl -0x6(%rbp),%edi
call   1040 <dec_bin@plt>
mov    %eax,%esi
lea    0xe86(%rip),%rdi
call   1030 <printf@plt>
movzwl -0x2(%rbp),%eax
movzwl -0x4(%rbp),%ecx
sar    %cl,%eax
mov    %ax,-0x8(%rbp)
movzwl -0x8(%rbp),%edi
call   1040 <dec_bin@plt>
mov    %eax,%esi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
movzwl -0x6(%rbp),%eax
movzwl -0x4(%rbp),%edx
mov    $0x10,%ecx
sub    %edx,%ecx
shl    %cl,%eax
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%edi
call   1040 <dec_bin@plt>
mov    %eax,%esi
lea    0xe54(%rip),%rdi
call   1030 <printf@plt>
movzwl -0x8(%rbp),%eax
movzwl -0xa(%rbp),%ecx
or     %ecx,%eax
mov    %ax,-0xc(%rbp)
movzwl -0xc(%rbp),%edi
call   1040 <dec_bin@plt>
mov    %eax,%esi
lea    0xe3f(%rip),%rdi
call   1030 <printf@plt>
movzwl -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rightrot>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    $0xffffffff,%ebx
mov    %r14d,%ecx
shl    %cl,%ebx
mov    %edi,%ebp
not    %ebx
and    %edi,%ebx
mov    %ebx,%edi
call   1040 <dec_bin@plt>
lea    0xebb(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r14d,%ecx
shr    %cl,%ebp
mov    %ebp,%edi
call   1040 <dec_bin@plt>
lea    0xeb0(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x10,%cl
sub    %r14b,%cl
shl    %cl,%ebx
movzwl %bx,%edi
call   1040 <dec_bin@plt>
lea    0xea3(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
or     %ebp,%ebx
movzwl %bx,%ebx
mov    %ebx,%edi
call   1040 <dec_bin@plt>
lea    0xe99(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"first = %52d;\0A\00"
@.str.1 = [16 x i8] c"second = %51d;\0A\00"
@.str.2 = [16 x i8] c"third = %52lu;\0A\00"
@.str.3 = [18 x i8] c"fourth = %51lu;\0A\0A\00"
define zeroext i16 @rightrot(i16 zeroext %0, i16 zeroext %1) {
%3 = alloca i16
%4 = alloca i16
%5 = alloca i16
%6 = alloca i16
%7 = alloca i16
%8 = alloca i16
store i16 %0, i16* %3
store i16 %1, i16* %4
store i16 0, i16* %5
store i16 0, i16* %6
store i16 0, i16* %7
store i16 0, i16* %8
%9 = load i16, i16* %3
%10 = zext i16 %9 to i32
%11 = load i16, i16* %4
%12 = zext i16 %11 to i32
%13 = shl i32 -1, %12
%14 = xor i32 %13, -1
%15 = and i32 %10, %14
%16 = trunc i32 %15 to i16
store i16 %16, i16* %5
%17 = load i16, i16* %5
%18 = call i32 @dec_bin(i16 zeroext %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = load i16, i16* %3
%21 = zext i16 %20 to i32
%22 = load i16, i16* %4
%23 = zext i16 %22 to i32
%24 = ashr i32 %21, %23
%25 = trunc i32 %24 to i16
store i16 %25, i16* %6
%26 = load i16, i16* %6
%27 = call i32 @dec_bin(i16 zeroext %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i16, i16* %5
%30 = zext i16 %29 to i32
%31 = load i16, i16* %4
%32 = zext i16 %31 to i32
%33 = sub nsw i32 16, %32
%34 = shl i32 %30, %33
%35 = trunc i32 %34 to i16
store i16 %35, i16* %7
%36 = load i16, i16* %7
%37 = call i32 @dec_bin(i16 zeroext %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %37)
%39 = load i16, i16* %6
%40 = zext i16 %39 to i32
%41 = load i16, i16* %7
%42 = zext i16 %41 to i32
%43 = or i32 %40, %42
%44 = trunc i32 %43 to i16
store i16 %44, i16* %8
%45 = load i16, i16* %8
%46 = call i32 @dec_bin(i16 zeroext %45)
%47 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %46)
%48 = load i16, i16* %8
ret i16 %48
}

LLVM IR (-O2):
@.str = [15 x i8] c"first = %52d;\0A\00"
@.str.1 = [16 x i8] c"second = %51d;\0A\00"
@.str.2 = [16 x i8] c"third = %52lu;\0A\00"
@.str.3 = [18 x i8] c"fourth = %51lu;\0A\0A\00"
define zeroext i16 @rightrot(i16 zeroext %0, i16 zeroext %1) {
%3 = zext i16 %0 to i32
%4 = zext i16 %1 to i32
%5 = shl nsw i32 -1, %4
%6 = trunc i32 %5 to i16
%7 = xor i16 %6, -1
%8 = and i16 %7, %0
%9 = tail call i32 @dec_bin(i16 zeroext %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = lshr i32 %3, %4
%12 = trunc i32 %11 to i16
%13 = tail call i32 @dec_bin(i16 zeroext %12)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = zext i16 %8 to i32
%16 = sub nsw i32 16, %4
%17 = shl nuw i32 %15, %16
%18 = trunc i32 %17 to i16
%19 = tail call i32 @dec_bin(i16 zeroext %18)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = or i32 %17, %11
%22 = trunc i32 %21 to i16
%23 = tail call i32 @dec_bin(i16 zeroext %22)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %23)
ret i16 %22
}