#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 printbin(const bool bitstring[], int n) {
  int i;
  for (i = 0; i < n; i++) {
    printf(bitstring[i] ? "1" : "0");
    if ((i + 1) % 8 == 0)
      printf(" ");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<printbin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118d <printbin+0x7d>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xebe(%rip),%rdi
lea    0xeb5(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117a <printbin+0x6a>
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
jmp    117f <printbin+0x6f>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <printbin+0x16>
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printbin>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %esi,%esi
jle    118c <printbin+0x6c>
mov    %rdi,%r14
mov    %esi,%r15d
neg    %r15
mov    $0x1,%ebx
lea    0xec0(%rip),%r12
lea    0xeb7(%rip),%r13
jmp    116c <printbin+0x4c>
nopl   0x0(%rax,%rax,1)
call   1040 <printf@plt>
test   $0x7,%bl
je     1180 <printbin+0x60>
lea    (%r15,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x1,%rax
je     118c <printbin+0x6c>
cmpl   $0x0,-0x4(%r14,%rbx,4)
mov    %r12,%rdi
je     1150 <printbin+0x30>
mov    %r13,%rdi
jmp    1150 <printbin+0x30>
nopl   0x0(%rax)
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    115a <printbin+0x3a>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

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

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