#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 dec_bin(unsigned short);
int /*<<< orphan*/ printf(char *, int);
int setbits2(int x, int p, int n, int y) {
  int first = 0;
  int second = 0;
  unsigned short int third = 0;
  unsigned short int fourth = 0;
  first = ((~(~0 << n) << (p + n + 1)));
  printf("first = %42d;\n", dec_bin(first));
  second = ((y & (~(~0 << n))) << (p + n + 1));
  printf("second = %41d;\n", dec_bin(second));
  third = x & (~first);
  printf("third = %42d;\n", dec_bin(third));
  fourth = third | second;
  printf("fourth = %41d;\n\n", dec_bin(fourth));
  return fourth;
}


x86 assembly (clang, -O0):
<setbits2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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)
movw   $0x0,-0x1a(%rbp)
movw   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
mov    -0x8(%rbp),%ecx
add    -0xc(%rbp),%ecx
add    $0x1,%ecx
shl    %cl,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
movzwl %ax,%edi
call   1040 <dec_bin@plt>
mov    %eax,%esi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0xffffffff,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    -0x8(%rbp),%ecx
add    -0xc(%rbp),%ecx
add    $0x1,%ecx
shl    %cl,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
movzwl %ax,%edi
call   1040 <dec_bin@plt>
mov    %eax,%esi
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    -0x14(%rbp),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %ax,-0x1a(%rbp)
movzwl -0x1a(%rbp),%edi
call   1040 <dec_bin@plt>
mov    %eax,%esi
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
movzwl -0x1a(%rbp),%eax
or     -0x18(%rbp),%eax
mov    %ax,-0x1c(%rbp)
movzwl -0x1c(%rbp),%edi
call   1040 <dec_bin@plt>
mov    %eax,%esi
lea    0xe2e(%rip),%rdi
call   1030 <printf@plt>
movzwl -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setbits2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %edx,%ecx
mov    $0xffffffff,%ebx
shl    %cl,%ebx
mov    %edi,%r14d
not    %ebx
lea    (%rsi,%rcx,1),%r12d
add    $0x1,%r12b
mov    %ebx,%ebp
mov    %r12d,%ecx
shl    %cl,%ebp
movzwl %bp,%edi
call   1040 <dec_bin@plt>
lea    0xea9(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
and    %r15d,%ebx
mov    %r12d,%ecx
shl    %cl,%ebx
movzwl %bx,%edi
call   1040 <dec_bin@plt>
lea    0xe9a(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
not    %ebp
and    %r14d,%ebp
movzwl %bp,%edi
call   1040 <dec_bin@plt>
lea    0xe8f(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
or     %ebx,%ebp
movzwl %bp,%ebx
mov    %ebx,%edi
call   1040 <dec_bin@plt>
lea    0xe84(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"first = %42d;\0A\00"
@.str.1 = [16 x i8] c"second = %41d;\0A\00"
@.str.2 = [15 x i8] c"third = %42d;\0A\00"
@.str.3 = [17 x i8] c"fourth = %41d;\0A\0A\00"
define i32 @setbits2(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 i16
%12 = alloca i16
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 i16 0, i16* %11
store i16 0, i16* %12
%13 = load i32, i32* %7
%14 = shl i32 -1, %13
%15 = xor i32 %14, -1
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = add nsw i32 %16, %17
%19 = add nsw i32 %18, 1
%20 = shl i32 %15, %19
store i32 %20, i32* %9
%21 = load i32, i32* %9
%22 = trunc i32 %21 to i16
%23 = call i32 @dec_bin(i16 zeroext %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %8
%26 = load i32, i32* %7
%27 = shl i32 -1, %26
%28 = xor i32 %27, -1
%29 = and i32 %25, %28
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = add nsw i32 %30, %31
%33 = add nsw i32 %32, 1
%34 = shl i32 %29, %33
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = trunc i32 %35 to i16
%37 = call i32 @dec_bin(i16 zeroext %36)
%38 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %5
%40 = load i32, i32* %9
%41 = xor i32 %40, -1
%42 = and i32 %39, %41
%43 = trunc i32 %42 to i16
store i16 %43, i16* %11
%44 = load i16, i16* %11
%45 = call i32 @dec_bin(i16 zeroext %44)
%46 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = load i16, i16* %11
%48 = zext i16 %47 to i32
%49 = load i32, i32* %10
%50 = or i32 %48, %49
%51 = trunc i32 %50 to i16
store i16 %51, i16* %12
%52 = load i16, i16* %12
%53 = call i32 @dec_bin(i16 zeroext %52)
%54 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %53)
%55 = load i16, i16* %12
%56 = zext i16 %55 to i32
ret i32 %56
}

LLVM IR (-O2):
@.str = [15 x i8] c"first = %42d;\0A\00"
@.str.1 = [16 x i8] c"second = %41d;\0A\00"
@.str.2 = [15 x i8] c"third = %42d;\0A\00"
@.str.3 = [17 x i8] c"fourth = %41d;\0A\0A\00"
define i32 @setbits2(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = shl nsw i32 -1, %2
%6 = xor i32 %5, -1
%7 = add i32 %1, 1
%8 = add i32 %7, %2
%9 = shl i32 %6, %8
%10 = trunc i32 %9 to i16
%11 = tail call i32 @dec_bin(i16 zeroext %10)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = and i32 %6, %3
%14 = shl i32 %13, %8
%15 = trunc i32 %14 to i16
%16 = tail call i32 @dec_bin(i16 zeroext %15)
%17 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = xor i32 %9, -1
%19 = and i32 %18, %0
%20 = trunc i32 %19 to i16
%21 = tail call i32 @dec_bin(i16 zeroext %20)
%22 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = or i32 %19, %14
%24 = trunc i32 %23 to i16
%25 = tail call i32 @dec_bin(i16 zeroext %24)
%26 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = and i32 %23, 65535
ret i32 %27
}