#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ print_binary(int);
int /*<<< orphan*/ printf(char *, ...);
void test_bit_toggle() {
  printf("\n===== test_bit_toggle\n");
  uint8_t value = 0xaf;
  uint8_t bp = 2;
  uint8_t result = value ^ (1 << bp);
  printf("Initial value              : ");
  print_binary(value);
  printf("Result of toggling bit %d   : ", bp);
  print_binary(result);
  assert(result == 0b10101011);
  printf("After again toggling bit %d : ", bp);
  result ^= 1 << bp;
  print_binary(result);
  assert(result == 0b10101111);
}


x86 assembly (clang, -O0):
<test_bit_toggle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xaf,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    %ecx,%eax
mov    %eax,-0xc(%rbp)
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <print_binary@plt>
mov    -0x8(%rbp),%esi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
call   1050 <print_binary@plt>
cmpl   $0xab,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <print_binary@plt>
cmpl   $0xaf,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_bit_toggle>:
push   %rax
lea    0xf14(%rip),%rdi
call   1030 <puts@plt>
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xaf,%edi
call   1060 <print_binary@plt>
lea    0xeb2(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xab,%edi
call   1060 <print_binary@plt>
mov    $0x1,%edi
call   1050 <assert@plt>
lea    0xeaa(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xaf,%edi
call   1060 <print_binary@plt>
mov    $0x1,%edi
pop    %rax
jmp    1050 <assert@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"\0A===== test_bit_toggle\0A\00"
@.str.1 = [30 x i8] c"Initial value : \00"
@.str.2 = [31 x i8] c"Result of toggling bit %d : \00"
@.str.3 = [31 x i8] c"After again toggling bit %d : \00"
define void @test_bit_toggle() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 175, i32* %1
store i32 2, i32* %2
%5 = load i32, i32* %1
%6 = load i32, i32* %2
%7 = shl i32 1, %6
%8 = xor i32 %5, %7
store i32 %8, i32* %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* %1
%11 = call i32 @print_binary(i32 %10)
%12 = load i32, i32* %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %3
%15 = call i32 @print_binary(i32 %14)
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 171
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %2
%23 = shl i32 1, %22
%24 = load i32, i32* %3
%25 = xor i32 %24, %23
store i32 %25, i32* %3
%26 = load i32, i32* %3
%27 = call i32 @print_binary(i32 %26)
%28 = load i32, i32* %3
%29 = icmp eq i32 %28, 175
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
ret void
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"Initial value : \00"
@.str.2 = [31 x i8] c"Result of toggling bit %d : \00"
@.str.3 = [31 x i8] c"After again toggling bit %d : \00"
@str = [23 x i8] c"\0A===== test_bit_toggle\00"
define void @test_bit_toggle() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @print_binary(i32 175)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 2)
%5 = tail call i32 @print_binary(i32 171)
%6 = tail call i32 @assert(i32 1)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 2)
%8 = tail call i32 @print_binary(i32 175)
%9 = tail call i32 @assert(i32 1)
ret void
}