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


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

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

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

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