#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 /*<<< orphan*/);
int /*<<< orphan*/ agile_bit_set(unsigned char *, int, int);
void agile_bit_rot_left(unsigned char *bits, int size, int count) {
  int fbit;
  int lbit;
  int i, j;
  if (size > 0) {
    for (j = 0; j < count; ++j) {
      for (i = 0; i <= ((size - 1) / 8); ++i) {
        lbit = agile_bit_get(&bits[i], 0);
        if (i == 0)
          fbit = lbit;
        else
          agile_bit_set(&bits[i - 1], 7, lbit);
        bits[i] <<= 1;
      }
      agile_bit_set(bits, size - 1, fbit);
    }
  }
}


x86 assembly (clang, -O0):
<agile_bit_rot_left>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1202 <agile_bit_rot_left+0xe2>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11fd <agile_bit_rot_left+0xdd>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jg     11dd <agile_bit_rot_left+0xbd>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
xor    %esi,%esi
call   1030 <agile_bit_get@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11a1 <agile_bit_rot_left+0x81>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11bd <agile_bit_rot_left+0x9d>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%edx
mov    $0x7,%esi
call   1040 <agile_bit_set@plt>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
shl    $0x1,%edx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1156 <agile_bit_rot_left+0x36>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x14(%rbp),%edx
call   1040 <agile_bit_set@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1143 <agile_bit_rot_left+0x23>
jmp    1202 <agile_bit_rot_left+0xe2>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<agile_bit_rot_left>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,0xc(%rsp)
mov    %rsi,0x10(%rsp)
test   %esi,%esi
jle    11d9 <agile_bit_rot_left+0xb9>
cmpl   $0x0,0xc(%rsp)
jle    11d9 <agile_bit_rot_left+0xb9>
mov    %rdi,%r13
mov    0x10(%rsp),%rax
lea    -0x1(%rax),%r12d
mov    %r12d,%eax
shr    $0x3,%eax
mov    %rax,0x20(%rsp)
lea    0x1(%rdi),%rax
mov    %rax,0x18(%rsp)
xor    %r14d,%r14d
jmp    1188 <agile_bit_rot_left+0x68>
nop
mov    %r13,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
call   1040 <agile_bit_set@plt>
add    $0x1,%r14d
cmp    0xc(%rsp),%r14d
je     11d9 <agile_bit_rot_left+0xb9>
mov    %r13,%rdi
xor    %esi,%esi
call   1030 <agile_bit_get@plt>
shlb   0x0(%r13)
mov    %eax,%ebx
cmpl   $0x9,0x10(%rsp)
jl     1170 <agile_bit_rot_left+0x50>
mov    0x20(%rsp),%r15
mov    0x18(%rsp),%rbp
nopl   0x0(%rax)
mov    %rbp,%rdi
xor    %esi,%esi
call   1030 <agile_bit_get@plt>
lea    -0x1(%rbp),%rdi
mov    $0x7,%esi
mov    %eax,%edx
call   1040 <agile_bit_set@plt>
shlb   0x0(%rbp)
add    $0x1,%rbp
add    $0xffffffffffffffff,%r15
jne    11b0 <agile_bit_rot_left+0x90>
jmp    1170 <agile_bit_rot_left+0x50>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @agile_bit_rot_left(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %65
13: ; preds = %3
store i32 0, i32* %10
br label %14
14: ; preds = %61, %13
%15 = load i32, i32* %10
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %64
18: ; preds = %14
store i32 0, i32* %9
br label %19
19: ; preds = %52, %18
%20 = load i32, i32* %9
%21 = load i32, i32* %5
%22 = sub nsw i32 %21, 1
%23 = sdiv i32 %22, 8
%24 = icmp sle i32 %20, %23
br i1 %24, label %25, label %55
25: ; preds = %19
%26 = load i8*, i8** %4
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = call i32 @agile_bit_get(i8* %29, i32 0)
store i32 %30, i32* %8
%31 = load i32, i32* %9
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %25
%34 = load i32, i32* %8
store i32 %34, i32* %7
br label %43
35: ; preds = %25
%36 = load i8*, i8** %4
%37 = load i32, i32* %9
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = load i32, i32* %8
%42 = call i32 @agile_bit_set(i8* %40, i32 7, i32 %41)
br label %43
43: ; preds = %35, %33
%44 = load i8*, i8** %4
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = shl i32 %49, 1
%51 = trunc i32 %50 to i8
store i8 %51, i8* %47
br label %52
52: ; preds = %43
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %19
55: ; preds = %19
%56 = load i8*, i8** %4
%57 = load i32, i32* %5
%58 = sub nsw i32 %57, 1
%59 = load i32, i32* %7
%60 = call i32 @agile_bit_set(i8* %56, i32 %58, i32 %59)
br label %61
61: ; preds = %55
%62 = load i32, i32* %10
%63 = add nsw i32 %62, 1
store i32 %63, i32* %10
br label %14
64: ; preds = %14
br label %65
65: ; preds = %64, %3
ret void
}

LLVM IR (-O2):
define void @agile_bit_rot_left(i8* %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
%5 = icmp sgt i32 %2, 0
%6 = and i1 %4, %5
br i1 %6, label %7, label %33
7: ; preds = %3
%8 = add nsw i32 %1, -1
%9 = lshr i32 %8, 3
%10 = add nuw nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = icmp slt i32 %1, 9
br label %13
13: ; preds = %29, %7
%14 = phi i32 [ 0, %7 ], [ %31, %29 ]
%15 = tail call i32 @agile_bit_get(i8* %0, i32 0)
%16 = load i8, i8* %0
%17 = shl i8 %16, 1
store i8 %17, i8* %0
br i1 %12, label %29, label %18
18: ; preds = %13, %18
%19 = phi i64 [ %27, %18 ], [ 1, %13 ]
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = tail call i32 @agile_bit_get(i8* %20, i32 0)
%22 = add nsw i64 %19, -1
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = tail call i32 @agile_bit_set(i8* %23, i32 7, i32 %21)
%25 = load i8, i8* %20
%26 = shl i8 %25, 1
store i8 %26, i8* %20
%27 = add nuw nsw i64 %19, 1
%28 = icmp eq i64 %27, %11
br i1 %28, label %29, label %18
29: ; preds = %18, %13
%30 = tail call i32 @agile_bit_set(i8* %0, i32 %8, i32 %15)
%31 = add nuw nsw i32 %14, 1
%32 = icmp eq i32 %31, %2
br i1 %32, label %33, label %13
33: ; preds = %29, %3
ret void
}