#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void hexdump_as_escstring(const uint8_t *data, size_t size) {
  size_t idx;
  char c;
  bool last_has_been_hex_escaped = false;
  for (idx = 0; idx < size; idx++) {
    if (!data[idx]) {
      printf("\\0");
      last_has_been_hex_escaped = true;
    } else if (data[idx] == 0x09) {
      printf("\\t");
      last_has_been_hex_escaped = false;
    } else if (data[idx] == 0x0a) {
      printf("\\n");
      last_has_been_hex_escaped = false;
    } else if (data[idx] == 0x0d) {
      printf("\\r");
      last_has_been_hex_escaped = false;
    } else if (data[idx] == 0x22) {
      printf("\\\"");
      last_has_been_hex_escaped = false;
    } else if (data[idx] == 0x5c) {
      printf("\\\\");
      last_has_been_hex_escaped = false;
    } else if (data[idx] >= 0x20 && data[idx] < 0x7f) {
      c = (char)data[idx];
      if (last_has_been_hex_escaped &&
          ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') ||
           (c >= 'a' && c <= 'f'))) {
        printf("\\x%02x", data[idx]);
        last_has_been_hex_escaped = true;
      } else {
        printf("%c", c);
        last_has_been_hex_escaped = false;
      }
    } else {
      printf("\\x%02x", data[idx]);
      last_has_been_hex_escaped = true;
    }
  }
}


