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


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    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0xffffffff,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%esi
lea    0xebb(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
sub    -0xc(%rbp),%ecx
mov    $0xffffffff,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
shr    %cl,%eax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
shl    %cl,%eax
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
sub    -0xc(%rbp),%ecx
shl    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

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

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