#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 *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ showbits(int);
int swap_bits(int, int, int);
int main(void) {
  int num;
  int src_pos;
  int dst_pos;
  printf("Enter a number:");
  scanf("%d", &num);
  printf("Enter source bit position:");
  scanf("%d", &src_pos);
  printf("Enter destination bit position:");
  scanf("%d", &dst_pos);
  if (num >= 0 && src_pos >= 0 && dst_pos >= 0) {
    printf("The entered number is:\n");
    showbits(num);
    num = swap_bits(num, src_pos, dst_pos);
    printf("The n umber after swapping bits:\n");
    showbits(num);
  } else {
    printf("Invalid input!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
lea    0xe92(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xea0(%rip),%rdi
call   1040 <printf@plt>
lea    0xe76(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jl     11ff <main+0xbf>
cmpl   $0x0,-0xc(%rbp)
jl     11ff <main+0xbf>
cmpl   $0x0,-0x10(%rbp)
jl     11ff <main+0xbf>
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1030 <showbits@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <swap_bits@plt>
mov    %eax,-0x8(%rbp)
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1030 <showbits@plt>
jmp    120b <main+0xcb>
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
call   1050 <printf@plt>
lea    0xea8(%rip),%rbx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
lea    0xe97(%rip),%rdi
call   1050 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
lea    0xe99(%rip),%rdi
call   1050 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
js     11fd <main+0xad>
cmpl   $0x0,0xc(%rsp)
js     11fd <main+0xad>
cmpl   $0x0,0x8(%rsp)
js     11fd <main+0xad>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%edi
call   1040 <showbits@plt>
mov    0x4(%rsp),%edi
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
call   1060 <swap_bits@plt>
mov    %eax,0x4(%rsp)
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%edi
call   1040 <showbits@plt>
jmp    1209 <main+0xb9>
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"Enter a number:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Enter source bit position:\00"
@.str.3 = [32 x i8] c"Enter destination bit position:\00"
@.str.4 = [24 x i8] c"The entered number is:\0A\00"
@.str.5 = [34 x i8] c"The n umber after swapping bits:\0A\00"
@.str.6 = [16 x i8] c"Invalid input!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%11 = load i32, i32* %2
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %30
13: ; preds = %0
%14 = load i32, i32* %3
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %30
16: ; preds = %13
%17 = load i32, i32* %4
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %30
19: ; preds = %16
%20 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%21 = load i32, i32* %2
%22 = call i32 @showbits(i32 %21)
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = call i32 @swap_bits(i32 %23, i32 %24, i32 %25)
store i32 %26, i32* %2
%27 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
%28 = load i32, i32* %2
%29 = call i32 @showbits(i32 %28)
br label %32
30: ; preds = %16, %13, %0
%31 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %32
32: ; preds = %30, %19
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"Enter a number:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [27 x i8] c"Enter source bit position:\00"
@.str.3 = [32 x i8] c"Enter destination bit position:\00"
@str = [15 x i8] c"Invalid input!\00"
@str.7 = [23 x i8] c"The entered number is:\00"
@str.8 = [33 x i8] c"The n umber after swapping bits:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%13 = load i32, i32* %1
%14 = icmp sgt i32 %13, -1
%15 = load i32, i32* %2
%16 = icmp sgt i32 %15, -1
%17 = select i1 %14, i1 %16, i1 false
%18 = load i32, i32* %3
%19 = icmp sgt i32 %18, -1
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %21, label %32
21: ; preds = %0
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
%23 = load i32, i32* %1
%24 = call i32 @showbits(i32 %23)
%25 = load i32, i32* %1
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = call i32 @swap_bits(i32 %25, i32 %26, i32 %27)
store i32 %28, i32* %1
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.8, i64 0, i64 0))
%30 = load i32, i32* %1
%31 = call i32 @showbits(i32 %30)
br label %34
32: ; preds = %0
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %34
34: ; preds = %32, %21
ret i32 0
}