x86 assembly (clang, -O0):
<hexdump_as_escstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1366 <hexdump_as_escstring+0x256>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    1169 <hexdump_as_escstring+0x59>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x20(%rbp)
jmp    1350 <hexdump_as_escstring+0x240>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpl   $0x9,(%rax,%rcx,4)
jne    1195 <hexdump_as_escstring+0x85>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
jmp    134b <hexdump_as_escstring+0x23b>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpl   $0xa,(%rax,%rcx,4)
jne    11c1 <hexdump_as_escstring+0xb1>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
jmp    1346 <hexdump_as_escstring+0x236>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpl   $0xd,(%rax,%rcx,4)
jne    11ed <hexdump_as_escstring+0xdd>
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
jmp    1341 <hexdump_as_escstring+0x231>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpl   $0x22,(%rax,%rcx,4)
jne    1219 <hexdump_as_escstring+0x109>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
jmp    133c <hexdump_as_escstring+0x22c>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpl   $0x5c,(%rax,%rcx,4)
jne    1245 <hexdump_as_escstring+0x135>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
jmp    1337 <hexdump_as_escstring+0x227>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpl   $0x20,(%rax,%rcx,4)
jl     1312 <hexdump_as_escstring+0x202>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmpl   $0x7f,(%rax,%rcx,4)
jge    1312 <hexdump_as_escstring+0x202>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %al,-0x19(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     12f4 <hexdump_as_escstring+0x1e4>
movsbl -0x19(%rbp),%eax
cmp    $0x30,%eax
jl     129b <hexdump_as_escstring+0x18b>
movsbl -0x19(%rbp),%eax
cmp    $0x39,%eax
jle    12cf <hexdump_as_escstring+0x1bf>
movsbl -0x19(%rbp),%eax
cmp    $0x41,%eax
jl     12b5 <hexdump_as_escstring+0x1a5>
movsbl -0x19(%rbp),%eax
cmp    $0x46,%eax
jle    12cf <hexdump_as_escstring+0x1bf>
movsbl -0x19(%rbp),%eax
cmp    $0x61,%eax
jl     12f4 <hexdump_as_escstring+0x1e4>
movsbl -0x19(%rbp),%eax
cmp    $0x66,%eax
jg     12f4 <hexdump_as_escstring+0x1e4>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x20(%rbp)
jmp    130d <hexdump_as_escstring+0x1fd>
movsbl -0x19(%rbp),%esi
lea    0xd1a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
jmp    1332 <hexdump_as_escstring+0x222>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xcee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x20(%rbp)
jmp    1337 <hexdump_as_escstring+0x227>
jmp    133c <hexdump_as_escstring+0x22c>
jmp    1341 <hexdump_as_escstring+0x231>
jmp    1346 <hexdump_as_escstring+0x236>
jmp    134b <hexdump_as_escstring+0x23b>
jmp    1350 <hexdump_as_escstring+0x240>
jmp    1355 <hexdump_as_escstring+0x245>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    112f <hexdump_as_escstring+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump_as_escstring>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     122f <hexdump_as_escstring+0x10f>
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xebf(%rip),%rbp
lea    0xf50(%rip),%r13
xor    %r12d,%r12d
xor    %r15d,%r15d
jmp    116e <hexdump_as_escstring+0x4e>
xor    %r12d,%r12d
lea    0xf35(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15
cmp    %r15,%rbx
je     122f <hexdump_as_escstring+0x10f>
mov    (%r14,%r15,4),%esi
cmp    $0x22,%rsi
ja     11a0 <hexdump_as_escstring+0x80>
movslq 0x0(%rbp,%rsi,4),%rax
add    %rbp,%rax
jmp    *%rax
lea    0xf03(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ec <hexdump_as_escstring+0xcc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x5c,%esi
jne    11b1 <hexdump_as_escstring+0x91>
xor    %r12d,%r12d
lea    0xeec(%rip),%rdi
jmp    115a <hexdump_as_escstring+0x3a>
lea    -0x20(%rsi),%eax
cmp    $0x5e,%eax
ja     11de <hexdump_as_escstring+0xbe>
test   %r12d,%r12d
je     1220 <hexdump_as_escstring+0x100>
lea    -0x30(%rsi),%eax
cmp    $0xa,%eax
jb     11de <hexdump_as_escstring+0xbe>
lea    -0x41(%rsi),%eax
cmp    $0x25,%eax
ja     1220 <hexdump_as_escstring+0x100>
movabs $0x3f0000003f,%rcx
bt     %rax,%rcx
jae    1220 <hexdump_as_escstring+0x100>
lea    0xeb9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r12d
jmp    1161 <hexdump_as_escstring+0x41>
xor    %r12d,%r12d
lea    0xe91(%rip),%rdi
jmp    115a <hexdump_as_escstring+0x3a>
xor    %r12d,%r12d
lea    0xe85(%rip),%rdi
jmp    115a <hexdump_as_escstring+0x3a>
xor    %r12d,%r12d
mov    %r13,%rdi
jmp    115a <hexdump_as_escstring+0x3a>
mov    %esi,%edi
call   1030 <putchar@plt>
xor    %r12d,%r12d
jmp    1161 <hexdump_as_escstring+0x41>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"\\0\00"
@.str.1 = [3 x i8] c"\\t\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"\\r\00"
@.str.4 = [3 x i8] c"\\\22\00"
@.str.5 = [3 x i8] c"\\\\\00"
@.str.6 = [7 x i8] c"\\x%02x\00"
define void @hexdump_as_escstring(i32* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %40, label %4
4: ; preds = %2, %36
%5 = phi i32 [ %37, %36 ], [ 0, %2 ]
%6 = phi i64 [ %38, %36 ], [ 0, %2 ]
%7 = getelementptr inbounds i32, i32* %0, i64 %6
%8 = load i32, i32* %7
switch i32 %8, label %21 [
i32 0, label %9
i32 9, label %11
i32 10, label %13
i32 13, label %15
i32 34, label %17
i32 92, label %19
]
9: ; preds = %4
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %36
11: ; preds = %4
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %36
13: ; preds = %4
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %36
15: ; preds = %4
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %36
17: ; preds = %4
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %36
19: ; preds = %4
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %36
21: ; preds = %4
%22 = add i32 %8, -32
%23 = icmp ult i32 %22, 95
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = icmp eq i32 %5, 0
br i1 %25, label %32, label %26
26: ; preds = %24
%27 = add nsw i32 %8, -48
%28 = icmp ult i32 %27, 10
br i1 %28, label %30, label %29
29: ; preds = %26
switch i32 %8, label %32 [
i32 102, label %30
i32 101, label %30
i32 100, label %30
i32 99, label %30
i32 98, label %30
i32 97, label %30
i32 70, label %30
i32 69, label %30
i32 68, label %30
i32 67, label %30
i32 66, label %30
i32 65, label %30
]
30: ; preds = %29, %29, %29, %29, %29, %29, %29, %29, %29, %29, %29, %29, %26
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %8)
br label %36
32: ; preds = %29, %24
%33 = tail call i32 @putchar(i32 %8)
br label %36
34: ; preds = %21
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %8)
br label %36
36: ; preds = %9, %13, %17, %34, %32, %30, %19, %15, %11
%37 = phi i32 [ 0, %11 ], [ 0, %13 ], [ 0, %15 ], [ 0, %17 ], [ 0, %19 ], [ 1, %30 ], [ 0, %32 ], [ 1, %34 ], [ 1, %9 ]
%38 = add nuw i64 %6, 1
%39 = icmp eq i64 %38, %1
br i1 %39, label %40, label %4
40: ; preds = %36, %2
ret void
}