#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*/ printf(char *, ...);
void printAsBinary(int numBytes, const char data) {
  const int numBits = numBytes * 8;
  for (int i = 0; i < numBits; ++i) {
    if (i > 3 && !(i % 4)) {
      printf(" ");
    }
    printf("%1d", (((data << i) & 0x80) >> 7) & 1);
  }
}


x86 assembly (clang, -O0):
<printAsBinary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x4(%rbp)
mov    %al,-0x5(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119a <printAsBinary+0x8a>
cmpl   $0x3,-0x10(%rbp)
jle    1169 <printAsBinary+0x59>
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1169 <printAsBinary+0x59>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x5(%rbp),%esi
mov    -0x10(%rbp),%ecx
shl    %cl,%esi
and    $0x80,%esi
sar    $0x7,%esi
and    $0x1,%esi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1131 <printAsBinary+0x21>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printAsBinary>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    1186 <printAsBinary+0x66>
shl    $0x3,%edi
movzbl %sil,%r15d
cmp    $0x2,%edi
mov    $0x1,%ebx
cmovge %edi,%ebx
lea    0xebc(%rip),%r14
xor    %ebp,%ebp
jmp    116e <printAsBinary+0x4e>
nopl   0x0(%rax,%rax,1)
mov    %r15d,%esi
mov    %ebp,%ecx
shl    %cl,%esi
shr    $0x7,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
je     1186 <printAsBinary+0x66>
cmp    $0x4,%ebp
jb     1150 <printAsBinary+0x30>
mov    %ebp,%eax
and    $0x3,%eax
jne    1150 <printAsBinary+0x30>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1150 <printAsBinary+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [4 x i8] c"%1d\00"
define void @printAsBinary(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8 %1, i8* %4
%7 = load i32, i32* %3
%8 = mul nsw i32 %7, 8
store i32 %8, i32* %5
store i32 0, i32* %6
br label %9
9: ; preds = %31, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %34
13: ; preds = %9
%14 = load i32, i32* %6
%15 = icmp sgt i32 %14, 3
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i32, i32* %6
%18 = srem i32 %17, 4
%19 = icmp ne i32 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %16, %13
%23 = load i8, i8* %4
%24 = sext i8 %23 to i32
%25 = load i32, i32* %6
%26 = shl i32 %24, %25
%27 = and i32 %26, 128
%28 = ashr i32 %27, 7
%29 = and i32 %28, 1
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %22
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %9
34: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%1d\00"
define void @printAsBinary(i32 %0, i8 signext %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = shl i32 %0, 3
%6 = zext i8 %1 to i32
%7 = call i32 @llvm.smax.i32(i32 %5, i32 1)
br label %9
8: ; preds = %17, %2
ret void
9: ; preds = %4, %17
%10 = phi i32 [ 0, %4 ], [ %22, %17 ]
%11 = icmp ugt i32 %10, 3
%12 = and i32 %10, 3
%13 = icmp eq i32 %12, 0
%14 = and i1 %11, %13
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = tail call i32 @putchar(i32 32)
br label %17
17: ; preds = %15, %9
%18 = shl i32 %6, %10
%19 = lshr i32 %18, 7
%20 = and i32 %19, 1
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = add nuw nsw i32 %10, 1
%23 = icmp eq i32 %22, %7
br i1 %23, label %8, label %9
}