#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*/ strcat(char *, char *);
int /*<<< orphan*/ strncat(char *, char *, int);
void xml_quote_string(char *s, char *o) {
  char *c;
  c = s;
  do {
    if (*c == '<')
      strcat(o, "&lt;");
    else if (*c == '>')
      strcat(o, "&gt;");
    else if (*c == '&')
      strcat(o, "&amp;");
    else if (*c == '"')
      strcat(o, "&quot;");
    else if (*c == '\n')
      strcat(o, " ");
    else
      strncat(o, c, 1);
  } while (*(c++));
  return;
}


x86 assembly (clang, -O0):
<xml_quote_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3c,%eax
jne    115d <xml_quote_string+0x3d>
mov    -0x10(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1040 <strcat@plt>
jmp    1217 <xml_quote_string+0xf7>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3e,%eax
jne    1182 <xml_quote_string+0x62>
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1040 <strcat@plt>
jmp    1212 <xml_quote_string+0xf2>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
jne    11a7 <xml_quote_string+0x87>
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1040 <strcat@plt>
jmp    120d <xml_quote_string+0xed>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    11cc <xml_quote_string+0xac>
mov    -0x10(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1040 <strcat@plt>
jmp    1208 <xml_quote_string+0xe8>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11f1 <xml_quote_string+0xd1>
mov    -0x10(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1040 <strcat@plt>
jmp    1203 <xml_quote_string+0xe3>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <strncat@plt>
jmp    1208 <xml_quote_string+0xe8>
jmp    120d <xml_quote_string+0xed>
jmp    1212 <xml_quote_string+0xf2>
jmp    1217 <xml_quote_string+0xf7>
jmp    121c <xml_quote_string+0xfc>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
cmpb   $0x0,(%rax)
jne    1138 <xml_quote_string+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xml_quote_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xec8(%rip),%r12
lea    0xf3f(%rip),%r13
lea    0xf2e(%rip),%rbp
lea    0xf2c(%rip),%r15
jmp    1169 <xml_quote_string+0x49>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <strncat@plt>
nop
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
je     11dc <xml_quote_string+0xbc>
movzbl (%rbx),%eax
lea    -0x22(%rax),%ecx
cmp    $0x1c,%cl
ja     11a0 <xml_quote_string+0x80>
movzbl %cl,%eax
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    %r14,%rdi
lea    0xefa(%rip),%rsi
call   1040 <strcat@plt>
jmp    1160 <xml_quote_string+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%al
jne    114f <xml_quote_string+0x2f>
mov    %r14,%rdi
lea    0xedd(%rip),%rsi
call   1040 <strcat@plt>
jmp    1160 <xml_quote_string+0x40>
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <strcat@plt>
jmp    1160 <xml_quote_string+0x40>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1040 <strcat@plt>
jmp    1160 <xml_quote_string+0x40>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
jmp    1160 <xml_quote_string+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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