#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 */
char *modifyString(char *, char *, char *, int /*<<< orphan*/);
scalar_t__ strchr(char const *, char);
char *strdup(char const *);
char *escape_tag(const char *tag, int force_alloc) {
  char *esc_tag = NULL;
  if (strchr(tag, '&') || strchr(tag, '<') || strchr(tag, '>') ||
      strchr(tag, '"')) {
    esc_tag = strdup(tag);
    esc_tag = modifyString(esc_tag, "&", "&amp;amp;", 0);
    esc_tag = modifyString(esc_tag, "<", "&amp;lt;", 0);
    esc_tag = modifyString(esc_tag, ">", "&amp;gt;", 0);
    esc_tag = modifyString(esc_tag, "\"", "&amp;quot;", 0);
  } else if (force_alloc)
    esc_tag = strdup(tag);
  return esc_tag;
}


x86 assembly (clang, -O0):
<escape_tag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x26,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    11a7 <escape_tag+0x77>
mov    -0x8(%rbp),%rdi
mov    $0x3c,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    11a7 <escape_tag+0x77>
mov    -0x8(%rbp),%rdi
mov    $0x3e,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    11a7 <escape_tag+0x77>
mov    -0x8(%rbp),%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     122d <escape_tag+0xfd>
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe41(%rip),%rsi
lea    0xe3c(%rip),%rdx
xor    %ecx,%ecx
call   1040 <modifyString@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe30(%rip),%rsi
lea    0xe2b(%rip),%rdx
xor    %ecx,%ecx
call   1040 <modifyString@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe1e(%rip),%rsi
lea    0xe19(%rip),%rdx
xor    %ecx,%ecx
call   1040 <modifyString@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe0c(%rip),%rsi
lea    0xe07(%rip),%rdx
xor    %ecx,%ecx
call   1040 <modifyString@plt>
mov    %rax,-0x18(%rbp)
jmp    1249 <escape_tag+0x119>
cmpl   $0x0,-0xc(%rbp)
je     1244 <escape_tag+0x114>
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    1249 <escape_tag+0x119>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_tag>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x26,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    117d <escape_tag+0x4d>
mov    %rbx,%rdi
mov    $0x3c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    117d <escape_tag+0x4d>
mov    %rbx,%rdi
mov    $0x3e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    117d <escape_tag+0x4d>
mov    %rbx,%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11eb <escape_tag+0xbb>
mov    %rbx,%rdi
call   1050 <strdup@plt>
lea    0xe74(%rip),%rsi
lea    0xe6f(%rip),%rdx
mov    %rax,%rdi
xor    %ecx,%ecx
call   1040 <modifyString@plt>
lea    0xe68(%rip),%rsi
lea    0xe63(%rip),%rdx
mov    %rax,%rdi
xor    %ecx,%ecx
call   1040 <modifyString@plt>
lea    0xe5b(%rip),%rsi
lea    0xe56(%rip),%rdx
mov    %rax,%rdi
xor    %ecx,%ecx
call   1040 <modifyString@plt>
lea    0xe4e(%rip),%rsi
lea    0xe49(%rip),%rdx
mov    %rax,%rdi
xor    %ecx,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <modifyString@plt>
test   %ebp,%ebp
je     11fd <escape_tag+0xcd>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <strdup@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"&\00"
@.str.1 = [10 x i8] c"&amp;amp;\00"
@.str.2 = [2 x i8] c"<\00"
@.str.3 = [9 x i8] c"&amp;lt;\00"
@.str.4 = [2 x i8] c">\00"
@.str.5 = [9 x i8] c"&amp;gt;\00"
@.str.6 = [2 x i8] c"\22\00"
@.str.7 = [11 x i8] c"&amp;quot;\00"
define i8* @escape_tag(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* null, i8** %5
%6 = load i8*, i8** %3
%7 = call i64 @strchr(i8* %6, i8 signext 38)
%8 = icmp ne i64 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = call i64 @strchr(i8* %10, i8 signext 60)
%12 = icmp ne i64 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = call i64 @strchr(i8* %14, i8 signext 62)
%16 = icmp ne i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = call i64 @strchr(i8* %18, i8 signext 34)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %17, %13, %9, %2
%22 = load i8*, i8** %3
%23 = call i8* @strdup(i8* %22)
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = call i8* @modifyString(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = call i8* @modifyString(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 0)
store i8* %27, i8** %5
%28 = load i8*, i8** %5
%29 = call i8* @modifyString(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 0)
store i8* %29, i8** %5
%30 = load i8*, i8** %5
%31 = call i8* @modifyString(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i32 0)
store i8* %31, i8** %5
br label %39
32: ; preds = %17
%33 = load i32, i32* %4
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i8*, i8** %3
%37 = call i8* @strdup(i8* %36)
store i8* %37, i8** %5
br label %38
38: ; preds = %35, %32
br label %39
39: ; preds = %38, %21
%40 = load i8*, i8** %5
ret i8* %40
}

LLVM IR (-O2):
@.str = [2 x i8] c"&\00"
@.str.1 = [10 x i8] c"&amp;amp;\00"
@.str.2 = [2 x i8] c"<\00"
@.str.3 = [9 x i8] c"&amp;lt;\00"
@.str.4 = [2 x i8] c">\00"
@.str.5 = [9 x i8] c"&amp;gt;\00"
@.str.6 = [2 x i8] c"\22\00"
@.str.7 = [11 x i8] c"&amp;quot;\00"
define i8* @escape_tag(i8* %0, i32 %1) {
%3 = tail call i64 @strchr(i8* %0, i8 signext 38)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = tail call i64 @strchr(i8* %0, i8 signext 60)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = tail call i64 @strchr(i8* %0, i8 signext 62)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i64 @strchr(i8* %0, i8 signext 34)
%13 = icmp eq i64 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %11, %8, %5, %2
%15 = tail call i8* @strdup(i8* %0)
%16 = tail call i8* @modifyString(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 0)
%17 = tail call i8* @modifyString(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 0)
%18 = tail call i8* @modifyString(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 0)
%19 = tail call i8* @modifyString(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i32 0)
br label %24
20: ; preds = %11
%21 = icmp eq i32 %1, 0
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = tail call i8* @strdup(i8* %0)
br label %24
24: ; preds = %20, %22, %14
%25 = phi i8* [ %19, %14 ], [ %23, %22 ], [ null, %20 ]
ret i8* %25
}