#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*/ printbinary(unsigned char);
void shiftarray(unsigned char *value, int amount, int shift) {
  for (int i = 0; i < amount; i++)
    printbinary((value[i + (shift / 8)] << (shift % 8)) |
                (value[i + (shift / 8) + 1] >> 8 - (shift % 8)));
}


x86 assembly (clang, -O0):
<shiftarray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d3 <shiftarray+0xc3>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
mov    $0x8,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x38(%rbp),%rax
add    %edx,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x2c(%rbp),%eax
mov    %edx,%ecx
shl    %cl,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%eax
mov    $0x8,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x28(%rbp),%rax
add    %edx,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    -0x1c(%rbp),%eax
mov    %edx,%esi
mov    -0x18(%rbp),%edx
mov    $0x8,%ecx
sub    %esi,%ecx
sar    %cl,%edx
mov    %edx,%ecx
or     %ecx,%eax
movzbl %al,%edi
call   1030 <printbinary@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <shiftarray+0x19>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shiftarray>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
jle    1176 <shiftarray+0x66>
mov    %edx,%r14d
lea    0x7(%r14),%eax
test   %edx,%edx
cmovns %edx,%eax
mov    %eax,%ecx
sar    $0x3,%ecx
and    $0xfffffff8,%eax
sub    %eax,%r14d
mov    $0x8,%r12d
sub    %r14d,%r12d
movslq %ecx,%rax
mov    %esi,%r15d
lea    (%rax,%rdi,1),%rbx
add    $0x1,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
movzbl -0x1(%rbx,%rbp,1),%eax
mov    %r14d,%ecx
shl    %cl,%eax
movzbl (%rbx,%rbp,1),%edx
mov    %r12d,%ecx
shr    %cl,%edx
or     %eax,%edx
movzbl %dl,%edi
call   1030 <printbinary@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1150 <shiftarray+0x40>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @shiftarray(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %42, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %45
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = load i32, i32* %7
%15 = load i32, i32* %6
%16 = sdiv i32 %15, 8
%17 = add nsw i32 %14, %16
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %13, i64 %18
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = load i32, i32* %6
%23 = srem i32 %22, 8
%24 = shl i32 %21, %23
%25 = load i8*, i8** %4
%26 = load i32, i32* %7
%27 = load i32, i32* %6
%28 = sdiv i32 %27, 8
%29 = add nsw i32 %26, %28
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %25, i64 %31
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = load i32, i32* %6
%36 = srem i32 %35, 8
%37 = sub nsw i32 8, %36
%38 = ashr i32 %34, %37
%39 = or i32 %24, %38
%40 = trunc i32 %39 to i8
%41 = call i32 @printbinary(i8 zeroext %40)
br label %42
42: ; preds = %12
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %8
45: ; preds = %8
ret void
}

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