#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 *, ...);
int print_bit(char *addr, int size) {
  unsigned char *ptr = (unsigned char *)addr;
  int print_bytes = 0;
  if (ptr == NULL) {
    return -1;
  }
  for (print_bytes = 0; print_bytes < size; print_bytes++, ptr++) {
    for (int print_bits = 7; print_bits >= 0; print_bits--) {
      printf("%d", ((*ptr >> print_bits) & 1));
    }
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_bit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1145 <print_bit+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <print_bit+0xb1>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b3 <print_bit+0xa3>
movl   $0x7,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     1194 <print_bit+0x84>
mov    -0x20(%rbp),%rax
movzbl (%rax),%esi
mov    -0x28(%rbp),%ecx
sar    %cl,%esi
and    $0x1,%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    115f <print_bit+0x4f>
jmp    1199 <print_bit+0x89>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    114c <print_bit+0x3c>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_bit>:
test   %rdi,%rdi
je     1213 <print_bit+0xf3>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    11fe <print_bit+0xde>
mov    %rdi,%r12
mov    %esi,%r15d
lea    0xeba(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%esi
shr    $0x7,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r12,%rbx,1),%esi
shr    $0x6,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r12,%rbx,1),%esi
shr    $0x5,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r12,%rbx,1),%esi
shr    $0x4,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r12,%rbx,1),%esi
shr    $0x3,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r12,%rbx,1),%esi
shr    $0x2,%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r12,%rbx,1),%esi
shr    %esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%r12,%rbx,1),%esi
and    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %ebx,%r15d
jne    1150 <print_bit+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
mov    $0xffffffff,%eax
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @print_bit(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %52, label %4
4: ; preds = %2
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %50
6: ; preds = %4, %6
%7 = phi i32 [ %47, %6 ], [ 0, %4 ]
%8 = phi i8* [ %48, %6 ], [ %0, %4 ]
%9 = load i8, i8* %8
%10 = lshr i8 %9, 7
%11 = zext i8 %10 to i32
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8, i8* %8
%14 = lshr i8 %13, 6
%15 = and i8 %14, 1
%16 = zext i8 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i8, i8* %8
%19 = lshr i8 %18, 5
%20 = and i8 %19, 1
%21 = zext i8 %20 to i32
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = load i8, i8* %8
%24 = lshr i8 %23, 4
%25 = and i8 %24, 1
%26 = zext i8 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i8, i8* %8
%29 = lshr i8 %28, 3
%30 = and i8 %29, 1
%31 = zext i8 %30 to i32
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = load i8, i8* %8
%34 = lshr i8 %33, 2
%35 = and i8 %34, 1
%36 = zext i8 %35 to i32
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load i8, i8* %8
%39 = lshr i8 %38, 1
%40 = and i8 %39, 1
%41 = zext i8 %40 to i32
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = load i8, i8* %8
%44 = and i8 %43, 1
%45 = zext i8 %44 to i32
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %45)
%47 = add nuw nsw i32 %7, 1
%48 = getelementptr inbounds i8, i8* %8, i64 1
%49 = icmp eq i32 %47, %1
br i1 %49, label %50, label %6
50: ; preds = %6, %4
%51 = tail call i32 @putchar(i32 10)
br label %52
52: ; preds = %2, %50
ret i32 -1
}