#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 setbits(unsigned x, unsigned y, int p, int n) {
  unsigned int y1, y2, xt;
  y1 = (~((~0 >> n) << n)) << p - n;
  y2 = (y & (~((~0 >> n) << n))) << p - n;
  xt = (x & ~y1) | y2;
  printf("%d\n", xt);
}


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

x86 assembly (clang, -O2):
<setbits>:
mov    %edx,%r8d
mov    $0xffffffff,%edx
shl    %cl,%edx
not    %edx
sub    %ecx,%r8d
mov    %edx,%eax
mov    %r8d,%ecx
shl    %cl,%eax
and    %edx,%esi
shl    %cl,%esi
not    %eax
and    %edi,%eax
or     %eax,%esi
lea    0xec9(%rip),%rdi
jmp    1030 <printf@plt>

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

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