#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 print_binary_rep(char *str) {
  int i = 0, j = 0;
  char curr;
  unsigned char mask;
  while (curr = str[i]) {
    mask = 0x80;
    for (j = 0; j < 8; j++) {
      if (curr & mask)
        printf("1");
      else
        printf("0");
      mask = mask >> 1;
    }
    printf(" ");
    i += 1;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_binary_rep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
cmp    $0x0,%al
je     11b7 <print_binary_rep+0xa7>
movb   $0x80,-0x12(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    119d <print_binary_rep+0x8d>
movsbl -0x11(%rbp),%eax
movzbl -0x12(%rbp),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1179 <print_binary_rep+0x69>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
jmp    1185 <print_binary_rep+0x75>
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
movzbl -0x12(%rbp),%eax
sar    $0x1,%eax
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114b <print_binary_rep+0x3b>
lea    0xe60(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112a <print_binary_rep+0x1a>
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_binary_rep>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     11ec <print_binary_rep+0xdc>
mov    %rdi,%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl %al,%ebp
mov    %ebp,%eax
and    $0xffffff80,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
and    $0x40,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
and    $0x20,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
and    $0x10,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
and    $0x8,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
and    $0x4,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
and    $0x2,%eax
cmp    $0x1,%eax
mov    $0x31,%edi
sbb    $0x0,%edi
call   1030 <putchar@plt>
and    $0x1,%ebp
or     $0x30,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <print_binary_rep+0x20>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
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 @print_binary_rep(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %7
7: ; preds = %37, %1
%8 = load i8*, i8** %2
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
store i8 %12, i8* %5
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %41
14: ; preds = %7
store i8 -128, i8* %6
store i32 0, i32* %4
br label %15
15: ; preds = %34, %14
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 8
br i1 %17, label %18, label %37
18: ; preds = %15
%19 = load i8, i8* %5
%20 = sext i8 %19 to i32
%21 = load i8, i8* %6
%22 = zext i8 %21 to i32
%23 = and i32 %20, %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %29
27: ; preds = %18
%28 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %25
%30 = load i8, i8* %6
%31 = zext i8 %30 to i32
%32 = ashr i32 %31, 1
%33 = trunc i32 %32 to i8
store i8 %33, i8* %6
br label %34
34: ; preds = %29
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %15
37: ; preds = %15
%38 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %7
41: ; preds = %7
%42 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
define void @print_binary_rep(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %44, label %4
4: ; preds = %1, %4
%5 = phi i64 [ %40, %4 ], [ 0, %1 ]
%6 = phi i8 [ %42, %4 ], [ %2, %1 ]
%7 = zext i8 %6 to i32
%8 = and i32 %7, 128
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i32 48, i32 49
%11 = tail call i32 @putchar(i32 %10)
%12 = and i32 %7, 64
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 48, i32 49
%15 = tail call i32 @putchar(i32 %14)
%16 = and i32 %7, 32
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i32 48, i32 49
%19 = tail call i32 @putchar(i32 %18)
%20 = and i32 %7, 16
%21 = icmp eq i32 %20, 0
%22 = select i1 %21, i32 48, i32 49
%23 = tail call i32 @putchar(i32 %22)
%24 = and i32 %7, 8
%25 = icmp eq i32 %24, 0
%26 = select i1 %25, i32 48, i32 49
%27 = tail call i32 @putchar(i32 %26)
%28 = and i32 %7, 4
%29 = icmp eq i32 %28, 0
%30 = select i1 %29, i32 48, i32 49
%31 = tail call i32 @putchar(i32 %30)
%32 = and i32 %7, 2
%33 = icmp eq i32 %32, 0
%34 = select i1 %33, i32 48, i32 49
%35 = tail call i32 @putchar(i32 %34)
%36 = and i32 %7, 1
%37 = or i32 %36, 48
%38 = tail call i32 @putchar(i32 %37)
%39 = tail call i32 @putchar(i32 32)
%40 = add nuw i64 %5, 1
%41 = getelementptr inbounds i8, i8* %0, i64 %40
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 0
br i1 %43, label %44, label %4
44: ; preds = %4, %1
%45 = tail call i32 @putchar(i32 10)
ret void
}