#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*/ showbit(int);
int main() {
  int snum;
  int dnum;
  int s;
  int d;
  printf("WELCOME TO SWAP BIT FOR 2 NUMBERS\n");
  printf("Enter source numbers\n");
  scanf("%d", &snum);
  printf("Enter destination numbers\n");
  scanf("%d", &dnum);
  printf("The numbers before swap\n");
  showbit(snum);
  printf("\n");
  showbit(dnum);
  printf("Enter the source and destination position\n");
  scanf("%d%d", &s, &d);
  if ((1 & (snum >> s)) != (1 & (dnum >> d))) {
    snum = (1 << s) ^ snum;
    dnum = (1 << d) ^ dnum;
  }
  printf("The numbers after swap\n");
  showbit(snum);
  printf("\n");
  showbit(dnum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
lea    0xf3c(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
lea    0xf1e(%rip),%rdi
lea    -0xc(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xec6(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <showbit@plt>
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <showbit@plt>
lea    0xeb7(%rip),%rdi
call   1030 <printf@plt>
lea    0xed6(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    -0xc(%rbp),%edx
mov    -0x14(%rbp),%ecx
sar    %cl,%edx
mov    %edx,%ecx
and    $0x1,%ecx
cmp    %ecx,%eax
je     1211 <main+0xe1>
mov    -0x10(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <showbit@plt>
lea    0xdf5(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <showbit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb9(%rip),%rdi
call   1040 <puts@plt>
lea    0xecf(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9e(%rip),%rbx
lea    0x4(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xec2(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xec3(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%edi
call   1060 <showbit@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%rsp),%edi
call   1060 <showbit@plt>
lea    0xeb4(%rip),%rdi
call   1040 <puts@plt>
lea    0xe3a(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x4(%rsp),%edx
mov    0xc(%rsp),%eax
mov    %edx,%edi
mov    %eax,%ecx
shr    %cl,%edi
mov    (%rsp),%ebx
mov    0x8(%rsp),%ecx
mov    %ebx,%esi
shr    %cl,%esi
xor    %edi,%esi
test   $0x1,%sil
je     1205 <main+0xc5>
btc    %eax,%edx
mov    %edx,0x4(%rsp)
btc    %ecx,%ebx
mov    %ebx,(%rsp)
lea    0xe8c(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%edi
call   1060 <showbit@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%rsp),%edi
call   1060 <showbit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"WELCOME TO SWAP BIT FOR 2 NUMBERS\0A\00"
@.str.1 = [22 x i8] c"Enter source numbers\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [27 x i8] c"Enter destination numbers\0A\00"
@.str.4 = [25 x i8] c"The numbers before swap\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [43 x i8] c"Enter the source and destination position\0A\00"
@.str.7 = [5 x i8] c"%d%d\00"
@.str.8 = [24 x i8] c"The numbers after swap\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%9 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%11 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%12 = load i32, i32* %2
%13 = call i32 @showbit(i32 %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%15 = load i32, i32* %3
%16 = call i32 @showbit(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0))
%18 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32* %4, i32* %5)
%19 = load i32, i32* %2
%20 = load i32, i32* %4
%21 = ashr i32 %19, %20
%22 = and i32 1, %21
%23 = load i32, i32* %3
%24 = load i32, i32* %5
%25 = ashr i32 %23, %24
%26 = and i32 1, %25
%27 = icmp ne i32 %22, %26
br i1 %27, label %28, label %37
28: ; preds = %0
%29 = load i32, i32* %4
%30 = shl i32 1, %29
%31 = load i32, i32* %2
%32 = xor i32 %30, %31
store i32 %32, i32* %2
%33 = load i32, i32* %5
%34 = shl i32 1, %33
%35 = load i32, i32* %3
%36 = xor i32 %34, %35
store i32 %36, i32* %3
br label %37
37: ; preds = %28, %0
%38 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%39 = load i32, i32* %2
%40 = call i32 @showbit(i32 %39)
%41 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%42 = load i32, i32* %3
%43 = call i32 @showbit(i32 %42)
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%d\00"
@.str.7 = [5 x i8] c"%d%d\00"
@str = [34 x i8] c"WELCOME TO SWAP BIT FOR 2 NUMBERS\00"
@str.9 = [21 x i8] c"Enter source numbers\00"
@str.10 = [26 x i8] c"Enter destination numbers\00"
@str.11 = [24 x i8] c"The numbers before swap\00"
@str.12 = [42 x i8] c"Enter the source and destination position\00"
@str.13 = [23 x i8] c"The numbers after swap\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.10, i64 0, i64 0))
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.11, i64 0, i64 0))
%15 = load i32, i32* %1
%16 = call i32 @showbit(i32 %15)
%17 = call i32 @putchar(i32 10)
%18 = load i32, i32* %2
%19 = call i32 @showbit(i32 %18)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.12, i64 0, i64 0))
%21 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32* %3, i32* %4)
%22 = load i32, i32* %1
%23 = load i32, i32* %3
%24 = lshr i32 %22, %23
%25 = load i32, i32* %2
%26 = load i32, i32* %4
%27 = lshr i32 %25, %26
%28 = xor i32 %27, %24
%29 = and i32 %28, 1
%30 = icmp eq i32 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %0
%32 = shl nuw i32 1, %23
%33 = xor i32 %32, %22
store i32 %33, i32* %1
%34 = shl nuw i32 1, %26
%35 = xor i32 %34, %25
store i32 %35, i32* %2
br label %36
36: ; preds = %31, %0
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.13, i64 0, i64 0))
%38 = load i32, i32* %1
%39 = call i32 @showbit(i32 %38)
%40 = call i32 @putchar(i32 10)
%41 = load i32, i32* %2
%42 = call i32 @showbit(i32 %41)
ret i32 0
}