#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_check() {
  printf("\n===== test_bit_check\n");
  uint8_t value = 0xf0;
  uint8_t bp = 2;
  uint8_t bp2 = 6;
  uint8_t result = (value & (1 << bp)) > 0;
  uint8_t result2 = (value & (1 << bp2)) > 0;
  printf("Initial value     : ");
  print_binary(value);
  printf("Test if bit %d set : ", bp);
  print_binary(result);
  assert(result == 0);
  printf("Test if bit %d set : ", bp2);
  print_binary(result2);
  assert(result2 == 1);
}


x86 assembly (clang, -O0):
<test_bit_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xf0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x6,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <print_binary@plt>
mov    -0x8(%rbp),%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%edi
call   1050 <print_binary@plt>
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%esi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <print_binary@plt>
cmpl   $0x1,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_bit_check>:
push   %rbx
lea    0xee3(%rip),%rdi
call   1030 <puts@plt>
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xf0,%edi
call   1060 <print_binary@plt>
lea    0xea9(%rip),%rbx
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <print_binary@plt>
mov    $0x1,%edi
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <print_binary@plt>
mov    $0x1,%edi
pop    %rbx
jmp    1050 <assert@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"\0A===== test_bit_check\0A\00"
@.str.1 = [21 x i8] c"Initial value : \00"
@.str.2 = [22 x i8] c"Test if bit %d set : \00"
define void @test_bit_check() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 240, i32* %1
store i32 2, i32* %2
store i32 6, i32* %3
%7 = load i32, i32* %1
%8 = load i32, i32* %2
%9 = shl i32 1, %8
%10 = and i32 %7, %9
%11 = icmp sgt i32 %10, 0
%12 = zext i1 %11 to i32
store i32 %12, i32* %4
%13 = load i32, i32* %1
%14 = load i32, i32* %3
%15 = shl i32 1, %14
%16 = and i32 %13, %15
%17 = icmp sgt i32 %16, 0
%18 = zext i1 %17 to i32
store i32 %18, i32* %5
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* %1
%21 = call i32 @print_binary(i32 %20)
%22 = load i32, i32* %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %4
%25 = call i32 @print_binary(i32 %24)
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 0
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %5
%33 = call i32 @print_binary(i32 %32)
%34 = load i32, i32* %5
%35 = icmp eq i32 %34, 1
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
ret void
}

LLVM IR (-O2):
@.str.1 = [21 x i8] c"Initial value : \00"
@.str.2 = [22 x i8] c"Test if bit %d set : \00"
@str = [22 x i8] c"\0A===== test_bit_check\00"
define void @test_bit_check() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 @print_binary(i32 240)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 2)
%5 = tail call i32 @print_binary(i32 0)
%6 = tail call i32 @assert(i32 1)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 6)
%8 = tail call i32 @print_binary(i32 1)
%9 = tail call i32 @assert(i32 1)
ret void
}