#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*/ ClearBitfieldBit(char *, unsigned long);
int GetBitfieldBit(char *, unsigned long);
int /*<<< orphan*/ SetBitfieldBit(char *, unsigned long);
void SwapBitfieldBits(char *bitfield, unsigned long bitpos1,
                      unsigned long bitpos2) {
  int bit1, bit2;
  bit1 = GetBitfieldBit(bitfield, bitpos1);
  bit2 = GetBitfieldBit(bitfield, bitpos2);
  if (bit1)
    SetBitfieldBit(bitfield, bitpos2);
  else
    ClearBitfieldBit(bitfield, bitpos2);
  if (bit2)
    SetBitfieldBit(bitfield, bitpos1);
  else
    ClearBitfieldBit(bitfield, bitpos1);
}


x86 assembly (clang, -O0):
<SwapBitfieldBits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <GetBitfieldBit@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <GetBitfieldBit@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1180 <SwapBitfieldBits+0x50>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <SetBitfieldBit@plt>
jmp    118d <SwapBitfieldBits+0x5d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <ClearBitfieldBit@plt>
cmpl   $0x0,-0x20(%rbp)
je     11a9 <SwapBitfieldBits+0x79>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <SetBitfieldBit@plt>
jmp    11b6 <SwapBitfieldBits+0x86>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <ClearBitfieldBit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SwapBitfieldBits>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <GetBitfieldBit@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <GetBitfieldBit@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    %r15,%rsi
test   %ebp,%ebp
je     1167 <SwapBitfieldBits+0x37>
call   1040 <SetBitfieldBit@plt>
jmp    116c <SwapBitfieldBits+0x3c>
call   1030 <ClearBitfieldBit@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
test   %r12d,%r12d
je     1184 <SwapBitfieldBits+0x54>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <SetBitfieldBit@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <ClearBitfieldBit@plt>

LLVM IR (-O0):
define void @SwapBitfieldBits(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i8*, i8** %4
%10 = load i64, i64* %5
%11 = call i32 @GetBitfieldBit(i8* %9, i64 %10)
store i32 %11, i32* %7
%12 = load i8*, i8** %4
%13 = load i64, i64* %6
%14 = call i32 @GetBitfieldBit(i8* %12, i64 %13)
store i32 %14, i32* %8
%15 = load i32, i32* %7
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %3
%18 = load i8*, i8** %4
%19 = load i64, i64* %6
%20 = call i32 @SetBitfieldBit(i8* %18, i64 %19)
br label %25
21: ; preds = %3
%22 = load i8*, i8** %4
%23 = load i64, i64* %6
%24 = call i32 @ClearBitfieldBit(i8* %22, i64 %23)
br label %25
25: ; preds = %21, %17
%26 = load i32, i32* %8
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i8*, i8** %4
%30 = load i64, i64* %5
%31 = call i32 @SetBitfieldBit(i8* %29, i64 %30)
br label %36
32: ; preds = %25
%33 = load i8*, i8** %4
%34 = load i64, i64* %5
%35 = call i32 @ClearBitfieldBit(i8* %33, i64 %34)
br label %36
36: ; preds = %32, %28
ret void
}

LLVM IR (-O2):
define void @SwapBitfieldBits(i8* %0, i64 %1, i64 %2) {
%4 = tail call i32 @GetBitfieldBit(i8* %0, i64 %1)
%5 = tail call i32 @GetBitfieldBit(i8* %0, i64 %2)
%6 = icmp eq i32 %4, 0
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i32 @SetBitfieldBit(i8* %0, i64 %2)
br label %11
9: ; preds = %3
%10 = tail call i32 @ClearBitfieldBit(i8* %0, i64 %2)
br label %11
11: ; preds = %9, %7
%12 = icmp eq i32 %5, 0
br i1 %12, label %15, label %13
13: ; preds = %11
%14 = tail call i32 @SetBitfieldBit(i8* %0, i64 %1)
br label %17
15: ; preds = %11
%16 = tail call i32 @ClearBitfieldBit(i8* %0, i64 %1)
br label %17
17: ; preds = %15, %13
ret void
}