#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*/ fprintf(int /*<<< orphan*/, char *);
size_t fwrite(char const *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void print_escaped_ascii(const char *prefix, const char *text) {
  const char *current;
  if (prefix) {
    printf("%s: ", prefix);
  }
  for (current = text; *current; current++) {
    const char c = *current;
    if (c < 32 || c >= 127) {
      while (text < current) {
        size_t count = fwrite(text, 1, (size_t)(current - text), stdout);
        if (!count) {
          fprintf(stderr, "fwrite error to stdout\n");
          return;
        }
        text += count;
      }
      printf("\\x%02x", (unsigned)(unsigned char)c);
      text++;
    }
  }
  printf("%s\n", text);
}


x86 assembly (clang, -O0):
<print_escaped_ascii>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     115d <print_escaped_ascii+0x2d>
mov    -0x8(%rbp),%rsi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1238 <print_escaped_ascii+0x108>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x20,%eax
jl     1195 <print_escaped_ascii+0x65>
movsbl -0x19(%rbp),%eax
cmp    $0x7f,%eax
jl     1222 <print_escaped_ascii+0xf2>
jmp    119a <print_escaped_ascii+0x6a>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1204 <print_escaped_ascii+0xd4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rax
sub    %rax,%rdx
mov    0x2e1a(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1050 <fwrite@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11f3 <print_escaped_ascii+0xc3>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
call   1040 <fprintf@plt>
jmp    124a <print_escaped_ascii+0x11a>
mov    -0x28(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    119a <print_escaped_ascii+0x6a>
movzbl -0x19(%rbp),%esi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1227 <print_escaped_ascii+0xf7>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1165 <print_escaped_ascii+0x35>
mov    -0x10(%rbp),%rsi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_escaped_ascii>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rbx
test   %rdi,%rdi
je     1162 <print_escaped_ascii+0x22>
mov    %rdi,%rsi
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%r13b
test   %r13b,%r13b
je     11da <print_escaped_ascii+0x9a>
mov    0x2e67(%rip),%r15
lea    0xea5(%rip),%r14
mov    %rbx,%r12
jmp    11a0 <print_escaped_ascii+0x60>
nopl   (%rax)
movzbl %r13b,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
mov    0x1(%r12),%r13b
add    $0x1,%r12
test   %r13b,%r13b
je     11da <print_escaped_ascii+0x9a>
lea    -0x7f(%r13),%eax
cmp    $0xa0,%al
ja     1192 <print_escaped_ascii+0x52>
nopl   0x0(%rax,%rax,1)
cmp    %r12,%rbx
jae    1180 <print_escaped_ascii+0x40>
mov    %r12,%rdx
sub    %rbx,%rdx
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <fwrite@plt>
test   %rax,%rax
je     11eb <print_escaped_ascii+0xab>
add    %rax,%rbx
cmp    %r12,%rbx
jb     11b5 <print_escaped_ascii+0x75>
jmp    1180 <print_escaped_ascii+0x40>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <puts@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%s: \00"
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"fwrite error to stdout\0A\00"
@.str.2 = [7 x i8] c"\\x%02x\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @print_escaped_ascii(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %10, %2
%14 = load i8*, i8** %4
store i8* %14, i8** %5
br label %15
15: ; preds = %59, %13
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %62
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = load i8, i8* %20
store i8 %21, i8* %6
%22 = load i8, i8* %6
%23 = sext i8 %22 to i32
%24 = icmp slt i32 %23, 32
br i1 %24, label %29, label %25
25: ; preds = %19
%26 = load i8, i8* %6
%27 = sext i8 %26 to i32
%28 = icmp sge i32 %27, 127
br i1 %28, label %29, label %58
29: ; preds = %25, %19
br label %30
30: ; preds = %48, %29
%31 = load i8*, i8** %4
%32 = load i8*, i8** %5
%33 = icmp ult i8* %31, %32
br i1 %33, label %34, label %52
34: ; preds = %30
%35 = load i8*, i8** %4
%36 = load i8*, i8** %5
%37 = load i8*, i8** %4
%38 = ptrtoint i8* %36 to i64
%39 = ptrtoint i8* %37 to i64
%40 = sub i64 %38, %39
%41 = load i32, i32* @stdout
%42 = call i64 @fwrite(i8* %35, i32 1, i64 %40, i32 %41)
store i64 %42, i64* %7
%43 = load i64, i64* %7
%44 = icmp ne i64 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %34
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %65
48: ; preds = %34
%49 = load i64, i64* %7
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i64 %49
store i8* %51, i8** %4
br label %30
52: ; preds = %30
%53 = load i8, i8* %6
%54 = zext i8 %53 to i32
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = load i8*, i8** %4
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %4
br label %58
58: ; preds = %52, %25
br label %59
59: ; preds = %58
%60 = load i8*, i8** %5
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %5
br label %15
62: ; preds = %15
%63 = load i8*, i8** %4
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %63)
br label %65
65: ; preds = %62, %45
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s: \00"
@stdout = global i32 0
@stderr = global i32 0
@.str.1 = [24 x i8] c"fwrite error to stdout\0A\00"
@.str.2 = [7 x i8] c"\\x%02x\00"
define void @print_escaped_ascii(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %6
6: ; preds = %4, %2
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 0
br i1 %8, label %42, label %9
9: ; preds = %6, %37
%10 = phi i8 [ %40, %37 ], [ %7, %6 ]
%11 = phi i8* [ %38, %37 ], [ %1, %6 ]
%12 = phi i8* [ %39, %37 ], [ %1, %6 ]
%13 = add i8 %10, -127
%14 = icmp ult i8 %13, -95
br i1 %14, label %15, label %37
15: ; preds = %9
%16 = icmp ult i8* %11, %12
br i1 %16, label %17, label %29
17: ; preds = %15
%18 = ptrtoint i8* %12 to i64
br label %19
19: ; preds = %17, %26
%20 = phi i8* [ %11, %17 ], [ %27, %26 ]
%21 = ptrtoint i8* %20 to i64
%22 = sub i64 %18, %21
%23 = load i32, i32* @stdout
%24 = tail call i64 @fwrite(i8* %20, i32 1, i64 %22, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %34, label %26
26: ; preds = %19
%27 = getelementptr inbounds i8, i8* %20, i64 %24
%28 = icmp ult i8* %27, %12
br i1 %28, label %19, label %29
29: ; preds = %26, %15
%30 = phi i8* [ %11, %15 ], [ %27, %26 ]
%31 = zext i8 %10 to i32
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds i8, i8* %30, i64 1
br label %37
34: ; preds = %19
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %45
37: ; preds = %9, %29
%38 = phi i8* [ %11, %9 ], [ %33, %29 ]
%39 = getelementptr inbounds i8, i8* %12, i64 1
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 0
br i1 %41, label %42, label %9
42: ; preds = %37, %6
%43 = phi i8* [ %1, %6 ], [ %38, %37 ]
%44 = tail call i32 @puts(i8* dereferenceable(1) %43)
br label %45
45: ; preds = %34, %42
ret void
}