#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*/ ErrFatal(char *);
int shellescape(char *to, const char *from) {
  int i, j;
  i = j = 0;
  to[j++] = '"';
  while (from[i]) {
    switch (from[i]) {
    case '"':
    case '$':
    case '`':
    case '\\':
      to[j++] = '\\';
    default:
      to[j++] = from[i++];
    }
    if (j >= 1024)
      ErrFatal("max path exceeded");
  }
  to[j++] = '"';
  return j;
}


x86 assembly (clang, -O0):
<shellescape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
movb   $0x22,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1204 <shellescape+0xf4>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x22,%eax
je     11a6 <shellescape+0x96>
jmp    1173 <shellescape+0x63>
mov    -0x1c(%rbp),%eax
sub    $0x24,%eax
je     11a6 <shellescape+0x96>
jmp    1184 <shellescape+0x74>
mov    -0x1c(%rbp),%eax
sub    $0x5c,%eax
je     11a6 <shellescape+0x96>
jmp    1195 <shellescape+0x85>
mov    -0x1c(%rbp),%eax
sub    $0x60,%eax
jne    11bc <shellescape+0xac>
jmp    11a6 <shellescape+0x96>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
movb   $0x5c,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0x400,-0x18(%rbp)
jl     11ff <shellescape+0xef>
lea    0xe06(%rip),%rdi
call   1030 <ErrFatal@plt>
jmp    1144 <shellescape+0x34>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
movb   $0x22,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shellescape>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
movb   $0x22,(%rdi)
mov    (%rsi),%al
test   %al,%al
je     1197 <shellescape+0x87>
mov    %rsi,%rbx
add    $0x1,%rbx
mov    $0x1,%ebp
lea    0xec9(%rip),%r15
movabs $0x4400000000000005,%r12
jmp    115e <shellescape+0x4e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%ebp
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     119c <shellescape+0x8c>
movsbl %al,%ecx
add    $0xffffffde,%ecx
cmp    $0x3e,%ecx
ja     117e <shellescape+0x6e>
bt     %rcx,%r12
jae    117e <shellescape+0x6e>
movslq %ebp,%rax
add    $0x1,%ebp
movb   $0x5c,(%r14,%rax,1)
movzbl -0x1(%rbx),%eax
movslq %ebp,%rcx
mov    %al,(%r14,%rcx,1)
cmp    $0x3ff,%ebp
jl     1150 <shellescape+0x40>
mov    %r15,%rdi
call   1030 <ErrFatal@plt>
jmp    1150 <shellescape+0x40>
mov    $0x1,%ebp
movslq %ebp,%rax
add    $0x1,%ebp
movb   $0x22,(%r14,%rax,1)
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"max path exceeded\00"
define i32 @shellescape(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
store i32 0, i32* %5
%7 = load i8*, i8** %3
%8 = load i32, i32* %6
%9 = add nsw i32 %8, 1
store i32 %9, i32* %6
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
store i8 34, i8* %11
br label %12
12: ; preds = %49, %2
%13 = load i8*, i8** %4
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %50
19: ; preds = %12
%20 = load i8*, i8** %4
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
switch i32 %25, label %32 [
i32 34, label %26
i32 36, label %26
i32 96, label %26
i32 92, label %26
]
26: ; preds = %19, %19, %19, %19
%27 = load i8*, i8** %3
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8 92, i8* %31
br label %32
32: ; preds = %19, %26
%33 = load i8*, i8** %4
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
%38 = load i8, i8* %37
%39 = load i8*, i8** %3
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %39, i64 %42
store i8 %38, i8* %43
br label %44
44: ; preds = %32
%45 = load i32, i32* %6
%46 = icmp sge i32 %45, 1024
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 @ErrFatal(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %49
49: ; preds = %47, %44
br label %12
50: ; preds = %12
%51 = load i8*, i8** %3
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
store i8 34, i8* %55
%56 = load i32, i32* %6
ret i32 %56
}

LLVM IR (-O2):
@.str = [18 x i8] c"max path exceeded\00"
define i32 @shellescape(i8* nocapture writeonly %0, i8* nocapture %1) {
store i8 34, i8* %0
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %30, label %5
5: ; preds = %2, %26
%6 = phi i64 [ %19, %26 ], [ 0, %2 ]
%7 = phi i8 [ %28, %26 ], [ %3, %2 ]
%8 = phi i8* [ %27, %26 ], [ %1, %2 ]
%9 = phi i32 [ %20, %26 ], [ 1, %2 ]
%10 = sext i8 %7 to i32
switch i32 %10, label %16 [
i32 34, label %11
i32 36, label %11
i32 96, label %11
i32 92, label %11
]
11: ; preds = %5, %5, %5, %5
%12 = add nsw i32 %9, 1
%13 = sext i32 %9 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 92, i8* %14
%15 = load i8, i8* %8
br label %16
16: ; preds = %5, %11
%17 = phi i8 [ %7, %5 ], [ %15, %11 ]
%18 = phi i32 [ %9, %5 ], [ %12, %11 ]
%19 = add nuw i64 %6, 1
%20 = add nsw i32 %18, 1
%21 = sext i32 %18 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
store i8 %17, i8* %22
%23 = icmp sgt i32 %18, 1022
br i1 %23, label %24, label %26
24: ; preds = %16
%25 = tail call i32 @ErrFatal(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %16
%27 = getelementptr inbounds i8, i8* %1, i64 %19
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %5
30: ; preds = %26, %2
%31 = phi i32 [ 1, %2 ], [ %20, %26 ]
%32 = add nsw i32 %31, 1
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %0, i64 %33
store i8 34, i8* %34
ret i32 %32
}