#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*/ strcpy(char *, char *);
char *scriptstr(const unsigned char *s) {
  static char buf[1024];
  int i = 0, db = 0;
  for (; *s && i < 1017; s++) {
    if (db == 1) {
      db = 0;
      if (*s < 32)
        buf[i - 1] = 32;
      buf[i] = *s;
      i++;
      continue;
    }
    if (*s == '\'') {
      strcpy(buf + i, "\\\'");
      i += 2;
    } else if (*s == '/') {
      strcpy(buf + i, "\\/");
      i += 2;
    } else if (*s == '\\') {
      strcpy(buf + i, "\\\\");
      i += 2;
    } else if (*s == '\r') {
      continue;
    } else if (*s == '\n') {
      strcpy(buf + i, "\\n");
      i += 2;
    } else {
      if (*s >= 128)
        db = 1;
      buf[i] = *s;
      i++;
    }
  }
  if (db)
    buf[i - 1] = 0;
  buf[i] = 0;
  return buf;
}


x86 assembly (clang, -O0):
<scriptstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     114c <scriptstr+0x3c>
cmpl   $0x3f9,-0xc(%rbp)
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    115c <scriptstr+0x4c>
jmp    1308 <scriptstr+0x1f8>
cmpl   $0x1,-0x10(%rbp)
jne    11b3 <scriptstr+0xa3>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jge    1191 <scriptstr+0x81>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2eb3(%rip),%rax
movb   $0x20,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    (%rax),%dl
movslq -0xc(%rbp),%rcx
lea    0x2e9e(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12f7 <scriptstr+0x1e7>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x27,%eax
jne    11eb <scriptstr+0xdb>
movslq -0xc(%rbp),%rax
lea    0x2e72(%rip),%rdi
add    %rax,%rdi
lea    0xe28(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    12f2 <scriptstr+0x1e2>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2f,%eax
jne    1223 <scriptstr+0x113>
movslq -0xc(%rbp),%rax
lea    0x2e3a(%rip),%rdi
add    %rax,%rdi
lea    0xdf3(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    12ed <scriptstr+0x1dd>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x5c,%eax
jne    125b <scriptstr+0x14b>
movslq -0xc(%rbp),%rax
lea    0x2e02(%rip),%rdi
add    %rax,%rdi
lea    0xdbe(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    12e8 <scriptstr+0x1d8>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xd,%eax
jne    1270 <scriptstr+0x160>
jmp    12f7 <scriptstr+0x1e7>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xa,%eax
jne    12a8 <scriptstr+0x198>
movslq -0xc(%rbp),%rax
lea    0x2db5(%rip),%rdi
add    %rax,%rdi
lea    0xd74(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
jmp    12de <scriptstr+0x1ce>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x80,%eax
jl     12c1 <scriptstr+0x1b1>
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%dl
movslq -0xc(%rbp),%rcx
lea    0x2d6e(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12e3 <scriptstr+0x1d3>
jmp    12e8 <scriptstr+0x1d8>
jmp    12ed <scriptstr+0x1dd>
jmp    12f2 <scriptstr+0x1e2>
jmp    12f7 <scriptstr+0x1e7>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112a <scriptstr+0x1a>
cmpl   $0x0,-0x10(%rbp)
je     1326 <scriptstr+0x216>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2d1e(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
movslq -0xc(%rbp),%rcx
lea    0x2d0f(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2d04(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scriptstr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1216 <scriptstr+0x106>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %r12d,%r12d
lea    0x2f0a(%rip),%r14
lea    0xec3(%rip),%r15
lea    0xf57(%rip),%r13
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
cmp    $0x1,%r12d
jne    1180 <scriptstr+0x70>
cmp    $0x1f,%al
ja     1167 <scriptstr+0x57>
movslq %ebp,%rax
movb   $0x20,-0x1(%rax,%r14,1)
movzbl -0x1(%rbx),%eax
movslq %ebp,%rcx
mov    %al,(%rcx,%r14,1)
add    $0x1,%ebp
xor    %r12d,%r12d
jmp    11ef <scriptstr+0xdf>
cs nopw 0x0(%rax,%rax,1)
xor    %r12d,%r12d
lea    -0xa(%rax),%ecx
cmp    $0x25,%cl
ja     11a7 <scriptstr+0x97>
movzbl %cl,%ecx
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
movslq %ebp,%rbp
lea    (%r14,%rbp,1),%rdi
lea    0xefc(%rip),%rsi
jmp    11e7 <scriptstr+0xd7>
cmp    $0x5c,%al
jne    11ba <scriptstr+0xaa>
movslq %ebp,%rdi
add    %r14,%rdi
lea    0xee6(%rip),%rsi
jmp    11e7 <scriptstr+0xd7>
mov    %eax,%ecx
shr    $0x7,%cl
movzbl %cl,%r12d
movslq %ebp,%rcx
mov    %al,(%rcx,%r14,1)
add    $0x1,%ebp
jmp    11ef <scriptstr+0xdf>
movslq %ebp,%rdi
add    %r14,%rdi
lea    0xebc(%rip),%rsi
jmp    11e7 <scriptstr+0xd7>
movslq %ebp,%rdi
add    %r14,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
add    $0x2,%ebp
movzbl (%rbx),%eax
test   %al,%al
je     1206 <scriptstr+0xf6>
add    $0x1,%rbx
cmp    $0x3f9,%ebp
jl     1150 <scriptstr+0x40>
test   %r12d,%r12d
je     1218 <scriptstr+0x108>
movslq %ebp,%rax
movb   $0x0,-0x1(%rax,%r14,1)
jmp    1218 <scriptstr+0x108>
xor    %ebp,%ebp
movslq %ebp,%rcx
lea    0x2e1e(%rip),%rax
movb   $0x0,(%rcx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@scriptstr.buf = internal global [1024 x i8] zeroinitializer
@.str = [3 x i8] c"\\'\00"
@.str.1 = [3 x i8] c"\\/\00"
@.str.2 = [3 x i8] c"\\\\\00"
@.str.3 = [3 x i8] c"\\n\00"
define i8* @scriptstr(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %63, label %4
4: ; preds = %1, %49
%5 = phi i8 [ %53, %49 ], [ %2, %1 ]
%6 = phi i32 [ %51, %49 ], [ 0, %1 ]
%7 = phi i32 [ %50, %49 ], [ 0, %1 ]
%8 = phi i8* [ %52, %49 ], [ %0, %1 ]
%9 = icmp eq i32 %6, 1
br i1 %9, label %10, label %22
10: ; preds = %4
%11 = icmp ult i8 %5, 32
br i1 %11, label %12, label %17
12: ; preds = %10
%13 = add nsw i32 %7, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* @scriptstr.buf, i64 0, i64 %14
store i8 32, i8* %15
%16 = load i8, i8* %8
br label %17
17: ; preds = %12, %10
%18 = phi i8 [ %16, %12 ], [ %5, %10 ]
%19 = sext i32 %7 to i64
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* @scriptstr.buf, i64 0, i64 %19
store i8 %18, i8* %20
%21 = add nsw i32 %7, 1
br label %49
22: ; preds = %4
switch i8 %5, label %43 [
i8 39, label %23
i8 47, label %28
i8 92, label %33
i8 13, label %49
i8 10, label %38
]
23: ; preds = %22
%24 = sext i32 %7 to i64
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* @scriptstr.buf, i64 0, i64 %24
%26 = tail call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%27 = add nsw i32 %7, 2
br label %49
28: ; preds = %22
%29 = sext i32 %7 to i64
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* @scriptstr.buf, i64 0, i64 %29
%31 = tail call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%32 = add nsw i32 %7, 2
br label %49
33: ; preds = %22
%34 = sext i32 %7 to i64
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* @scriptstr.buf, i64 0, i64 %34
%36 = tail call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%37 = add nsw i32 %7, 2
br label %49
38: ; preds = %22
%39 = sext i32 %7 to i64
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* @scriptstr.buf, i64 0, i64 %39
%41 = tail call i32 @strcpy(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%42 = add nsw i32 %7, 2
br label %49
43: ; preds = %22
%44 = lshr i8 %5, 7
%45 = zext i8 %44 to i32
%46 = sext i32 %7 to i64
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* @scriptstr.buf, i64 0, i64 %46
store i8 %5, i8* %47
%48 = add nsw i32 %7, 1
br label %49
49: ; preds = %22, %23, %33, %38, %43, %28, %17
%50 = phi i32 [ %21, %17 ], [ %27, %23 ], [ %32, %28 ], [ %37, %33 ], [ %42, %38 ], [ %48, %43 ], [ %7, %22 ]
%51 = phi i32 [ 0, %17 ], [ 0, %23 ], [ 0, %28 ], [ 0, %33 ], [ 0, %38 ], [ %45, %43 ], [ 0, %22 ]
%52 = getelementptr inbounds i8, i8* %8, i64 1
%53 = load i8, i8* %52
%54 = icmp ne i8 %53, 0
%55 = icmp slt i32 %50, 1017
%56 = select i1 %54, i1 %55, i1 false
br i1 %56, label %4, label %57
57: ; preds = %49
%58 = icmp eq i32 %51, 0
br i1 %58, label %63, label %59
59: ; preds = %57
%60 = add nsw i32 %50, -1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* @scriptstr.buf, i64 0, i64 %61
store i8 0, i8* %62
br label %63
63: ; preds = %1, %59, %57
%64 = phi i32 [ %50, %59 ], [ %50, %57 ], [ 0, %1 ]
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* @scriptstr.buf, i64 0, i64 %65
store i8 0, i8* %66
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @scriptstr.buf, i64 0, i64 0)
}