#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*/ free(char *);
char *malloc(int);
size_t strcspn(char const *, char *);
int strlen(char const *);
const char *xml_escape_quote(const char *string) {
  static char *temp = NULL;
  char cc, *s;
  if (string == NULL)
    return string;
  if (string[strcspn(string, "\"\\<>")] == '\0')
    return string;
  if (temp)
    free(temp);
  s = temp = malloc(strlen(string) * 2 + 1);
  while ((cc = *string++) != '\0') {
    if (cc == '"' || cc == '<' || cc == '>')
      cc = '\'';
    else if (cc == '\\' || cc == '&')
      cc = '/';
    *s++ = cc;
  }
  *s++ = '\0';
  return temp;
}


x86 assembly (clang, -O0):
<xml_escape_quote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <xml_escape_quote+0x24>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1281 <xml_escape_quote+0x141>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1050 <strcspn@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    119d <xml_escape_quote+0x5d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1281 <xml_escape_quote+0x141>
cmpq   $0x0,0x2ea3(%rip)
je     11b7 <xml_escape_quote+0x77>
mov    0x2e96(%rip),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,0x2e74(%rip)
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     1264 <xml_escape_quote+0x124>
movsbl -0x11(%rbp),%eax
cmp    $0x22,%eax
je     121f <xml_escape_quote+0xdf>
movsbl -0x11(%rbp),%eax
cmp    $0x3c,%eax
je     121f <xml_escape_quote+0xdf>
movsbl -0x11(%rbp),%eax
cmp    $0x3e,%eax
jne    1228 <xml_escape_quote+0xe8>
movb   $0x27,-0x11(%rbp)
jmp    124b <xml_escape_quote+0x10b>
movsbl -0x11(%rbp),%eax
cmp    $0x5c,%eax
je     1242 <xml_escape_quote+0x102>
movsbl -0x11(%rbp),%eax
cmp    $0x26,%eax
jne    1246 <xml_escape_quote+0x106>
movb   $0x2f,-0x11(%rbp)
jmp    124b <xml_escape_quote+0x10b>
mov    -0x11(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11d8 <xml_escape_quote+0x98>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
mov    0x2dcb(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xml_escape_quote>:
push   %rbx
test   %rdi,%rdi
je     11df <xml_escape_quote+0x9f>
mov    %rdi,%rbx
lea    0xeac(%rip),%rsi
call   1050 <strcspn@plt>
cmpb   $0x0,(%rbx,%rax,1)
je     11e3 <xml_escape_quote+0xa3>
mov    0x2ede(%rip),%rdi
test   %rdi,%rdi
je     1174 <xml_escape_quote+0x34>
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    (%rax,%rax,1),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,0x2eba(%rip)
xor    %ecx,%ecx
mov    $0x2f,%edi
jmp    11b7 <xml_escape_quote+0x77>
nopw   0x0(%rax,%rax,1)
cmp    $0x26,%dl
movzbl %dl,%esi
cmove  %edi,%esi
cmp    $0x5c,%dl
cmove  %edi,%esi
mov    %sil,(%rax,%rcx,1)
add    $0x1,%rcx
movzbl (%rbx,%rcx,1),%edx
mov    $0x27,%sil
cmp    $0x3b,%dl
jle    11d0 <xml_escape_quote+0x90>
cmp    $0x3c,%dl
je     11af <xml_escape_quote+0x6f>
cmp    $0x3e,%dl
je     11af <xml_escape_quote+0x6f>
jmp    11a0 <xml_escape_quote+0x60>
nop
cmp    $0x22,%dl
je     11af <xml_escape_quote+0x6f>
test   %dl,%dl
jne    11a0 <xml_escape_quote+0x60>
movb   $0x0,(%rax,%rcx,1)
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@xml_escape_quote.temp = internal global i8* null
@.str = [5 x i8] c"\22\\<>\00"
define i8* @xml_escape_quote(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load i8*, i8** %3
store i8* %9, i8** %2
br label %69
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = load i8*, i8** %3
%13 = call i64 @strcspn(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = load i8*, i8** %3
store i8* %19, i8** %2
br label %69
20: ; preds = %10
%21 = load i8*, i8** @xml_escape_quote.temp
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i8*, i8** @xml_escape_quote.temp
%25 = call i32 @free(i8* %24)
br label %26
26: ; preds = %23, %20
%27 = load i8*, i8** %3
%28 = call i32 @strlen(i8* %27)
%29 = mul nsw i32 %28, 2
%30 = add nsw i32 %29, 1
%31 = call i8* @malloc(i32 %30)
store i8* %31, i8** @xml_escape_quote.temp
store i8* %31, i8** %5
br label %32
32: ; preds = %61, %26
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %3
%35 = load i8, i8* %33
store i8 %35, i8* %4
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %65
38: ; preds = %32
%39 = load i8, i8* %4
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 34
br i1 %41, label %50, label %42
42: ; preds = %38
%43 = load i8, i8* %4
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 60
br i1 %45, label %50, label %46
46: ; preds = %42
%47 = load i8, i8* %4
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 62
br i1 %49, label %50, label %51
50: ; preds = %46, %42, %38
store i8 39, i8* %4
br label %61
51: ; preds = %46
%52 = load i8, i8* %4
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 92
br i1 %54, label %59, label %55
55: ; preds = %51
%56 = load i8, i8* %4
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 38
br i1 %58, label %59, label %60
59: ; preds = %55, %51
store i8 47, i8* %4
br label %60
60: ; preds = %59, %55
br label %61
61: ; preds = %60, %50
%62 = load i8, i8* %4
%63 = load i8*, i8** %5
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %5
store i8 %62, i8* %63
br label %32
65: ; preds = %32
%66 = load i8*, i8** %5
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %5
store i8 0, i8* %66
%68 = load i8*, i8** @xml_escape_quote.temp
store i8* %68, i8** %2
br label %69
69: ; preds = %65, %18, %8
%70 = load i8*, i8** %2
ret i8* %70
}

LLVM IR (-O2):
@xml_escape_quote.temp = internal unnamed_addr global i8* null
@.str = [5 x i8] c"\22\\<>\00"
define i8* @xml_escape_quote(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %32, label %3
3: ; preds = %1
%4 = tail call i64 @strcspn(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %32, label %8
8: ; preds = %3
%9 = load i8*, i8** @xml_escape_quote.temp
%10 = icmp eq i8* %9, null
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @free(i8* %9)
br label %13
13: ; preds = %11, %8
%14 = tail call i32 @strlen(i8* %0)
%15 = shl nsw i32 %14, 1
%16 = or i32 %15, 1
%17 = tail call i8* @malloc(i32 %16)
store i8* %17, i8** @xml_escape_quote.temp
br label %18
18: ; preds = %28, %13
%19 = phi i8* [ %0, %13 ], [ %21, %28 ]
%20 = phi i8* [ %17, %13 ], [ %30, %28 ]
%21 = getelementptr inbounds i8, i8* %19, i64 1
%22 = load i8, i8* %19
switch i8 %22, label %23 [
i8 0, label %31
i8 62, label %28
i8 60, label %28
i8 34, label %28
]
23: ; preds = %18
%24 = icmp eq i8 %22, 92
%25 = icmp eq i8 %22, 38
%26 = or i1 %24, %25
%27 = select i1 %26, i8 47, i8 %22
br label %28
28: ; preds = %18, %18, %18, %23
%29 = phi i8 [ %27, %23 ], [ 39, %18 ], [ 39, %18 ], [ 39, %18 ]
%30 = getelementptr inbounds i8, i8* %20, i64 1
store i8 %29, i8* %20
br label %18
31: ; preds = %18
store i8 0, i8* %20
br label %32
32: ; preds = %3, %1, %31
%33 = phi i8* [ %17, %31 ], [ null, %1 ], [ %0, %3 ]
ret i8* %33
}