#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*/ assert(void *);
int /*<<< orphan*/ printf(char *, ...);
void memory_print(void *p_memory, size_t size) {
  assert(size);
  assert(p_memory);
  unsigned char *p_as_byte = (unsigned char *)p_memory;
  size_t curr_idx = 0;
  for (; curr_idx < size; ++curr_idx)
    printf("%u", (p_as_byte[curr_idx] != 0 ? 1 : 0));
  printf("\n");
}


x86 assembly (clang, -O0):
<memory_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1198 <memory_print+0x78>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1152 <memory_print+0x32>
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memory_print>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <assert@plt>
mov    %r14,%rdi
call   1050 <assert@plt>
test   %r12,%r12
je     117e <memory_print+0x4e>
lea    0xea6(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %esi,%esi
cmpb   $0x0,(%r14,%rbx,1)
setne  %sil
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <memory_print+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%u\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @memory_print(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
%8 = inttoptr i64 %7 to i8*
%9 = call i32 @assert(i8* %8)
%10 = load i8*, i8** %3
%11 = call i32 @assert(i8* %10)
%12 = load i8*, i8** %3
store i8* %12, i8** %5
store i64 0, i64* %6
br label %13
13: ; preds = %27, %2
%14 = load i64, i64* %6
%15 = load i64, i64* %4
%16 = icmp ult i64 %14, %15
br i1 %16, label %17, label %30
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = getelementptr inbounds i8, i8* %18, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 1, i32 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %17
%28 = load i64, i64* %6
%29 = add i64 %28, 1
store i64 %29, i64* %6
br label %13
30: ; preds = %13
%31 = 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 = [3 x i8] c"%u\00"
define void @memory_print(i8* %0, i64 %1) {
%3 = inttoptr i64 %1 to i8*
%4 = tail call i32 @assert(i8* %3)
%5 = tail call i32 @assert(i8* %0)
%6 = icmp eq i64 %1, 0
br i1 %6, label %16, label %7
7: ; preds = %2, %7
%8 = phi i64 [ %14, %7 ], [ 0, %2 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
%12 = zext i1 %11 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = add nuw i64 %8, 1
%15 = icmp eq i64 %14, %1
br i1 %15, label %16, label %7
16: ; preds = %7, %2
%17 = tail call i32 @putchar(i32 10)
ret void
}