#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*/ fputc(char const, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strchr(char const *, char const);
void print_escaped_string(const char *str) {
  static const char escaped[] = "\f\n\r\t\v";
  static const char literals[] = "fnrtv";
  size_t index = 0;
  while (str[index]) {
    const char c = str[index];
    const char *match = strchr(escaped, c);
    if (match != NULL) {
      const char literal = literals[match - escaped];
      fputc('\\', stderr);
      fputc(literal, stderr);
    } else {
      fputc(c, stderr);
    }
    index += 1;
  }
}


x86 assembly (clang, -O0):
<print_escaped_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11df <print_escaped_string+0xbf>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
lea    0xea5(%rip),%rdi
movsbl -0x11(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ba <print_escaped_string+0x9a>
mov    -0x20(%rbp),%rcx
lea    0xe82(%rip),%rax
sub    %rax,%rcx
lea    0xe7e(%rip),%rax
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
mov    $0x5c,%edi
call   1040 <fputc@plt>
mov    -0x21(%rbp),%al
mov    0x2e35(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    11ce <print_escaped_string+0xae>
mov    -0x11(%rbp),%al
mov    0x2e1c(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <print_escaped_string+0x14>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_escaped_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    (%rdi),%bl
test   %bl,%bl
je     118f <print_escaped_string+0x6f>
mov    %rdi,%r12
add    $0x1,%r12
lea    0xec3(%rip),%r14
mov    0x2e9c(%rip),%r15
lea    0xebb(%rip),%r13
jmp    1168 <print_escaped_string+0x48>
nopl   (%rax)
mov    (%r15),%esi
movsbl %bl,%edi
call   1040 <fputc@plt>
movzbl (%r12),%ebx
add    $0x1,%r12
test   %bl,%bl
je     118f <print_escaped_string+0x6f>
movsbl %bl,%esi
mov    %r14,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     1150 <print_escaped_string+0x30>
sub    %r14,%rax
movzbl (%rax,%r13,1),%ebx
mov    (%r15),%esi
mov    $0x5c,%edi
call   1040 <fputc@plt>
jmp    1150 <print_escaped_string+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@print_escaped_string.escaped = internal constant [6 x i8] c"\0C\0A\0D\09\0B\00"
@print_escaped_string.literals = internal constant [6 x i8] c"fnrtv\00"
@stderr = global i32 0
define void @print_escaped_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8
store i8* %0, i8** %2
store i64 0, i64* %3
br label %7
7: ; preds = %37, %1
%8 = load i8*, i8** %2
%9 = load i64, i64* %3
%10 = getelementptr inbounds i8, i8* %8, i64 %9
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %40
13: ; preds = %7
%14 = load i8*, i8** %2
%15 = load i64, i64* %3
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
store i8 %17, i8* %4
%18 = load i8, i8* %4
%19 = call i8* @strchr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @print_escaped_string.escaped, i64 0, i64 0), i8 signext %18)
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %33
22: ; preds = %13
%23 = load i8*, i8** %5
%24 = ptrtoint i8* %23 to i64
%25 = sub i64 %24, ptrtoint ([6 x i8]* @print_escaped_string.escaped to i64)
%26 = getelementptr inbounds [6 x i8], [6 x i8]* @print_escaped_string.literals, i64 0, i64 %25
%27 = load i8, i8* %26
store i8 %27, i8* %6
%28 = load i32, i32* @stderr
%29 = call i32 @fputc(i8 signext 92, i32 %28)
%30 = load i8, i8* %6
%31 = load i32, i32* @stderr
%32 = call i32 @fputc(i8 signext %30, i32 %31)
br label %37
33: ; preds = %13
%34 = load i8, i8* %4
%35 = load i32, i32* @stderr
%36 = call i32 @fputc(i8 signext %34, i32 %35)
br label %37
37: ; preds = %33, %22
%38 = load i64, i64* %3
%39 = add i64 %38, 1
store i64 %39, i64* %3
br label %7
40: ; preds = %7
ret void
}

LLVM IR (-O2):
@print_escaped_string.escaped = internal constant [6 x i8] c"\0C\0A\0D\09\0B\00"
@print_escaped_string.literals = internal unnamed_addr constant [6 x i8] c"fnrtv\00"
@stderr = global i32 0
define void @print_escaped_string(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %24, label %4
4: ; preds = %1, %16
%5 = phi i8 [ %22, %16 ], [ %2, %1 ]
%6 = phi i64 [ %20, %16 ], [ 0, %1 ]
%7 = tail call i8* @strchr(i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @print_escaped_string.escaped, i64 0, i64 0), i8 signext %5)
%8 = icmp eq i8* %7, null
br i1 %8, label %16, label %9
9: ; preds = %4
%10 = ptrtoint i8* %7 to i64
%11 = sub i64 %10, ptrtoint ([6 x i8]* @print_escaped_string.escaped to i64)
%12 = getelementptr inbounds [6 x i8], [6 x i8]* @print_escaped_string.literals, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = load i32, i32* @stderr
%15 = tail call i32 @fputc(i8 signext 92, i32 %14)
br label %16
16: ; preds = %4, %9
%17 = phi i8 [ %13, %9 ], [ %5, %4 ]
%18 = load i32, i32* @stderr
%19 = tail call i32 @fputc(i8 signext %17, i32 %18)
%20 = add i64 %6, 1
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %4
24: ; preds = %16, %1
ret void
}