#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 /*<<< orphan*/ showbits(char);
int /*<<< orphan*/ swap_bits(char, char, int, int);
unsigned int validate(char);
int main() {
  char num1;
  char num2;
  unsigned int src_num;
  unsigned int dst_num;
  int src_pos;
  int dst_pos;
  printf("Enter source number:");
  scanf("%s", &num1);
  src_num = validate(num1);
  if (src_num) {
    printf("Enter destination number:");
    scanf("%s", &num2);
  }
  dst_num = validate(num2);
  if (dst_num) {
    showbits(num1);
    showbits(num2);
  }
  printf("Enter source bit position:");
  scanf("%d", &src_pos);
  printf("Enter destination bit position:");
  scanf("%d", &dst_pos);
  printf("Numbers after swapping bits:\n");
  swap_bits(num1, num2, src_pos, dst_pos);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <printf@plt>
lea    0xea3(%rip),%rdi
lea    -0x5(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
movsbl -0x5(%rbp),%edi
call   1060 <validate@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11b1 <main+0x61>
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
lea    0xe6f(%rip),%rdi
lea    -0x6(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
movsbl -0x6(%rbp),%edi
call   1060 <validate@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11d9 <main+0x89>
movsbl -0x5(%rbp),%edi
call   1030 <showbits@plt>
movsbl -0x6(%rbp),%edi
call   1030 <showbits@plt>
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
lea    0xe61(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
lea    0xe43(%rip),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
mov    -0x5(%rbp),%sil
mov    -0x6(%rbp),%al
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
movsbl %sil,%edi
movsbl %al,%esi
call   1050 <swap_bits@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rdi
call   1050 <printf@plt>
lea    0xe9d(%rip),%rbx
lea    0x7(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <scanf@plt>
movsbl 0x7(%rsp),%edi
call   1070 <validate@plt>
lea    0xe80(%rip),%rdi
call   1050 <printf@plt>
lea    0x6(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <scanf@plt>
movsbl 0x6(%rsp),%edi
call   1070 <validate@plt>
test   %eax,%eax
je     11ce <main+0x6e>
movsbl 0x7(%rsp),%edi
call   1040 <showbits@plt>
movsbl 0x6(%rsp),%edi
call   1040 <showbits@plt>
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
lea    0xe6c(%rip),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <scanf@plt>
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <scanf@plt>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
movsbl 0x7(%rsp),%edi
movsbl 0x6(%rsp),%esi
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
call   1060 <swap_bits@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

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