#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) {
  char *esc_tag = NULL;
  if (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);
  }
  return esc_tag;
}


x86 assembly (clang, -O0):
<escape_tag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x26,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    118c <escape_tag+0x5c>
mov    -0x8(%rbp),%rdi
mov    $0x3c,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    118c <escape_tag+0x5c>
mov    -0x8(%rbp),%rdi
mov    $0x3e,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     11f0 <escape_tag+0xc0>
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe5c(%rip),%rsi
lea    0xe57(%rip),%rdx
xor    %ecx,%ecx
call   1040 <modifyString@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4b(%rip),%rsi
lea    0xe46(%rip),%rdx
xor    %ecx,%ecx
call   1040 <modifyString@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe39(%rip),%rsi
lea    0xe34(%rip),%rdx
xor    %ecx,%ecx
call   1040 <modifyString@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_tag>:
push   %rbx
mov    %rdi,%rbx
mov    $0x26,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1167 <escape_tag+0x37>
mov    %rbx,%rdi
mov    $0x3c,%esi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1167 <escape_tag+0x37>
mov    %rbx,%rdi
mov    $0x3e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11b8 <escape_tag+0x88>
mov    %rbx,%rdi
call   1050 <strdup@plt>
lea    0xe8a(%rip),%rsi
lea    0xe85(%rip),%rdx
mov    %rax,%rdi
xor    %ecx,%ecx
call   1040 <modifyString@plt>
lea    0xe7e(%rip),%rsi
lea    0xe79(%rip),%rdx
mov    %rax,%rdi
xor    %ecx,%ecx
call   1040 <modifyString@plt>
lea    0xe71(%rip),%rsi
lea    0xe6c(%rip),%rdx
mov    %rax,%rdi
xor    %ecx,%ecx
pop    %rbx
jmp    1040 <modifyString@plt>
xor    %eax,%eax
pop    %rbx
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"
define i8* @escape_tag(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%4 = load i8*, i8** %2
%5 = call i64 @strchr(i8* %4, i8 signext 38)
%6 = icmp ne i64 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i64 @strchr(i8* %8, i8 signext 60)
%10 = icmp ne i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = load i8*, i8** %2
%13 = call i64 @strchr(i8* %12, i8 signext 62)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %11, %7, %1
%16 = load i8*, i8** %2
%17 = call i8* @strdup(i8* %16)
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = call i8* @modifyString(i8* %18, 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* %19, i8** %3
%20 = load i8*, i8** %3
%21 = call i8* @modifyString(i8* %20, 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* %21, i8** %3
%22 = load i8*, i8** %3
%23 = call i8* @modifyString(i8* %22, 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* %23, i8** %3
br label %24
24: ; preds = %15, %11
%25 = load i8*, i8** %3
ret i8* %25
}

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"
define i8* @escape_tag(i8* %0) {
%2 = tail call i64 @strchr(i8* %0, i8 signext 38)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = tail call i64 @strchr(i8* %0, i8 signext 60)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i64 @strchr(i8* %0, i8 signext 62)
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %7, %4, %1
%11 = tail call i8* @strdup(i8* %0)
%12 = tail call i8* @modifyString(i8* %11, 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)
%13 = tail call i8* @modifyString(i8* %12, 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)
%14 = tail call i8* @modifyString(i8* %13, 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)
br label %15
15: ; preds = %10, %7
%16 = phi i8* [ %14, %10 ], [ null, %7 ]
ret i8* %16
}