#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*/ memset(char *, int /*<<< orphan*/, int);
char *strchr(char const *, char);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncat(char *, char const *, scalar_t__);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *txt2html(const char *string) {
  static char buf[1024];
  char *ptr = NULL;
  char *nextptr = NULL;
  memset(buf, 0, 1024);
  ptr = strchr(string, '<');
  if (ptr != NULL) {
    nextptr = ptr + 1;
    *ptr = 0;
    strncpy(buf, string, 1023);
    strncat(buf, "&lt;", 1023 - strlen(buf));
    string = nextptr;
  }
  ptr = strchr(string, '>');
  if (ptr != NULL) {
    nextptr = ptr + 1;
    *ptr = 0;
    strncat(buf, string, 1023 - strlen(buf));
    strncat(buf, "&gt;", 1023 - strlen(buf));
    string = nextptr;
  }
  strncat(buf, string, 1023 - strlen(buf));
  return buf;
}


x86 assembly (clang, -O0):
<txt2html>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0x2eed(%rip),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    $0x3c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f3 <txt2html+0xa3>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rsi
lea    0x2ea6(%rip),%rdi
mov    $0x3ff,%edx
call   1030 <strncpy@plt>
lea    0x2e95(%rip),%rdi
call   1040 <strlen@plt>
mov    $0x3ff,%edx
sub    %rax,%rdx
lea    0x2e81(%rip),%rdi
lea    0xe1a(%rip),%rsi
call   1070 <strncat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     127e <txt2html+0x12e>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0x2e2e(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rsi
mov    $0x3ff,%edx
sub    %rax,%rdx
lea    0x2e16(%rip),%rdi
call   1070 <strncat@plt>
lea    0x2e0a(%rip),%rdi
call   1040 <strlen@plt>
mov    $0x3ff,%edx
sub    %rax,%rdx
lea    0x2df6(%rip),%rdi
lea    0xd94(%rip),%rsi
call   1070 <strncat@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0x2dd3(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rsi
mov    $0x3ff,%edx
sub    %rax,%rdx
lea    0x2dbb(%rip),%rdi
call   1070 <strncat@plt>
lea    0x2daf(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<txt2html>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x2efe(%rip),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
mov    $0x3c,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11c3 <txt2html+0x73>
mov    %rax,%r15
add    $0x1,%r15
movb   $0x0,(%rax)
lea    0x2ecf(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0x3ff,%edx
sub    %rax,%rdx
lea    0xe48(%rip),%rsi
mov    %r14,%rdi
call   1070 <strncat@plt>
mov    %r15,%rbx
mov    %rbx,%rdi
mov    $0x3e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1227 <txt2html+0xd7>
mov    %rax,%r12
add    $0x1,%r12
movb   $0x0,(%rax)
lea    0x2e7a(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0x3ff,%r15d
mov    $0x3ff,%edx
sub    %rax,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <strncat@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
sub    %rax,%r15
lea    0xdec(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
call   1070 <strncat@plt>
mov    %r12,%rbx
lea    0x2e32(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    $0x3ff,%edx
sub    %rax,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <strncat@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@txt2html.buf = internal global [1024 x i8] zeroinitializer
@.str = [5 x i8] c"&lt;\00"
@.str.1 = [5 x i8] c"&gt;\00"
define i8* @txt2html(i8* %0) {
%2 = tail call i32 @memset(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @txt2html.buf, i64 0, i64 0), i32 0, i32 1024)
%3 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 60)
%4 = icmp eq i8* %3, null
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %3, i64 1
store i8 0, i8* %3
%7 = tail call i32 @strncpy(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @txt2html.buf, i64 0, i64 0), i8* %0, i32 1023)
%8 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @txt2html.buf, i64 0, i64 0))
%9 = sub nsw i64 1023, %8
%10 = tail call i32 @strncat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @txt2html.buf, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %9)
br label %11
11: ; preds = %5, %1
%12 = phi i8* [ %6, %5 ], [ %0, %1 ]
%13 = tail call i8* @strchr(i8* dereferenceable(1) %12, i8 signext 62)
%14 = icmp eq i8* %13, null
br i1 %14, label %23, label %15
15: ; preds = %11
%16 = getelementptr inbounds i8, i8* %13, i64 1
store i8 0, i8* %13
%17 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @txt2html.buf, i64 0, i64 0))
%18 = sub nsw i64 1023, %17
%19 = tail call i32 @strncat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @txt2html.buf, i64 0, i64 0), i8* %12, i64 %18)
%20 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @txt2html.buf, i64 0, i64 0))
%21 = sub nsw i64 1023, %20
%22 = tail call i32 @strncat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @txt2html.buf, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 %21)
br label %23
23: ; preds = %15, %11
%24 = phi i8* [ %16, %15 ], [ %12, %11 ]
%25 = tail call i64 @strlen(i8* dereferenceable(1) getelementptr inbounds ([1024 x i8], [1024 x i8]* @txt2html.buf, i64 0, i64 0))
%26 = sub nsw i64 1023, %25
%27 = tail call i32 @strncat(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @txt2html.buf, i64 0, i64 0), i8* %24, i64 %26)
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @txt2html.buf, i64 0, i64 0)
}