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


x86 assembly (clang, -O0):
<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    11e6 <bit_rot_left+0xc6>
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     11d4 <bit_rot_left+0xb4>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
xor    %esi,%esi
call   1030 <bit_get@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    118e <bit_rot_left+0x6e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11aa <bit_rot_left+0x8a>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%edx
mov    $0x7,%esi
call   1040 <bit_set@plt>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
shl    $0x1,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1143 <bit_rot_left+0x23>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x14(%rbp),%edx
call   1040 <bit_set@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_rot_left>:
test   %esi,%esi
jle    119d <bit_rot_left+0x7d>
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r12
lea    -0x1(%rbp),%r15d
xor    %esi,%esi
call   1030 <bit_get@plt>
shlb   (%r12)
mov    %eax,%r14d
cmp    $0x9,%ebp
jb     1187 <bit_rot_left+0x67>
mov    %r15d,%ebx
shr    $0x3,%ebx
add    $0x1,%ebx
lea    0x1(%r12),%rbp
add    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
xor    %esi,%esi
call   1030 <bit_get@plt>
lea    -0x1(%rbp),%rdi
mov    $0x7,%esi
mov    %eax,%edx
call   1040 <bit_set@plt>
shlb   0x0(%rbp)
add    $0x1,%rbp
add    $0xffffffffffffffff,%rbx
jne    1160 <bit_rot_left+0x40>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r14d,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <bit_set@plt>
ret

LLVM IR (-O0):
define void @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 %60
13: ; preds = %3
store i32 0, i32* %9
br label %14
14: ; preds = %51, %13
%15 = load i32, i32* %9
%16 = load i32, i32* %5
%17 = sub nsw i32 %16, 1
%18 = sdiv i32 %17, 8
%19 = icmp sle i32 %15, %18
br i1 %19, label %20, label %54
20: ; preds = %14
%21 = load i8*, i8** %4
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = call i32 @bit_get(i8* %24, i32 0)
store i32 %25, i32* %8
%26 = load i32, i32* %9
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %20
%29 = load i32, i32* %8
store i32 %29, i32* %7
br label %38
30: ; preds = %20
%31 = load i8*, i8** %4
%32 = load i32, i32* %9
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i32, i32* %8
%37 = call i32 @bit_set(i8* %35, i32 7, i32 %36)
br label %38
38: ; preds = %30, %28
%39 = load i8*, i8** %4
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = shl i32 %44, 1
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %4
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 %46, i8* %50
br label %51
51: ; preds = %38
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 1
store i32 %53, i32* %9
br label %14
54: ; preds = %14
%55 = load i8*, i8** %4
%56 = load i32, i32* %5
%57 = sub nsw i32 %56, 1
%58 = load i32, i32* %7
%59 = call i32 @bit_set(i8* %55, i32 %57, i32 %58)
br label %60
60: ; preds = %54, %3
ret void
}

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