#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 agile_bit_get(unsigned char *, int);
int /*<<< orphan*/ agile_bit_rot_left(unsigned char *, int, int);
int /*<<< orphan*/ agile_bit_set(unsigned char *, int, int);
int /*<<< orphan*/ dump_bits(unsigned char *, int);
int /*<<< orphan*/ printf(char *, int);
void test_agile_bit() {
  unsigned char bits[4] = {0};
  int size = 32;
  dump_bits(bits, size);
  agile_bit_set(bits, 7, 1);
  agile_bit_set(bits, 9, 1);
  dump_bits(bits, size);
  agile_bit_rot_left(bits, size, 7);
  dump_bits(bits, size);
  printf("bit2: %d\n", agile_bit_get(bits, 2));
}


x86 assembly (clang, -O0):
<test_agile_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x4(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
movl   $0x20,-0x8(%rbp)
lea    -0x4(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <dump_bits@plt>
lea    -0x4(%rbp),%rdi
mov    $0x7,%esi
mov    $0x1,%edx
call   1080 <agile_bit_set@plt>
lea    -0x4(%rbp),%rdi
mov    $0x9,%esi
mov    $0x1,%edx
call   1080 <agile_bit_set@plt>
lea    -0x4(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <dump_bits@plt>
lea    -0x4(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x7,%edx
call   1060 <agile_bit_rot_left@plt>
lea    -0x4(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <dump_bits@plt>
lea    -0x4(%rbp),%rdi
mov    $0x2,%esi
call   1070 <agile_bit_get@plt>
mov    %eax,%esi
lea    0xe0f(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_agile_bit>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <dump_bits@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
mov    $0x1,%edx
call   1070 <agile_bit_set@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
mov    $0x1,%edx
call   1070 <agile_bit_set@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <dump_bits@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
mov    $0x7,%edx
call   1050 <agile_bit_rot_left@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <dump_bits@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1060 <agile_bit_get@plt>
lea    0xe2d(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"bit2: %d\0A\00"
define void @test_agile_bit() {
%1 = alloca [4 x i8]
%2 = alloca i32
%3 = bitcast [4 x i8]* %1 to i8*
store i32 32, i32* %2
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* %2
%6 = call i32 @dump_bits(i8* %4, i32 %5)
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%8 = call i32 @agile_bit_set(i8* %7, i32 7, i32 1)
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%10 = call i32 @agile_bit_set(i8* %9, i32 9, i32 1)
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%12 = load i32, i32* %2
%13 = call i32 @dump_bits(i8* %11, i32 %12)
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%15 = load i32, i32* %2
%16 = call i32 @agile_bit_rot_left(i8* %14, i32 %15, i32 7)
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%18 = load i32, i32* %2
%19 = call i32 @dump_bits(i8* %17, i32 %18)
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%21 = call i32 @agile_bit_get(i8* %20, i32 2)
%22 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %21)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"bit2: %d\0A\00"
define void @test_agile_bit() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = call i32 @dump_bits(i8* %2, i32 32)
%4 = call i32 @agile_bit_set(i8* %2, i32 7, i32 1)
%5 = call i32 @agile_bit_set(i8* %2, i32 9, i32 1)
%6 = call i32 @dump_bits(i8* %2, i32 32)
%7 = call i32 @agile_bit_rot_left(i8* %2, i32 32, i32 7)
%8 = call i32 @dump_bits(i8* %2, i32 32)
%9 = call i32 @agile_bit_get(i8* %2, i32 2)
%10 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
ret void
}