#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 */
unsigned int getbits(unsigned int, int /*<<< orphan*/, int);
unsigned setbits(unsigned x, int p, int n, int y) {
  unsigned x_prim = 0;
  unsigned y_prim = 0;
  unsigned x_sec = 0;
  unsigned x_final = 0;
  x_prim = ((x >> (p + 1 - n)) >> n) << n;
  y_prim = getbits(y, 0, n);
  x_sec = (x_prim | y_prim);
  x_final = ((x_sec << (p + 1 - n)) | getbits(x, 0, (p + 1 - n)));
  return x_final;
}


x86 assembly (clang, -O0):
<setbits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
sub    -0xc(%rbp),%ecx
shr    %cl,%eax
mov    -0xc(%rbp),%ecx
shr    %cl,%eax
mov    -0xc(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1030 <getbits@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
sub    -0xc(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%edx
add    $0x1,%edx
sub    -0xc(%rbp),%edx
xor    %esi,%esi
call   1030 <getbits@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setbits>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%eax
mov    %edi,%r14d
sub    %edx,%esi
lea    0x1(%rsi),%r15d
mov    %edi,%ebp
mov    %r15d,%ecx
shr    %cl,%ebp
mov    %edx,%ecx
shr    %cl,%ebp
shl    %cl,%ebp
mov    %eax,%edi
xor    %esi,%esi
call   1030 <getbits@plt>
mov    %eax,%ebx
or     %ebp,%ebx
mov    %r15d,%ecx
shl    %cl,%ebx
mov    %r14d,%edi
xor    %esi,%esi
mov    %r15d,%edx
call   1030 <getbits@plt>
or     %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
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* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 1
%16 = load i32, i32* %7
%17 = sub nsw i32 %15, %16
%18 = lshr i32 %13, %17
%19 = load i32, i32* %7
%20 = lshr i32 %18, %19
%21 = load i32, i32* %7
%22 = shl i32 %20, %21
store i32 %22, i32* %9
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = call i32 @getbits(i32 %23, i32 0, i32 %24)
store i32 %25, i32* %10
%26 = load i32, i32* %9
%27 = load i32, i32* %10
%28 = or i32 %26, %27
store i32 %28, i32* %11
%29 = load i32, i32* %11
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
%32 = load i32, i32* %7
%33 = sub nsw i32 %31, %32
%34 = shl i32 %29, %33
%35 = load i32, i32* %5
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %7
%39 = sub nsw i32 %37, %38
%40 = call i32 @getbits(i32 %35, i32 0, i32 %39)
%41 = or i32 %34, %40
store i32 %41, i32* %12
%42 = load i32, i32* %12
ret i32 %42
}

LLVM IR (-O2):
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 = and i32 %7, %8
%10 = tail call i32 @getbits(i32 %3, i32 0, i32 %2)
%11 = or i32 %10, %9
%12 = shl i32 %11, %6
%13 = tail call i32 @getbits(i32 %0, i32 0, i32 %6)
%14 = or i32 %12, %13
ret i32 %14
}