#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int strlen(char *);
int sanitize_print_string(char *string, FILE *fff) {
  int i;
  for (i = 0; i < strlen(string); i++) {
    switch (string[i]) {
    case '\n':
      fputc('\\', fff);
      fputc('n', fff);
      break;
    case '\t':
      fputc('\\', fff);
      fputc('t', fff);
      break;
    case '\\':
      fputc('\\', fff);
      fputc('\\', fff);
      break;
    case '%':
      fputc('\\', fff);
      fputc('%', fff);
      break;
    case '\r':
      fputc('\\', fff);
      fputc('r', fff);
      break;
    case '"':
      fputc('\\', fff);
      fputc('"', fff);
      break;
    case '\'':
      fputc('\\', fff);
      fputc('\'', fff);
      break;
    default:
      fputc(string[i], fff);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<sanitize_print_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    12e7 <sanitize_print_string+0x1c7>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x9,%eax
je     11f7 <sanitize_print_string+0xd7>
jmp    1170 <sanitize_print_string+0x50>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     11d6 <sanitize_print_string+0xb6>
jmp    1181 <sanitize_print_string+0x61>
mov    -0x1c(%rbp),%eax
sub    $0xd,%eax
je     125a <sanitize_print_string+0x13a>
jmp    1192 <sanitize_print_string+0x72>
mov    -0x1c(%rbp),%eax
sub    $0x22,%eax
je     127b <sanitize_print_string+0x15b>
jmp    11a3 <sanitize_print_string+0x83>
mov    -0x1c(%rbp),%eax
sub    $0x25,%eax
je     1239 <sanitize_print_string+0x119>
jmp    11b4 <sanitize_print_string+0x94>
mov    -0x1c(%rbp),%eax
sub    $0x27,%eax
je     129c <sanitize_print_string+0x17c>
jmp    11c5 <sanitize_print_string+0xa5>
mov    -0x1c(%rbp),%eax
sub    $0x5c,%eax
je     1218 <sanitize_print_string+0xf8>
jmp    12bd <sanitize_print_string+0x19d>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <fputc@plt>
mov    -0x10(%rbp),%rsi
mov    $0x6e,%edi
call   1040 <fputc@plt>
jmp    12d4 <sanitize_print_string+0x1b4>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <fputc@plt>
mov    -0x10(%rbp),%rsi
mov    $0x74,%edi
call   1040 <fputc@plt>
jmp    12d4 <sanitize_print_string+0x1b4>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <fputc@plt>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <fputc@plt>
jmp    12d4 <sanitize_print_string+0x1b4>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <fputc@plt>
mov    -0x10(%rbp),%rsi
mov    $0x25,%edi
call   1040 <fputc@plt>
jmp    12d4 <sanitize_print_string+0x1b4>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <fputc@plt>
mov    -0x10(%rbp),%rsi
mov    $0x72,%edi
call   1040 <fputc@plt>
jmp    12d4 <sanitize_print_string+0x1b4>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <fputc@plt>
mov    -0x10(%rbp),%rsi
mov    $0x22,%edi
call   1040 <fputc@plt>
jmp    12d4 <sanitize_print_string+0x1b4>
mov    -0x10(%rbp),%rsi
mov    $0x5c,%edi
call   1040 <fputc@plt>
mov    -0x10(%rbp),%rsi
mov    $0x27,%edi
call   1040 <fputc@plt>
jmp    12d4 <sanitize_print_string+0x1b4>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    12d9 <sanitize_print_string+0x1b9>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <sanitize_print_string+0x17>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanitize_print_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
jle    11b7 <sanitize_print_string+0x97>
xor    %ebx,%ebx
lea    0xebc(%rip),%r12
jmp    117d <sanitize_print_string+0x5d>
mov    $0x27,%bpl
nopl   0x0(%rax)
mov    $0x5c,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
mov    %ebp,%eax
movsbl %al,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11b7 <sanitize_print_string+0x97>
movzbl (%r15,%rbx,1),%eax
movsbl %al,%edx
lea    -0x9(%rdx),%ecx
cmp    $0x1e,%ecx
ja     119e <sanitize_print_string+0x7e>
mov    $0x6e,%bpl
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
mov    $0x74,%bpl
jmp    1150 <sanitize_print_string+0x30>
cmp    $0x5c,%edx
jne    115f <sanitize_print_string+0x3f>
mov    $0x5c,%bpl
jmp    1150 <sanitize_print_string+0x30>
mov    $0x72,%bpl
jmp    1150 <sanitize_print_string+0x30>
mov    $0x22,%bpl
jmp    1150 <sanitize_print_string+0x30>
mov    $0x25,%bpl
jmp    1150 <sanitize_print_string+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sanitize_print_string(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
store i32 0, i32* %5
br label %6
6: ; preds = %62, %2
%7 = load i32, i32* %5
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %65
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
switch i32 %17, label %53 [
i32 10, label %18
i32 9, label %23
i32 92, label %28
i32 37, label %33
i32 13, label %38
i32 34, label %43
i32 39, label %48
]
18: ; preds = %11
%19 = load i32*, i32** %4
%20 = call i32 @fputc(i8 signext 92, i32* %19)
%21 = load i32*, i32** %4
%22 = call i32 @fputc(i8 signext 110, i32* %21)
br label %61
23: ; preds = %11
%24 = load i32*, i32** %4
%25 = call i32 @fputc(i8 signext 92, i32* %24)
%26 = load i32*, i32** %4
%27 = call i32 @fputc(i8 signext 116, i32* %26)
br label %61
28: ; preds = %11
%29 = load i32*, i32** %4
%30 = call i32 @fputc(i8 signext 92, i32* %29)
%31 = load i32*, i32** %4
%32 = call i32 @fputc(i8 signext 92, i32* %31)
br label %61
33: ; preds = %11
%34 = load i32*, i32** %4
%35 = call i32 @fputc(i8 signext 92, i32* %34)
%36 = load i32*, i32** %4
%37 = call i32 @fputc(i8 signext 37, i32* %36)
br label %61
38: ; preds = %11
%39 = load i32*, i32** %4
%40 = call i32 @fputc(i8 signext 92, i32* %39)
%41 = load i32*, i32** %4
%42 = call i32 @fputc(i8 signext 114, i32* %41)
br label %61
43: ; preds = %11
%44 = load i32*, i32** %4
%45 = call i32 @fputc(i8 signext 92, i32* %44)
%46 = load i32*, i32** %4
%47 = call i32 @fputc(i8 signext 34, i32* %46)
br label %61
48: ; preds = %11
%49 = load i32*, i32** %4
%50 = call i32 @fputc(i8 signext 92, i32* %49)
%51 = load i32*, i32** %4
%52 = call i32 @fputc(i8 signext 39, i32* %51)
br label %61
53: ; preds = %11
%54 = load i8*, i8** %3
%55 = load i32, i32* %5
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = load i32*, i32** %4
%60 = call i32 @fputc(i8 signext %58, i32* %59)
br label %61
61: ; preds = %53, %48, %43, %38, %33, %28, %23, %18
br label %62
62: ; preds = %61
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
br label %6
65: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
define i32 @sanitize_print_string(i8* %0, i32* nocapture %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %26
5: ; preds = %2, %19
%6 = phi i64 [ %22, %19 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
switch i32 %9, label %19 [
i32 10, label %16
i32 9, label %10
i32 92, label %11
i32 37, label %12
i32 13, label %13
i32 34, label %14
i32 39, label %15
]
10: ; preds = %5
br label %16
11: ; preds = %5
br label %16
12: ; preds = %5
br label %16
13: ; preds = %5
br label %16
14: ; preds = %5
br label %16
15: ; preds = %5
br label %16
16: ; preds = %5, %15, %14, %13, %12, %11, %10
%17 = phi i8 [ 39, %15 ], [ 34, %14 ], [ 114, %13 ], [ 37, %12 ], [ 92, %11 ], [ 116, %10 ], [ 110, %5 ]
%18 = tail call i32 @fputc(i8 signext 92, i32* %1)
br label %19
19: ; preds = %16, %5
%20 = phi i8 [ %8, %5 ], [ %17, %16 ]
%21 = tail call i32 @fputc(i8 signext %20, i32* %1)
%22 = add nuw nsw i64 %6, 1
%23 = tail call i32 @strlen(i8* %0)
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %5, label %26
26: ; preds = %19, %2
ret i32 0
}