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


x86 assembly (clang, -O0):
<invert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dx,%ax
mov    %si,%cx
mov    %di,%dx
mov    %dx,-0x2(%rbp)
mov    %cx,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
movw   $0x0,-0x8(%rbp)
movw   $0x0,-0xa(%rbp)
movw   $0x0,-0xc(%rbp)
movw   $0x0,-0xe(%rbp)
movw   $0x0,-0x10(%rbp)
movzwl -0x6(%rbp),%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
movzwl -0x4(%rbp),%ecx
movzwl -0x6(%rbp),%edx
sub    %edx,%ecx
add    $0x1,%ecx
shl    %cl,%eax
mov    %ax,-0x8(%rbp)
movzwl -0x8(%rbp),%edi
call   1040 <dec_bin@plt>
mov    %eax,%esi
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
movzwl -0x2(%rbp),%eax
movzwl -0x6(%rbp),%ecx
mov    $0xffffffff,%edx
shl    %cl,%edx
xor    $0xffffffff,%edx
movzwl -0x4(%rbp),%ecx
movzwl -0x6(%rbp),%esi
sub    %esi,%ecx
add    $0x1,%ecx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%edi
call   1040 <dec_bin@plt>
mov    %eax,%esi
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
movzwl -0x2(%rbp),%eax
movzwl -0x8(%rbp),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %ax,-0xc(%rbp)
movzwl -0xc(%rbp),%edi
call   1040 <dec_bin@plt>
mov    %eax,%esi
lea    0xe29(%rip),%rdi
call   1030 <printf@plt>
movzwl -0x8(%rbp),%eax
movzwl -0xa(%rbp),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %ax,-0xe(%rbp)
movzwl -0xe(%rbp),%edi
call   1040 <dec_bin@plt>
mov    %eax,%esi
lea    0xe10(%rip),%rdi
call   1030 <printf@plt>
movzwl -0xc(%rbp),%eax
movzwl -0xe(%rbp),%ecx
or     %ecx,%eax
mov    %ax,-0x10(%rbp)
movzwl -0x10(%rbp),%edi
call   1040 <dec_bin@plt>
mov    %eax,%esi
lea    0xdfc(%rip),%rdi
call   1030 <printf@plt>
movzwl -0xa(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<invert>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ecx
mov    $0xffffffff,%ebx
shl    %cl,%ebx
mov    %edi,%r14d
not    %ebx
sub    %edx,%esi
lea    0x1(%rsi),%ecx
shl    %cl,%ebx
movzwl %bx,%edi
call   1040 <dec_bin@plt>
lea    0xeb4(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%r15d
and    %r14d,%r15d
mov    %r15d,%edi
call   1040 <dec_bin@plt>
lea    0xea7(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %ebx,%r12d
not    %r12d
and    %r14d,%r12d
mov    %r12d,%edi
call   1040 <dec_bin@plt>
lea    0xe98(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r15d,%ebp
not    %ebp
and    %ebx,%ebp
movzwl %bp,%edi
call   1040 <dec_bin@plt>
lea    0xe8a(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
or     %r12d,%ebp
movzwl %bp,%edi
call   1040 <dec_bin@plt>
lea    0xe82(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r15d,%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"
@.str.4 = [16 x i8] c"fifth = %42d;\0A \00"
define zeroext i16 @invert(i16 zeroext %0, i16 zeroext %1, i16 zeroext %2) {
%4 = alloca i16
%5 = alloca i16
%6 = alloca i16
%7 = alloca i16
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16
%11 = alloca i16
store i16 %0, i16* %4
store i16 %1, i16* %5
store i16 %2, i16* %6
store i16 0, i16* %7
store i16 0, i16* %8
store i16 0, i16* %9
store i16 0, i16* %10
store i16 0, i16* %11
%12 = load i16, i16* %6
%13 = zext i16 %12 to i32
%14 = shl i32 -1, %13
%15 = xor i32 %14, -1
%16 = load i16, i16* %5
%17 = zext i16 %16 to i32
%18 = load i16, i16* %6
%19 = zext i16 %18 to i32
%20 = sub nsw i32 %17, %19
%21 = add nsw i32 %20, 1
%22 = shl i32 %15, %21
%23 = trunc i32 %22 to i16
store i16 %23, i16* %7
%24 = load i16, i16* %7
%25 = call i32 @dec_bin(i16 zeroext %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i16, i16* %4
%28 = zext i16 %27 to i32
%29 = load i16, i16* %6
%30 = zext i16 %29 to i32
%31 = shl i32 -1, %30
%32 = xor i32 %31, -1
%33 = load i16, i16* %5
%34 = zext i16 %33 to i32
%35 = load i16, i16* %6
%36 = zext i16 %35 to i32
%37 = sub nsw i32 %34, %36
%38 = add nsw i32 %37, 1
%39 = shl i32 %32, %38
%40 = and i32 %28, %39
%41 = trunc i32 %40 to i16
store i16 %41, i16* %8
%42 = load i16, i16* %8
%43 = call i32 @dec_bin(i16 zeroext %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %43)
%45 = load i16, i16* %4
%46 = zext i16 %45 to i32
%47 = load i16, i16* %7
%48 = zext i16 %47 to i32
%49 = xor i32 %48, -1
%50 = and i32 %46, %49
%51 = trunc i32 %50 to i16
store i16 %51, i16* %9
%52 = load i16, i16* %9
%53 = call i32 @dec_bin(i16 zeroext %52)
%54 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %53)
%55 = load i16, i16* %7
%56 = zext i16 %55 to i32
%57 = load i16, i16* %8
%58 = zext i16 %57 to i32
%59 = xor i32 %58, -1
%60 = and i32 %56, %59
%61 = trunc i32 %60 to i16
store i16 %61, i16* %10
%62 = load i16, i16* %10
%63 = call i32 @dec_bin(i16 zeroext %62)
%64 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %63)
%65 = load i16, i16* %9
%66 = zext i16 %65 to i32
%67 = load i16, i16* %10
%68 = zext i16 %67 to i32
%69 = or i32 %66, %68
%70 = trunc i32 %69 to i16
store i16 %70, i16* %11
%71 = load i16, i16* %11
%72 = call i32 @dec_bin(i16 zeroext %71)
%73 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %72)
%74 = load i16, i16* %8
ret i16 %74
}

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"
@.str.4 = [16 x i8] c"fifth = %42d;\0A \00"
define zeroext i16 @invert(i16 zeroext %0, i16 zeroext %1, i16 zeroext %2) {
%4 = zext i16 %2 to i32
%5 = shl nsw i32 -1, %4
%6 = xor i32 %5, -1
%7 = zext i16 %1 to i32
%8 = add nuw nsw i32 %7, 1
%9 = sub nsw i32 %8, %4
%10 = shl i32 %6, %9
%11 = trunc i32 %10 to i16
%12 = tail call i32 @dec_bin(i16 zeroext %11)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = and i16 %11, %0
%15 = tail call i32 @dec_bin(i16 zeroext %14)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = xor i16 %11, -1
%18 = and i16 %17, %0
%19 = tail call i32 @dec_bin(i16 zeroext %18)
%20 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = zext i16 %14 to i32
%22 = xor i32 %21, -1
%23 = and i32 %10, %22
%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 = or i16 %18, %24
%28 = tail call i32 @dec_bin(i16 zeroext %27)
%29 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %28)
ret i16 %14
}