#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 (j = 0; j < count; j++) {
      for (i = 0; i < (size / 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);
    }
  }
  return;
}


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    1209 <bit_rot_left+0xe9>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1204 <bit_rot_left+0xe4>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11e4 <bit_rot_left+0xc4>
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    119e <bit_rot_left+0x7e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11ba <bit_rot_left+0x9a>
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    1156 <bit_rot_left+0x36>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    -0x14(%rbp),%edx
call   1040 <bit_set@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1143 <bit_rot_left+0x23>
jmp    1209 <bit_rot_left+0xe9>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bit_rot_left>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %esi,%esi
jle    11f1 <bit_rot_left+0xd1>
mov    %edx,%r15d
test   %edx,%edx
jle    11f1 <bit_rot_left+0xd1>
mov    %esi,%r12d
mov    %rdi,%rbp
mov    %esi,%eax
shr    $0x3,%eax
lea    -0x1(%r12),%ebx
mov    %esi,%ecx
and    $0xfffffff8,%ecx
mov    %ecx,0x14(%rsp)
lea    0x1(%rdi),%rcx
mov    %rcx,0x18(%rsp)
add    $0xffffffffffffffff,%rax
mov    %rax,0x20(%rsp)
xor    %r14d,%r14d
mov    %r15d,0x10(%rsp)
mov    %ebx,0xc(%rsp)
jmp    1196 <bit_rot_left+0x76>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r13d,%edx
call   1040 <bit_set@plt>
add    $0x1,%r14d
cmp    %r15d,%r14d
je     11f1 <bit_rot_left+0xd1>
cmp    $0x8,%r12d
jb     1180 <bit_rot_left+0x60>
mov    %rbp,%rdi
xor    %esi,%esi
call   1030 <bit_get@plt>
shlb   0x0(%rbp)
mov    %eax,%r13d
cmpl   $0x8,0x14(%rsp)
je     1180 <bit_rot_left+0x60>
mov    0x20(%rsp),%r15
mov    0x18(%rsp),%rbx
nopl   (%rax)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <bit_get@plt>
lea    -0x1(%rbx),%rdi
mov    $0x7,%esi
mov    %eax,%edx
call   1040 <bit_set@plt>
shlb   (%rbx)
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
jne    11c0 <bit_rot_left+0xa0>
mov    0x10(%rsp),%r15d
mov    0xc(%rsp),%ebx
jmp    1180 <bit_rot_left+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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 %68
13: ; preds = %3
store i32 0, i32* %10
br label %14
14: ; preds = %64, %13
%15 = load i32, i32* %10
%16 = load i32, i32* %6
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %67
18: ; preds = %14
store i32 0, i32* %9
br label %19
19: ; preds = %55, %18
%20 = load i32, i32* %9
%21 = load i32, i32* %5
%22 = sdiv i32 %21, 8
%23 = icmp slt i32 %20, %22
br i1 %23, label %24, label %58
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = call i32 @bit_get(i8* %28, i32 0)
store i32 %29, i32* %8
%30 = load i32, i32* %9
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = load i32, i32* %8
store i32 %33, i32* %7
br label %42
34: ; preds = %24
%35 = load i8*, i8** %4
%36 = load i32, i32* %9
%37 = sub nsw i32 %36, 1
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
%40 = load i32, i32* %8
%41 = call i32 @bit_set(i8* %39, i32 7, i32 %40)
br label %42
42: ; preds = %34, %32
%43 = load i8*, i8** %4
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = shl i32 %48, 1
%50 = trunc i32 %49 to i8
%51 = load i8*, i8** %4
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 %50, i8* %54
br label %55
55: ; preds = %42
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %19
58: ; preds = %19
%59 = load i8*, i8** %4
%60 = load i32, i32* %5
%61 = sub nsw i32 %60, 1
%62 = load i32, i32* %7
%63 = call i32 @bit_set(i8* %59, i32 %61, i32 %62)
br label %64
64: ; preds = %58
%65 = load i32, i32* %10
%66 = add nsw i32 %65, 1
store i32 %66, i32* %10
br label %14
67: ; preds = %14
br label %68
68: ; preds = %67, %3
ret void
}

LLVM IR (-O2):
define void @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 %37
7: ; preds = %3
%8 = lshr i32 %1, 3
%9 = icmp ugt i32 %1, 7
%10 = add nsw i32 %1, -1
%11 = zext i32 %8 to i64
%12 = and i32 %1, -8
%13 = icmp eq i32 %12, 8
br label %14
14: ; preds = %7, %32
%15 = phi i32 [ 0, %7 ], [ %35, %32 ]
%16 = phi i32 [ undef, %7 ], [ %33, %32 ]
br i1 %9, label %17, label %32
17: ; preds = %14
%18 = tail call i32 @bit_get(i8* %0, i32 0)
%19 = load i8, i8* %0
%20 = shl i8 %19, 1
store i8 %20, i8* %0
br i1 %13, label %32, label %21
21: ; preds = %17, %21
%22 = phi i64 [ %30, %21 ], [ 1, %17 ]
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = tail call i32 @bit_get(i8* %23, i32 0)
%25 = add nsw i64 %22, -1
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = tail call i32 @bit_set(i8* %26, i32 7, i32 %24)
%28 = load i8, i8* %23
%29 = shl i8 %28, 1
store i8 %29, i8* %23
%30 = add nuw nsw i64 %22, 1
%31 = icmp eq i64 %30, %11
br i1 %31, label %32, label %21
32: ; preds = %21, %17, %14
%33 = phi i32 [ %16, %14 ], [ %18, %17 ], [ %18, %21 ]
%34 = tail call i32 @bit_set(i8* %0, i32 %10, i32 %33)
%35 = add nuw nsw i32 %15, 1
%36 = icmp eq i32 %35, %2
br i1 %36, label %37, label %14
37: ; preds = %32, %3
ret void
}