#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 bitwidth(int);
int /*<<< orphan*/ printf(char *, int, int);
int lrotate(int x, int n) {
  int y = ~(~0 << n);
  int w = bitwidth(x);
  y <<= (w - n);
  y &= x;
  int k = ~y;
  y >>= (w - n);
  x &= k;
  x <<= n;
  printf("y is 0x%x, x is 0x%x\n", y, x);
  return y | x;
}


x86 assembly (clang, -O0):
<lrotate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <bitwidth@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
sub    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%eax
shl    %cl,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%ecx
sub    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%eax
sar    %cl,%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
and    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
shl    %cl,%eax
mov    %eax,-0x4(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x4(%rbp),%edx
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
or     -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lrotate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
mov    $0xffffffff,%ebx
mov    %r14d,%ecx
shl    %cl,%ebx
not    %ebx
call   1040 <bitwidth@plt>
mov    %eax,%ecx
sub    %r14d,%ecx
shl    %cl,%ebx
and    %r15d,%ebx
mov    %ebx,%ebp
sar    %cl,%ebp
xor    %r15d,%ebx
mov    %r14d,%ecx
shl    %cl,%ebx
lea    0xea5(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
or     %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"y is 0x%x, x is 0x%x\0A\00"
define i32 @lrotate(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
%8 = load i32, i32* %4
%9 = shl i32 -1, %8
%10 = xor i32 %9, -1
store i32 %10, i32* %5
%11 = load i32, i32* %3
%12 = call i32 @bitwidth(i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = load i32, i32* %4
%15 = sub nsw i32 %13, %14
%16 = load i32, i32* %5
%17 = shl i32 %16, %15
store i32 %17, i32* %5
%18 = load i32, i32* %3
%19 = load i32, i32* %5
%20 = and i32 %19, %18
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = xor i32 %21, -1
store i32 %22, i32* %7
%23 = load i32, i32* %6
%24 = load i32, i32* %4
%25 = sub nsw i32 %23, %24
%26 = load i32, i32* %5
%27 = ashr i32 %26, %25
store i32 %27, i32* %5
%28 = load i32, i32* %7
%29 = load i32, i32* %3
%30 = and i32 %29, %28
store i32 %30, i32* %3
%31 = load i32, i32* %4
%32 = load i32, i32* %3
%33 = shl i32 %32, %31
store i32 %33, i32* %3
%34 = load i32, i32* %5
%35 = load i32, i32* %3
%36 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %34, i32 %35)
%37 = load i32, i32* %5
%38 = load i32, i32* %3
%39 = or i32 %37, %38
ret i32 %39
}

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