#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*/ print_bin(int);
int /*<<< orphan*/ printf(char *);
int main() {
  uint8_t reg = 0b00000000;
  reg |= 1 << 2;
  print_bin(reg);
  printf("\n");
  reg &= ~(1 << 2);
  print_bin(reg);
  printf("\n");
  reg ^= 1 << 2;
  print_bin(reg);
  printf("\n");
  if (reg & (1 << 2))
    printf("bit 2 is set\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <print_bin@plt>
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
and    $0xfffffffb,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <print_bin@plt>
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
xor    $0x4,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <print_bin@plt>
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11a8 <main+0x88>
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0x4,%edi
call   1050 <print_bin@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   1050 <print_bin@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x4,%edi
call   1050 <print_bin@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe8f(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [14 x i8] c"bit 2 is set\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%3 = load i32, i32* %2
%4 = or i32 %3, 4
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @print_bin(i32 %5)
%7 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %2
%9 = and i32 %8, -5
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = call i32 @print_bin(i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %2
%14 = xor i32 %13, 4
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = call i32 @print_bin(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* %2
%19 = and i32 %18, 4
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %0
ret i32 0
}

LLVM IR (-O2):
@str = [13 x i8] c"bit 2 is set\00"
define i32 @main() {
%1 = tail call i32 @print_bin(i32 4)
%2 = tail call i32 @putchar(i32 10)
%3 = tail call i32 @print_bin(i32 0)
%4 = tail call i32 @putchar(i32 10)
%5 = tail call i32 @print_bin(i32 4)
%6 = tail call i32 @putchar(i32 10)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
ret i32 0
}