#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*/ bsDel(char *);
int /*<<< orphan*/ bsLCat(char **, char *);
char *bsNew(char *);
char *bsEscape(char *bs) {
  char *copy = bsNew(bs);
  char *res = bsNew("");
  char *c = copy;
  char *p = copy;
  while (*c != '\0') {
    if (*c == '<') {
      *c = '\0';
      bsLCat(&res, p);
      bsLCat(&res, "&lt;");
      p = c + 1;
    } else if (*c == '>') {
      *c = '\0';
      bsLCat(&res, p);
      bsLCat(&res, "&gt;");
      p = c + 1;
    }
    c++;
  }
  bsLCat(&res, p);
  bsDel(copy);
  return res;
}


x86 assembly (clang, -O0):
<bsEscape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <bsNew@plt>
mov    %rax,-0x10(%rbp)
lea    0xeb9(%rip),%rdi
call   1040 <bsNew@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1214 <bsEscape+0xe4>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3c,%eax
jne    11be <bsEscape+0x8e>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rsi
lea    -0x18(%rbp),%rdi
call   1030 <bsLCat@plt>
lea    -0x18(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1030 <bsLCat@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1203 <bsEscape+0xd3>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3e,%eax
jne    11fe <bsEscape+0xce>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rsi
lea    -0x18(%rbp),%rdi
call   1030 <bsLCat@plt>
lea    -0x18(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1030 <bsLCat@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1203 <bsEscape+0xd3>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1169 <bsEscape+0x39>
mov    -0x28(%rbp),%rsi
lea    -0x18(%rbp),%rdi
call   1030 <bsLCat@plt>
mov    -0x10(%rbp),%rdi
call   1050 <bsDel@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bsEscape>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
call   1040 <bsNew@plt>
mov    %rax,%r14
lea    0xebf(%rip),%rdi
call   1040 <bsNew@plt>
mov    %rax,(%rsp)
mov    %r14,%rbx
add    $0x1,%rbx
lea    0xe9f(%rip),%r13
mov    %rsp,%r15
lea    0xe9a(%rip),%rbp
mov    %r14,%rsi
jmp    1191 <bsEscape+0x61>
mov    %rbp,%r12
movb   $0x0,-0x1(%rbx)
mov    %r15,%rdi
call   1030 <bsLCat@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <bsLCat@plt>
mov    %rbx,%rsi
add    $0x1,%rbx
movzbl -0x1(%rbx),%eax
mov    %r13,%r12
cmp    $0x3c,%al
je     1173 <bsEscape+0x43>
cmp    $0x3e,%al
je     1170 <bsEscape+0x40>
test   %al,%al
jne    118d <bsEscape+0x5d>
mov    %rsp,%rdi
call   1030 <bsLCat@plt>
mov    %r14,%rdi
call   1050 <bsDel@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"&lt;\00"
@.str.2 = [5 x i8] c"&gt;\00"
define i8* @bsEscape(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i8* @bsNew(i8* %7)
store i8* %8, i8** %3
%9 = call i8* @bsNew(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %4
%10 = load i8*, i8** %3
store i8* %10, i8** %5
%11 = load i8*, i8** %3
store i8* %11, i8** %6
br label %12
12: ; preds = %42, %1
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %45
17: ; preds = %12
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 60
br i1 %21, label %22, label %29
22: ; preds = %17
%23 = load i8*, i8** %5
store i8 0, i8* %23
%24 = load i8*, i8** %6
%25 = call i32 @bsLCat(i8** %4, i8* %24)
%26 = call i32 @bsLCat(i8** %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8* %28, i8** %6
br label %42
29: ; preds = %17
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 62
br i1 %33, label %34, label %41
34: ; preds = %29
%35 = load i8*, i8** %5
store i8 0, i8* %35
%36 = load i8*, i8** %6
%37 = call i32 @bsLCat(i8** %4, i8* %36)
%38 = call i32 @bsLCat(i8** %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8* %40, i8** %6
br label %41
41: ; preds = %34, %29
br label %42
42: ; preds = %41, %22
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %5
br label %12
45: ; preds = %12
%46 = load i8*, i8** %6
%47 = call i32 @bsLCat(i8** %4, i8* %46)
%48 = load i8*, i8** %3
%49 = call i32 @bsDel(i8* %48)
%50 = load i8*, i8** %4
ret i8* %50
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"&lt;\00"
@.str.2 = [5 x i8] c"&gt;\00"
define i8* @bsEscape(i8* %0) {
%2 = alloca i8*
%3 = tail call i8* @bsNew(i8* %0)
%4 = bitcast i8** %2 to i8*
%5 = tail call i8* @bsNew(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %2
br label %6
6: ; preds = %16, %1
%7 = phi i8* [ %3, %1 ], [ %18, %16 ]
%8 = phi i8* [ %3, %1 ], [ %17, %16 ]
%9 = load i8, i8* %7
switch i8 %9, label %16 [
i8 0, label %19
i8 60, label %11
i8 62, label %10
]
10: ; preds = %6
br label %11
11: ; preds = %6, %10
%12 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %10 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %6 ]
store i8 0, i8* %7
%13 = call i32 @bsLCat(i8** %2, i8* %8)
%14 = call i32 @bsLCat(i8** %2, i8* %12)
%15 = getelementptr inbounds i8, i8* %7, i64 1
br label %16
16: ; preds = %11, %6
%17 = phi i8* [ %8, %6 ], [ %15, %11 ]
%18 = getelementptr inbounds i8, i8* %7, i64 1
br label %6
19: ; preds = %6
%20 = call i32 @bsLCat(i8** %2, i8* %8)
%21 = call i32 @bsDel(i8* %3)
%22 = load i8*, i8** %2
ret i8* %22
}