#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void print_binary(void *p, int size, int chunks, const char *name) {
  int i, k;
  uint8_t *ar = p;
  printf("\n%s: \n", name);
  for (k = 0; k < chunks; k++) {
    if (k && k % 4 == 0)
      printf("\n");
    for (i = size - 1; i >= 0; i--) {
      printf("%u", *(int *)&ar[k] >> i & 1);
      if (i == 0)
        printf(" ");
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11f1 <print_binary+0xe1>
cmpl   $0x0,-0x20(%rbp)
je     117f <print_binary+0x6f>
mov    -0x20(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117f <print_binary+0x6f>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11de <print_binary+0xce>
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x1c(%rbp),%ecx
sar    %cl,%esi
and    $0x1,%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11cb <print_binary+0xbb>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d0 <print_binary+0xc0>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1188 <print_binary+0x78>
jmp    11e3 <print_binary+0xd3>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1147 <print_binary+0x37>
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_binary>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xec6(%rip),%rdi
mov    %rcx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    11b6 <print_binary+0x96>
mov    %ebp,%r12d
lea    -0x1(%r14),%eax
mov    %eax,0x4(%rsp)
lea    0xead(%rip),%r15
xor    %r13d,%r13d
jmp    1169 <print_binary+0x49>
nop
add    $0x1,%r13
cmp    %r12,%r13
je     11b6 <print_binary+0x96>
test   %r13,%r13
je     1183 <print_binary+0x63>
mov    %r13d,%eax
and    $0x3,%eax
test   %rax,%rax
jne    1183 <print_binary+0x63>
mov    $0xa,%edi
call   1030 <putchar@plt>
test   %r14d,%r14d
jle    1160 <print_binary+0x40>
mov    0x4(%rsp),%ebp
nopl   0x0(%rax)
mov    (%rbx,%r13,4),%esi
mov    %ebp,%ecx
shr    %cl,%esi
and    $0x1,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jb     1190 <print_binary+0x70>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    1160 <print_binary+0x40>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"\0A%s: \0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [3 x i8] c"%u\00"
@.str.3 = [2 x i8] c" \00"
define void @print_binary(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%12 = load i8*, i8** %5
%13 = bitcast i8* %12 to i32*
store i32* %13, i32** %11
%14 = load i8*, i8** %8
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 0, i32* %10
br label %16
16: ; preds = %54, %4
%17 = load i32, i32* %10
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %57
20: ; preds = %16
%21 = load i32, i32* %10
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32, i32* %10
%25 = srem i32 %24, 4
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %23, %20
%30 = load i32, i32* %6
%31 = sub nsw i32 %30, 1
store i32 %31, i32* %9
br label %32
32: ; preds = %50, %29
%33 = load i32, i32* %9
%34 = icmp sge i32 %33, 0
br i1 %34, label %35, label %53
35: ; preds = %32
%36 = load i32*, i32** %11
%37 = load i32, i32* %10
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = load i32, i32* %9
%42 = ashr i32 %40, %41
%43 = and i32 %42, 1
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %43)
%45 = load i32, i32* %9
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %35
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %47, %35
br label %50
50: ; preds = %49
%51 = load i32, i32* %9
%52 = add nsw i32 %51, -1
store i32 %52, i32* %9
br label %32
53: ; preds = %32
br label %54
54: ; preds = %53
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %16
57: ; preds = %16
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"\0A%s: \0A\00"
@.str.2 = [3 x i8] c"%u\00"
define void @print_binary(i8* nocapture %0, i32 %1, i32 %2, i8* %3) {
%5 = bitcast i8* %0 to i32*
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %3)
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %35
8: ; preds = %4
%9 = icmp sgt i32 %1, 0
%10 = zext i32 %2 to i64
br label %11
11: ; preds = %8, %32
%12 = phi i64 [ 0, %8 ], [ %33, %32 ]
%13 = icmp ne i64 %12, 0
%14 = and i64 %12, 3
%15 = icmp eq i64 %14, 0
%16 = and i1 %13, %15
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i32 @putchar(i32 10)
br label %19
19: ; preds = %17, %11
br i1 %9, label %20, label %32
20: ; preds = %19
%21 = getelementptr inbounds i32, i32* %5, i64 %12
br label %22
22: ; preds = %22, %20
%23 = phi i32 [ %1, %20 ], [ %24, %22 ]
%24 = add nsw i32 %23, -1
%25 = load i32, i32* %21
%26 = lshr i32 %25, %24
%27 = and i32 %26, 1
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = icmp eq i32 %24, 0
br i1 %29, label %30, label %22
30: ; preds = %22
%31 = tail call i32 @putchar(i32 32)
br label %32
32: ; preds = %30, %19
%33 = add nuw nsw i64 %12, 1
%34 = icmp eq i64 %33, %10
br i1 %34, label %35, label %11
35: ; preds = %32, %4
%36 = tail call i32 @putchar(i32 10)
ret void
}