#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 */
typedef int /*<<< orphan*/ value;

/* Variables and functions */
int CHAR_BIT;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, unsigned int *);
int main(int argc, char **argv) {
  unsigned int value, temp, max_val, lbit, rbit, lmask, rmask;
  int rotate;
  max_val = -1;
  rotate = CHAR_BIT * sizeof(value) - 1;
  rmask = 0x01;
  lmask = rmask << rotate;
  printf("\nPlease provide hex value to swap bits\n");
  scanf("0x%x", &value);
  printf("\nValue: 0x%x\n", value);
  printf("bits in a byte %d, size of value %d, lmask 0x%x, rmask 0x%x, rotate "
         "%d\n",
         CHAR_BIT, sizeof(value), lmask, rmask, rotate);
  while (lmask != (rmask >> 1)) {
    lbit = value & lmask;
    rbit = value & rmask;
    if ((!(lbit) && (rbit)) || (lbit) && !(rbit)) {
      printf("left bit 0x%x right bit 0x%x\n", lbit, rbit);
      temp = ((lbit >> rotate) | (value & ~rmask));
      printf("L->R: Value 0x%x, New Value 0x%x, rotate %d, lmask 0x%x, rmask "
             "0x%x\n",
             value, temp, rotate, lmask, rmask);
      temp = ((rbit << rotate) | (temp & ~lmask));
      printf("R->L: Value 0x%x, New Value 0x%x, rotate %d, lmask 0x%x, rmask "
             "0x%x\n",
             value, temp, rotate, lmask, rmask);
      value = temp;
    } else {
      printf("Skipping...\n");
    }
    lmask >>= 1;
    rmask <<= 1;
    rotate -= 2;
    printf("L mask and L mask -1 0x%x, lmask 0x%x, lmask -1 0x%x \n",
           (lmask | (lmask - 1)), lmask, lmask - 1);
    temp &= (lmask | (lmask - 1));
    printf("L+R Mask Left clear: 0x%x, lmask 0x%x\n", temp, lmask);
    printf("R mask R mask -1 0x%x, rmask 0x%x \n", ~rmask, rmask);
    temp &= (~(rmask | (rmask - 1)) | rmask);
    printf("Masked value 0x%x, value 0x%x, mask 0x%x\n", value & temp, value,
           temp);
    if ((value & temp) == 0) {
      printf("All bits remaining to swap are zeroes.\n");
      break;
    }
    if ((value & temp) == (max_val & temp)) {
      printf("All bits remaining to swap are 1s.\n");
      break;
    }
    printf("\n");
  }
  printf("\nBit Swapped Value: 0x%x, Rotate Position %d\n\n", value,
         rotate < 0 ? 0 : rotate);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    0x2e9c(%rip),%rax
movslq (%rax),%rax
shl    $0x2,%rax
sub    $0x1,%rax
mov    %eax,-0x30(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x30(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x28(%rbp)
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeaf(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x14(%rbp),%esi
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%r9d
lea    0xe8d(%rip),%rdi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
mov    -0x2c(%rbp),%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
je     13a6 <main+0x286>
mov    -0x14(%rbp),%eax
and    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
and    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11f1 <main+0xd1>
cmpl   $0x0,-0x24(%rbp)
jne    1205 <main+0xe5>
cmpl   $0x0,-0x20(%rbp)
je     1292 <main+0x172>
cmpl   $0x0,-0x24(%rbp)
jne    1292 <main+0x172>
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
mov    -0x30(%rbp),%ecx
shr    %cl,%eax
mov    -0x14(%rbp),%ecx
mov    -0x2c(%rbp),%edx
xor    $0xffffffff,%edx
and    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
mov    -0x30(%rbp),%ecx
shl    %cl,%eax
mov    -0x18(%rbp),%ecx
mov    -0x28(%rbp),%edx
xor    $0xffffffff,%edx
and    %edx,%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    12a0 <main+0x180>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%esi
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
or     %eax,%esi
mov    -0x28(%rbp),%edx
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
or     %ecx,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%esi
xor    $0xffffffff,%esi
mov    -0x2c(%rbp),%edx
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
or     %ecx,%eax
xor    $0xffffffff,%eax
or     -0x2c(%rbp),%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
and    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
and    -0x18(%rbp),%eax
cmp    $0x0,%eax
jne    136c <main+0x24c>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    13a6 <main+0x286>
mov    -0x14(%rbp),%eax
and    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
and    -0x18(%rbp),%ecx
cmp    %ecx,%eax
jne    1393 <main+0x273>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    13a6 <main+0x286>
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ba <main+0x9a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    13c0 <main+0x2a0>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    13c6 <main+0x2a6>
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e8b(%rip),%rbx
mov    (%rbx),%eax
lea    -0x1(,%rax,4),%r12d
ff
mov    $0x1,%r14d
mov    $0x1,%r15d
mov    %r12d,%ecx
shl    %cl,%r15d
lea    0x1066(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7c(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%esi
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%esi
lea    0xe6a(%rip),%rdi
mov    $0x4,%edx
mov    %r15d,%ecx
mov    $0x1,%r8d
mov    %r12d,%r9d
xor    %eax,%eax
call   1050 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12d,%eax
mov    %rax,0x8(%rsp)
mov    0x4(%rsp),%r13d
mov    %r13d,%r12d
and    %r14d,%r12d
and    %r15d,%r13d
jne    11ed <main+0xad>
test   %r12d,%r12d
jne    11ff <main+0xbf>
test   %r13d,%r13d
je     1290 <main+0x150>
test   %r12d,%r12d
jne    1290 <main+0x150>
lea    0xe55(%rip),%rdi
mov    %r13d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,0x10(%rsp)
mov    0x8(%rsp),%r14
mov    %r14d,%ecx
shr    %cl,%r13d
mov    0x4(%rsp),%esi
mov    0x10(%rsp),%rax
mov    %eax,%ebx
not    %ebx
and    %esi,%ebx
or     %r13d,%ebx
lea    0xe3d(%rip),%rdi
mov    %ebx,%edx
mov    %r14d,%ecx
mov    %r15d,%r8d
mov    0x10(%rsp),%r9
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%ecx
shl    %cl,%r12d
mov    %r15d,%ebp
not    %ebp
and    %ebx,%ebp
or     %r12d,%ebp
mov    0x4(%rsp),%esi
lea    0xe53(%rip),%rdi
mov    %ebp,%edx
mov    %r14d,%ecx
mov    0x10(%rsp),%r14
mov    %r15d,%r8d
mov    %r14d,%r9d
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,0x4(%rsp)
jmp    129c <main+0x15c>
nopl   0x0(%rax,%rax,1)
lea    0xfb8(%rip),%rdi
call   1040 <puts@plt>
shr    %r15d
lea    (%r14,%r14,1),%r13d
lea    -0x1(%r15),%ecx
mov    %ecx,%ebx
or     %r15d,%ebx
lea    0xe50(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
and    %ebp,%ebx
lea    0xe72(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13d,%esi
not    %esi
lea    0xe81(%rip),%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13d,%ebp
neg    %ebp
or     %r13d,%ebp
and    %ebx,%ebp
mov    0x4(%rsp),%edx
mov    %edx,%esi
and    %ebp,%esi
lea    0xe82(%rip),%rdi
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rsp),%eax
and    %ebp,%eax
je     1340 <main+0x200>
cmp    %ebp,%eax
je     1349 <main+0x209>
mov    $0xa,%edi
call   1030 <putchar@plt>
and    $0x7fffffff,%r14d
mov    0x8(%rsp),%rdx
lea    -0x2(%rdx),%r12d
cmp    %r14d,%r15d
mov    %r13d,%r14d
jne    11d0 <main+0x90>
jmp    135a <main+0x21a>
lea    0xee1(%rip),%rdi
jmp    1350 <main+0x210>
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%rdx
mov    0x4(%rsp),%esi
xor    %eax,%eax
add    $0xfffffffe,%edx
cmovs  %eax,%edx
lea    0xe42(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
@.str = [40 x i8] c"\0APlease provide hex value to swap bits\0A\00"
@.str.1 = [5 x i8] c"0x%x\00"
@.str.2 = [14 x i8] c"\0AValue: 0x%x\0A\00"
@.str.3 = [72 x i8] c"bits in a byte %d, size of value %d, lmask 0x%x, rmask 0x%x, rotate %d\0A\00"
@.str.4 = [30 x i8] c"left bit 0x%x right bit 0x%x\0A\00"
@.str.5 = [69 x i8] c"L->R: Value 0x%x, New Value 0x%x, rotate %d, lmask 0x%x, rmask 0x%x\0A\00"
@.str.6 = [69 x i8] c"R->L: Value 0x%x, New Value 0x%x, rotate %d, lmask 0x%x, rmask 0x%x\0A\00"
@.str.7 = [13 x i8] c"Skipping...\0A\00"
@.str.8 = [55 x i8] c"L mask and L mask -1 0x%x, lmask 0x%x, lmask -1 0x%x \0A\00"
@.str.9 = [39 x i8] c"L+R Mask Left clear: 0x%x, lmask 0x%x\0A\00"
@.str.10 = [36 x i8] c"R mask R mask -1 0x%x, rmask 0x%x \0A\00"
@.str.11 = [42 x i8] c"Masked value 0x%x, value 0x%x, mask 0x%x\0A\00"
@.str.12 = [40 x i8] c"All bits remaining to swap are zeroes.\0A\00"
@.str.13 = [36 x i8] c"All bits remaining to swap are 1s.\0A\00"
@.str.14 = [2 x i8] c"\0A\00"
@.str.15 = [47 x i8] c"\0ABit Swapped Value: 0x%x, Rotate Position %d\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %8
%14 = load i32, i32* @CHAR_BIT
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = sub i64 %16, 1
%18 = trunc i64 %17 to i32
store i32 %18, i32* %13
store i32 1, i32* %12
%19 = load i32, i32* %12
%20 = load i32, i32* %13
%21 = shl i32 %19, %20
store i32 %21, i32* %11
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%24 = load i32, i32* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* @CHAR_BIT
%27 = load i32, i32* %11
%28 = load i32, i32* %12
%29 = load i32, i32* %13
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), i32 %26, i64 4, i32 %27, i32 %28, i32 %29)
br label %31
31: ; preds = %148, %2
%32 = load i32, i32* %11
%33 = load i32, i32* %12
%34 = lshr i32 %33, 1
%35 = icmp ne i32 %32, %34
br i1 %35, label %36, label %150
36: ; preds = %31
%37 = load i32, i32* %6
%38 = load i32, i32* %11
%39 = and i32 %37, %38
store i32 %39, i32* %9
%40 = load i32, i32* %6
%41 = load i32, i32* %12
%42 = and i32 %40, %41
store i32 %42, i32* %10
%43 = load i32, i32* %9
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %36
%46 = load i32, i32* %10
%47 = icmp ne i32 %46, 0
br i1 %47, label %54, label %48
48: ; preds = %45, %36
%49 = load i32, i32* %9
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %87
51: ; preds = %48
%52 = load i32, i32* %10
%53 = icmp ne i32 %52, 0
br i1 %53, label %87, label %54
54: ; preds = %51, %45
%55 = load i32, i32* %9
%56 = load i32, i32* %10
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %55, i32 %56)
%58 = load i32, i32* %9
%59 = load i32, i32* %13
%60 = lshr i32 %58, %59
%61 = load i32, i32* %6
%62 = load i32, i32* %12
%63 = xor i32 %62, -1
%64 = and i32 %61, %63
%65 = or i32 %60, %64
store i32 %65, i32* %7
%66 = load i32, i32* %6
%67 = load i32, i32* %7
%68 = load i32, i32* %13
%69 = load i32, i32* %11
%70 = load i32, i32* %12
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.5, i64 0, i64 0), i32 %66, i32 %67, i32 %68, i32 %69, i32 %70)
%72 = load i32, i32* %10
%73 = load i32, i32* %13
%74 = shl i32 %72, %73
%75 = load i32, i32* %7
%76 = load i32, i32* %11
%77 = xor i32 %76, -1
%78 = and i32 %75, %77
%79 = or i32 %74, %78
store i32 %79, i32* %7
%80 = load i32, i32* %6
%81 = load i32, i32* %7
%82 = load i32, i32* %13
%83 = load i32, i32* %11
%84 = load i32, i32* %12
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0), i32 %80, i32 %81, i32 %82, i32 %83, i32 %84)
%86 = load i32, i32* %7
store i32 %86, i32* %6
br label %89
87: ; preds = %51, %48
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %89
89: ; preds = %87, %54
%90 = load i32, i32* %11
%91 = lshr i32 %90, 1
store i32 %91, i32* %11
%92 = load i32, i32* %12
%93 = shl i32 %92, 1
store i32 %93, i32* %12
%94 = load i32, i32* %13
%95 = sub nsw i32 %94, 2
store i32 %95, i32* %13
%96 = load i32, i32* %11
%97 = load i32, i32* %11
%98 = sub i32 %97, 1
%99 = or i32 %96, %98
%100 = load i32, i32* %11
%101 = load i32, i32* %11
%102 = sub i32 %101, 1
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.8, i64 0, i64 0), i32 %99, i32 %100, i32 %102)
%104 = load i32, i32* %11
%105 = load i32, i32* %11
%106 = sub i32 %105, 1
%107 = or i32 %104, %106
%108 = load i32, i32* %7
%109 = and i32 %108, %107
store i32 %109, i32* %7
%110 = load i32, i32* %7
%111 = load i32, i32* %11
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0), i32 %110, i32 %111)
%113 = load i32, i32* %12
%114 = xor i32 %113, -1
%115 = load i32, i32* %12
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i32 %114, i32 %115)
%117 = load i32, i32* %12
%118 = load i32, i32* %12
%119 = sub i32 %118, 1
%120 = or i32 %117, %119
%121 = xor i32 %120, -1
%122 = load i32, i32* %12
%123 = or i32 %121, %122
%124 = load i32, i32* %7
%125 = and i32 %124, %123
store i32 %125, i32* %7
%126 = load i32, i32* %6
%127 = load i32, i32* %7
%128 = and i32 %126, %127
%129 = load i32, i32* %6
%130 = load i32, i32* %7
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i32 %128, i32 %129, i32 %130)
%132 = load i32, i32* %6
%133 = load i32, i32* %7
%134 = and i32 %132, %133
%135 = icmp eq i32 %134, 0
br i1 %135, label %136, label %138
136: ; preds = %89
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.12, i64 0, i64 0))
br label %150
138: ; preds = %89
%139 = load i32, i32* %6
%140 = load i32, i32* %7
%141 = and i32 %139, %140
%142 = load i32, i32* %8
%143 = load i32, i32* %7
%144 = and i32 %142, %143
%145 = icmp eq i32 %141, %144
br i1 %145, label %146, label %148
146: ; preds = %138
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.13, i64 0, i64 0))
br label %150
148: ; preds = %138
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
br label %31
150: ; preds = %146, %136, %31
%151 = load i32, i32* %6
%152 = load i32, i32* %13
%153 = icmp slt i32 %152, 0
br i1 %153, label %154, label %155
154: ; preds = %150
br label %157
155: ; preds = %150
%156 = load i32, i32* %13
br label %157
157: ; preds = %155, %154
%158 = phi i32 [ 0, %154 ], [ %156, %155 ]
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.15, i64 0, i64 0), i32 %151, i32 %158)
%160 = load i32, i32* %3
ret i32 %160
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@.str.1 = [5 x i8] c"0x%x\00"
@.str.2 = [14 x i8] c"\0AValue: 0x%x\0A\00"
@.str.3 = [72 x i8] c"bits in a byte %d, size of value %d, lmask 0x%x, rmask 0x%x, rotate %d\0A\00"
@.str.4 = [30 x i8] c"left bit 0x%x right bit 0x%x\0A\00"
@.str.5 = [69 x i8] c"L->R: Value 0x%x, New Value 0x%x, rotate %d, lmask 0x%x, rmask 0x%x\0A\00"
@.str.6 = [69 x i8] c"R->L: Value 0x%x, New Value 0x%x, rotate %d, lmask 0x%x, rmask 0x%x\0A\00"
@.str.8 = [55 x i8] c"L mask and L mask -1 0x%x, lmask 0x%x, lmask -1 0x%x \0A\00"
@.str.9 = [39 x i8] c"L+R Mask Left clear: 0x%x, lmask 0x%x\0A\00"
@.str.10 = [36 x i8] c"R mask R mask -1 0x%x, rmask 0x%x \0A\00"
@.str.11 = [42 x i8] c"Masked value 0x%x, value 0x%x, mask 0x%x\0A\00"
@.str.15 = [47 x i8] c"\0ABit Swapped Value: 0x%x, Rotate Position %d\0A\0A\00"
@str = [39 x i8] c"\0APlease provide hex value to swap bits\00"
@str.16 = [35 x i8] c"All bits remaining to swap are 1s.\00"
@str.17 = [39 x i8] c"All bits remaining to swap are zeroes.\00"
@str.18 = [12 x i8] c"Skipping...\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @CHAR_BIT
%6 = shl i32 %5, 2
%7 = add i32 %6, -1
%8 = shl nuw i32 1, %7
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%11 = load i32, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @CHAR_BIT
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str.3, i64 0, i64 0), i32 %13, i64 4, i32 %8, i32 1, i32 %7)
br label %15
15: ; preds = %2, %67
%16 = phi i32 [ %7, %2 ], [ %48, %67 ]
%17 = phi i32 [ 1, %2 ], [ %47, %67 ]
%18 = phi i32 [ %8, %2 ], [ %46, %67 ]
%19 = phi i32 [ undef, %2 ], [ %58, %67 ]
%20 = load i32, i32* %3
%21 = and i32 %20, %18
%22 = and i32 %20, %17
%23 = icmp eq i32 %21, 0
%24 = icmp ne i32 %22, 0
%25 = select i1 %23, i1 %24, i1 false
br i1 %25, label %28, label %26
26: ; preds = %15
%27 = select i1 %23, i1 true, i1 %24
br i1 %27, label %42, label %28
28: ; preds = %26, %15
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %21, i32 %22)
%30 = lshr i32 %21, %16
%31 = load i32, i32* %3
%32 = xor i32 %17, -1
%33 = and i32 %31, %32
%34 = or i32 %33, %30
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str.5, i64 0, i64 0), i32 %31, i32 %34, i32 %16, i32 %18, i32 %17)
%36 = shl i32 %22, %16
%37 = xor i32 %18, -1
%38 = and i32 %34, %37
%39 = or i32 %38, %36
%40 = load i32, i32* %3
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0), i32 %40, i32 %39, i32 %16, i32 %18, i32 %17)
store i32 %39, i32* %3
br label %44
42: ; preds = %26
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.18, i64 0, i64 0))
br label %44
44: ; preds = %42, %28
%45 = phi i32 [ %39, %28 ], [ %19, %42 ]
%46 = lshr i32 %18, 1
%47 = shl i32 %17, 1
%48 = add nsw i32 %16, -2
%49 = add nsw i32 %46, -1
%50 = or i32 %49, %46
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.8, i64 0, i64 0), i32 %50, i32 %46, i32 %49)
%52 = and i32 %45, %50
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.9, i64 0, i64 0), i32 %52, i32 %46)
%54 = xor i32 %47, -1
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.10, i64 0, i64 0), i32 %54, i32 %47)
%56 = sub i32 0, %47
%57 = or i32 %47, %56
%58 = and i32 %52, %57
%59 = load i32, i32* %3
%60 = and i32 %59, %58
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i32 %60, i32 %59, i32 %58)
%62 = load i32, i32* %3
%63 = and i32 %62, %58
%64 = icmp eq i32 %63, 0
br i1 %64, label %71, label %65
65: ; preds = %44
%66 = icmp eq i32 %63, %58
br i1 %66, label %71, label %67
67: ; preds = %65
%68 = call i32 @putchar(i32 10)
%69 = and i32 %17, 2147483647
%70 = icmp eq i32 %46, %69
br i1 %70, label %74, label %15
71: ; preds = %65, %44
%72 = phi i8* [ getelementptr inbounds ([39 x i8], [39 x i8]* @str.17, i64 0, i64 0), %44 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @str.16, i64 0, i64 0), %65 ]
%73 = call i32 @puts(i8* dereferenceable(1) %72)
br label %74
74: ; preds = %67, %71
%75 = load i32, i32* %3
%76 = icmp sgt i32 %48, 0
%77 = select i1 %76, i32 %48, i32 0
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.15, i64 0, i64 0), i32 %75, i32 %77)
ret i32 0
}