#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, int p, int n, unsigned y) {
  unsigned zero_mask, clean_x, y_mask, y_bits;
  printf("%o ", x);
  zero_mask = ~(~(~0 << n) << p);
  printf(" %o ", zero_mask);
  clean_x = x & zero_mask;
  printf(" %o ", clean_x);
  y_mask = ~(~0 << n);
  y_bits = (y & y_mask) << p;
  return (y_bits | clean_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    -0x4(%rbp),%esi
lea    0xed3(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
mov    -0x8(%rbp),%ecx
shl    %cl,%eax
xor    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
and    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
or     -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

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

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