#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 mask(int, int);
int /*<<< orphan*/ printf(char *);
int swap_bits(int f_num, int f_src_pos, int f_dst_pos) {
  int mask1;
  int mask2;
  mask1 = (f_num & (mask(f_src_pos, 1)));
  mask2 = (f_num & (mask(f_dst_pos, 1)));
  if (mask1 == mask2) {
    printf("Swapping is not required\n");
  } else {
    f_num = f_num ^ ((1 << f_src_pos) | (1 << f_dst_pos));
  }
  return f_num;
}


x86 assembly (clang, -O0):
<swap_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1040 <mask@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    $0x1,%esi
call   1040 <mask@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
and    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1188 <swap_bits+0x68>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
jmp    11ac <swap_bits+0x8c>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,-0x20(%rbp)
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    -0x20(%rbp),%ecx
or     %edx,%ecx
xor    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_bits>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%r14d
mov    %edi,%ebx
mov    $0x1,%ebp
mov    %esi,%edi
mov    $0x1,%esi
call   1040 <mask@plt>
mov    %eax,%r12d
mov    %r15d,%edi
mov    $0x1,%esi
call   1040 <mask@plt>
xor    %r12d,%eax
test   %ebx,%eax
je     1165 <swap_bits+0x45>
mov    %r15d,%ecx
shl    %cl,%ebp
bts    %r14d,%ebp
xor    %ebp,%ebx
jmp    1171 <swap_bits+0x51>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Swapping is not required\0A\00"
define i32 @swap_bits(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = call i32 @mask(i32 %10, i32 1)
%12 = and i32 %9, %11
store i32 %12, i32* %7
%13 = load i32, i32* %4
%14 = load i32, i32* %6
%15 = call i32 @mask(i32 %14, i32 1)
%16 = and i32 %13, %15
store i32 %16, i32* %8
%17 = load i32, i32* %7
%18 = load i32, i32* %8
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %30
22: ; preds = %3
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = shl i32 1, %24
%26 = load i32, i32* %6
%27 = shl i32 1, %26
%28 = or i32 %25, %27
%29 = xor i32 %23, %28
store i32 %29, i32* %4
br label %30
30: ; preds = %22, %20
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@str = [25 x i8] c"Swapping is not required\00"
define i32 @swap_bits(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @mask(i32 %1, i32 1)
%5 = tail call i32 @mask(i32 %2, i32 1)
%6 = xor i32 %5, %4
%7 = and i32 %6, %0
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %16
11: ; preds = %3
%12 = shl nuw i32 1, %1
%13 = shl nuw i32 1, %2
%14 = or i32 %13, %12
%15 = xor i32 %14, %0
br label %16
16: ; preds = %11, %9
%17 = phi i32 [ %0, %9 ], [ %15, %11 ]
ret i32 %17
}