#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 printb(const void *buf, size_t len, bool bracket, bool noquote) {
  if (bracket) {
    printf("[");
  }
  for (const unsigned char *it = buf, *end = buf + len; it != end; ++it) {
    unsigned char c = *it;
    if (c < 32 || c > 127 || (noquote && c == '"')) {
      printf(".");
    } else {
      printf("%c", c);
    }
  }
  if (bracket) {
    printf("]");
  }
}


x86 assembly (clang, -O0):
<printb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     113e <printb+0x2e>
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11d5 <printb+0xc5>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
movzbl -0x29(%rbp),%eax
cmp    $0x20,%eax
jl     119a <printb+0x8a>
movzbl -0x29(%rbp),%eax
cmp    $0x7f,%eax
jg     119a <printb+0x8a>
cmpl   $0x0,-0x18(%rbp)
je     11ad <printb+0x9d>
movzbl -0x29(%rbp),%eax
cmp    $0x22,%eax
jne    11ad <printb+0x9d>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bf <printb+0xaf>
movzbl -0x29(%rbp),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c4 <printb+0xb4>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1152 <printb+0x42>
cmpl   $0x0,-0x14(%rbp)
je     11ed <printb+0xdd>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printb>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %rsi,%r13
mov    %rdi,%r12
test   %edx,%edx
je     1135 <printb+0x25>
mov    $0x5b,%edi
call   1030 <putchar@plt>
test   %r13,%r13
je     1175 <printb+0x65>
xor    %ebp,%ebp
mov    $0x2e,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%rbp,1),%eax
cmp    $0x22,%al
mov    %eax,%edi
cmove  %ebx,%edi
test   %r15d,%r15d
cmove  %eax,%edi
cmp    $0x20,%al
cmovl  %ebx,%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    1150 <printb+0x40>
test   %r14d,%r14d
je     1192 <printb+0x82>
mov    $0x5d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"[\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [2 x i8] c"]\00"
define void @printb(i8* %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %4
%17 = load i8*, i8** %5
store i8* %17, i8** %9
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = getelementptr i8, i8* %18, i64 %19
store i8* %20, i8** %10
br label %21
21: ; preds = %49, %16
%22 = load i8*, i8** %9
%23 = load i8*, i8** %10
%24 = icmp ne i8* %22, %23
br i1 %24, label %25, label %52
25: ; preds = %21
%26 = load i8*, i8** %9
%27 = load i8, i8* %26
store i8 %27, i8* %11
%28 = load i8, i8* %11
%29 = zext i8 %28 to i32
%30 = icmp slt i32 %29, 32
br i1 %30, label %42, label %31
31: ; preds = %25
%32 = load i8, i8* %11
%33 = zext i8 %32 to i32
%34 = icmp sgt i32 %33, 127
br i1 %34, label %42, label %35
35: ; preds = %31
%36 = load i32, i32* %8
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load i8, i8* %11
%40 = zext i8 %39 to i32
%41 = icmp eq i32 %40, 34
br i1 %41, label %42, label %44
42: ; preds = %38, %31, %25
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %48
44: ; preds = %38, %35
%45 = load i8, i8* %11
%46 = zext i8 %45 to i32
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %44, %42
br label %49
49: ; preds = %48
%50 = load i8*, i8** %9
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %9
br label %21
52: ; preds = %21
%53 = load i32, i32* %7
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %55, %52
ret void
}

LLVM IR (-O2):
define void @printb(i8* %0, i64 %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, 0
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 @putchar(i32 91)
br label %8
8: ; preds = %6, %4
%9 = getelementptr i8, i8* %0, i64 %1
%10 = icmp eq i8* %9, %0
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = icmp ne i32 %3, 0
br label %14
13: ; preds = %14, %8
br i1 %5, label %28, label %26
14: ; preds = %11, %14
%15 = phi i8* [ %0, %11 ], [ %24, %14 ]
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = icmp slt i8 %16, 32
%19 = icmp eq i8 %16, 34
%20 = select i1 %12, i1 %19, i1 false
%21 = or i1 %18, %20
%22 = select i1 %21, i32 46, i32 %17
%23 = tail call i32 @putchar(i32 %22)
%24 = getelementptr inbounds i8, i8* %15, i64 1
%25 = icmp eq i8* %24, %9
br i1 %25, label %13, label %14
26: ; preds = %13
%27 = tail call i32 @putchar(i32 93)
br label %28
28: ; preds = %26, %13
ret void
}