#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 escapeprint(const char *str, size_t len) {
  size_t i;
  printf(" (length %d bytes):\n\t", (int)len);
  for (i = 0; i < len; i++) {
    if (((str[i] & 0xFF) >= 'A' && (str[i] & 0xFF) <= 'Z') ||
        ((str[i] & 0xFF) >= 'a' && (str[i] & 0xFF) <= 'z') ||
        ((str[i] & 0xFF) >= '0' && (str[i] & 0xFF) <= '9') ||
        (str[i] & 0xFF) == ' ' || (str[i] & 0xFF) == '.')
      printf("%c", (str[i] & 0xFF));
    else
      printf("\\x%02X", (str[i] & 0xFF));
    if ((i + 1) % 16 == 0 && (i + 1) < len)
      printf("'\n\t'");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<escapeprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    12ab <escapeprint+0x19b>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
cmp    $0x41,%eax
jl     117e <escapeprint+0x6e>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
cmp    $0x5a,%eax
jle    121a <escapeprint+0x10a>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
cmp    $0x61,%eax
jl     11b2 <escapeprint+0xa2>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
cmp    $0x7a,%eax
jle    121a <escapeprint+0x10a>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
cmp    $0x30,%eax
jl     11e6 <escapeprint+0xd6>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
cmp    $0x39,%eax
jle    121a <escapeprint+0x10a>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
cmp    $0x20,%eax
je     121a <escapeprint+0x10a>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
cmp    $0x2e,%eax
jne    123f <escapeprint+0x12f>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125f <escapeprint+0x14f>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    1295 <escapeprint+0x185>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
cmp    -0x10(%rbp),%rax
jae    1295 <escapeprint+0x185>
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129a <escapeprint+0x18a>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113c <escapeprint+0x2c>
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escapeprint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%r14
lea    0xec8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r13,%r13
je     11e3 <escapeprint+0xc3>
mov    %r13,%rbx
neg    %rbx
mov    $0x1,%ebp
lea    0xec3(%rip),%r15
lea    0xeb5(%rip),%r12
jmp    1182 <escapeprint+0x62>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbp
cmp    $0x1,%rax
je     11e3 <escapeprint+0xc3>
movzbl -0x1(%r14,%rbp,1),%esi
mov    %esi,%eax
and    $0xdf,%al
add    $0xbf,%al
cmp    $0x1a,%al
jb     11b0 <escapeprint+0x90>
lea    -0x30(%rsi),%eax
cmp    $0xa,%al
jb     11b0 <escapeprint+0x90>
cmp    $0x2e,%sil
je     11b0 <escapeprint+0x90>
cmp    $0x20,%sil
jne    11d2 <escapeprint+0xb2>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %esi,%edi
call   1030 <putchar@plt>
cmp    %r13,%rbp
jae    1170 <escapeprint+0x50>
mov    %ebp,%eax
and    $0xf,%eax
test   %rax,%rax
jne    1170 <escapeprint+0x50>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1170 <escapeprint+0x50>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r13,%rbp
jb     11bc <escapeprint+0x9c>
jmp    1170 <escapeprint+0x50>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [22 x i8] c" (length %d bytes):\0A\09\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [7 x i8] c"\\x%02X\00"
@.str.3 = [5 x i8] c"'\0A\09'\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @escapeprint(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = trunc i64 %6 to i32
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %7)
store i64 0, i64* %5
br label %9
9: ; preds = %106, %2
%10 = load i64, i64* %5
%11 = load i64, i64* %4
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %109
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = load i64, i64* %5
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = and i32 %18, 255
%20 = icmp sge i32 %19, 65
br i1 %20, label %21, label %29
21: ; preds = %13
%22 = load i8*, i8** %3
%23 = load i64, i64* %5
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = and i32 %26, 255
%28 = icmp sle i32 %27, 90
br i1 %28, label %77, label %29
29: ; preds = %21, %13
%30 = load i8*, i8** %3
%31 = load i64, i64* %5
%32 = getelementptr inbounds i8, i8* %30, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = and i32 %34, 255
%36 = icmp sge i32 %35, 97
br i1 %36, label %37, label %45
37: ; preds = %29
%38 = load i8*, i8** %3
%39 = load i64, i64* %5
%40 = getelementptr inbounds i8, i8* %38, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = and i32 %42, 255
%44 = icmp sle i32 %43, 122
br i1 %44, label %77, label %45
45: ; preds = %37, %29
%46 = load i8*, i8** %3
%47 = load i64, i64* %5
%48 = getelementptr inbounds i8, i8* %46, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = and i32 %50, 255
%52 = icmp sge i32 %51, 48
br i1 %52, label %53, label %61
53: ; preds = %45
%54 = load i8*, i8** %3
%55 = load i64, i64* %5
%56 = getelementptr inbounds i8, i8* %54, i64 %55
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = and i32 %58, 255
%60 = icmp sle i32 %59, 57
br i1 %60, label %77, label %61
61: ; preds = %53, %45
%62 = load i8*, i8** %3
%63 = load i64, i64* %5
%64 = getelementptr inbounds i8, i8* %62, i64 %63
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = and i32 %66, 255
%68 = icmp eq i32 %67, 32
br i1 %68, label %77, label %69
69: ; preds = %61
%70 = load i8*, i8** %3
%71 = load i64, i64* %5
%72 = getelementptr inbounds i8, i8* %70, i64 %71
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = and i32 %74, 255
%76 = icmp eq i32 %75, 46
br i1 %76, label %77, label %85
77: ; preds = %69, %61, %53, %37, %21
%78 = load i8*, i8** %3
%79 = load i64, i64* %5
%80 = getelementptr inbounds i8, i8* %78, i64 %79
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = and i32 %82, 255
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %83)
br label %93
85: ; preds = %69
%86 = load i8*, i8** %3
%87 = load i64, i64* %5
%88 = getelementptr inbounds i8, i8* %86, i64 %87
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = and i32 %90, 255
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %91)
br label %93
93: ; preds = %85, %77
%94 = load i64, i64* %5
%95 = add i64 %94, 1
%96 = urem i64 %95, 16
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %105
98: ; preds = %93
%99 = load i64, i64* %5
%100 = add i64 %99, 1
%101 = load i64, i64* %4
%102 = icmp ult i64 %100, %101
br i1 %102, label %103, label %105
103: ; preds = %98
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %105
105: ; preds = %103, %98, %93
br label %106
106: ; preds = %105
%107 = load i64, i64* %5
%108 = add i64 %107, 1
store i64 %108, i64* %5
br label %9
109: ; preds = %9
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c" (length %d bytes):\0A\09\00"
@.str.2 = [7 x i8] c"\\x%02X\00"
@.str.3 = [5 x i8] c"'\0A\09'\00"
define void @escapeprint(i8* nocapture %0, i64 %1) {
%3 = trunc i64 %1 to i32
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i64 %1, 0
br i1 %5, label %33, label %6
6: ; preds = %2, %31
%7 = phi i64 [ %24, %31 ], [ 0, %2 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = and i8 %9, -33
%11 = add i8 %10, -65
%12 = icmp ult i8 %11, 26
%13 = add i8 %9, -48
%14 = icmp ult i8 %13, 10
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %17, label %16
16: ; preds = %6
switch i8 %9, label %20 [
i8 32, label %17
i8 46, label %17
]
17: ; preds = %16, %16, %6
%18 = zext i8 %9 to i32
%19 = tail call i32 @putchar(i32 %18)
br label %23
20: ; preds = %16
%21 = zext i8 %9 to i32
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20, %17
%24 = add nuw i64 %7, 1
%25 = and i64 %24, 15
%26 = icmp eq i64 %25, 0
%27 = icmp ult i64 %24, %1
%28 = and i1 %27, %26
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %23, %29
%32 = icmp eq i64 %24, %1
br i1 %32, label %33, label %6
33: ; preds = %31, %2
%34 = tail call i32 @putchar(i32 10)
ret void
}