#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*/ assert(int);
int /*<<< orphan*/ assign_bit(unsigned char *, int, int);
int /*<<< orphan*/ clear_bit(unsigned char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_bit(unsigned char *, int);
int test_bit(unsigned char *, int);
void test_one_bit() {
  printf("test one bit start...\n");
  unsigned char c = 0;
  set_bit(&c, 1);
  assert(test_bit(&c, 1) == 1);
  clear_bit(&c, 1);
  assert(test_bit(&c, 1) == 0);
  assign_bit(&c, 1, 1);
  assert(test_bit(&c, 1) == 1);
  assert(c == 2);
  assign_bit(&c, 1, 0);
  assert(test_bit(&c, 1) == 0);
  assert(c == 0);
}


x86 assembly (clang, -O0):
<test_one_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
movb   $0x0,-0x1(%rbp)
lea    -0x1(%rbp),%rdi
mov    $0x1,%esi
call   1050 <set_bit@plt>
lea    -0x1(%rbp),%rdi
mov    $0x1,%esi
call   1070 <test_bit@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x1(%rbp),%rdi
mov    $0x1,%esi
call   1040 <clear_bit@plt>
lea    -0x1(%rbp),%rdi
mov    $0x1,%esi
call   1070 <test_bit@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x1(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1080 <assign_bit@plt>
lea    -0x1(%rbp),%rdi
mov    $0x1,%esi
call   1070 <test_bit@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movzbl -0x1(%rbp),%eax
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    -0x1(%rbp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1080 <assign_bit@plt>
lea    -0x1(%rbp),%rdi
mov    $0x1,%esi
call   1070 <test_bit@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movzbl -0x1(%rbp),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_one_bit>:
push   %rbx
sub    $0x10,%rsp
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
movb   $0x0,0xf(%rsp)
lea    0xf(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1050 <set_bit@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1070 <test_bit@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <clear_bit@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1070 <test_bit@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1080 <assign_bit@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1070 <test_bit@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
cmpb   $0x2,0xf(%rsp)
sete   %dil
call   1060 <assert@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1080 <assign_bit@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1070 <test_bit@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
cmpb   $0x0,0xf(%rsp)
sete   %dil
call   1060 <assert@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"test one bit start...\0A\00"
define void @test_one_bit() {
%1 = alloca i8
%2 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i8 0, i8* %1
%3 = call i32 @set_bit(i8* %1, i32 1)
%4 = call i32 @test_bit(i8* %1, i32 1)
%5 = icmp eq i32 %4, 1
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = call i32 @clear_bit(i8* %1, i32 1)
%9 = call i32 @test_bit(i8* %1, i32 1)
%10 = icmp eq i32 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = call i32 @assign_bit(i8* %1, i32 1, i32 1)
%14 = call i32 @test_bit(i8* %1, i32 1)
%15 = icmp eq i32 %14, 1
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8, i8* %1
%19 = zext i8 %18 to i32
%20 = icmp eq i32 %19, 2
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = call i32 @assign_bit(i8* %1, i32 1, i32 0)
%24 = call i32 @test_bit(i8* %1, i32 1)
%25 = icmp eq i32 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = load i8, i8* %1
%29 = zext i8 %28 to i32
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
ret void
}

LLVM IR (-O2):
@str = [22 x i8] c"test one bit start...\00"
define void @test_one_bit() {
%1 = alloca i8
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
store i8 0, i8* %1
%3 = call i32 @set_bit(i8* %1, i32 1)
%4 = call i32 @test_bit(i8* %1, i32 1)
%5 = icmp eq i32 %4, 1
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = call i32 @clear_bit(i8* %1, i32 1)
%9 = call i32 @test_bit(i8* %1, i32 1)
%10 = icmp eq i32 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = call i32 @assign_bit(i8* %1, i32 1, i32 1)
%14 = call i32 @test_bit(i8* %1, i32 1)
%15 = icmp eq i32 %14, 1
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i8, i8* %1
%19 = icmp eq i8 %18, 2
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = call i32 @assign_bit(i8* %1, i32 1, i32 0)
%23 = call i32 @test_bit(i8* %1, i32 1)
%24 = icmp eq i32 %23, 0
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = load i8, i8* %1
%28 = icmp eq i8 %27, 0
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
ret void
}