#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);
int setbits(unsigned x, int p, int n, unsigned y) {
  int tmp = (x >> (p + 1 - n)) & ~(~0 << n);
  tmp |= (~0 << n);
  printf("tmp is 0x%x\n", tmp);
  y |= (~(~0 << n));
  printf("y is 0x%x\n", y);
  return tmp & y;
}


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

x86 assembly (clang, -O2):
<setbits>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %edi,%ebx
sub    %edx,%esi
lea    0x1(%rsi),%ecx
shr    %cl,%ebx
mov    $0xffffffff,%ebp
mov    %edx,%ecx
shl    %cl,%ebp
or     %ebp,%ebx
not    %ebp
lea    0xecc(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
or     %r14d,%ebp
lea    0xec8(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
and    %ebx,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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