#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*/ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, unsigned char);
void print_binary(void const *const ptr) {
  unsigned char *b = (unsigned char *)ptr;
  unsigned char byte;
  size_t size = sizeof(uint64_t);
  int i, j;
  for (i = size - 1; i >= 0; i--) {
    for (j = 7; j >= 0; j--) {
      byte = b[i] & (1 << j);
      byte >>= j;
      printf("%u", byte);
    }
  }
}


x86 assembly (clang, -O0):
<print_binary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movq   $0x4,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11ac <print_binary+0x9c>
movl   $0x7,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     1199 <print_binary+0x89>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x28(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    %al,-0x11(%rbp)
mov    -0x28(%rbp),%ecx
movzbl -0x11(%rbp),%eax
sar    %cl,%eax
mov    %al,-0x11(%rbp)
lea    0xe7e(%rip),%rdi
movzbl -0x11(%rbp),%esi
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    1148 <print_binary+0x38>
jmp    119e <print_binary+0x8e>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1137 <print_binary+0x27>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_binary>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    $0x3,%ebx
lea    0xedc(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r15,%rbx,1),%eax
shr    $0x7,%al
movzbl %al,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl (%r15,%rbx,1),%esi
shr    $0x6,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl (%r15,%rbx,1),%esi
shr    $0x5,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl (%r15,%rbx,1),%esi
shr    $0x4,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl (%r15,%rbx,1),%esi
shr    $0x3,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl (%r15,%rbx,1),%esi
shr    $0x2,%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl (%r15,%rbx,1),%esi
shr    %esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl (%r15,%rbx,1),%esi
and    $0x1,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0xffffffffffffffff,%rbx
jb     1130 <print_binary+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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