#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 */
char *BinString(char, char *, int);
scalar_t__ isprint(char);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int, char, char, char *);
scalar_t__ strlen(char const *);
void DumpBinString(const char *str) {
  int idx = 0;
  char c = 0;
  char buf[9];
  int len = 0;
  memset(buf, 0, 9 * sizeof(char));
  len = (int)strlen(str);
  for (idx = 0; idx < len; ++idx) {
    c = str[idx];
    printf("[%3d] 0x%02x %c %s\n", idx, c, (isprint(c) ? c : '.'),
           BinString(c, buf, 8));
  }
}


x86 assembly (clang, -O0):
<DumpBinString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x16(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1229 <DumpBinString+0xd9>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xd(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0xd(%rbp),%al
mov    %al,-0x1d(%rbp)
movsbl -0xd(%rbp),%edi
call   1070 <isprint@plt>
cmp    $0x0,%rax
je     11d6 <DumpBinString+0x86>
movsbl -0xd(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11e3 <DumpBinString+0x93>
mov    $0x2e,%eax
mov    %eax,-0x28(%rbp)
jmp    11e3 <DumpBinString+0x93>
mov    -0x28(%rbp),%eax
mov    %al,-0x29(%rbp)
mov    -0xd(%rbp),%al
lea    -0x16(%rbp),%rsi
mov    $0x8,%edx
movsbl %al,%edi
call   1060 <BinString@plt>
mov    -0x24(%rbp),%esi
mov    -0x1d(%rbp),%cl
mov    %rax,%r8
mov    -0x29(%rbp),%al
lea    0xdf0(%rip),%rdi
movsbl %cl,%edx
movsbl %al,%ecx
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1191 <DumpBinString+0x41>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DumpBinString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0xf(%rsp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11d7 <DumpBinString+0x87>
mov    %eax,%r15d
xor    %ebx,%ebx
lea    0xe76(%rip),%r12
nopw   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%ebp
mov    %ebp,%edi
call   1070 <isprint@plt>
test   %rax,%rax
mov    %ebp,%r13d
mov    $0x2e,%eax
cmove  %eax,%r13d
mov    %ebp,%edi
lea    0xf(%rsp),%rsi
mov    $0x8,%edx
call   1060 <BinString@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %r13d,%ecx
mov    %rax,%r8
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1190 <DumpBinString+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [20 x i8] c"[%3d] 0x%02x %c %s\0A\00"
define void @DumpBinString(i8* nocapture %0) {
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 9)
%5 = call i64 @strlen(i8* dereferenceable(1) %0)
%6 = trunc i64 %5 to i32
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %22
8: ; preds = %1
%9 = and i64 %5, 4294967295
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %20, %10 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = call i64 @isprint(i8 signext %13)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i8 46, i8 %13
%17 = call i8* @BinString(i8 signext %13, i8* %3, i32 8)
%18 = trunc i64 %11 to i32
%19 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %18, i8 signext %13, i8 signext %16, i8* %17)
%20 = add nuw nsw i64 %11, 1
%21 = icmp eq i64 %20, %9
br i1 %21, label %22, label %10
22: ; preds = %10, %1
ret void
}