#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 const *find_violation(char const *, int);
int /*<<< orphan*/ fwrite(char const *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int strlen(char const *);
void printescaped(const char *fn) {
  const char *end = fn + strlen(fn);
  if (find_violation(fn, 0) != end) {
    const char *ep = fn;
    const char *last;
    while (end != ep) {
      last = ep;
      ep = find_violation(last, 1);
      fwrite(last, sizeof(char), ep - last, stdout);
      if (ep == end)
        break;
      printf("#(%d)", (unsigned char)*ep);
      ep++;
    }
  } else {
    printf("%s", fn);
  }
}


x86 assembly (clang, -O0):
<printescaped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <find_violation@plt>
cmp    -0x10(%rbp),%rax
je     1214 <printescaped+0xd4>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     120f <printescaped+0xcf>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1050 <find_violation@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    0x2e16(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11e9 <printescaped+0xa9>
jmp    120f <printescaped+0xcf>
mov    -0x18(%rbp),%rax
movzbl (%rax),%esi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    118a <printescaped+0x4a>
jmp    1226 <printescaped+0xe6>
mov    -0x8(%rbp),%rsi
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printescaped>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebx
movslq %eax,%r12
add    %r15,%r12
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <find_violation@plt>
cmp    %r12,%rax
je     11ce <printescaped+0x8e>
test   %ebx,%ebx
je     11c4 <printescaped+0x84>
mov    0x2e6d(%rip),%r13
lea    0xe86(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x1,%esi
call   1050 <find_violation@plt>
mov    %rax,%rbx
mov    %ebx,%edx
sub    %r15d,%edx
mov    0x0(%r13),%ecx
mov    %r15,%rdi
mov    $0x1,%esi
call   1060 <fwrite@plt>
cmp    %r12,%rbx
je     11c4 <printescaped+0x84>
movzbl (%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
mov    %rbx,%r15
cmp    %rbx,%r12
jne    1180 <printescaped+0x40>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe31(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [6 x i8] c"#(%d)\00"
@.str.1 = [3 x i8] c"%s\00"
define void @printescaped(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %6, i64 %9
store i8* %10, i8** %3
%11 = load i8*, i8** %2
%12 = call i8* @find_violation(i8* %11, i32 0)
%13 = load i8*, i8** %3
%14 = icmp ne i8* %12, %13
br i1 %14, label %15, label %46
15: ; preds = %1
%16 = load i8*, i8** %2
store i8* %16, i8** %4
br label %17
17: ; preds = %38, %15
%18 = load i8*, i8** %3
%19 = load i8*, i8** %4
%20 = icmp ne i8* %18, %19
br i1 %20, label %21, label %45
21: ; preds = %17
%22 = load i8*, i8** %4
store i8* %22, i8** %5
%23 = load i8*, i8** %5
%24 = call i8* @find_violation(i8* %23, i32 1)
store i8* %24, i8** %4
%25 = load i8*, i8** %5
%26 = load i8*, i8** %4
%27 = load i8*, i8** %5
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = trunc i64 %30 to i32
%32 = load i32, i32* @stdout
%33 = call i32 @fwrite(i8* %25, i32 1, i32 %31, i32 %32)
%34 = load i8*, i8** %4
%35 = load i8*, i8** %3
%36 = icmp eq i8* %34, %35
br i1 %36, label %37, label %38
37: ; preds = %21
br label %45
38: ; preds = %21
%39 = load i8*, i8** %4
%40 = load i8, i8* %39
%41 = zext i8 %40 to i32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %4
br label %17
45: ; preds = %37, %17
br label %49
46: ; preds = %1
%47 = load i8*, i8** %2
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %46, %45
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [6 x i8] c"#(%d)\00"
@.str.1 = [3 x i8] c"%s\00"
define void @printescaped(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = tail call i8* @find_violation(i8* %0, i32 0)
%6 = icmp eq i8* %5, %4
br i1 %6, label %25, label %7
7: ; preds = %1
%8 = icmp eq i32 %2, 0
br i1 %8, label %27, label %9
9: ; preds = %7, %19
%10 = phi i8* [ %23, %19 ], [ %0, %7 ]
%11 = tail call i8* @find_violation(i8* %10, i32 1)
%12 = ptrtoint i8* %11 to i64
%13 = ptrtoint i8* %10 to i64
%14 = sub i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = load i32, i32* @stdout
%17 = tail call i32 @fwrite(i8* %10, i32 1, i32 %15, i32 %16)
%18 = icmp eq i8* %11, %4
br i1 %18, label %27, label %19
19: ; preds = %9
%20 = load i8, i8* %11
%21 = zext i8 %20 to i32
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds i8, i8* %11, i64 1
%24 = icmp eq i8* %4, %23
br i1 %24, label %27, label %9
25: ; preds = %1
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %27
27: ; preds = %9, %19, %7, %25
ret void
}